16
Dependencies: Ball Ball1 Gamepad N5110 Paddle1 PongEngine cab lab mbed
Fork of Pong by
main.cpp
- Committer:
- eencae
- Date:
- 2017-03-01
- Revision:
- 1:25a839625a1e
- Parent:
- 0:e1442f3aa3c7
- Child:
- 3:910d7e87f367
File content as of revision 1:25a839625a1e:
///////// pre-processor directives //////// #include "mbed.h" #include "Gamepad.h" #include "N5110.h" #include "PongEngine.h" #define PADDLE_WIDTH 2 #define PADDLE_HEIGHT 10 #define BALL_RADIUS 2 #define BALL_SPEED 3 /////////////// structs ///////////////// struct UserInput { Direction d; float mag; }; /////////////// objects /////////////// N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); Gamepad pad; PongEngine pong; ///////////// prototypes /////////////// void init(); void update_game(UserInput input); void render(); ///////////// functions //////////////// int main() { int fps = 8; init(); render(); // draw initial frame wait(1.0f/fps); while (1) { pong.read_input(pad); pong.update(pad); render(); wait(1.0f/fps); } } void init() { lcd.init(); pad.init(); float rand1 = pad.read_pot(); Vector2D rand2 = pad.get_coord(); int seed = int(1.0e6f*(rand1 + (rand2.x/rand2.y))); // create some random number from ADC pins to use in srand pong.init(PADDLE_WIDTH,PADDLE_HEIGHT,BALL_RADIUS,BALL_SPEED,seed); } void render() { lcd.clear(); // clear screen, re-draw and refresh pong.draw(lcd); lcd.refresh(); }