Missile Control Game with uLCD
Dependencies: 4DGL-uLCD-SE SDFileSystem mbed wave_player
Fork of missile_command by
main.cpp@2:eba4ed0263a4, 2015-10-20 (annotated)
- Committer:
- ajindia6
- Date:
- Tue Oct 20 19:13:03 2015 +0000
- Revision:
- 2:eba4ed0263a4
- Parent:
- 1:3da29f1d84b4
Mbed Mission Control Game
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
arvahsu | 0:532cb55d6136 | 1 | #include "mbed.h" |
arvahsu | 0:532cb55d6136 | 2 | #include "uLCD_4DGL.h" |
arvahsu | 0:532cb55d6136 | 3 | #include "wave_player.h" |
arvahsu | 0:532cb55d6136 | 4 | #include "SDFileSystem.h" |
arvahsu | 0:532cb55d6136 | 5 | #include "segment_display.h" |
arvahsu | 0:532cb55d6136 | 6 | |
arvahsu | 0:532cb55d6136 | 7 | // Include header files for missile command project |
arvahsu | 0:532cb55d6136 | 8 | #include "globals.h" |
arvahsu | 0:532cb55d6136 | 9 | #include "city_landscape_public.h" |
arvahsu | 0:532cb55d6136 | 10 | #include "missile_public.h" |
arvahsu | 0:532cb55d6136 | 11 | #include "player.h" |
arvahsu | 0:532cb55d6136 | 12 | |
arvahsu | 0:532cb55d6136 | 13 | // Platform initialization |
ajindia6 | 2:eba4ed0263a4 | 14 | DigitalIn left_pb(p23); DigitalIn right_pb(p21); DigitalIn fire_pb(p22); DigitalIn reset_pb(p24); |
arvahsu | 0:532cb55d6136 | 15 | uLCD_4DGL uLCD(p28,p27,p29); |
arvahsu | 0:532cb55d6136 | 16 | AnalogOut DACout(p18); |
arvahsu | 0:532cb55d6136 | 17 | wave_player waver(&DACout); |
arvahsu | 0:532cb55d6136 | 18 | SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, sck, cs |
arvahsu | 0:532cb55d6136 | 19 | |
ajindia6 | 2:eba4ed0263a4 | 20 | |
arvahsu | 0:532cb55d6136 | 21 | void playSound(char * wav); |
ajindia6 | 2:eba4ed0263a4 | 22 | //Initialize variables |
ajindia6 | 2:eba4ed0263a4 | 23 | PLAYER_MISSILE missileArr [5]; |
ajindia6 | 2:eba4ed0263a4 | 24 | PLAYER player; |
ajindia6 | 2:eba4ed0263a4 | 25 | int radius = 10; |
ajindia6 | 2:eba4ed0263a4 | 26 | int missileCount = 5; |
ajindia6 | 2:eba4ed0263a4 | 27 | |
ajindia6 | 2:eba4ed0263a4 | 28 | |
arvahsu | 0:532cb55d6136 | 29 | |
ajindia6 | 2:eba4ed0263a4 | 30 | //draw the anti missile |
ajindia6 | 2:eba4ed0263a4 | 31 | void player_missile_draw(PLAYER_MISSILE missile, int color) { |
ajindia6 | 2:eba4ed0263a4 | 32 | |
ajindia6 | 2:eba4ed0263a4 | 33 | int init_x, init_y, current_x, current_y; |
ajindia6 | 2:eba4ed0263a4 | 34 | init_x = missile.source_x; |
ajindia6 | 2:eba4ed0263a4 | 35 | init_y = 96; |
ajindia6 | 2:eba4ed0263a4 | 36 | current_x = init_x; |
ajindia6 | 2:eba4ed0263a4 | 37 | current_y = missile.y; |
ajindia6 | 2:eba4ed0263a4 | 38 | uLCD.line(init_x, init_y, current_x, current_y, color); |
ajindia6 | 2:eba4ed0263a4 | 39 | } |
ajindia6 | 2:eba4ed0263a4 | 40 | // create the anti missile |
ajindia6 | 2:eba4ed0263a4 | 41 | void player_missile_create(void){ |
ajindia6 | 2:eba4ed0263a4 | 42 | int z; |
ajindia6 | 2:eba4ed0263a4 | 43 | for(z=0;z<5;z++){ |
ajindia6 | 2:eba4ed0263a4 | 44 | if(missileArr[z].status == PLAYER_MISSILE_DEACTIVE){ |
ajindia6 | 2:eba4ed0263a4 | 45 | missileArr[z].y = 96; |
ajindia6 | 2:eba4ed0263a4 | 46 | //each missile has its own tick |
ajindia6 | 2:eba4ed0263a4 | 47 | |
ajindia6 | 2:eba4ed0263a4 | 48 | //set a random source for the missile |
ajindia6 | 2:eba4ed0263a4 | 49 | missileArr[z].source_x = player.x + 5; |
ajindia6 | 2:eba4ed0263a4 | 50 | //set a random target for the missile |
ajindia6 | 2:eba4ed0263a4 | 51 | missileArr[z].origin_y = 96; |
ajindia6 | 2:eba4ed0263a4 | 52 | //the missile starts at its source |
ajindia6 | 2:eba4ed0263a4 | 53 | |
ajindia6 | 2:eba4ed0263a4 | 54 | missileArr[z].status = PLAYER_MISSILE_ACTIVE; |
ajindia6 | 2:eba4ed0263a4 | 55 | break; |
ajindia6 | 2:eba4ed0263a4 | 56 | } |
ajindia6 | 2:eba4ed0263a4 | 57 | } |
ajindia6 | 2:eba4ed0263a4 | 58 | } |
ajindia6 | 2:eba4ed0263a4 | 59 | |
ajindia6 | 2:eba4ed0263a4 | 60 | |
ajindia6 | 2:eba4ed0263a4 | 61 | |
ajindia6 | 2:eba4ed0263a4 | 62 | void player_missile_update_position(void){ |
ajindia6 | 2:eba4ed0263a4 | 63 | int b; |
ajindia6 | 2:eba4ed0263a4 | 64 | //controls how fast the missile will move |
ajindia6 | 2:eba4ed0263a4 | 65 | |
ajindia6 | 2:eba4ed0263a4 | 66 | //delta_x and delta_y account for the slope of the missile |
ajindia6 | 2:eba4ed0263a4 | 67 | double delta_y; |
ajindia6 | 2:eba4ed0263a4 | 68 | for(b=0;b<5;b++){ |
ajindia6 | 2:eba4ed0263a4 | 69 | if(missileArr[b].status == PLAYER_MISSILE_ACTIVE){ |
ajindia6 | 2:eba4ed0263a4 | 70 | // update missile position |
ajindia6 | 2:eba4ed0263a4 | 71 | delta_y = 5; |
ajindia6 | 2:eba4ed0263a4 | 72 | |
ajindia6 | 2:eba4ed0263a4 | 73 | |
ajindia6 | 2:eba4ed0263a4 | 74 | missileArr[b].y = missileArr[b].y - delta_y; |
ajindia6 | 2:eba4ed0263a4 | 75 | |
ajindia6 | 2:eba4ed0263a4 | 76 | |
ajindia6 | 2:eba4ed0263a4 | 77 | // draw missile |
ajindia6 | 2:eba4ed0263a4 | 78 | player_missile_draw(missileArr[b], PLAYER_COLOR); |
ajindia6 | 2:eba4ed0263a4 | 79 | } |
ajindia6 | 2:eba4ed0263a4 | 80 | if(missileArr[b].y < 0) { |
ajindia6 | 2:eba4ed0263a4 | 81 | |
ajindia6 | 2:eba4ed0263a4 | 82 | player_missile_draw(missileArr[b], BLACK_COLOR ); |
ajindia6 | 2:eba4ed0263a4 | 83 | missileArr[b].status = PLAYER_MISSILE_DEACTIVE; |
ajindia6 | 2:eba4ed0263a4 | 84 | |
ajindia6 | 2:eba4ed0263a4 | 85 | |
ajindia6 | 2:eba4ed0263a4 | 86 | |
ajindia6 | 2:eba4ed0263a4 | 87 | } |
ajindia6 | 2:eba4ed0263a4 | 88 | else if(missileArr[b].status == PLAYER_MISSILE_EXPLODED){ |
ajindia6 | 2:eba4ed0263a4 | 89 | // clear the missile on the screen |
ajindia6 | 2:eba4ed0263a4 | 90 | player_missile_draw(missileArr[b], BLACK_COLOR); |
ajindia6 | 2:eba4ed0263a4 | 91 | |
ajindia6 | 2:eba4ed0263a4 | 92 | |
ajindia6 | 2:eba4ed0263a4 | 93 | // we have done with this missile, remove it from record |
ajindia6 | 2:eba4ed0263a4 | 94 | missileArr[b].status = PLAYER_MISSILE_DEACTIVE; |
ajindia6 | 2:eba4ed0263a4 | 95 | //resets the missile's internal tick |
ajindia6 | 2:eba4ed0263a4 | 96 | missileCount = missileCount + 1; |
ajindia6 | 2:eba4ed0263a4 | 97 | |
ajindia6 | 2:eba4ed0263a4 | 98 | |
ajindia6 | 2:eba4ed0263a4 | 99 | } |
ajindia6 | 2:eba4ed0263a4 | 100 | } |
ajindia6 | 2:eba4ed0263a4 | 101 | |
ajindia6 | 2:eba4ed0263a4 | 102 | } |
ajindia6 | 2:eba4ed0263a4 | 103 | |
ajindia6 | 2:eba4ed0263a4 | 104 | void player_set_exploded(int index){ |
ajindia6 | 2:eba4ed0263a4 | 105 | // Error check |
ajindia6 | 2:eba4ed0263a4 | 106 | ASSERT_P(index<MAX_NUM_MISSILE,ERROR_MISSILE_INDEX_UPDATE_STATUS); |
ajindia6 | 2:eba4ed0263a4 | 107 | |
ajindia6 | 2:eba4ed0263a4 | 108 | missileArr[index].status = PLAYER_MISSILE_EXPLODED; |
ajindia6 | 2:eba4ed0263a4 | 109 | missileCount = missileCount + 1; |
ajindia6 | 2:eba4ed0263a4 | 110 | } |
ajindia6 | 2:eba4ed0263a4 | 111 | |
ajindia6 | 2:eba4ed0263a4 | 112 | |
ajindia6 | 2:eba4ed0263a4 | 113 | |
ajindia6 | 2:eba4ed0263a4 | 114 | |
ajindia6 | 2:eba4ed0263a4 | 115 | int main() { |
ajindia6 | 2:eba4ed0263a4 | 116 | |
ajindia6 | 2:eba4ed0263a4 | 117 | uLCD.locate(0, 0); |
ajindia6 | 2:eba4ed0263a4 | 118 | //uLCD.printf("Lvl:", level()); |
ajindia6 | 2:eba4ed0263a4 | 119 | //uLCD.printf("Score: %2d", s); |
ajindia6 | 2:eba4ed0263a4 | 120 | //uLCD.prinf("Missiles: ", |
ajindia6 | 2:eba4ed0263a4 | 121 | //uLCD.printf("Lives: ", |
arvahsu | 0:532cb55d6136 | 122 | setup_sequence(); |
arvahsu | 0:532cb55d6136 | 123 | seg_driver_initialize(); |
arvahsu | 0:532cb55d6136 | 124 | // 2.show numbers |
arvahsu | 0:532cb55d6136 | 125 | int i; |
arvahsu | 0:532cb55d6136 | 126 | for(i=0;i<10;i++){ |
arvahsu | 0:532cb55d6136 | 127 | seg_driver(i); |
arvahsu | 0:532cb55d6136 | 128 | wait(0.2); |
arvahsu | 0:532cb55d6136 | 129 | } |
arvahsu | 0:532cb55d6136 | 130 | |
ajindia6 | 2:eba4ed0263a4 | 131 | |
arvahsu | 0:532cb55d6136 | 132 | playSound("/sd/wavfiles/BUZZER.wav"); |
arvahsu | 0:532cb55d6136 | 133 | |
arvahsu | 0:532cb55d6136 | 134 | |
ajindia6 | 2:eba4ed0263a4 | 135 | // Draw cities |
arvahsu | 0:532cb55d6136 | 136 | city_landscape_init(4); |
arvahsu | 0:532cb55d6136 | 137 | // Initialize the buttons |
arvahsu | 0:532cb55d6136 | 138 | left_pb.mode(PullUp); // The variable left_pb will be zero when the pushbutton for moving the player left is pressed |
arvahsu | 0:532cb55d6136 | 139 | right_pb.mode(PullUp); // The variable rightt_pb will be zero when the pushbutton for moving the player right is pressed |
arvahsu | 0:532cb55d6136 | 140 | fire_pb.mode(PullUp); //the variable fire_pb will be zero when the pushbutton for firing a missile is pressed |
ajindia6 | 2:eba4ed0263a4 | 141 | reset_pb.mode(PullUp); |
arvahsu | 0:532cb55d6136 | 142 | |
ajindia6 | 2:eba4ed0263a4 | 143 | ///Begin the game loop |
ajindia6 | 2:eba4ed0263a4 | 144 | |
ajindia6 | 2:eba4ed0263a4 | 145 | player.x = 60; |
ajindia6 | 2:eba4ed0263a4 | 146 | player_draw(player.x,100); |
ajindia6 | 2:eba4ed0263a4 | 147 | int d, w, l; |
ajindia6 | 2:eba4ed0263a4 | 148 | int s = 0; |
ajindia6 | 2:eba4ed0263a4 | 149 | int cityCount = 4; |
ajindia6 | 2:eba4ed0263a4 | 150 | int lives = 3; |
ajindia6 | 2:eba4ed0263a4 | 151 | |
ajindia6 | 2:eba4ed0263a4 | 152 | |
arvahsu | 0:532cb55d6136 | 153 | while(1){ |
arvahsu | 0:532cb55d6136 | 154 | |
ajindia6 | 2:eba4ed0263a4 | 155 | |
ajindia6 | 2:eba4ed0263a4 | 156 | //print Score and Lives |
ajindia6 | 2:eba4ed0263a4 | 157 | uLCD.locate(0,0); |
ajindia6 | 2:eba4ed0263a4 | 158 | uLCD.color(0x00FF00); |
ajindia6 | 2:eba4ed0263a4 | 159 | uLCD.printf("Score: %2d \n", s); |
ajindia6 | 2:eba4ed0263a4 | 160 | uLCD.printf("Lives: %2d" , lives); |
arvahsu | 0:532cb55d6136 | 161 | |
ajindia6 | 2:eba4ed0263a4 | 162 | if (reset_pb == 0) { |
ajindia6 | 2:eba4ed0263a4 | 163 | while(1) { |
ajindia6 | 2:eba4ed0263a4 | 164 | wait(1); |
ajindia6 | 2:eba4ed0263a4 | 165 | if(reset_pb == 0) { |
ajindia6 | 2:eba4ed0263a4 | 166 | break; |
ajindia6 | 2:eba4ed0263a4 | 167 | } |
ajindia6 | 2:eba4ed0263a4 | 168 | } |
ajindia6 | 2:eba4ed0263a4 | 169 | } |
ajindia6 | 2:eba4ed0263a4 | 170 | |
arvahsu | 0:532cb55d6136 | 171 | |
ajindia6 | 2:eba4ed0263a4 | 172 | //If all 4 pushbuttons are pressed, jump to next level |
ajindia6 | 2:eba4ed0263a4 | 173 | if (((left_pb == 0) && (right_pb == 0) && (fire_pb == 0) && (reset_pb == 0))) { |
ajindia6 | 2:eba4ed0263a4 | 174 | while(1) { |
ajindia6 | 2:eba4ed0263a4 | 175 | uLCD.filled_rectangle(0, 0, 128, 128, 0x000000); |
ajindia6 | 2:eba4ed0263a4 | 176 | uLCD.locate(4, 5); |
ajindia6 | 2:eba4ed0263a4 | 177 | uLCD.printf("Level 2!! \n \n"); |
ajindia6 | 2:eba4ed0263a4 | 178 | uLCD.printf("Incoming missiles are faster!"); |
ajindia6 | 2:eba4ed0263a4 | 179 | |
ajindia6 | 2:eba4ed0263a4 | 180 | wait(5); |
ajindia6 | 2:eba4ed0263a4 | 181 | uLCD.locate(4,5); |
ajindia6 | 2:eba4ed0263a4 | 182 | uLCD.color(0x000000); |
ajindia6 | 2:eba4ed0263a4 | 183 | uLCD.printf("Level 2!! \n \n"); |
ajindia6 | 2:eba4ed0263a4 | 184 | uLCD.printf("Incoming missiles are faster!"); |
ajindia6 | 2:eba4ed0263a4 | 185 | break; |
ajindia6 | 2:eba4ed0263a4 | 186 | } |
ajindia6 | 2:eba4ed0263a4 | 187 | city_landscape_init(4); |
ajindia6 | 2:eba4ed0263a4 | 188 | set_missile_speed(3); |
ajindia6 | 2:eba4ed0263a4 | 189 | player_draw(player.x,100); |
ajindia6 | 2:eba4ed0263a4 | 190 | |
ajindia6 | 2:eba4ed0263a4 | 191 | } |
ajindia6 | 2:eba4ed0263a4 | 192 | |
ajindia6 | 2:eba4ed0263a4 | 193 | missileCount = 5; |
ajindia6 | 2:eba4ed0263a4 | 194 | for(l = 0; l<5; l++) { |
ajindia6 | 2:eba4ed0263a4 | 195 | if(missileArr[l].status == PLAYER_MISSILE_ACTIVE) { |
ajindia6 | 2:eba4ed0263a4 | 196 | missileCount = missileCount - 1; |
ajindia6 | 2:eba4ed0263a4 | 197 | } |
ajindia6 | 2:eba4ed0263a4 | 198 | seg_driver(missileCount); |
ajindia6 | 2:eba4ed0263a4 | 199 | } |
ajindia6 | 2:eba4ed0263a4 | 200 | |
ajindia6 | 2:eba4ed0263a4 | 201 | |
ajindia6 | 2:eba4ed0263a4 | 202 | |
ajindia6 | 2:eba4ed0263a4 | 203 | |
ajindia6 | 2:eba4ed0263a4 | 204 | |
ajindia6 | 2:eba4ed0263a4 | 205 | missile_generator(); /// updates all incoming missiles on the screen |
ajindia6 | 2:eba4ed0263a4 | 206 | |
ajindia6 | 2:eba4ed0263a4 | 207 | |
ajindia6 | 2:eba4ed0263a4 | 208 | if(left_pb == 0 && player.x>0){ |
ajindia6 | 2:eba4ed0263a4 | 209 | //Move player left |
ajindia6 | 2:eba4ed0263a4 | 210 | player_draw(player.x,100); |
ajindia6 | 2:eba4ed0263a4 | 211 | player_delete(player.x,100); |
ajindia6 | 2:eba4ed0263a4 | 212 | player.x = player.x - 10; |
ajindia6 | 2:eba4ed0263a4 | 213 | player_draw(player.x,100); |
ajindia6 | 2:eba4ed0263a4 | 214 | |
arvahsu | 0:532cb55d6136 | 215 | } |
ajindia6 | 2:eba4ed0263a4 | 216 | if(right_pb == 0 && player.x<110){ |
ajindia6 | 2:eba4ed0263a4 | 217 | //Move player right |
ajindia6 | 2:eba4ed0263a4 | 218 | player_draw(player.x,100); |
ajindia6 | 2:eba4ed0263a4 | 219 | player_delete(player.x,100); |
ajindia6 | 2:eba4ed0263a4 | 220 | player.x = player.x + 10; |
ajindia6 | 2:eba4ed0263a4 | 221 | player_draw(player.x,100); |
arvahsu | 0:532cb55d6136 | 222 | } |
arvahsu | 0:532cb55d6136 | 223 | if(fire_pb == 0){ |
ajindia6 | 2:eba4ed0263a4 | 224 | |
ajindia6 | 2:eba4ed0263a4 | 225 | |
ajindia6 | 2:eba4ed0263a4 | 226 | //fire missile and make laser sound |
ajindia6 | 2:eba4ed0263a4 | 227 | player_missile_create(); |
ajindia6 | 2:eba4ed0263a4 | 228 | |
ajindia6 | 2:eba4ed0263a4 | 229 | // |
ajindia6 | 2:eba4ed0263a4 | 230 | playSound("/sd/wavfiles/LASER.wav"); |
ajindia6 | 2:eba4ed0263a4 | 231 | } |
ajindia6 | 2:eba4ed0263a4 | 232 | player_missile_update_position(); |
arvahsu | 0:532cb55d6136 | 233 | |
ajindia6 | 2:eba4ed0263a4 | 234 | //missile-player collision |
ajindia6 | 2:eba4ed0263a4 | 235 | for ( int p=0; p<5; p++) { |
ajindia6 | 2:eba4ed0263a4 | 236 | MISSILE missile_record = missile_get_info(p); |
ajindia6 | 2:eba4ed0263a4 | 237 | |
ajindia6 | 2:eba4ed0263a4 | 238 | int q,w, r, t; |
ajindia6 | 2:eba4ed0263a4 | 239 | q = player.x + 10; |
ajindia6 | 2:eba4ed0263a4 | 240 | w = 100; |
ajindia6 | 2:eba4ed0263a4 | 241 | r = player.x; |
ajindia6 | 2:eba4ed0263a4 | 242 | t = 96; |
ajindia6 | 2:eba4ed0263a4 | 243 | if((missile_record.x > r & missile_record.x<q) & (missile_record.y<w & missile_record.y>t & (missile_record.status==MISSILE_ACTIVE))) { |
ajindia6 | 2:eba4ed0263a4 | 244 | lives -= 1; |
ajindia6 | 2:eba4ed0263a4 | 245 | missile_set_exploded(p); |
ajindia6 | 2:eba4ed0263a4 | 246 | wait(1); |
ajindia6 | 2:eba4ed0263a4 | 247 | if(lives == 0) { |
ajindia6 | 2:eba4ed0263a4 | 248 | gameover(s); |
ajindia6 | 2:eba4ed0263a4 | 249 | |
ajindia6 | 2:eba4ed0263a4 | 250 | break; |
ajindia6 | 2:eba4ed0263a4 | 251 | } |
ajindia6 | 2:eba4ed0263a4 | 252 | |
ajindia6 | 2:eba4ed0263a4 | 253 | for(int j=0; j<11; j=j+3) { |
ajindia6 | 2:eba4ed0263a4 | 254 | uLCD.circle(missile_record.x, missile_record.y, j, YELLOW_COLOR); |
ajindia6 | 2:eba4ed0263a4 | 255 | uLCD.circle(missile_record.x, missile_record.y, j, BLACK_COLOR); |
ajindia6 | 2:eba4ed0263a4 | 256 | |
ajindia6 | 2:eba4ed0263a4 | 257 | |
ajindia6 | 2:eba4ed0263a4 | 258 | } |
ajindia6 | 2:eba4ed0263a4 | 259 | |
ajindia6 | 2:eba4ed0263a4 | 260 | |
arvahsu | 0:532cb55d6136 | 261 | } |
arvahsu | 0:532cb55d6136 | 262 | } |
ajindia6 | 2:eba4ed0263a4 | 263 | |
ajindia6 | 2:eba4ed0263a4 | 264 | |
ajindia6 | 2:eba4ed0263a4 | 265 | |
ajindia6 | 2:eba4ed0263a4 | 266 | //missile-city collision |
ajindia6 | 2:eba4ed0263a4 | 267 | for ( int e=0; e<5; e++) { |
ajindia6 | 2:eba4ed0263a4 | 268 | MISSILE missile_record = missile_get_info(e); |
ajindia6 | 2:eba4ed0263a4 | 269 | for (int d = 0; d<5; d++) { |
ajindia6 | 2:eba4ed0263a4 | 270 | CITY city_record = city_get_info(d); |
ajindia6 | 2:eba4ed0263a4 | 271 | int f, g, h, i; |
ajindia6 | 2:eba4ed0263a4 | 272 | f = city_record.x + city_record.width; |
ajindia6 | 2:eba4ed0263a4 | 273 | g = city_record.y - city_record.height; |
ajindia6 | 2:eba4ed0263a4 | 274 | h = city_record.x; |
ajindia6 | 2:eba4ed0263a4 | 275 | i = city_record.y; |
ajindia6 | 2:eba4ed0263a4 | 276 | if((missile_record.x > h & missile_record.x<f) & (missile_record.y<i & missile_record.y>g) & (city_record.status == EXIST)) { |
ajindia6 | 2:eba4ed0263a4 | 277 | for(int j=0; j<11; j=j+3) { |
ajindia6 | 2:eba4ed0263a4 | 278 | uLCD.circle(missile_record.x, missile_record.y, j, YELLOW_COLOR); |
ajindia6 | 2:eba4ed0263a4 | 279 | uLCD.circle(missile_record.x, missile_record.y, j, BLACK_COLOR); |
ajindia6 | 2:eba4ed0263a4 | 280 | |
ajindia6 | 2:eba4ed0263a4 | 281 | |
ajindia6 | 2:eba4ed0263a4 | 282 | } |
ajindia6 | 2:eba4ed0263a4 | 283 | missile_set_exploded(e); |
ajindia6 | 2:eba4ed0263a4 | 284 | city_destroy(d); |
ajindia6 | 2:eba4ed0263a4 | 285 | cityCount = cityCount -1; |
ajindia6 | 2:eba4ed0263a4 | 286 | if(cityCount == 0) { |
ajindia6 | 2:eba4ed0263a4 | 287 | gameover(s); |
ajindia6 | 2:eba4ed0263a4 | 288 | } |
ajindia6 | 2:eba4ed0263a4 | 289 | |
ajindia6 | 2:eba4ed0263a4 | 290 | break; |
ajindia6 | 2:eba4ed0263a4 | 291 | |
ajindia6 | 2:eba4ed0263a4 | 292 | } |
ajindia6 | 2:eba4ed0263a4 | 293 | |
ajindia6 | 2:eba4ed0263a4 | 294 | } |
ajindia6 | 2:eba4ed0263a4 | 295 | |
ajindia6 | 2:eba4ed0263a4 | 296 | |
ajindia6 | 2:eba4ed0263a4 | 297 | } |
ajindia6 | 2:eba4ed0263a4 | 298 | |
ajindia6 | 2:eba4ed0263a4 | 299 | |
ajindia6 | 2:eba4ed0263a4 | 300 | |
ajindia6 | 2:eba4ed0263a4 | 301 | |
ajindia6 | 2:eba4ed0263a4 | 302 | |
ajindia6 | 2:eba4ed0263a4 | 303 | //missile-player_missile collision |
ajindia6 | 2:eba4ed0263a4 | 304 | for(d=0; d<5; d++) { |
ajindia6 | 2:eba4ed0263a4 | 305 | for(w=0; w<5; w++) { |
ajindia6 | 2:eba4ed0263a4 | 306 | MISSILE missile_record = missile_get_info(w); |
ajindia6 | 2:eba4ed0263a4 | 307 | double f; |
ajindia6 | 2:eba4ed0263a4 | 308 | f = (int)sqrt(pow((double)(missile_record.x-missileArr[d].source_x),2.0) + pow((double)(missile_record.y-missileArr[d].y),2.0)); |
ajindia6 | 2:eba4ed0263a4 | 309 | |
ajindia6 | 2:eba4ed0263a4 | 310 | if((f<radius) && (missile_record.status == MISSILE_ACTIVE) && (missileArr[d].status== PLAYER_MISSILE_ACTIVE)) { |
ajindia6 | 2:eba4ed0263a4 | 311 | for (int j=0; j< (radius+1); j = j+3) { |
ajindia6 | 2:eba4ed0263a4 | 312 | uLCD.circle(missile_record.x, missile_record.y, j, 0xFFFF00); |
ajindia6 | 2:eba4ed0263a4 | 313 | |
ajindia6 | 2:eba4ed0263a4 | 314 | } |
ajindia6 | 2:eba4ed0263a4 | 315 | for (int j=0; j<(radius+1); j=j+3) { |
ajindia6 | 2:eba4ed0263a4 | 316 | uLCD.circle(missile_record.x, missile_record.y, j, BLACK_COLOR); |
ajindia6 | 2:eba4ed0263a4 | 317 | |
ajindia6 | 2:eba4ed0263a4 | 318 | } |
ajindia6 | 2:eba4ed0263a4 | 319 | missile_set_exploded(w); |
ajindia6 | 2:eba4ed0263a4 | 320 | |
ajindia6 | 2:eba4ed0263a4 | 321 | player_set_exploded(d); |
ajindia6 | 2:eba4ed0263a4 | 322 | playSound("/sd/wavfiles/hit.wav"); |
ajindia6 | 2:eba4ed0263a4 | 323 | s= s+1; |
ajindia6 | 2:eba4ed0263a4 | 324 | |
ajindia6 | 2:eba4ed0263a4 | 325 | if (s==10 ) { |
ajindia6 | 2:eba4ed0263a4 | 326 | while(1) { |
ajindia6 | 2:eba4ed0263a4 | 327 | uLCD.filled_rectangle(0, 0, 128, 128, 0x000000); |
ajindia6 | 2:eba4ed0263a4 | 328 | uLCD.locate(4, 5); |
ajindia6 | 2:eba4ed0263a4 | 329 | uLCD.printf("Level 2!! \n \n"); |
ajindia6 | 2:eba4ed0263a4 | 330 | uLCD.printf("Incoming missiles are faster!"); |
ajindia6 | 2:eba4ed0263a4 | 331 | |
ajindia6 | 2:eba4ed0263a4 | 332 | wait(5); |
ajindia6 | 2:eba4ed0263a4 | 333 | uLCD.locate(4,5); |
ajindia6 | 2:eba4ed0263a4 | 334 | uLCD.color(0x000000); |
ajindia6 | 2:eba4ed0263a4 | 335 | uLCD.printf("Level 2!! \n \n"); |
ajindia6 | 2:eba4ed0263a4 | 336 | uLCD.printf("Incoming missiles are faster!"); |
ajindia6 | 2:eba4ed0263a4 | 337 | break; |
ajindia6 | 2:eba4ed0263a4 | 338 | } |
ajindia6 | 2:eba4ed0263a4 | 339 | city_landscape_init(4); |
ajindia6 | 2:eba4ed0263a4 | 340 | set_missile_speed(3); |
ajindia6 | 2:eba4ed0263a4 | 341 | player_draw(player.x,100); |
ajindia6 | 2:eba4ed0263a4 | 342 | |
ajindia6 | 2:eba4ed0263a4 | 343 | } |
ajindia6 | 2:eba4ed0263a4 | 344 | |
ajindia6 | 2:eba4ed0263a4 | 345 | |
ajindia6 | 2:eba4ed0263a4 | 346 | } |
ajindia6 | 2:eba4ed0263a4 | 347 | |
ajindia6 | 2:eba4ed0263a4 | 348 | } |
ajindia6 | 2:eba4ed0263a4 | 349 | |
ajindia6 | 2:eba4ed0263a4 | 350 | } |
ajindia6 | 2:eba4ed0263a4 | 351 | |
ajindia6 | 2:eba4ed0263a4 | 352 | |
ajindia6 | 2:eba4ed0263a4 | 353 | |
ajindia6 | 2:eba4ed0263a4 | 354 | |
ajindia6 | 2:eba4ed0263a4 | 355 | } |
ajindia6 | 2:eba4ed0263a4 | 356 | } |
arvahsu | 0:532cb55d6136 | 357 | |
ajindia6 | 2:eba4ed0263a4 | 358 | |
ajindia6 | 2:eba4ed0263a4 | 359 | |
ajindia6 | 2:eba4ed0263a4 | 360 | void playSound(char * wav) { |
arvahsu | 0:532cb55d6136 | 361 | // open wav file |
arvahsu | 0:532cb55d6136 | 362 | FILE *wave_file; |
arvahsu | 0:532cb55d6136 | 363 | wave_file=fopen(wav,"r"); |
arvahsu | 0:532cb55d6136 | 364 | |
arvahsu | 0:532cb55d6136 | 365 | // play wav file |
arvahsu | 0:532cb55d6136 | 366 | waver.play(wave_file); |
arvahsu | 0:532cb55d6136 | 367 | |
arvahsu | 0:532cb55d6136 | 368 | // close wav file |
arvahsu | 0:532cb55d6136 | 369 | fclose(wave_file); |
arvahsu | 0:532cb55d6136 | 370 | } |
ajindia6 | 2:eba4ed0263a4 | 371 |