James Heavey
/
EL17JH
FINAL VERSION
BreakoutEngine/BreakoutEngine.h@27:1b5038b0a7a2, 2019-04-24 (annotated)
- Committer:
- jamesheavey
- Date:
- Wed Apr 24 05:04:01 2019 +0000
- Revision:
- 27:1b5038b0a7a2
- Child:
- 29:5168318d3e88
Renamed some folders and classes, still need to clean up code, change comments etc.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jamesheavey | 27:1b5038b0a7a2 | 1 | #ifndef BREAKOUTENGINE_H |
jamesheavey | 27:1b5038b0a7a2 | 2 | #define BREAKOUTENGINE_H |
jamesheavey | 27:1b5038b0a7a2 | 3 | |
jamesheavey | 27:1b5038b0a7a2 | 4 | #include "mbed.h" |
jamesheavey | 27:1b5038b0a7a2 | 5 | #include "N5110.h" |
jamesheavey | 27:1b5038b0a7a2 | 6 | #include "Gamepad.h" |
jamesheavey | 27:1b5038b0a7a2 | 7 | #include "Ball.h" |
jamesheavey | 27:1b5038b0a7a2 | 8 | #include "Paddle.h" |
jamesheavey | 27:1b5038b0a7a2 | 9 | #include "Brick.h" |
jamesheavey | 27:1b5038b0a7a2 | 10 | |
jamesheavey | 27:1b5038b0a7a2 | 11 | #include <cmath> |
jamesheavey | 27:1b5038b0a7a2 | 12 | #include <list> |
jamesheavey | 27:1b5038b0a7a2 | 13 | #include <iostream> |
jamesheavey | 27:1b5038b0a7a2 | 14 | #include <string> |
jamesheavey | 27:1b5038b0a7a2 | 15 | #include <iterator> |
jamesheavey | 27:1b5038b0a7a2 | 16 | #include <algorithm> |
jamesheavey | 27:1b5038b0a7a2 | 17 | |
jamesheavey | 27:1b5038b0a7a2 | 18 | // gap from edge of screen |
jamesheavey | 27:1b5038b0a7a2 | 19 | #define GAP 2 |
jamesheavey | 27:1b5038b0a7a2 | 20 | #define BRICK_WIDTH 12 |
jamesheavey | 27:1b5038b0a7a2 | 21 | #define BRICK_HEIGHT 4 |
jamesheavey | 27:1b5038b0a7a2 | 22 | #define PADDLE_WIDTH 15 |
jamesheavey | 27:1b5038b0a7a2 | 23 | |
jamesheavey | 27:1b5038b0a7a2 | 24 | class BreakoutEngine |
jamesheavey | 27:1b5038b0a7a2 | 25 | { |
jamesheavey | 27:1b5038b0a7a2 | 26 | |
jamesheavey | 27:1b5038b0a7a2 | 27 | public: |
jamesheavey | 27:1b5038b0a7a2 | 28 | BreakoutEngine(); |
jamesheavey | 27:1b5038b0a7a2 | 29 | ~BreakoutEngine(); |
jamesheavey | 27:1b5038b0a7a2 | 30 | |
jamesheavey | 27:1b5038b0a7a2 | 31 | void init(int paddle_width,int paddle_height,int ball_size,int speed); |
jamesheavey | 27:1b5038b0a7a2 | 32 | void read_input(Gamepad &pad, bool x); |
jamesheavey | 27:1b5038b0a7a2 | 33 | void update(Gamepad &pad); |
jamesheavey | 27:1b5038b0a7a2 | 34 | void draw(N5110 &lcd); |
jamesheavey | 27:1b5038b0a7a2 | 35 | void lives_leds(Gamepad &pad); |
jamesheavey | 27:1b5038b0a7a2 | 36 | void flash_backlight(N5110 &lcd); |
jamesheavey | 27:1b5038b0a7a2 | 37 | int get_lives(); |
jamesheavey | 27:1b5038b0a7a2 | 38 | int get_num_left(); |
jamesheavey | 27:1b5038b0a7a2 | 39 | bool check_goal(Gamepad &pad); |
jamesheavey | 27:1b5038b0a7a2 | 40 | |
jamesheavey | 27:1b5038b0a7a2 | 41 | private: |
jamesheavey | 27:1b5038b0a7a2 | 42 | |
jamesheavey | 27:1b5038b0a7a2 | 43 | void check_wall_collision(Gamepad &pad); |
jamesheavey | 27:1b5038b0a7a2 | 44 | void check_paddle_collisions(Gamepad &pad); |
jamesheavey | 27:1b5038b0a7a2 | 45 | void check_brick_collisions(Gamepad &pad); |
jamesheavey | 27:1b5038b0a7a2 | 46 | void print_scores(N5110 &lcd); |
jamesheavey | 27:1b5038b0a7a2 | 47 | void one_less(); |
jamesheavey | 27:1b5038b0a7a2 | 48 | |
jamesheavey | 27:1b5038b0a7a2 | 49 | Paddle _p1; |
jamesheavey | 27:1b5038b0a7a2 | 50 | |
jamesheavey | 27:1b5038b0a7a2 | 51 | int _paddle_width; |
jamesheavey | 27:1b5038b0a7a2 | 52 | int _paddle_height; |
jamesheavey | 27:1b5038b0a7a2 | 53 | int _ball_size; |
jamesheavey | 27:1b5038b0a7a2 | 54 | int _speed; |
jamesheavey | 27:1b5038b0a7a2 | 55 | |
jamesheavey | 27:1b5038b0a7a2 | 56 | // y positions of the paddle |
jamesheavey | 27:1b5038b0a7a2 | 57 | int _p1y; |
jamesheavey | 27:1b5038b0a7a2 | 58 | int _number_left; |
jamesheavey | 27:1b5038b0a7a2 | 59 | |
jamesheavey | 27:1b5038b0a7a2 | 60 | Ball _ball; |
jamesheavey | 27:1b5038b0a7a2 | 61 | |
jamesheavey | 27:1b5038b0a7a2 | 62 | Direction _d; |
jamesheavey | 27:1b5038b0a7a2 | 63 | float _mag; |
jamesheavey | 27:1b5038b0a7a2 | 64 | |
jamesheavey | 27:1b5038b0a7a2 | 65 | |
jamesheavey | 27:1b5038b0a7a2 | 66 | std::list<Brick> listofBricks; |
jamesheavey | 27:1b5038b0a7a2 | 67 | std::list<Brick>::iterator it; |
jamesheavey | 27:1b5038b0a7a2 | 68 | |
jamesheavey | 27:1b5038b0a7a2 | 69 | Brick _brick11; |
jamesheavey | 27:1b5038b0a7a2 | 70 | Brick _brick12; |
jamesheavey | 27:1b5038b0a7a2 | 71 | Brick _brick13; |
jamesheavey | 27:1b5038b0a7a2 | 72 | Brick _brick14; |
jamesheavey | 27:1b5038b0a7a2 | 73 | Brick _brick15; |
jamesheavey | 27:1b5038b0a7a2 | 74 | Brick _brick16; |
jamesheavey | 27:1b5038b0a7a2 | 75 | |
jamesheavey | 27:1b5038b0a7a2 | 76 | Brick _brick21; |
jamesheavey | 27:1b5038b0a7a2 | 77 | Brick _brick22; |
jamesheavey | 27:1b5038b0a7a2 | 78 | Brick _brick23; |
jamesheavey | 27:1b5038b0a7a2 | 79 | Brick _brick24; |
jamesheavey | 27:1b5038b0a7a2 | 80 | Brick _brick25; |
jamesheavey | 27:1b5038b0a7a2 | 81 | Brick _brick26; |
jamesheavey | 27:1b5038b0a7a2 | 82 | |
jamesheavey | 27:1b5038b0a7a2 | 83 | Brick _brick31; |
jamesheavey | 27:1b5038b0a7a2 | 84 | Brick _brick32; |
jamesheavey | 27:1b5038b0a7a2 | 85 | Brick _brick33; |
jamesheavey | 27:1b5038b0a7a2 | 86 | Brick _brick34; |
jamesheavey | 27:1b5038b0a7a2 | 87 | Brick _brick35; |
jamesheavey | 27:1b5038b0a7a2 | 88 | Brick _brick36; |
jamesheavey | 27:1b5038b0a7a2 | 89 | |
jamesheavey | 27:1b5038b0a7a2 | 90 | |
jamesheavey | 27:1b5038b0a7a2 | 91 | |
jamesheavey | 27:1b5038b0a7a2 | 92 | }; |
jamesheavey | 27:1b5038b0a7a2 | 93 | |
jamesheavey | 27:1b5038b0a7a2 | 94 | #endif |