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
PongEngine/PongEngine.h@5:3c9407e2fe55, 2018-02-16 (annotated)
- Committer:
- eencae
- Date:
- Fri Feb 16 13:37:49 2018 +0000
- Revision:
- 5:3c9407e2fe55
Converted to folders.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| eencae | 5:3c9407e2fe55 | 1 | #ifndef PONGENGINE_H |
| eencae | 5:3c9407e2fe55 | 2 | #define PONGENGINE_H |
| eencae | 5:3c9407e2fe55 | 3 | |
| eencae | 5:3c9407e2fe55 | 4 | #include "mbed.h" |
| eencae | 5:3c9407e2fe55 | 5 | #include "N5110.h" |
| eencae | 5:3c9407e2fe55 | 6 | #include "Gamepad.h" |
| eencae | 5:3c9407e2fe55 | 7 | #include "Ball.h" |
| eencae | 5:3c9407e2fe55 | 8 | #include "Paddle.h" |
| eencae | 5:3c9407e2fe55 | 9 | |
| eencae | 5:3c9407e2fe55 | 10 | // gap from edge of screen |
| eencae | 5:3c9407e2fe55 | 11 | #define GAP 2 |
| eencae | 5:3c9407e2fe55 | 12 | |
| eencae | 5:3c9407e2fe55 | 13 | class PongEngine |
| eencae | 5:3c9407e2fe55 | 14 | { |
| eencae | 5:3c9407e2fe55 | 15 | |
| eencae | 5:3c9407e2fe55 | 16 | public: |
| eencae | 5:3c9407e2fe55 | 17 | PongEngine(); |
| eencae | 5:3c9407e2fe55 | 18 | ~PongEngine(); |
| eencae | 5:3c9407e2fe55 | 19 | |
| eencae | 5:3c9407e2fe55 | 20 | void init(int paddle_width,int paddle_height,int ball_size,int speed); |
| eencae | 5:3c9407e2fe55 | 21 | void read_input(Gamepad &pad); |
| eencae | 5:3c9407e2fe55 | 22 | void update(Gamepad &pad); |
| eencae | 5:3c9407e2fe55 | 23 | void draw(N5110 &lcd); |
| eencae | 5:3c9407e2fe55 | 24 | |
| eencae | 5:3c9407e2fe55 | 25 | private: |
| eencae | 5:3c9407e2fe55 | 26 | |
| eencae | 5:3c9407e2fe55 | 27 | void check_wall_collision(Gamepad &pad); |
| eencae | 5:3c9407e2fe55 | 28 | void check_paddle_collisions(Gamepad &pad); |
| eencae | 5:3c9407e2fe55 | 29 | void check_goal(Gamepad &pad); |
| eencae | 5:3c9407e2fe55 | 30 | void print_scores(N5110 &lcd); |
| eencae | 5:3c9407e2fe55 | 31 | |
| eencae | 5:3c9407e2fe55 | 32 | Paddle _p1; |
| eencae | 5:3c9407e2fe55 | 33 | Paddle _p2; |
| eencae | 5:3c9407e2fe55 | 34 | |
| eencae | 5:3c9407e2fe55 | 35 | int _paddle_width; |
| eencae | 5:3c9407e2fe55 | 36 | int _paddle_height; |
| eencae | 5:3c9407e2fe55 | 37 | int _ball_size; |
| eencae | 5:3c9407e2fe55 | 38 | int _speed; |
| eencae | 5:3c9407e2fe55 | 39 | |
| eencae | 5:3c9407e2fe55 | 40 | // x positions of the paddles |
| eencae | 5:3c9407e2fe55 | 41 | int _p1x; |
| eencae | 5:3c9407e2fe55 | 42 | int _p2x; |
| eencae | 5:3c9407e2fe55 | 43 | |
| eencae | 5:3c9407e2fe55 | 44 | Ball _ball; |
| eencae | 5:3c9407e2fe55 | 45 | |
| eencae | 5:3c9407e2fe55 | 46 | Direction _d; |
| eencae | 5:3c9407e2fe55 | 47 | float _mag; |
| eencae | 5:3c9407e2fe55 | 48 | |
| eencae | 5:3c9407e2fe55 | 49 | }; |
| eencae | 5:3c9407e2fe55 | 50 | |
| eencae | 5:3c9407e2fe55 | 51 | #endif |