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
main.cpp
- Committer:
- agamemaker
- Date:
- 2016-03-12
- Revision:
- 1:0328ad927150
- Parent:
- 0:16094a49131e
- Child:
- 2:332ca4f1a3e3
File content as of revision 1:0328ad927150:
#include "mbed.h" #include "rtos.h" #include "uLCD_4DGL.h" #include <math.h> #include <list> using namespace std; 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 int hit_rad; // hit box radius of object bool wrap; Movement(double xp,double yp,double xv,double yv,double a,double r,double w); void move(); void accelerate(); }; Movement::Movement(double xp,double yp,double xv,double yv,double a,double r,double w) { x_pos = xp; y_pos = yp; x_vel = xv; y_vel = yv; angle = a; hit_rad = r; wrap = w; } void Movement::move() { x_pos += x_vel; y_pos += y_vel; } void Movement::accelerate() { x_vel += cos(angle); y_vel += sin(angle); if(sqrt(pow(x_vel,2) + pow(y_vel,2)) > 10){ x_vel = x_vel * 10 / sqrt(pow(x_vel,2) + pow(y_vel,2)); y_vel = y_vel * 10 / sqrt(pow(x_vel,2) + pow(y_vel,2)); } } bool collision(Movement p1, Movement p2) { int rad = p1.hit_rad + p2.hit_rad; double dist = sqrt(pow((p1.x_pos - p2.x_pos),2) + pow((p1.y_pos - p2.y_pos),2)); return dist < rad; } void calc_collisions(){ } void draw_objs(Movement player, list<Movement> asteroids, list<Movement> bullets){ } int main() { Movement player(50, 100, 0, -5, 0, 5, 1); list<Movement> asteroids(); list<Movement> bullets(); while(1) { player.move(); calc_collisions(); //draw_objs(player, asteroids, bullets); } }