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
Catch_Model.h@14:6764bb61d413, 2017-04-27 (annotated)
- Committer:
- Nathanj94
- Date:
- Thu Apr 27 12:39:53 2017 +0000
- Revision:
- 14:6764bb61d413
- Parent:
- 13:ae2dac4ab786
- Child:
- 15:1a0bd800f1f1
All documentation added
Who changed what in which revision?
User | Revision | Line number | New 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 | 14:6764bb61d413 | 20 | * |
Nathanj94 | 14:6764bb61d413 | 21 | * Main initialisation function. The parameters are used to call |
Nathanj94 | 14:6764bb61d413 | 22 | * Basket::init(int y, int width) and Objects::init(int speed), as well |
Nathanj94 | 14:6764bb61d413 | 23 | * as set the number of lives/misses the player will be allowed and set |
Nathanj94 | 14:6764bb61d413 | 24 | * the default value of a variable that restricts how often the player |
Nathanj94 | 14:6764bb61d413 | 25 | * can use the A and B buttons. |
Nathanj94 | 14:6764bb61d413 | 26 | * @param basket_y - y co-ordinate of the basket (0 to 47) |
Nathanj94 | 14:6764bb61d413 | 27 | * @param basket_width - width of the basket (0 to 83) |
Nathanj94 | 14:6764bb61d413 | 28 | * @param objects_speed - "fall" speed of the object (2,3,4,5) |
Nathanj94 | 14:6764bb61d413 | 29 | * @param lives - number of lives/misses the player has |
Nathanj94 | 14:6764bb61d413 | 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 | 14:6764bb61d413 | 37 | * |
Nathanj94 | 14:6764bb61d413 | 38 | * Read the direction and magnitude of the joystick and assign |
Nathanj94 | 14:6764bb61d413 | 39 | * the values to variables by calling functions from the Gamepad |
Nathanj94 | 14:6764bb61d413 | 40 | * library. |
Nathanj94 | 14:6764bb61d413 | 41 | * @param pad - Gamepad custom library |
Nathanj94 | 14:6764bb61d413 | 42 | */ |
Nathanj94 | 0:8d02400f792a | 43 | void input(Gamepad &pad); |
Nathanj94 | 14:6764bb61d413 | 44 | |
Nathanj94 | 14:6764bb61d413 | 45 | /** Update Game |
Nathanj94 | 14:6764bb61d413 | 46 | * |
Nathanj94 | 14:6764bb61d413 | 47 | * Checks if an object is caught by the basket or not then increases |
Nathanj94 | 14:6764bb61d413 | 48 | * score or reduces lives appropriately. Moves the basket with either |
Nathanj94 | 14:6764bb61d413 | 49 | * joystick or buttons and moves the objects too. |
Nathanj94 | 14:6764bb61d413 | 50 | * @param lcd - N5110 custom library |
Nathanj94 | 14:6764bb61d413 | 51 | * @param pad - Gamepad custom library |
Nathanj94 | 14:6764bb61d413 | 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 | 14:6764bb61d413 | 59 | * |
Nathanj94 | 14:6764bb61d413 | 60 | * Gets the x and y reference co-ordinates of the basket and the |
Nathanj94 | 14:6764bb61d413 | 61 | * falling object from their respective libraries; if the x co-ordinate |
Nathanj94 | 14:6764bb61d413 | 62 | * of the object is within the width of the basket and the y co-ordinate |
Nathanj94 | 14:6764bb61d413 | 63 | * of the object is greater than that of the basket the object will be |
Nathanj94 | 14:6764bb61d413 | 64 | * undrawn, the appropriate score will be added and the object will be |
Nathanj94 | 14:6764bb61d413 | 65 | * re-initialised. |
Nathanj94 | 14:6764bb61d413 | 66 | * @param lcd - N5110 custom library |
Nathanj94 | 14:6764bb61d413 | 67 | * @param pad - Gamepad custom library |
Nathanj94 | 14:6764bb61d413 | 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 | 14:6764bb61d413 | 72 | * |
Nathanj94 | 14:6764bb61d413 | 73 | * Gets the x and y reference co-ordinates of the basket and the |
Nathanj94 | 14:6764bb61d413 | 74 | * falling object from their respective libraries; if the x co-ordinate |
Nathanj94 | 14:6764bb61d413 | 75 | * of the object is outside the width of the basket and the y co-ordinate |
Nathanj94 | 14:6764bb61d413 | 76 | * of the object is greater than that of the basket the object will be |
Nathanj94 | 14:6764bb61d413 | 77 | * undrawn, the number of lives will be reduced and the object will be |
Nathanj94 | 14:6764bb61d413 | 78 | * re-initialised. |
Nathanj94 | 14:6764bb61d413 | 79 | * @param lcd - N5110 custom library |
Nathanj94 | 14:6764bb61d413 | 80 | * @param pad - Gamepad custom library |
Nathanj94 | 14:6764bb61d413 | 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 | 14:6764bb61d413 | 85 | * |
Nathanj94 | 14:6764bb61d413 | 86 | * Gets the value of a variable from Objects that is specific to each |
Nathanj94 | 14:6764bb61d413 | 87 | * object (type of fruit) and uses it to call the appropriate add_score |
Nathanj94 | 14:6764bb61d413 | 88 | * function from Basket; increasing the score by 1, 2, 5 or 10. |
Nathanj94 | 14:6764bb61d413 | 89 | */ |
Nathanj94 | 5:7db3e43e5aca | 90 | void add_score(); |
Nathanj94 | 14:6764bb61d413 | 91 | |
Nathanj94 | 14:6764bb61d413 | 92 | /** Get Lives |
Nathanj94 | 14:6764bb61d413 | 93 | * |
Nathanj94 | 14:6764bb61d413 | 94 | * Return the remaining number of lives available to the player. |
Nathanj94 | 14:6764bb61d413 | 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 | 14:6764bb61d413 | 102 | * |
Nathanj94 | 14:6764bb61d413 | 103 | * If the A button is pressed, call Objects::undraw(N5110 &lcd) wherever |
Nathanj94 | 14:6764bb61d413 | 104 | * it is on the display and call Objects::init(int speed) to give |
Nathanj94 | 14:6764bb61d413 | 105 | * the player a second chance. Also set the value of a variable to zero |
Nathanj94 | 14:6764bb61d413 | 106 | * so that the function cannot be recalled straight away. |
Nathanj94 | 14:6764bb61d413 | 107 | * @param lcd - N5110 custom library |
Nathanj94 | 14:6764bb61d413 | 108 | * @param pad - Gamepad custom library |
Nathanj94 | 14:6764bb61d413 | 109 | */ |
Nathanj94 | 13:ae2dac4ab786 | 110 | void check_a(N5110 &lcd, Gamepad &pad); |
Nathanj94 | 14:6764bb61d413 | 111 | |
Nathanj94 | 14:6764bb61d413 | 112 | /** Check B Button |
Nathanj94 | 14:6764bb61d413 | 113 | * |
Nathanj94 | 14:6764bb61d413 | 114 | * If the B button is pressed, increase number of lives by 1. Also set |
Nathanj94 | 14:6764bb61d413 | 115 | * the value of a variable to zero so that the function cannot be |
Nathanj94 | 14:6764bb61d413 | 116 | * recalled straight away. |
Nathanj94 | 14:6764bb61d413 | 117 | * @param lcd - N5110 custom library |
Nathanj94 | 14:6764bb61d413 | 118 | * @param pad - Gamepad custom library |
Nathanj94 | 14:6764bb61d413 | 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 | 14:6764bb61d413 | 123 | * |
Nathanj94 | 14:6764bb61d413 | 124 | * 10 seconds after the buttons A or B are pressed this function is called |
Nathanj94 | 14:6764bb61d413 | 125 | * resetting the value of a variable to 1 so the buttons can be used again. |
Nathanj94 | 14:6764bb61d413 | 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 | 14:6764bb61d413 | 133 | * |
Nathanj94 | 14:6764bb61d413 | 134 | * Calls draw functions from the Basket and Objects libraries as well |
Nathanj94 | 14:6764bb61d413 | 135 | * as functions to display the score, remaining lives and an indicator |
Nathanj94 | 14:6764bb61d413 | 136 | * that tells the player if the A and B buttons are ready to be used. |
Nathanj94 | 14:6764bb61d413 | 137 | * @param lcd - N5110 custom library |
Nathanj94 | 14:6764bb61d413 | 138 | */ |
Nathanj94 | 13:ae2dac4ab786 | 139 | void draw(N5110 &lcd); |
Nathanj94 | 14:6764bb61d413 | 140 | |
Nathanj94 | 14:6764bb61d413 | 141 | /** Display the Number of Lives |
Nathanj94 | 14:6764bb61d413 | 142 | * |
Nathanj94 | 14:6764bb61d413 | 143 | * Print a string of characters to the buffer, indicating how many lives |
Nathanj94 | 14:6764bb61d413 | 144 | * remain. |
Nathanj94 | 14:6764bb61d413 | 145 | * @param lcd - N5110 custom library |
Nathanj94 | 14:6764bb61d413 | 146 | */ |
Nathanj94 | 4:84e29254b988 | 147 | void print_lives(N5110 &lcd); |
Nathanj94 | 14:6764bb61d413 | 148 | |
Nathanj94 | 14:6764bb61d413 | 149 | /** Display the Score |
Nathanj94 | 14:6764bb61d413 | 150 | * |
Nathanj94 | 14:6764bb61d413 | 151 | * Print a string of characters to the buffer, indicating the score. |
Nathanj94 | 14:6764bb61d413 | 152 | * @param lcd - N5110 custom library |
Nathanj94 | 14:6764bb61d413 | 153 | */ |
Nathanj94 | 3:fc9133faec7a | 154 | void print_score(N5110 &lcd); |
Nathanj94 | 14:6764bb61d413 | 155 | |
Nathanj94 | 14:6764bb61d413 | 156 | /** Display the Powerup Indicator |
Nathanj94 | 14:6764bb61d413 | 157 | * |
Nathanj94 | 14:6764bb61d413 | 158 | * Print a tick or cross to the buffer, indicating whether or not |
Nathanj94 | 14:6764bb61d413 | 159 | * the A and B buttons are ready to be used. |
Nathanj94 | 14:6764bb61d413 | 160 | * @param lcd - N5110 custom library |
Nathanj94 | 14:6764bb61d413 | 161 | */ |
Nathanj94 | 8:db24c475f64f | 162 | void print_delay(N5110 &lcd); |
Nathanj94 | 14:6764bb61d413 | 163 | |
Nathanj94 | 14:6764bb61d413 | 164 | private: |
Nathanj94 | 14:6764bb61d413 | 165 | |
Nathanj94 | 14:6764bb61d413 | 166 | //OBJECTS// |
Nathanj94 | 4:84e29254b988 | 167 | Basket basket; |
Nathanj94 | 4:84e29254b988 | 168 | Objects objects; |
Nathanj94 | 7:ec6dc66ee196 | 169 | Timeout timeout; |
Nathanj94 | 14:6764bb61d413 | 170 | |
Nathanj94 | 14:6764bb61d413 | 171 | //VARIABLES// |
Nathanj94 | 0:8d02400f792a | 172 | int _basket_y; |
Nathanj94 | 0:8d02400f792a | 173 | int _basket_width; |
Nathanj94 | 1:43fbcc3584d6 | 174 | int _objects_speed; |
Nathanj94 | 4:84e29254b988 | 175 | int _lives; |
Nathanj94 | 7:ec6dc66ee196 | 176 | int _delay; |
Nathanj94 | 14:6764bb61d413 | 177 | |
Nathanj94 | 14:6764bb61d413 | 178 | //JOYSTICK PARAMETERS// |
Nathanj94 | 0:8d02400f792a | 179 | Direction _d; |
Nathanj94 | 0:8d02400f792a | 180 | float _mag; |
Nathanj94 | 14:6764bb61d413 | 181 | |
Nathanj94 | 0:8d02400f792a | 182 | }; |
Nathanj94 | 0:8d02400f792a | 183 | #endif |