Asteroids for MBED game with Bluetooth LE UART Friend Controller, uLCD, speaker, and uSD.
Dependencies: 4DGL-uLCD-SE mbed-rtos mbed
Asteroids for MBED game with Bluetooth LE UART Friend Controller
Diff: main.cpp
- Revision:
- 0:16094a49131e
- Child:
- 1:0328ad927150
diff -r 000000000000 -r 16094a49131e main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Mar 11 17:43:25 2016 +0000 @@ -0,0 +1,59 @@ +#include "mbed.h" +#include "rtos.h" +#include "uLCD_4DGL.h" + +DigitalOut myled(LED1); +uLCD_4DGL uLCD(p28,p27,p29); + +class Movement +{ + public: + double x_pos; // x position of object + double y_pos; // + double x_vel; // x velocity of object + double y_vel; // + double angle; // angle of object + double hit_rad // hit box radius of object + + Movement(double xp,yp,xv,yv,a,r){ + x_pos = xp; + y_pos = yp; + x_vel = xv; + y_vel = yv; + angle = a; + hit_rad = r; + } + + void move(){ + p.x_pos = (p.x_pos + p.x_vel)%144; + p.y_pos = (p.x_pos + p.y_vel)%144; + + } + + void accelerate(){ + p.x_vel += cos(angle); + p.y_vel += sin(angle); + if(sqrt(p.x_vel^2 + p.y_vel^2) > 10) + x_vel = p.x_vel * 10 / sqrt(x_vel^2 + y_vel^2); + y_vel = p.y_vel * 10 / sqrt(x_vel^2 + y_vel^2); + + bool collision(&Movent p2){ + rad = hit_rad + p2.hitrad; + dist = sqrt((x_pos - p2.x_pos)^2 + (y_pos - p2.y_pos); + return dist < rad; + } +}; + +int main() { + Movement player(50, 100, 0, -5, 0, 5); + Movement asteroid(50, 100, 0, -5, 0, 5); + while(1) { + player.move(); + asteroid.move(); + if(player.collision(asteroid)){ + + } + + + } +}