![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
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:
- 3:14a2729625f6
- Parent:
- 2:332ca4f1a3e3
- Child:
- 4:563648944ecc
File content as of revision 3:14a2729625f6:
#include "mbed.h" #include "rtos.h" #include "uLCD_4DGL.h" #include <math.h> #include <list> using namespace std; //constants #define ACCEL .5 #define ROTTA .2 //devices 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(); void turn_left(); void turn_right(); }; 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; if(x_pos < 0 || x_pos > 144 && x_pos < 0 || x_pos > 144) { if(wrap) { x_pos += 144*(1 - ceil(x_pos/144)); y_pos += 144*(1 - ceil(y_pos/144)); } else { } } } void Movement::accelerate() { x_vel += ACCEL * cos(angle); y_vel += ACCEL * 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)); } } void Movement::turn_left(){ angle -= ROTTA; } void Movement::turn_right(){ angle += ROTTA; } //collisions 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(Movement player, list<Movement> asteroids, list<Movement> bullets) { } //drawing 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); } }