A project that creates falling asteroids at random positions along the top of the screen for a space ship at the bottom to shoot, using a Nokia N5110 LCD, joystick and pushbuttons
Dependencies: DebounceIn N5110 PowerControl mbed
main.h@4:51f8b719f671, 2015-05-11 (annotated)
- Committer:
- wray2303
- Date:
- Mon May 11 14:40:23 2015 +0000
- Revision:
- 4:51f8b719f671
- Parent:
- 3:39c95d65bee5
final program bugs fixed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wray2303 | 0:6eba0e66ce01 | 1 | /** |
wray2303 | 0:6eba0e66ce01 | 2 | @file main.h |
wray2303 | 0:6eba0e66ce01 | 3 | @brief Header file containing functions prototypes, defines and global variables. |
wray2303 | 0:6eba0e66ce01 | 4 | @author Louis Wray |
wray2303 | 0:6eba0e66ce01 | 5 | @date 14th April 2015 |
wray2303 | 0:6eba0e66ce01 | 6 | */ |
wray2303 | 0:6eba0e66ce01 | 7 | |
wray2303 | 0:6eba0e66ce01 | 8 | #ifndef MAIN_H |
wray2303 | 0:6eba0e66ce01 | 9 | #define MAIN_H |
wray2303 | 0:6eba0e66ce01 | 10 | #include "mbed.h" |
wray2303 | 0:6eba0e66ce01 | 11 | #include "N5110.h" |
wray2303 | 0:6eba0e66ce01 | 12 | #include "PowerControl/PowerControl.h" |
wray2303 | 0:6eba0e66ce01 | 13 | #include "PowerControl/EthernetPowerControl.h" |
wray2303 | 0:6eba0e66ce01 | 14 | #include "DebounceIn.h" |
wray2303 | 0:6eba0e66ce01 | 15 | #define DIRECTION_TOLERANCE 0.05 |
wray2303 | 0:6eba0e66ce01 | 16 | |
wray2303 | 0:6eba0e66ce01 | 17 | /** |
wray2303 | 2:8d28a2f491eb | 18 | @namespace LocalFileSystem |
wray2303 | 2:8d28a2f491eb | 19 | @brief defines a local filesystem |
wray2303 | 2:8d28a2f491eb | 20 | */ |
wray2303 | 2:8d28a2f491eb | 21 | LocalFileSystem local("local"); // create local filesystem |
wray2303 | 2:8d28a2f491eb | 22 | |
wray2303 | 2:8d28a2f491eb | 23 | /** |
wray2303 | 0:6eba0e66ce01 | 24 | @namespace button |
wray2303 | 0:6eba0e66ce01 | 25 | @brief represents button input pin from joystick |
wray2303 | 0:6eba0e66ce01 | 26 | */ |
wray2303 | 0:6eba0e66ce01 | 27 | DebounceIn button(p17); |
wray2303 | 0:6eba0e66ce01 | 28 | |
wray2303 | 0:6eba0e66ce01 | 29 | /** |
wray2303 | 0:6eba0e66ce01 | 30 | @namespace buzzer |
wray2303 | 0:6eba0e66ce01 | 31 | @brief represents buzzer output pin from pwm |
wray2303 | 0:6eba0e66ce01 | 32 | */ |
wray2303 | 0:6eba0e66ce01 | 33 | PwmOut PWM1(p25); |
wray2303 | 0:6eba0e66ce01 | 34 | |
wray2303 | 0:6eba0e66ce01 | 35 | /** |
wray2303 | 0:6eba0e66ce01 | 36 | @namespace xPot |
wray2303 | 0:6eba0e66ce01 | 37 | @brief analog input from potentiometer reading x position |
wray2303 | 0:6eba0e66ce01 | 38 | */ |
wray2303 | 0:6eba0e66ce01 | 39 | AnalogIn xPot(p15); |
wray2303 | 0:6eba0e66ce01 | 40 | |
wray2303 | 0:6eba0e66ce01 | 41 | /** |
wray2303 | 0:6eba0e66ce01 | 42 | @namespace yPot |
wray2303 | 0:6eba0e66ce01 | 43 | @brief analog input from potentiometer reading y position |
wray2303 | 0:6eba0e66ce01 | 44 | */ |
wray2303 | 0:6eba0e66ce01 | 45 | AnalogIn yPot(p16); |
wray2303 | 0:6eba0e66ce01 | 46 | |
wray2303 | 0:6eba0e66ce01 | 47 | /** |
wray2303 | 0:6eba0e66ce01 | 48 | @namespace randomPin |
wray2303 | 0:6eba0e66ce01 | 49 | @brief analog input to seed random function |
wray2303 | 0:6eba0e66ce01 | 50 | */ |
wray2303 | 0:6eba0e66ce01 | 51 | AnalogIn randomPin(p19); |
wray2303 | 0:6eba0e66ce01 | 52 | |
wray2303 | 0:6eba0e66ce01 | 53 | /** |
wray2303 | 0:6eba0e66ce01 | 54 | @namespace serial |
wray2303 | 0:6eba0e66ce01 | 55 | @brief serial connection established |
wray2303 | 0:6eba0e66ce01 | 56 | */ |
wray2303 | 0:6eba0e66ce01 | 57 | Serial serial(USBTX,USBRX); |
wray2303 | 0:6eba0e66ce01 | 58 | |
wray2303 | 0:6eba0e66ce01 | 59 | /** |
wray2303 | 0:6eba0e66ce01 | 60 | @namespace myled |
wray2303 | 0:6eba0e66ce01 | 61 | @brief GPIO for on board mbed LED1 |
wray2303 | 0:6eba0e66ce01 | 62 | */ |
wray2303 | 0:6eba0e66ce01 | 63 | DigitalOut myled(LED1); |
wray2303 | 0:6eba0e66ce01 | 64 | |
wray2303 | 0:6eba0e66ce01 | 65 | /** |
wray2303 | 0:6eba0e66ce01 | 66 | @namespace lcd |
wray2303 | 0:6eba0e66ce01 | 67 | @brief creates object for display. |
wray2303 | 0:6eba0e66ce01 | 68 | @brief shows pins used and there configuration |
wray2303 | 0:6eba0e66ce01 | 69 | */ |
wray2303 | 0:6eba0e66ce01 | 70 | N5110 lcd(p7,p8,p9,p10,p11,p13,p26); // pin settings |
wray2303 | 0:6eba0e66ce01 | 71 | |
wray2303 | 0:6eba0e66ce01 | 72 | /** |
wray2303 | 0:6eba0e66ce01 | 73 | @namespace buttonS |
wray2303 | 0:6eba0e66ce01 | 74 | @brief creates interrupt in for shooting function. |
wray2303 | 0:6eba0e66ce01 | 75 | */ |
wray2303 | 0:6eba0e66ce01 | 76 | DebounceIn buttonS(p22); // create interrupt button shoot |
wray2303 | 0:6eba0e66ce01 | 77 | |
wray2303 | 0:6eba0e66ce01 | 78 | /** |
wray2303 | 0:6eba0e66ce01 | 79 | @namespace buttonP |
wray2303 | 0:6eba0e66ce01 | 80 | @brief creates interrupt in for other functions. |
wray2303 | 0:6eba0e66ce01 | 81 | */ |
wray2303 | 0:6eba0e66ce01 | 82 | DebounceIn buttonP(p23); // create interrupt button |
wray2303 | 0:6eba0e66ce01 | 83 | |
wray2303 | 0:6eba0e66ce01 | 84 | /** |
wray2303 | 0:6eba0e66ce01 | 85 | @brief class created for user component ship. |
wray2303 | 0:6eba0e66ce01 | 86 | *code will access the components of this ship class to control user component on the screen |
wray2303 | 0:6eba0e66ce01 | 87 | */ |
wray2303 | 0:6eba0e66ce01 | 88 | class Ship |
wray2303 | 0:6eba0e66ce01 | 89 | { |
wray2303 | 0:6eba0e66ce01 | 90 | public: |
wray2303 | 0:6eba0e66ce01 | 91 | int xs; /**< ships integer x coordinate */ |
wray2303 | 0:6eba0e66ce01 | 92 | int ys; /**< ships integer y coordinate */ |
wray2303 | 0:6eba0e66ce01 | 93 | |
wray2303 | 0:6eba0e66ce01 | 94 | /** |
wray2303 | 0:6eba0e66ce01 | 95 | *set the values for the ship, used for drawing and moving etc |
wray2303 | 0:6eba0e66ce01 | 96 | */ |
wray2303 | 0:6eba0e66ce01 | 97 | void SetValues(int,int); |
wray2303 | 0:6eba0e66ce01 | 98 | |
wray2303 | 0:6eba0e66ce01 | 99 | /** |
wray2303 | 0:6eba0e66ce01 | 100 | *function to draw ships shape |
wray2303 | 0:6eba0e66ce01 | 101 | @param xs - ships integer x coordinate |
wray2303 | 0:6eba0e66ce01 | 102 | @param ys - ships integer y coordinate |
wray2303 | 0:6eba0e66ce01 | 103 | */ |
wray2303 | 0:6eba0e66ce01 | 104 | void shape() { |
wray2303 | 0:6eba0e66ce01 | 105 | lcd.drawLine(xs,ys,xs-5,ys+6,1); |
wray2303 | 0:6eba0e66ce01 | 106 | lcd.drawLine(xs,ys,xs+5,ys+6,1); |
wray2303 | 0:6eba0e66ce01 | 107 | lcd.drawLine(xs-5,ys+6,xs+5,ys+6,1); |
wray2303 | 0:6eba0e66ce01 | 108 | lcd.setPixel(xs-3,ys+7); |
wray2303 | 0:6eba0e66ce01 | 109 | lcd.setPixel(xs+3,ys+7); |
wray2303 | 0:6eba0e66ce01 | 110 | // lcd.refresh(); |
wray2303 | 0:6eba0e66ce01 | 111 | } |
wray2303 | 0:6eba0e66ce01 | 112 | |
wray2303 | 0:6eba0e66ce01 | 113 | /** |
wray2303 | 0:6eba0e66ce01 | 114 | *function for moving the ship to the left |
wray2303 | 0:6eba0e66ce01 | 115 | */ |
wray2303 | 0:6eba0e66ce01 | 116 | void ShipLeft() { |
wray2303 | 0:6eba0e66ce01 | 117 | xs = xs-1; |
wray2303 | 0:6eba0e66ce01 | 118 | clearShapeL(); |
wray2303 | 0:6eba0e66ce01 | 119 | shape(); |
wray2303 | 0:6eba0e66ce01 | 120 | } |
wray2303 | 0:6eba0e66ce01 | 121 | |
wray2303 | 0:6eba0e66ce01 | 122 | /** |
wray2303 | 0:6eba0e66ce01 | 123 | *function for moving the ship to the right |
wray2303 | 0:6eba0e66ce01 | 124 | */ |
wray2303 | 0:6eba0e66ce01 | 125 | void ShipRight() { |
wray2303 | 0:6eba0e66ce01 | 126 | xs = xs+1; |
wray2303 | 0:6eba0e66ce01 | 127 | clearShapeR(); |
wray2303 | 0:6eba0e66ce01 | 128 | shape(); |
wray2303 | 0:6eba0e66ce01 | 129 | } |
wray2303 | 0:6eba0e66ce01 | 130 | |
wray2303 | 0:6eba0e66ce01 | 131 | /** |
wray2303 | 0:6eba0e66ce01 | 132 | *function for clearing the previous shape when moved to the left |
wray2303 | 0:6eba0e66ce01 | 133 | */ |
wray2303 | 0:6eba0e66ce01 | 134 | void clearShapeL() { |
wray2303 | 0:6eba0e66ce01 | 135 | lcd.drawLine(xs+1,ys,xs-4,ys+6,0); |
wray2303 | 0:6eba0e66ce01 | 136 | lcd.drawLine(xs+1,ys,xs+6,ys+6,0); |
wray2303 | 0:6eba0e66ce01 | 137 | lcd.drawLine(xs-4,ys+6,xs+6,ys+6,0); |
wray2303 | 0:6eba0e66ce01 | 138 | lcd.clearPixel(xs-2,ys+7); |
wray2303 | 0:6eba0e66ce01 | 139 | lcd.clearPixel(xs+4,ys+7); |
wray2303 | 0:6eba0e66ce01 | 140 | } |
wray2303 | 0:6eba0e66ce01 | 141 | |
wray2303 | 0:6eba0e66ce01 | 142 | /** |
wray2303 | 0:6eba0e66ce01 | 143 | *function for clearing the previous shape when moved to the right |
wray2303 | 0:6eba0e66ce01 | 144 | */ |
wray2303 | 0:6eba0e66ce01 | 145 | void clearShapeR() { |
wray2303 | 0:6eba0e66ce01 | 146 | lcd.drawLine(xs-1,ys,xs-6,ys+6,0); |
wray2303 | 0:6eba0e66ce01 | 147 | lcd.drawLine(xs-1,ys,xs+4,ys+6,0); |
wray2303 | 0:6eba0e66ce01 | 148 | lcd.drawLine(xs-6,ys+6,xs+4,ys+6,0); |
wray2303 | 0:6eba0e66ce01 | 149 | lcd.clearPixel(xs-4,ys+7); |
wray2303 | 0:6eba0e66ce01 | 150 | lcd.clearPixel(xs+2,ys+7); |
wray2303 | 0:6eba0e66ce01 | 151 | } |
wray2303 | 0:6eba0e66ce01 | 152 | } ship; |
wray2303 | 0:6eba0e66ce01 | 153 | |
wray2303 | 0:6eba0e66ce01 | 154 | /** function which sets the ships xs and ys coordinates, used in the main program as an initialisation |
wray2303 | 0:6eba0e66ce01 | 155 | @param X - integer value to set xs |
wray2303 | 0:6eba0e66ce01 | 156 | @param Y - integer value to set ys |
wray2303 | 0:6eba0e66ce01 | 157 | */ |
wray2303 | 0:6eba0e66ce01 | 158 | void Ship::SetValues(int X,int Y) |
wray2303 | 0:6eba0e66ce01 | 159 | { |
wray2303 | 0:6eba0e66ce01 | 160 | xs = X; |
wray2303 | 0:6eba0e66ce01 | 161 | ys = Y; |
wray2303 | 0:6eba0e66ce01 | 162 | } |
wray2303 | 0:6eba0e66ce01 | 163 | |
wray2303 | 0:6eba0e66ce01 | 164 | /** |
wray2303 | 0:6eba0e66ce01 | 165 | @brief class created for bullet fired. |
wray2303 | 0:6eba0e66ce01 | 166 | *code will access the components of this Bullet class to control the bullet |
wray2303 | 0:6eba0e66ce01 | 167 | */ |
wray2303 | 0:6eba0e66ce01 | 168 | class Bullet |
wray2303 | 0:6eba0e66ce01 | 169 | { |
wray2303 | 0:6eba0e66ce01 | 170 | public: |
wray2303 | 0:6eba0e66ce01 | 171 | int x; /**< bullets integer x coordinate */ |
wray2303 | 0:6eba0e66ce01 | 172 | int y; /**< bullets integer y coordinate */ |
wray2303 | 0:6eba0e66ce01 | 173 | |
wray2303 | 0:6eba0e66ce01 | 174 | /** |
wray2303 | 0:6eba0e66ce01 | 175 | *set the values for the bullet, used when first fired for other commands to work off |
wray2303 | 0:6eba0e66ce01 | 176 | */ |
wray2303 | 0:6eba0e66ce01 | 177 | void SetValues(int,int); |
wray2303 | 0:6eba0e66ce01 | 178 | |
wray2303 | 0:6eba0e66ce01 | 179 | /** |
wray2303 | 0:6eba0e66ce01 | 180 | *function to draw bullets shape |
wray2303 | 0:6eba0e66ce01 | 181 | @param x - bullets integer x coordinate |
wray2303 | 0:6eba0e66ce01 | 182 | @param y - bullets integer y coordinate |
wray2303 | 0:6eba0e66ce01 | 183 | */ |
wray2303 | 0:6eba0e66ce01 | 184 | void createBullet() { |
wray2303 | 0:6eba0e66ce01 | 185 | lcd.setPixel(x,y); |
wray2303 | 0:6eba0e66ce01 | 186 | lcd.setPixel(x+1,y); |
wray2303 | 0:6eba0e66ce01 | 187 | lcd.setPixel(x-1,y); |
wray2303 | 0:6eba0e66ce01 | 188 | lcd.setPixel(x,y-1); |
wray2303 | 0:6eba0e66ce01 | 189 | lcd.refresh(); |
wray2303 | 0:6eba0e66ce01 | 190 | } |
wray2303 | 0:6eba0e66ce01 | 191 | |
wray2303 | 0:6eba0e66ce01 | 192 | /** |
wray2303 | 0:6eba0e66ce01 | 193 | *function to erase previous bullets when moving forward |
wray2303 | 0:6eba0e66ce01 | 194 | *always followed by create bullet so no need for lcd refresh when drawing |
wray2303 | 0:6eba0e66ce01 | 195 | */ |
wray2303 | 0:6eba0e66ce01 | 196 | void erasePrevBullet() { |
wray2303 | 0:6eba0e66ce01 | 197 | lcd.clearPixel(x,y+1); |
wray2303 | 0:6eba0e66ce01 | 198 | lcd.clearPixel(x+1,y+1); |
wray2303 | 0:6eba0e66ce01 | 199 | lcd.clearPixel(x-1,y+1); |
wray2303 | 0:6eba0e66ce01 | 200 | } |
wray2303 | 0:6eba0e66ce01 | 201 | |
wray2303 | 0:6eba0e66ce01 | 202 | /** |
wray2303 | 0:6eba0e66ce01 | 203 | *bool function, which determines whether the bullet has collided with any enemies returns true or false |
wray2303 | 0:6eba0e66ce01 | 204 | */ |
wray2303 | 0:6eba0e66ce01 | 205 | bool collision() { |
wray2303 | 0:6eba0e66ce01 | 206 | if(lcd.getPixel(x+1,y-1)||lcd.getPixel(x-1,y-1)||lcd.getPixel(x,y-2)) { |
wray2303 | 0:6eba0e66ce01 | 207 | clearBullet(); |
wray2303 | 0:6eba0e66ce01 | 208 | return true; |
wray2303 | 0:6eba0e66ce01 | 209 | } else {return false;} |
wray2303 | 0:6eba0e66ce01 | 210 | } |
wray2303 | 0:6eba0e66ce01 | 211 | /** |
wray2303 | 0:6eba0e66ce01 | 212 | *bool function, which determines whether the bullet has reached the edge of the screen returns true or false |
wray2303 | 0:6eba0e66ce01 | 213 | */ |
wray2303 | 0:6eba0e66ce01 | 214 | bool offScreen() { |
wray2303 | 0:6eba0e66ce01 | 215 | if(y<4) { |
wray2303 | 0:6eba0e66ce01 | 216 | clearBullet(); |
wray2303 | 0:6eba0e66ce01 | 217 | return true; |
wray2303 | 0:6eba0e66ce01 | 218 | } else { |
wray2303 | 0:6eba0e66ce01 | 219 | return false; |
wray2303 | 0:6eba0e66ce01 | 220 | } |
wray2303 | 0:6eba0e66ce01 | 221 | } |
wray2303 | 0:6eba0e66ce01 | 222 | /** |
wray2303 | 0:6eba0e66ce01 | 223 | *function to clear bullets current position |
wray2303 | 0:6eba0e66ce01 | 224 | */ |
wray2303 | 0:6eba0e66ce01 | 225 | void clearBullet() { |
wray2303 | 0:6eba0e66ce01 | 226 | lcd.clearPixel(x,y); |
wray2303 | 0:6eba0e66ce01 | 227 | lcd.clearPixel(x+1,y); |
wray2303 | 0:6eba0e66ce01 | 228 | lcd.clearPixel(x-1,y); |
wray2303 | 0:6eba0e66ce01 | 229 | lcd.clearPixel(x,y-1); |
wray2303 | 0:6eba0e66ce01 | 230 | lcd.refresh(); |
wray2303 | 0:6eba0e66ce01 | 231 | } |
wray2303 | 0:6eba0e66ce01 | 232 | } bullet; |
wray2303 | 0:6eba0e66ce01 | 233 | |
wray2303 | 0:6eba0e66ce01 | 234 | /** function which sets the bullets x and y coordinates, used in the shooting program to initialise where the bullet was fired |
wray2303 | 0:6eba0e66ce01 | 235 | @param Xb - integer value to set x |
wray2303 | 0:6eba0e66ce01 | 236 | @param Yb - integer value to set y |
wray2303 | 0:6eba0e66ce01 | 237 | */ |
wray2303 | 0:6eba0e66ce01 | 238 | void Bullet::SetValues(int Xb,int Yb) |
wray2303 | 0:6eba0e66ce01 | 239 | { |
wray2303 | 0:6eba0e66ce01 | 240 | x = Xb; |
wray2303 | 0:6eba0e66ce01 | 241 | y = Yb; |
wray2303 | 0:6eba0e66ce01 | 242 | } |
wray2303 | 0:6eba0e66ce01 | 243 | |
wray2303 | 0:6eba0e66ce01 | 244 | /** |
wray2303 | 0:6eba0e66ce01 | 245 | @brief class created for Asteroids. |
wray2303 | 0:6eba0e66ce01 | 246 | *code will access the components of this Asteroid class to control the Asteroid |
wray2303 | 0:6eba0e66ce01 | 247 | */ |
wray2303 | 0:6eba0e66ce01 | 248 | class Asteroid |
wray2303 | 0:6eba0e66ce01 | 249 | { |
wray2303 | 0:6eba0e66ce01 | 250 | public: |
wray2303 | 0:6eba0e66ce01 | 251 | int xa; /**< asteroids integer x coordinate */ |
wray2303 | 0:6eba0e66ce01 | 252 | int ya; /**< asteroids integer y coordinate */ |
wray2303 | 0:6eba0e66ce01 | 253 | int nscore; /**< an integer value score that increments every time the player has destroyed an asteroid */ |
wray2303 | 0:6eba0e66ce01 | 254 | |
wray2303 | 0:6eba0e66ce01 | 255 | /** |
wray2303 | 0:6eba0e66ce01 | 256 | *set the x value for the asteroid, used at intervals called by a ticker |
wray2303 | 0:6eba0e66ce01 | 257 | */ |
wray2303 | 0:6eba0e66ce01 | 258 | void SetAsteroidValue(int,int); |
wray2303 | 0:6eba0e66ce01 | 259 | |
wray2303 | 0:6eba0e66ce01 | 260 | /** |
wray2303 | 0:6eba0e66ce01 | 261 | *function to draw and asteroid according to given coordinates |
wray2303 | 0:6eba0e66ce01 | 262 | */ |
wray2303 | 0:6eba0e66ce01 | 263 | void createAsteroid() { |
wray2303 | 0:6eba0e66ce01 | 264 | lcd.drawCircle(xa,ya,3,0,1); |
wray2303 | 0:6eba0e66ce01 | 265 | lcd.refresh(); |
wray2303 | 0:6eba0e66ce01 | 266 | } |
wray2303 | 0:6eba0e66ce01 | 267 | |
wray2303 | 0:6eba0e66ce01 | 268 | /** |
wray2303 | 0:6eba0e66ce01 | 269 | *function to clear previous asteroid when moving forward(forward being from the aseroids point of view, looking at |
wray2303 | 0:6eba0e66ce01 | 270 | *the screen would be downwards) |
wray2303 | 0:6eba0e66ce01 | 271 | */ |
wray2303 | 0:6eba0e66ce01 | 272 | void erasePrevAsteroid() { |
wray2303 | 0:6eba0e66ce01 | 273 | lcd.drawCircle(xa,ya-1,3,0,0); |
wray2303 | 0:6eba0e66ce01 | 274 | lcd.refresh(); |
wray2303 | 0:6eba0e66ce01 | 275 | } |
wray2303 | 0:6eba0e66ce01 | 276 | |
wray2303 | 0:6eba0e66ce01 | 277 | /** |
wray2303 | 0:6eba0e66ce01 | 278 | *function to eliminate asteroid, this will be called when a bullet has made a collision with the asteroid |
wray2303 | 0:6eba0e66ce01 | 279 | */ |
wray2303 | 0:6eba0e66ce01 | 280 | void destroyAsteroid() { |
wray2303 | 0:6eba0e66ce01 | 281 | lcd.drawCircle(xa,ya,3,0,0); |
wray2303 | 0:6eba0e66ce01 | 282 | nscore = nscore+1; |
wray2303 | 0:6eba0e66ce01 | 283 | bullet.clearBullet(); |
wray2303 | 0:6eba0e66ce01 | 284 | lcd.refresh(); |
wray2303 | 0:6eba0e66ce01 | 285 | } |
wray2303 | 0:6eba0e66ce01 | 286 | |
wray2303 | 0:6eba0e66ce01 | 287 | /** |
wray2303 | 0:6eba0e66ce01 | 288 | *boolean function which returns true or false, determining whether the asteroid has reached the bottom of the screen or not |
wray2303 | 0:6eba0e66ce01 | 289 | */ |
wray2303 | 0:6eba0e66ce01 | 290 | bool armageddon() { |
wray2303 | 0:6eba0e66ce01 | 291 | if(ya+4 == 47) { |
wray2303 | 0:6eba0e66ce01 | 292 | return true; |
wray2303 | 0:6eba0e66ce01 | 293 | } else { |
wray2303 | 0:6eba0e66ce01 | 294 | return false; |
wray2303 | 0:6eba0e66ce01 | 295 | } |
wray2303 | 0:6eba0e66ce01 | 296 | } |
wray2303 | 0:6eba0e66ce01 | 297 | } asteroid; |
wray2303 | 0:6eba0e66ce01 | 298 | |
wray2303 | 0:6eba0e66ce01 | 299 | /** function which sets the asteroids x position (y posisition is set to top of the screen) |
wray2303 | 0:6eba0e66ce01 | 300 | @param XA - integer value to set xa |
wray2303 | 0:6eba0e66ce01 | 301 | @param YA - integer value to set ya |
wray2303 | 0:6eba0e66ce01 | 302 | */ |
wray2303 | 0:6eba0e66ce01 | 303 | void Asteroid::SetAsteroidValue(int XA, int YA) |
wray2303 | 0:6eba0e66ce01 | 304 | { |
wray2303 | 0:6eba0e66ce01 | 305 | xa = XA; |
wray2303 | 0:6eba0e66ce01 | 306 | ya = YA; |
wray2303 | 0:6eba0e66ce01 | 307 | } |
wray2303 | 0:6eba0e66ce01 | 308 | |
wray2303 | 0:6eba0e66ce01 | 309 | /** |
wray2303 | 0:6eba0e66ce01 | 310 | *function prototype to caibrate the joystick and centre values |
wray2303 | 0:6eba0e66ce01 | 311 | */ |
wray2303 | 0:6eba0e66ce01 | 312 | void calibrateJoystick(); |
wray2303 | 0:6eba0e66ce01 | 313 | |
wray2303 | 0:6eba0e66ce01 | 314 | /** |
wray2303 | 0:6eba0e66ce01 | 315 | *function which when called upon will update the joystick position |
wray2303 | 0:6eba0e66ce01 | 316 | */ |
wray2303 | 0:6eba0e66ce01 | 317 | void updateJoystick(); |
wray2303 | 0:6eba0e66ce01 | 318 | |
wray2303 | 0:6eba0e66ce01 | 319 | /** |
wray2303 | 0:6eba0e66ce01 | 320 | *function which shows initial display and sleeps(low power sleep) untill interrupt made and game started |
wray2303 | 0:6eba0e66ce01 | 321 | */ |
wray2303 | 0:6eba0e66ce01 | 322 | void startUpDisplay(); |
wray2303 | 0:6eba0e66ce01 | 323 | |
wray2303 | 0:6eba0e66ce01 | 324 | /** |
wray2303 | 0:6eba0e66ce01 | 325 | *function for gameplay |
wray2303 | 0:6eba0e66ce01 | 326 | */ |
wray2303 | 0:6eba0e66ce01 | 327 | void Game(); |
wray2303 | 0:6eba0e66ce01 | 328 | |
wray2303 | 0:6eba0e66ce01 | 329 | /** |
wray2303 | 0:6eba0e66ce01 | 330 | *function which reads the position of the bullet on screen and reprints according to position also checking |
wray2303 | 0:6eba0e66ce01 | 331 | *whether it has made contact with enemies or the end of the screen |
wray2303 | 0:6eba0e66ce01 | 332 | */ |
wray2303 | 0:6eba0e66ce01 | 333 | void ReadBullet(); |
wray2303 | 0:6eba0e66ce01 | 334 | |
wray2303 | 0:6eba0e66ce01 | 335 | /** |
wray2303 | 0:6eba0e66ce01 | 336 | *function which reads the position and state of the asteroid and refeshes accordingly |
wray2303 | 0:6eba0e66ce01 | 337 | */ |
wray2303 | 0:6eba0e66ce01 | 338 | void ReadAsteroid(); |
wray2303 | 0:6eba0e66ce01 | 339 | |
wray2303 | 0:6eba0e66ce01 | 340 | /** |
wray2303 | 0:6eba0e66ce01 | 341 | *function which shows end display with score, and sleeps(low power sleep) untill interrupt made and game re-started |
wray2303 | 0:6eba0e66ce01 | 342 | */ |
wray2303 | 0:6eba0e66ce01 | 343 | void EndDisplay(); |
wray2303 | 0:6eba0e66ce01 | 344 | |
wray2303 | 0:6eba0e66ce01 | 345 | /** |
wray2303 | 0:6eba0e66ce01 | 346 | *function which shows Pause Display and will restart when shoot button pressed , sleep() mode untill then |
wray2303 | 0:6eba0e66ce01 | 347 | */ |
wray2303 | 0:6eba0e66ce01 | 348 | void PauseDisplay(); |
wray2303 | 0:6eba0e66ce01 | 349 | |
wray2303 | 2:8d28a2f491eb | 350 | /** |
wray2303 | 2:8d28a2f491eb | 351 | *funtion to read from the local file system created |
wray2303 | 2:8d28a2f491eb | 352 | *used in highscore |
wray2303 | 2:8d28a2f491eb | 353 | */ |
wray2303 | 2:8d28a2f491eb | 354 | void Read(); |
wray2303 | 2:8d28a2f491eb | 355 | |
wray2303 | 2:8d28a2f491eb | 356 | /** |
wray2303 | 2:8d28a2f491eb | 357 | *funtion to write to the local file system created |
wray2303 | 2:8d28a2f491eb | 358 | *used in highscore |
wray2303 | 2:8d28a2f491eb | 359 | */ |
wray2303 | 2:8d28a2f491eb | 360 | void Write(); |
wray2303 | 2:8d28a2f491eb | 361 | |
wray2303 | 3:39c95d65bee5 | 362 | /** |
wray2303 | 3:39c95d65bee5 | 363 | *funtion to flag the end screen for timeout |
wray2303 | 3:39c95d65bee5 | 364 | */ |
wray2303 | 3:39c95d65bee5 | 365 | void endState(); |
wray2303 | 3:39c95d65bee5 | 366 | |
wray2303 | 3:39c95d65bee5 | 367 | |
wray2303 | 3:39c95d65bee5 | 368 | |
wray2303 | 0:6eba0e66ce01 | 369 | #endif |