Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed Gamepad2 ELEC2645_Project_el18rg
Dependents: ELEC2645_Project_el18rg
Revision 3:2f4a7787beb3, committed 2020-05-27
- Comitter:
- el18rg
- Date:
- Wed May 27 16:50:00 2020 +0000
- Parent:
- 2:b936aa854de2
- Child:
- 4:5cc1b81999a9
- Commit message:
- Basic collision working
Changed in this revision
--- a/Collision/Collision.cpp Wed May 27 01:35:20 2020 +0000
+++ b/Collision/Collision.cpp Wed May 27 16:50:00 2020 +0000
@@ -4,21 +4,3 @@
}
Collision::~Collision() { // Destructor
}
-
-//Checks if any pixels below the width of the arrow are activated
-bool Collision::bottom(N5110 &lcd, int x,int y)
-{
- if (lcd.getPixel(x+1, y+10)==1) {
- return true;
- }
- else if (lcd.getPixel(x+2, y+10)==1) {
- return true;
- }
- else if (lcd.getPixel(x+3, y+10)==1) {
- return true;
- }
- else {
- return false;
- }
-}
-
\ No newline at end of file
--- a/Collision/Collision.h Wed May 27 01:35:20 2020 +0000
+++ b/Collision/Collision.h Wed May 27 16:50:00 2020 +0000
@@ -4,6 +4,9 @@
#include "mbed.h"
#include "N5110.h"
#include "Gamepad.h"
+#include "Ball.h"
+#include "Engine.h"
+#include "Cups.h"
class Collision {
@@ -15,10 +18,22 @@
/** Destructor */
~Collision();
- /** Checks if the pixel below the arrow has hit another activated pixel
- * @return Return true if a activatd pixel is detected, false if not
- */
- bool bottom(N5110 &lcd, int x, int y);
+ void check_wall_collision(Gamepad &pad);
+ void check_paddle_collisions(Gamepad &pad);
+
+private:
+ void check_goal(Gamepad &pad);
+ void print_scores(N5110 &lcd);
+ int height;
+ int width;
+ int x;
+ int _speed;
+ Direction _d;
+ float _mag;
+ Ball _ball;
+ Cups _cup;
+ int _px;
+ Cups _p1;
};
--- a/Engine/Engine.cpp Wed May 27 01:35:20 2020 +0000
+++ b/Engine/Engine.cpp Wed May 27 16:50:00 2020 +0000
@@ -66,18 +66,30 @@
void Engine::check_paddle_collisions(Gamepad &pad)
{
Vector2D ball_pos = _ball.get_pos();
- Vector2D ball_velocity = _ball.get_velocity();
-
- // check p1 first
- Vector2D p1_pos = _p1.get_pos();
+ Vector2D p_pos = _cup.get_pos();
- if(ball_pos.x = p1_pos.x) {
- for (int i = 0; i < 5; i++) {
- pad.leds_on();
- wait_ms(200);
- pad.leds_off();
- wait_ms(200);
+ if (ball_pos.x == p_pos.x )
+ {
+ collisionX=true;
+ }
+ else
+ {
+ collisionX=false;
+ }
+
+ if (ball_pos.y +10 == p_pos.y )
+ {
+ collisionY=true;
+ }
+ else
+ {
+ collisionY=false;
}
- }
+ if (collisionX && collisionY)
+ {
+ pad.leds_on();
+ wait_ms(100);
+ pad.leds_off();
+ }
}
--- a/Engine/Engine.h Wed May 27 01:35:20 2020 +0000
+++ b/Engine/Engine.h Wed May 27 16:50:00 2020 +0000
@@ -21,7 +21,7 @@
void read_input(Gamepad &pad);
void update(Gamepad &pad);
void draw(N5110 &lcd);
- void check_wall_collision(Gamepad &pad);
+ void check_wall_collision(Gamepad &pad);
void check_paddle_collisions(Gamepad &pad);
//void check_goal(Gamepad &pad);
private:
@@ -34,8 +34,8 @@
Direction _d;
float _mag;
Ball _ball;
+ bool collisionX;
+ bool collisionY;
Cups _cup;
- int _px;
- Cups _p1;
};
#endif