Uses accompanying Basket, Objects and Fruit libraries to create Fruit Basket game. If an object is caught, points are added; if an object in missed, a 'life' is lost.

Dependents:   Game_Controller_Project

Committer:
Nathanj94
Date:
Thu May 04 11:16:33 2017 +0000
Revision:
17:20abf995c040
Parent:
15:1a0bd800f1f1
Child:
18:99ccfa1bb2ca
Doxygen updated

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Nathanj94 0:8d02400f792a 1 #ifndef CATCH_MODEL_H
Nathanj94 0:8d02400f792a 2 #define CATCH_MODEL_H
Nathanj94 0:8d02400f792a 3
Nathanj94 0:8d02400f792a 4 #include "mbed.h"
Nathanj94 0:8d02400f792a 5 #include "N5110.h"
Nathanj94 0:8d02400f792a 6 #include "Gamepad.h"
Nathanj94 0:8d02400f792a 7 #include "Basket.h"
Nathanj94 1:43fbcc3584d6 8 #include "Objects.h"
Nathanj94 0:8d02400f792a 9
Nathanj94 0:8d02400f792a 10 class Catch_Model
Nathanj94 0:8d02400f792a 11 {
Nathanj94 14:6764bb61d413 12 public:
Nathanj94 14:6764bb61d413 13
Nathanj94 0:8d02400f792a 14 Catch_Model();
Nathanj94 0:8d02400f792a 15 ~Catch_Model();
Nathanj94 14:6764bb61d413 16
Nathanj94 13:ae2dac4ab786 17 //INITILISATION FUNCTIONS//
Nathanj94 14:6764bb61d413 18
Nathanj94 14:6764bb61d413 19 /** Initialise Game
Nathanj94 17:20abf995c040 20 *
Nathanj94 17:20abf995c040 21 * Main initialisation function. The parameters are used to call
Nathanj94 17:20abf995c040 22 * Basket::init(int y, int width) and Objects::init(int speed), as well
Nathanj94 17:20abf995c040 23 * as set the number of lives/misses the player will be allowed and set
Nathanj94 17:20abf995c040 24 * the default value of a variable that restricts how often the player
Nathanj94 17:20abf995c040 25 * can use the A and B buttons.
Nathanj94 17:20abf995c040 26 * @param basket_y - y co-ordinate of the basket (0 to 47)
Nathanj94 17:20abf995c040 27 * @param basket_width - width of the basket (0 to 83)
Nathanj94 17:20abf995c040 28 * @param objects_speed - "fall" speed of the object (2,3,4,5)
Nathanj94 17:20abf995c040 29 * @param lives - number of lives/misses the player has
Nathanj94 17:20abf995c040 30 */
Nathanj94 4:84e29254b988 31 void init(int basket_y, int basket_width, int objects_speed, int lives);
Nathanj94 14:6764bb61d413 32
Nathanj94 14:6764bb61d413 33
Nathanj94 14:6764bb61d413 34 //UPDATE FUNCTIONS//
Nathanj94 14:6764bb61d413 35
Nathanj94 14:6764bb61d413 36 /** Read Joystick Input
Nathanj94 17:20abf995c040 37 *
Nathanj94 17:20abf995c040 38 * Read the direction and magnitude of the joystick and assign
Nathanj94 17:20abf995c040 39 * the values to variables by calling functions from the Gamepad
Nathanj94 17:20abf995c040 40 * library.
Nathanj94 17:20abf995c040 41 * @param pad - Gamepad custom library
Nathanj94 17:20abf995c040 42 */
Nathanj94 0:8d02400f792a 43 void input(Gamepad &pad);
Nathanj94 14:6764bb61d413 44
Nathanj94 14:6764bb61d413 45 /** Update Game
Nathanj94 17:20abf995c040 46 *
Nathanj94 17:20abf995c040 47 * Checks if an object is caught by the basket or not then increases
Nathanj94 17:20abf995c040 48 * score or reduces lives appropriately. Moves the basket with either
Nathanj94 17:20abf995c040 49 * joystick or buttons and moves the objects too.
Nathanj94 17:20abf995c040 50 * @param lcd - N5110 custom library
Nathanj94 17:20abf995c040 51 * @param pad - Gamepad custom library
Nathanj94 17:20abf995c040 52 */
Nathanj94 3:fc9133faec7a 53 void update(N5110 &lcd, Gamepad &pad);
Nathanj94 14:6764bb61d413 54
Nathanj94 14:6764bb61d413 55
Nathanj94 13:ae2dac4ab786 56 //GAME RULES FUNCTIONS//
Nathanj94 14:6764bb61d413 57
Nathanj94 14:6764bb61d413 58 /** Check Object has been Caught
Nathanj94 17:20abf995c040 59 *
Nathanj94 17:20abf995c040 60 * Gets the x and y reference co-ordinates of the basket and the
Nathanj94 17:20abf995c040 61 * falling object from their respective libraries; if the x co-ordinate
Nathanj94 17:20abf995c040 62 * of the object is within the width of the basket and the y co-ordinate
Nathanj94 17:20abf995c040 63 * of the object is greater than that of the basket the object will be
Nathanj94 17:20abf995c040 64 * undrawn, the appropriate score will be added and the object will be
Nathanj94 17:20abf995c040 65 * re-initialised.
Nathanj94 17:20abf995c040 66 * @param lcd - N5110 custom library
Nathanj94 17:20abf995c040 67 * @param pad - Gamepad custom library
Nathanj94 17:20abf995c040 68 */
Nathanj94 3:fc9133faec7a 69 void check_basket_catch(N5110 &lcd, Gamepad &pad);
Nathanj94 14:6764bb61d413 70
Nathanj94 14:6764bb61d413 71 /** Check Object has Missed
Nathanj94 17:20abf995c040 72 *
Nathanj94 17:20abf995c040 73 * Gets the x and y reference co-ordinates of the basket and the
Nathanj94 17:20abf995c040 74 * falling object from their respective libraries; if the x co-ordinate
Nathanj94 17:20abf995c040 75 * of the object is outside the width of the basket and the y co-ordinate
Nathanj94 17:20abf995c040 76 * of the object is greater than that of the basket the object will be
Nathanj94 17:20abf995c040 77 * undrawn, the number of lives will be reduced and the object will be
Nathanj94 17:20abf995c040 78 * re-initialised.
Nathanj94 17:20abf995c040 79 * @param lcd - N5110 custom library
Nathanj94 17:20abf995c040 80 * @param pad - Gamepad custom library
Nathanj94 17:20abf995c040 81 */
Nathanj94 3:fc9133faec7a 82 void check_basket_miss(N5110 &lcd, Gamepad &pad);
Nathanj94 14:6764bb61d413 83
Nathanj94 14:6764bb61d413 84 /** Add Correct Score
Nathanj94 17:20abf995c040 85 *
Nathanj94 17:20abf995c040 86 * Gets the value of a variable from Objects that is specific to each
Nathanj94 17:20abf995c040 87 * object (type of fruit) and uses it to call the appropriate add_score
Nathanj94 17:20abf995c040 88 * function from Basket; increasing the score by 1, 2, 5 or 10.
Nathanj94 17:20abf995c040 89 */
Nathanj94 5:7db3e43e5aca 90 void add_score();
Nathanj94 14:6764bb61d413 91
Nathanj94 14:6764bb61d413 92 /** Get Lives
Nathanj94 17:20abf995c040 93 *
Nathanj94 17:20abf995c040 94 * Return the remaining number of lives available to the player.
Nathanj94 17:20abf995c040 95 */
Nathanj94 4:84e29254b988 96 int get_lives();
Nathanj94 14:6764bb61d413 97
Nathanj94 14:6764bb61d413 98
Nathanj94 13:ae2dac4ab786 99 //BUTTON FUNCTIONS//
Nathanj94 14:6764bb61d413 100
Nathanj94 14:6764bb61d413 101 /** Check A Button
Nathanj94 17:20abf995c040 102 *
Nathanj94 17:20abf995c040 103 * If the A button is pressed, call Objects::undraw(N5110 &lcd) wherever
Nathanj94 17:20abf995c040 104 * it is on the display and call Objects::init(int speed) to give
Nathanj94 17:20abf995c040 105 * the player a second chance. Also set the value of a variable to zero
Nathanj94 17:20abf995c040 106 * so that the function cannot be recalled straight away.
Nathanj94 17:20abf995c040 107 * @param lcd - N5110 custom library
Nathanj94 17:20abf995c040 108 * @param pad - Gamepad custom library
Nathanj94 17:20abf995c040 109 */
Nathanj94 13:ae2dac4ab786 110 void check_a(N5110 &lcd, Gamepad &pad);
Nathanj94 14:6764bb61d413 111
Nathanj94 14:6764bb61d413 112 /** Check B Button
Nathanj94 17:20abf995c040 113 *
Nathanj94 17:20abf995c040 114 * If the B button is pressed, increase number of lives by 1. Also set
Nathanj94 17:20abf995c040 115 * the value of a variable to zero so that the function cannot be
Nathanj94 17:20abf995c040 116 * recalled straight away.
Nathanj94 17:20abf995c040 117 * @param lcd - N5110 custom library
Nathanj94 17:20abf995c040 118 * @param pad - Gamepad custom library
Nathanj94 17:20abf995c040 119 */
Nathanj94 13:ae2dac4ab786 120 void check_b(N5110 &lcd, Gamepad &pad);
Nathanj94 14:6764bb61d413 121
Nathanj94 14:6764bb61d413 122 /** Set Delay to ON
Nathanj94 17:20abf995c040 123 *
Nathanj94 17:20abf995c040 124 * 10 seconds after the buttons A or B are pressed this function is called
Nathanj94 17:20abf995c040 125 * resetting the value of a variable to 1 so the buttons can be used again.
Nathanj94 17:20abf995c040 126 */
Nathanj94 13:ae2dac4ab786 127 void set_delay();
Nathanj94 14:6764bb61d413 128
Nathanj94 14:6764bb61d413 129
Nathanj94 14:6764bb61d413 130 //DISPLAY FUNCTIONS//
Nathanj94 13:ae2dac4ab786 131
Nathanj94 14:6764bb61d413 132 /** Draw All Features
Nathanj94 17:20abf995c040 133 *
Nathanj94 17:20abf995c040 134 * Calls draw functions from the Basket and Objects libraries as well
Nathanj94 17:20abf995c040 135 * as functions to display the score, remaining lives and an indicator
Nathanj94 17:20abf995c040 136 * that tells the player if the A and B buttons are ready to be used.
Nathanj94 17:20abf995c040 137 * Once the game is finished, a 'Game Over' screen is displayed showing
Nathanj94 17:20abf995c040 138 * the final score.
Nathanj94 17:20abf995c040 139 * @param lcd - N5110 custom library
Nathanj94 17:20abf995c040 140 * @param pad - Gamepad custom library
Nathanj94 17:20abf995c040 141 */
Nathanj94 15:1a0bd800f1f1 142 void draw(N5110 &lcd, Gamepad &pad);
Nathanj94 14:6764bb61d413 143
Nathanj94 14:6764bb61d413 144 /** Display the Number of Lives
Nathanj94 17:20abf995c040 145 *
Nathanj94 17:20abf995c040 146 * Print a string of characters to the buffer, indicating how many lives
Nathanj94 17:20abf995c040 147 * remain.
Nathanj94 17:20abf995c040 148 * @param lcd - N5110 custom library
Nathanj94 17:20abf995c040 149 */
Nathanj94 4:84e29254b988 150 void print_lives(N5110 &lcd);
Nathanj94 14:6764bb61d413 151
Nathanj94 14:6764bb61d413 152 /** Display the Score
Nathanj94 17:20abf995c040 153 *
Nathanj94 17:20abf995c040 154 * Print a string of characters to the buffer, indicating the score.
Nathanj94 17:20abf995c040 155 * @param lcd - N5110 custom library
Nathanj94 17:20abf995c040 156 */
Nathanj94 3:fc9133faec7a 157 void print_score(N5110 &lcd);
Nathanj94 14:6764bb61d413 158
Nathanj94 15:1a0bd800f1f1 159 /** Display the Final Score
Nathanj94 17:20abf995c040 160 *
Nathanj94 17:20abf995c040 161 * Print two strings of characters to the buffer, one indicating the
Nathanj94 17:20abf995c040 162 * score and another saying 'Game Over'.
Nathanj94 17:20abf995c040 163 * @param lcd - N5110 custom library
Nathanj94 17:20abf995c040 164 */
Nathanj94 15:1a0bd800f1f1 165 void final_score(N5110 &lcd);
Nathanj94 15:1a0bd800f1f1 166
Nathanj94 14:6764bb61d413 167 /** Display the Powerup Indicator
Nathanj94 17:20abf995c040 168 *
Nathanj94 17:20abf995c040 169 * Print a tick or cross to the buffer, indicating whether or not
Nathanj94 17:20abf995c040 170 * the A and B buttons are ready to be used.
Nathanj94 17:20abf995c040 171 * @param lcd - N5110 custom library
Nathanj94 17:20abf995c040 172 */
Nathanj94 8:db24c475f64f 173 void print_delay(N5110 &lcd);
Nathanj94 14:6764bb61d413 174
Nathanj94 14:6764bb61d413 175 private:
Nathanj94 14:6764bb61d413 176
Nathanj94 14:6764bb61d413 177 //OBJECTS//
Nathanj94 4:84e29254b988 178 Basket basket;
Nathanj94 4:84e29254b988 179 Objects objects;
Nathanj94 7:ec6dc66ee196 180 Timeout timeout;
Nathanj94 14:6764bb61d413 181
Nathanj94 14:6764bb61d413 182 //VARIABLES//
Nathanj94 0:8d02400f792a 183 int _basket_y;
Nathanj94 0:8d02400f792a 184 int _basket_width;
Nathanj94 1:43fbcc3584d6 185 int _objects_speed;
Nathanj94 4:84e29254b988 186 int _lives;
Nathanj94 7:ec6dc66ee196 187 int _delay;
Nathanj94 14:6764bb61d413 188
Nathanj94 14:6764bb61d413 189 //JOYSTICK PARAMETERS//
Nathanj94 0:8d02400f792a 190 Direction _d;
Nathanj94 0:8d02400f792a 191 float _mag;
Nathanj94 14:6764bb61d413 192
Nathanj94 0:8d02400f792a 193 };
Nathanj94 0:8d02400f792a 194 #endif