ELEC2645 (2018/19) / Mbed 2 deprecated el17ebs

Dependencies:   mbed FATFileSystem

Committer:
ellisbhastroud
Date:
Tue Apr 23 12:03:38 2019 +0000
Revision:
10:9f54a6366e94
Parent:
9:bc34f2243e43
Child:
11:6d2027253aa9
Added corner bounces to bounce check algorithm. More levels now added with complex courses.

Who changed what in which revision?

UserRevisionLine numberNew 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 9:bc34f2243e43 9 enum WallType {
ellisbhastroud 8:d410856c6d04 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 10:9f54a6366e94 20
ellisbhastroud 8:d410856c6d04 21 };
ellisbhastroud 8:d410856c6d04 22
ellisbhastroud 8:d410856c6d04 23 /** Pixel Coordinate Struct*/
ellisbhastroud 8:d410856c6d04 24 struct Coord {
ellisbhastroud 8:d410856c6d04 25 int x; /**< coordinate of x pixel */
ellisbhastroud 8:d410856c6d04 26 int y; /**< coordinate of y pixel */
ellisbhastroud 8:d410856c6d04 27 };
ellisbhastroud 8:d410856c6d04 28
ellisbhastroud 9:bc34f2243e43 29 /** Map Layout struct */
ellisbhastroud 9:bc34f2243e43 30 struct WallMap {
ellisbhastroud 9:bc34f2243e43 31 WallType wall; /**< wall type */
ellisbhastroud 8:d410856c6d04 32 Coord start; /**< coordinate of line start */
ellisbhastroud 8:d410856c6d04 33 Coord end; /**< coordinate of line end */
ellisbhastroud 8:d410856c6d04 34 };
ellisbhastroud 8:d410856c6d04 35
ellisbhastroud 9:bc34f2243e43 36 /** Levels Information struct */
ellisbhastroud 9:bc34f2243e43 37 struct Levels {
ellisbhastroud 9:bc34f2243e43 38 Coord ball; /**< start position of ball */
ellisbhastroud 9:bc34f2243e43 39 Coord hole; /**< position of hole */
ellisbhastroud 10:9f54a6366e94 40 WallMap walls[15]; /**< array of wall plots */
ellisbhastroud 9:bc34f2243e43 41 int wall_count;
ellisbhastroud 9:bc34f2243e43 42
ellisbhastroud 9:bc34f2243e43 43 };
ellisbhastroud 9:bc34f2243e43 44
ellisbhastroud 3:a8960004d261 45 /** Ball Class
ellisbhastroud 3:a8960004d261 46 * @brief Class for controlling the golf ball
ellisbhastroud 3:a8960004d261 47 * @author Ellis Blackford Stroud
ellisbhastroud 3:a8960004d261 48 * @date May, 2018
ellisbhastroud 3:a8960004d261 49 */
ellisbhastroud 3:a8960004d261 50
ellisbhastroud 5:0b31909caf7f 51 class Ball
ellisbhastroud 5:0b31909caf7f 52 {
ellisbhastroud 3:a8960004d261 53
ellisbhastroud 3:a8960004d261 54 public:
ellisbhastroud 3:a8960004d261 55
ellisbhastroud 3:a8960004d261 56 /** Constructor */
ellisbhastroud 3:a8960004d261 57 Ball();
ellisbhastroud 3:a8960004d261 58
ellisbhastroud 3:a8960004d261 59 /** Destructor */
ellisbhastroud 3:a8960004d261 60 ~Ball();
ellisbhastroud 3:a8960004d261 61
ellisbhastroud 9:bc34f2243e43 62 void init(Coord start_pos);
ellisbhastroud 3:a8960004d261 63
ellisbhastroud 5:0b31909caf7f 64 void drawBall(N5110 &lcd);
ellisbhastroud 3:a8960004d261 65
ellisbhastroud 5:0b31909caf7f 66 void printShotCount(N5110 &lcd);
ellisbhastroud 4:035448357749 67
ellisbhastroud 8:d410856c6d04 68 void drawPower(N5110 &lcd, float mag);
ellisbhastroud 8:d410856c6d04 69
ellisbhastroud 8:d410856c6d04 70 void drawAim(N5110 &lcd, Vector2D joy_coord ,float angle);
ellisbhastroud 8:d410856c6d04 71
ellisbhastroud 10:9f54a6366e94 72 void move_ball();
ellisbhastroud 4:035448357749 73
ellisbhastroud 4:035448357749 74 Vector2D get_ball_pos();
ellisbhastroud 3:a8960004d261 75
ellisbhastroud 8:d410856c6d04 76 void shoot_ball(Gamepad &pad, Vector2D joy_coord);
ellisbhastroud 3:a8960004d261 77
ellisbhastroud 4:035448357749 78 int get_shot_count();
ellisbhastroud 9:bc34f2243e43 79
ellisbhastroud 9:bc34f2243e43 80 int get_total_shot_count();
ellisbhastroud 5:0b31909caf7f 81
ellisbhastroud 9:bc34f2243e43 82 void set_total_shot_count(int total_shot_count);
ellisbhastroud 9:bc34f2243e43 83
ellisbhastroud 9:bc34f2243e43 84 bool check_hole(Coord hole);
ellisbhastroud 8:d410856c6d04 85
ellisbhastroud 9:bc34f2243e43 86 void check_wall_bounce(WallMap map[], int size);
ellisbhastroud 8:d410856c6d04 87
ellisbhastroud 8:d410856c6d04 88 void left_bounce(Coord start, Coord end);
ellisbhastroud 3:a8960004d261 89
ellisbhastroud 8:d410856c6d04 90 void right_bounce(Coord start, Coord end);
ellisbhastroud 8:d410856c6d04 91
ellisbhastroud 8:d410856c6d04 92 void top_bounce(Coord start, Coord end);
ellisbhastroud 5:0b31909caf7f 93
ellisbhastroud 8:d410856c6d04 94 void bottom_bounce(Coord start, Coord end);
ellisbhastroud 10:9f54a6366e94 95
ellisbhastroud 10:9f54a6366e94 96 void bottom_left_bounce(Coord start, Coord end);
ellisbhastroud 10:9f54a6366e94 97
ellisbhastroud 10:9f54a6366e94 98 void bottom_right_bounce(Coord start, Coord end);
ellisbhastroud 10:9f54a6366e94 99
ellisbhastroud 10:9f54a6366e94 100 void top_left_bounce(Coord start, Coord end);
ellisbhastroud 10:9f54a6366e94 101
ellisbhastroud 10:9f54a6366e94 102 void top_right_bounce(Coord start, Coord end);
ellisbhastroud 10:9f54a6366e94 103
ellisbhastroud 10:9f54a6366e94 104 void set_frame_rate(int frame_rate);
ellisbhastroud 8:d410856c6d04 105
ellisbhastroud 3:a8960004d261 106 private:
ellisbhastroud 4:035448357749 107
ellisbhastroud 3:a8960004d261 108 float _x_pos;
ellisbhastroud 3:a8960004d261 109 float _y_pos;
ellisbhastroud 3:a8960004d261 110 float _x_vel;
ellisbhastroud 3:a8960004d261 111 float _y_vel;
ellisbhastroud 4:035448357749 112 int _shot_count;
ellisbhastroud 9:bc34f2243e43 113 int _total_shot_count;
ellisbhastroud 10:9f54a6366e94 114 int _frame_rate;
ellisbhastroud 5:0b31909caf7f 115 Direction _direction;
ellisbhastroud 3:a8960004d261 116 };
ellisbhastroud 3:a8960004d261 117
ellisbhastroud 3:a8960004d261 118 #endif