ELEC2645 (2018/19) / Mbed 2 deprecated el17ebs

Dependencies:   mbed FATFileSystem

Committer:
ellisbhastroud
Date:
Thu May 09 09:58:51 2019 +0000
Revision:
16:c8d68cbd1ae2
Parent:
14:08ac9aaa34c3
Child:
17:98127ac75195
Penultimate Commit - Tidied a little and checking documentation.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ellisbhastroud 5:0b31909caf7f 1 #ifndef GOLFENGINE_H
ellisbhastroud 5:0b31909caf7f 2 #define GOLFENGINE_H
ellisbhastroud 5:0b31909caf7f 3
ellisbhastroud 5:0b31909caf7f 4 #include "mbed.h"
ellisbhastroud 5:0b31909caf7f 5 #include "N5110.h"
ellisbhastroud 13:681192091568 6 #include "SDFileSystem.h"
ellisbhastroud 5:0b31909caf7f 7 #include "Gamepad.h"
ellisbhastroud 5:0b31909caf7f 8 #include "Ball.h"
ellisbhastroud 5:0b31909caf7f 9
ellisbhastroud 8:d410856c6d04 10
ellisbhastroud 5:0b31909caf7f 11 /** Golf Engine Class
ellisbhastroud 5:0b31909caf7f 12 * @brief Library to run golf game
ellisbhastroud 5:0b31909caf7f 13 * @author Ellis Blackford Stroud
ellisbhastroud 5:0b31909caf7f 14 * @date May, 2018
ellisbhastroud 5:0b31909caf7f 15 */
ellisbhastroud 5:0b31909caf7f 16 class GolfEngine
ellisbhastroud 5:0b31909caf7f 17 {
ellisbhastroud 5:0b31909caf7f 18 public:
ellisbhastroud 5:0b31909caf7f 19 /** Constructor */
ellisbhastroud 5:0b31909caf7f 20 GolfEngine();
ellisbhastroud 5:0b31909caf7f 21
ellisbhastroud 5:0b31909caf7f 22 /** Destructor */
ellisbhastroud 5:0b31909caf7f 23 ~GolfEngine();
ellisbhastroud 5:0b31909caf7f 24
ellisbhastroud 14:08ac9aaa34c3 25 /** Sets values for new game
ellisbhastroud 14:08ac9aaa34c3 26 * @param the frame rate in Hz
ellisbhastroud 14:08ac9aaa34c3 27 */
ellisbhastroud 10:9f54a6366e94 28 void init(int frame_rate);
ellisbhastroud 14:08ac9aaa34c3 29
ellisbhastroud 14:08ac9aaa34c3 30 /** Draws game screen
ellisbhastroud 14:08ac9aaa34c3 31 * @param the class used to interact with the lcd display
ellisbhastroud 14:08ac9aaa34c3 32 */
ellisbhastroud 14:08ac9aaa34c3 33 void drawGame(N5110 &lcd);
ellisbhastroud 5:0b31909caf7f 34
ellisbhastroud 14:08ac9aaa34c3 35 /** Reads input from gamepad
ellisbhastroud 14:08ac9aaa34c3 36 * @param the class used to interact with the gamepad
ellisbhastroud 14:08ac9aaa34c3 37 */
ellisbhastroud 8:d410856c6d04 38 void read_input(Gamepad &pad);
ellisbhastroud 5:0b31909caf7f 39
ellisbhastroud 14:08ac9aaa34c3 40 /** Updates ball position according to input
ellisbhastroud 14:08ac9aaa34c3 41 * @param the class used to interact with the gamepad
ellisbhastroud 14:08ac9aaa34c3 42 */
ellisbhastroud 14:08ac9aaa34c3 43 void update_ball(Gamepad &pad, N5110 &lcd);
ellisbhastroud 14:08ac9aaa34c3 44
ellisbhastroud 14:08ac9aaa34c3 45 /** Checks if level is over
ellisbhastroud 14:08ac9aaa34c3 46 * @param the class used to interact with the lcd display
ellisbhastroud 14:08ac9aaa34c3 47 * @param the class used to interact with the gamepad
ellisbhastroud 14:08ac9aaa34c3 48 * @param the class used to interact with the sd card
ellisbhastroud 14:08ac9aaa34c3 49 */
ellisbhastroud 14:08ac9aaa34c3 50 void check_end_level(N5110 &lcd, Gamepad &pad, SDFileSystem &sd);
ellisbhastroud 9:bc34f2243e43 51
ellisbhastroud 14:08ac9aaa34c3 52 /** Prints current level
ellisbhastroud 14:08ac9aaa34c3 53 * @param the class used to interact with the lcd display
ellisbhastroud 14:08ac9aaa34c3 54 */
ellisbhastroud 14:08ac9aaa34c3 55 void printLevel(N5110 &lcd);
ellisbhastroud 13:681192091568 56
ellisbhastroud 14:08ac9aaa34c3 57 /** Resets game over flag */
ellisbhastroud 14:08ac9aaa34c3 58 void reset_game_over_flag();
ellisbhastroud 12:7f7fadb5c106 59
ellisbhastroud 14:08ac9aaa34c3 60 /** Returns game over flag
ellisbhastroud 14:08ac9aaa34c3 61 * @param true if game over and false if now
ellisbhastroud 14:08ac9aaa34c3 62 */
ellisbhastroud 14:08ac9aaa34c3 63 bool get_game_over_flag();
ellisbhastroud 9:bc34f2243e43 64
ellisbhastroud 5:0b31909caf7f 65 private:
ellisbhastroud 5:0b31909caf7f 66
ellisbhastroud 16:c8d68cbd1ae2 67 void drawCourseWalls(N5110 &lcd, const WallMap map[], int size);
ellisbhastroud 12:7f7fadb5c106 68 void drawHole(N5110 &lcd, Coord hole);
ellisbhastroud 13:681192091568 69 void file_append(int value, SDFileSystem &sd);
ellisbhastroud 14:08ac9aaa34c3 70 void new_level(N5110 &lcd, SDFileSystem &sd);
ellisbhastroud 14:08ac9aaa34c3 71 void c_maj(Gamepad &pad);
ellisbhastroud 14:08ac9aaa34c3 72 void g_maj7_flash(Gamepad &pad, N5110 &lcd);
ellisbhastroud 14:08ac9aaa34c3 73
ellisbhastroud 8:d410856c6d04 74 int _level;
ellisbhastroud 14:08ac9aaa34c3 75 bool _game_over_flag;
ellisbhastroud 8:d410856c6d04 76 float _mag;
ellisbhastroud 8:d410856c6d04 77 Vector2D _joy_coord;
ellisbhastroud 8:d410856c6d04 78 float _angle;
ellisbhastroud 16:c8d68cbd1ae2 79 Ball _ball;
ellisbhastroud 5:0b31909caf7f 80 };
ellisbhastroud 5:0b31909caf7f 81
ellisbhastroud 16:c8d68cbd1ae2 82 //Array of Levels struct contains all information needed to draw and run all levels
ellisbhastroud 16:c8d68cbd1ae2 83 //Contains coordinates of ball start position, hole position and all walls with types. The game engine uses
ellisbhastroud 16:c8d68cbd1ae2 84 //these coordinates to draw the ball and hole for each level, to check for bounces and to check if the ball is in the hole and the level is over.
ellisbhastroud 16:c8d68cbd1ae2 85 const Levels levels[6] = {
ellisbhastroud 16:c8d68cbd1ae2 86
ellisbhastroud 16:c8d68cbd1ae2 87 {{15,32}, {68,31}, //level one - //element one is coordinate of ball and element two is coordinate of hole
ellisbhastroud 16:c8d68cbd1ae2 88 {{LEFT,{9,24},{9,39}}, //wall types with coordinates used to check for bounces
ellisbhastroud 16:c8d68cbd1ae2 89 {BOTTOM,{9,39},{74,39}},
ellisbhastroud 16:c8d68cbd1ae2 90 {RIGHT,{74,24},{74,39}},
ellisbhastroud 16:c8d68cbd1ae2 91 {TOP,{9,24},{74,24}}},4}, //size used to stop for loops drawing/bounce checking walls that do not exist in the 16 term WallType array
ellisbhastroud 16:c8d68cbd1ae2 92
ellisbhastroud 16:c8d68cbd1ae2 93 {{18,30}, {64,15}, //level two
ellisbhastroud 16:c8d68cbd1ae2 94 {{LEFT,{9,27},{9,41}},
ellisbhastroud 16:c8d68cbd1ae2 95 {BOTTOM,{9,41},{73,41}},
ellisbhastroud 16:c8d68cbd1ae2 96 {RIGHT,{73,11},{73,41}},
ellisbhastroud 16:c8d68cbd1ae2 97 {BOTTOMRIGHT,{65,41},{73,33}},
ellisbhastroud 16:c8d68cbd1ae2 98 {TOP,{56,11},{73,11}},
ellisbhastroud 16:c8d68cbd1ae2 99 {LEFT,{56,11},{56,27}},
ellisbhastroud 16:c8d68cbd1ae2 100 {TOP,{9,27},{56,27}}}, 7},
ellisbhastroud 16:c8d68cbd1ae2 101
ellisbhastroud 16:c8d68cbd1ae2 102 {{18,17}, {64,17}, //level three
ellisbhastroud 16:c8d68cbd1ae2 103 {{TOP,{9,10},{27,10}},
ellisbhastroud 16:c8d68cbd1ae2 104 {LEFT,{9,10},{9,45}},
ellisbhastroud 16:c8d68cbd1ae2 105 {BOTTOM,{9,45},{73,45}},
ellisbhastroud 16:c8d68cbd1ae2 106 {BOTTOMRIGHT,{63,45},{73,35}},
ellisbhastroud 16:c8d68cbd1ae2 107 {RIGHT,{73,10},{73,45}},
ellisbhastroud 16:c8d68cbd1ae2 108 {TOP,{56,10},{73,10}},
ellisbhastroud 16:c8d68cbd1ae2 109 {LEFT,{56,10},{56,32}},
ellisbhastroud 16:c8d68cbd1ae2 110 {TOP,{27,32},{56,32}},
ellisbhastroud 16:c8d68cbd1ae2 111 {RIGHT,{27,10},{27,32}}}, 9},
ellisbhastroud 16:c8d68cbd1ae2 112
ellisbhastroud 16:c8d68cbd1ae2 113 {{15,39}, {70,18}, //level four
ellisbhastroud 16:c8d68cbd1ae2 114 {{LEFT,{9,31},{9,44}},
ellisbhastroud 16:c8d68cbd1ae2 115 {BOTTOM,{9,44},{53,44}},
ellisbhastroud 16:c8d68cbd1ae2 116 {RIGHT,{53,25},{53,44}},
ellisbhastroud 16:c8d68cbd1ae2 117 {TOP,{9,31},{36,31}},
ellisbhastroud 16:c8d68cbd1ae2 118 {LEFT,{36,12},{36,31}},
ellisbhastroud 16:c8d68cbd1ae2 119 {TOPLEFT,{36,20},{44,12}},
ellisbhastroud 16:c8d68cbd1ae2 120 {TOP,{36,12},{78,12}},
ellisbhastroud 16:c8d68cbd1ae2 121 {BOTTOM,{53,25},{78,25}},
ellisbhastroud 16:c8d68cbd1ae2 122 {RIGHT,{78,12},{78,25}}}, 9},
ellisbhastroud 16:c8d68cbd1ae2 123
ellisbhastroud 16:c8d68cbd1ae2 124 {{31,39}, {70,38}, //level five
ellisbhastroud 16:c8d68cbd1ae2 125 {{LEFT,{7,18},{7,43}},
ellisbhastroud 16:c8d68cbd1ae2 126 {BOTTOMLEFT,{7,37},{13,43}},
ellisbhastroud 16:c8d68cbd1ae2 127 {TOPLEFT,{7,24},{13,18}},
ellisbhastroud 16:c8d68cbd1ae2 128 {BOTTOM,{7,43},{34,43}},
ellisbhastroud 16:c8d68cbd1ae2 129 {RIGHT,{34,26},{34,43}},
ellisbhastroud 16:c8d68cbd1ae2 130 {TOP,{7,18},{76,18}},
ellisbhastroud 16:c8d68cbd1ae2 131 {BOTTOM,{34,26},{51,26}},
ellisbhastroud 16:c8d68cbd1ae2 132 {LEFT,{51,26},{51,43}},
ellisbhastroud 16:c8d68cbd1ae2 133 {BOTTOM,{51,43},{76,43}},
ellisbhastroud 16:c8d68cbd1ae2 134 {RIGHT,{60,26},{60,35}},
ellisbhastroud 16:c8d68cbd1ae2 135 {BOTTOM,{60,26},{76,26}},
ellisbhastroud 16:c8d68cbd1ae2 136 {TOP,{60,35},{76,35}},
ellisbhastroud 16:c8d68cbd1ae2 137 {RIGHT,{76,35},{76,43}},
ellisbhastroud 16:c8d68cbd1ae2 138 {RIGHT,{76,18},{76,26}}}, 14},
ellisbhastroud 16:c8d68cbd1ae2 139
ellisbhastroud 16:c8d68cbd1ae2 140 {{31,40}, {72,29}, //level six
ellisbhastroud 16:c8d68cbd1ae2 141 {{LEFT,{7,18},{7,43}},
ellisbhastroud 16:c8d68cbd1ae2 142 {BOTTOM,{7,43},{34,43}},
ellisbhastroud 16:c8d68cbd1ae2 143 {TOP,{7,18},{34,18}},
ellisbhastroud 16:c8d68cbd1ae2 144 {RIGHT,{34,18},{34,27}},
ellisbhastroud 16:c8d68cbd1ae2 145 {RIGHT,{34,34},{34,43}},
ellisbhastroud 16:c8d68cbd1ae2 146 {TOP,{34,27},{50,27}},
ellisbhastroud 16:c8d68cbd1ae2 147 {BOTTOM,{34,34},{50,34}},
ellisbhastroud 16:c8d68cbd1ae2 148 {LEFT,{50,18},{50,27}},
ellisbhastroud 16:c8d68cbd1ae2 149 {LEFT,{50,34},{50,43}},
ellisbhastroud 16:c8d68cbd1ae2 150 {TOP,{50,18},{77,18}},
ellisbhastroud 16:c8d68cbd1ae2 151 {BOTTOM,{50,43},{77,43}},
ellisbhastroud 16:c8d68cbd1ae2 152 {RIGHT,{77,18},{77,43}},
ellisbhastroud 16:c8d68cbd1ae2 153 {RIGHT,{60,25},{60,36}},
ellisbhastroud 16:c8d68cbd1ae2 154 {BOTTOM,{60,25},{67,25}},
ellisbhastroud 16:c8d68cbd1ae2 155 {LEFT,{67,25},{67,36}},
ellisbhastroud 16:c8d68cbd1ae2 156 {TOP,{60,36},{67,36}}}, 16}
ellisbhastroud 16:c8d68cbd1ae2 157 };
ellisbhastroud 5:0b31909caf7f 158 #endif