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 FATFileSystem
Ball/Ball.h@12:7f7fadb5c106, 2019-05-03 (annotated)
- Committer:
- ellisbhastroud
- Date:
- Fri May 03 09:39:24 2019 +0000
- Revision:
- 12:7f7fadb5c106
- Parent:
- 11:6d2027253aa9
- Child:
- 14:08ac9aaa34c3
Added more detailed in line comments. Added Doxygen comments for classes. Reorganised some class methods. Removed unnecessary methods. Split large methods into multiple smaller.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ellisbhastroud | 3:a8960004d261 | 1 | #ifndef BALL_H |
| ellisbhastroud | 3:a8960004d261 | 2 | #define BALL_H |
| ellisbhastroud | 3:a8960004d261 | 3 | |
| ellisbhastroud | 3:a8960004d261 | 4 | #include "mbed.h" |
| ellisbhastroud | 3:a8960004d261 | 5 | #include "N5110.h" |
| ellisbhastroud | 3:a8960004d261 | 6 | #include "Gamepad.h" |
| ellisbhastroud | 3:a8960004d261 | 7 | |
| ellisbhastroud | 8:d410856c6d04 | 8 | /** Enum for wall types */ |
| ellisbhastroud | 12:7f7fadb5c106 | 9 | enum WallType { |
| ellisbhastroud | 12:7f7fadb5c106 | 10 | |
| ellisbhastroud | 8:d410856c6d04 | 11 | LEFT, /**< left wall */ |
| ellisbhastroud | 8:d410856c6d04 | 12 | RIGHT, /**< right wall */ |
| ellisbhastroud | 8:d410856c6d04 | 13 | TOP, /**< top wall */ |
| ellisbhastroud | 8:d410856c6d04 | 14 | BOTTOM, /**< bottom wall */ |
| ellisbhastroud | 10:9f54a6366e94 | 15 | BOTTOMLEFT, /**< bottom left 45 deg wall */ |
| ellisbhastroud | 10:9f54a6366e94 | 16 | BOTTOMRIGHT, /**< bottom right 45 deg wall */ |
| ellisbhastroud | 10:9f54a6366e94 | 17 | TOPLEFT, /**< top left 45 deg wall */ |
| ellisbhastroud | 10:9f54a6366e94 | 18 | TOPRIGHT, /**< top right 45 deg wall */ |
| ellisbhastroud | 10:9f54a6366e94 | 19 | |
| ellisbhastroud | 8:d410856c6d04 | 20 | }; |
| ellisbhastroud | 8:d410856c6d04 | 21 | |
| ellisbhastroud | 8:d410856c6d04 | 22 | /** Pixel Coordinate Struct*/ |
| ellisbhastroud | 8:d410856c6d04 | 23 | struct Coord { |
| ellisbhastroud | 12:7f7fadb5c106 | 24 | |
| ellisbhastroud | 8:d410856c6d04 | 25 | int x; /**< coordinate of x pixel */ |
| ellisbhastroud | 8:d410856c6d04 | 26 | int y; /**< coordinate of y pixel */ |
| ellisbhastroud | 12:7f7fadb5c106 | 27 | |
| ellisbhastroud | 8:d410856c6d04 | 28 | }; |
| ellisbhastroud | 8:d410856c6d04 | 29 | |
| ellisbhastroud | 12:7f7fadb5c106 | 30 | /** Wall Information struct */ |
| ellisbhastroud | 9:bc34f2243e43 | 31 | struct WallMap { |
| ellisbhastroud | 12:7f7fadb5c106 | 32 | |
| ellisbhastroud | 9:bc34f2243e43 | 33 | WallType wall; /**< wall type */ |
| ellisbhastroud | 8:d410856c6d04 | 34 | Coord start; /**< coordinate of line start */ |
| ellisbhastroud | 8:d410856c6d04 | 35 | Coord end; /**< coordinate of line end */ |
| ellisbhastroud | 12:7f7fadb5c106 | 36 | |
| ellisbhastroud | 8:d410856c6d04 | 37 | }; |
| ellisbhastroud | 8:d410856c6d04 | 38 | |
| ellisbhastroud | 9:bc34f2243e43 | 39 | /** Levels Information struct */ |
| ellisbhastroud | 9:bc34f2243e43 | 40 | struct Levels { |
| ellisbhastroud | 12:7f7fadb5c106 | 41 | |
| ellisbhastroud | 9:bc34f2243e43 | 42 | Coord ball; /**< start position of ball */ |
| ellisbhastroud | 9:bc34f2243e43 | 43 | Coord hole; /**< position of hole */ |
| ellisbhastroud | 12:7f7fadb5c106 | 44 | WallMap walls[16]; /**< array of walls */ |
| ellisbhastroud | 12:7f7fadb5c106 | 45 | int wall_count; /**< number of walls in level */ |
| ellisbhastroud | 12:7f7fadb5c106 | 46 | |
| ellisbhastroud | 9:bc34f2243e43 | 47 | |
| ellisbhastroud | 9:bc34f2243e43 | 48 | }; |
| ellisbhastroud | 9:bc34f2243e43 | 49 | |
| ellisbhastroud | 3:a8960004d261 | 50 | /** Ball Class |
| ellisbhastroud | 3:a8960004d261 | 51 | * @brief Class for controlling the golf ball |
| ellisbhastroud | 3:a8960004d261 | 52 | * @author Ellis Blackford Stroud |
| ellisbhastroud | 3:a8960004d261 | 53 | * @date May, 2018 |
| ellisbhastroud | 3:a8960004d261 | 54 | */ |
| ellisbhastroud | 3:a8960004d261 | 55 | |
| ellisbhastroud | 5:0b31909caf7f | 56 | class Ball |
| ellisbhastroud | 5:0b31909caf7f | 57 | { |
| ellisbhastroud | 3:a8960004d261 | 58 | |
| ellisbhastroud | 3:a8960004d261 | 59 | public: |
| ellisbhastroud | 3:a8960004d261 | 60 | |
| ellisbhastroud | 3:a8960004d261 | 61 | /** Constructor */ |
| ellisbhastroud | 3:a8960004d261 | 62 | Ball(); |
| ellisbhastroud | 3:a8960004d261 | 63 | |
| ellisbhastroud | 3:a8960004d261 | 64 | /** Destructor */ |
| ellisbhastroud | 3:a8960004d261 | 65 | ~Ball(); |
| ellisbhastroud | 3:a8960004d261 | 66 | |
| ellisbhastroud | 9:bc34f2243e43 | 67 | void init(Coord start_pos); |
| ellisbhastroud | 3:a8960004d261 | 68 | |
| ellisbhastroud | 5:0b31909caf7f | 69 | void drawBall(N5110 &lcd); |
| ellisbhastroud | 3:a8960004d261 | 70 | |
| ellisbhastroud | 5:0b31909caf7f | 71 | void printShotCount(N5110 &lcd); |
| ellisbhastroud | 4:035448357749 | 72 | |
| ellisbhastroud | 8:d410856c6d04 | 73 | void drawPower(N5110 &lcd, float mag); |
| ellisbhastroud | 8:d410856c6d04 | 74 | |
| ellisbhastroud | 8:d410856c6d04 | 75 | void drawAim(N5110 &lcd, Vector2D joy_coord ,float angle); |
| ellisbhastroud | 8:d410856c6d04 | 76 | |
| ellisbhastroud | 10:9f54a6366e94 | 77 | void move_ball(); |
| ellisbhastroud | 12:7f7fadb5c106 | 78 | |
| ellisbhastroud | 8:d410856c6d04 | 79 | void shoot_ball(Gamepad &pad, Vector2D joy_coord); |
| ellisbhastroud | 12:7f7fadb5c106 | 80 | |
| ellisbhastroud | 12:7f7fadb5c106 | 81 | void set_total_shot_count(int total_shot_count); |
| ellisbhastroud | 9:bc34f2243e43 | 82 | |
| ellisbhastroud | 9:bc34f2243e43 | 83 | int get_total_shot_count(); |
| ellisbhastroud | 5:0b31909caf7f | 84 | |
| ellisbhastroud | 9:bc34f2243e43 | 85 | bool check_hole(Coord hole); |
| ellisbhastroud | 8:d410856c6d04 | 86 | |
| ellisbhastroud | 9:bc34f2243e43 | 87 | void check_wall_bounce(WallMap map[], int size); |
| ellisbhastroud | 8:d410856c6d04 | 88 | |
| ellisbhastroud | 12:7f7fadb5c106 | 89 | void set_frame_rate(int frame_rate); |
| ellisbhastroud | 12:7f7fadb5c106 | 90 | |
| ellisbhastroud | 12:7f7fadb5c106 | 91 | private: |
| ellisbhastroud | 12:7f7fadb5c106 | 92 | |
| ellisbhastroud | 8:d410856c6d04 | 93 | void left_bounce(Coord start, Coord end); |
| ellisbhastroud | 3:a8960004d261 | 94 | |
| ellisbhastroud | 8:d410856c6d04 | 95 | void right_bounce(Coord start, Coord end); |
| ellisbhastroud | 8:d410856c6d04 | 96 | |
| ellisbhastroud | 8:d410856c6d04 | 97 | void top_bounce(Coord start, Coord end); |
| ellisbhastroud | 5:0b31909caf7f | 98 | |
| ellisbhastroud | 8:d410856c6d04 | 99 | void bottom_bounce(Coord start, Coord end); |
| ellisbhastroud | 10:9f54a6366e94 | 100 | |
| ellisbhastroud | 10:9f54a6366e94 | 101 | void bottom_left_bounce(Coord start, Coord end); |
| ellisbhastroud | 10:9f54a6366e94 | 102 | |
| ellisbhastroud | 10:9f54a6366e94 | 103 | void bottom_right_bounce(Coord start, Coord end); |
| ellisbhastroud | 10:9f54a6366e94 | 104 | |
| ellisbhastroud | 10:9f54a6366e94 | 105 | void top_left_bounce(Coord start, Coord end); |
| ellisbhastroud | 10:9f54a6366e94 | 106 | |
| ellisbhastroud | 10:9f54a6366e94 | 107 | void top_right_bounce(Coord start, Coord end); |
| ellisbhastroud | 10:9f54a6366e94 | 108 | |
| ellisbhastroud | 12:7f7fadb5c106 | 109 | float _x_pos; |
| ellisbhastroud | 4:035448357749 | 110 | |
| ellisbhastroud | 3:a8960004d261 | 111 | float _y_pos; |
| ellisbhastroud | 12:7f7fadb5c106 | 112 | |
| ellisbhastroud | 3:a8960004d261 | 113 | float _x_vel; |
| ellisbhastroud | 12:7f7fadb5c106 | 114 | |
| ellisbhastroud | 3:a8960004d261 | 115 | float _y_vel; |
| ellisbhastroud | 12:7f7fadb5c106 | 116 | |
| ellisbhastroud | 4:035448357749 | 117 | int _shot_count; |
| ellisbhastroud | 12:7f7fadb5c106 | 118 | |
| ellisbhastroud | 9:bc34f2243e43 | 119 | int _total_shot_count; |
| ellisbhastroud | 12:7f7fadb5c106 | 120 | |
| ellisbhastroud | 10:9f54a6366e94 | 121 | int _frame_rate; |
| ellisbhastroud | 12:7f7fadb5c106 | 122 | |
| ellisbhastroud | 5:0b31909caf7f | 123 | Direction _direction; |
| ellisbhastroud | 12:7f7fadb5c106 | 124 | |
| ellisbhastroud | 3:a8960004d261 | 125 | }; |
| ellisbhastroud | 3:a8960004d261 | 126 | |
| ellisbhastroud | 3:a8960004d261 | 127 | #endif |