ECE2035 class project

Dependencies:   4DGL-uLCD-SE SDFileSystem mbed wave_player

Fork of missile_command by ECE 2035 TA

Committer:
slin77
Date:
Mon Nov 17 21:23:02 2014 +0000
Revision:
5:3f356592ee9c
Parent:
4:0dc720aa3c71
add big_shoot

Who changed what in which revision?

UserRevisionLine numberNew contents of line
arvahsu 0:532cb55d6136 1 /* Gatech ECE2035 2014 FALL missile command
arvahsu 0:532cb55d6136 2 * Copyright (c) 2014 Gatech ECE2035
arvahsu 0:532cb55d6136 3 *
arvahsu 0:532cb55d6136 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
arvahsu 0:532cb55d6136 5 * of this software and associated documentation files (the "Software"), to deal
arvahsu 0:532cb55d6136 6 * in the Software without restriction, including without limitation the rights
arvahsu 0:532cb55d6136 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
arvahsu 0:532cb55d6136 8 * copies of the Software, and to permit persons to whom the Software is
arvahsu 0:532cb55d6136 9 * furnished to do so, subject to the following conditions:
arvahsu 0:532cb55d6136 10 *
arvahsu 0:532cb55d6136 11 * The above copyright notice and this permission notice shall be included in
arvahsu 0:532cb55d6136 12 * all copies or substantial portions of the Software.
arvahsu 0:532cb55d6136 13 *
arvahsu 0:532cb55d6136 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
arvahsu 0:532cb55d6136 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
arvahsu 0:532cb55d6136 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
arvahsu 0:532cb55d6136 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
arvahsu 0:532cb55d6136 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
arvahsu 0:532cb55d6136 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
arvahsu 0:532cb55d6136 20 * SOFTWARE.
arvahsu 0:532cb55d6136 21 */
arvahsu 0:532cb55d6136 22 /** @file main.cpp */
arvahsu 0:532cb55d6136 23 // Include header files for platform
arvahsu 0:532cb55d6136 24 #include "mbed.h"
arvahsu 0:532cb55d6136 25 #include "uLCD_4DGL.h"
arvahsu 0:532cb55d6136 26 #include "wave_player.h"
arvahsu 0:532cb55d6136 27 #include "SDFileSystem.h"
arvahsu 0:532cb55d6136 28 #include "segment_display.h"
arvahsu 0:532cb55d6136 29
arvahsu 0:532cb55d6136 30 // Include header files for missile command project
arvahsu 0:532cb55d6136 31 #include "globals.h"
arvahsu 0:532cb55d6136 32 #include "city_landscape_public.h"
arvahsu 0:532cb55d6136 33 #include "missile_public.h"
arvahsu 0:532cb55d6136 34 #include "player.h"
slin77 2:d39a6a36e0c0 35 #include <stdio.h>
slin77 2:d39a6a36e0c0 36 #include <stdlib.h>
arvahsu 0:532cb55d6136 37
arvahsu 0:532cb55d6136 38 // Platform initialization
arvahsu 0:532cb55d6136 39 DigitalIn left_pb(p23); DigitalIn right_pb(p21); DigitalIn fire_pb(p22);
slin77 2:d39a6a36e0c0 40 DigitalIn fouth_pb(p24);
arvahsu 0:532cb55d6136 41 uLCD_4DGL uLCD(p28,p27,p29);
arvahsu 0:532cb55d6136 42 AnalogOut DACout(p18);
arvahsu 0:532cb55d6136 43 wave_player waver(&DACout);
arvahsu 0:532cb55d6136 44 SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, sck, cs
arvahsu 0:532cb55d6136 45
arvahsu 0:532cb55d6136 46 // Example of the decleration of your implementation
arvahsu 0:532cb55d6136 47 void playSound(char * wav);
slin77 2:d39a6a36e0c0 48 void check_interception();
slin77 2:d39a6a36e0c0 49 int within_range(MISSILE m, ANTIMISSILE a);
slin77 2:d39a6a36e0c0 50 int check_destruction_range(MISSILE m,CITY c);
slin77 2:d39a6a36e0c0 51 void check_city_destruction();
slin77 2:d39a6a36e0c0 52 void display_victory();
slin77 2:d39a6a36e0c0 53 void display_failure();
slin77 2:d39a6a36e0c0 54 void advance_level();
slin77 2:d39a6a36e0c0 55
slin77 2:d39a6a36e0c0 56
slin77 2:d39a6a36e0c0 57 PLAYER current_player;
slin77 2:d39a6a36e0c0 58 CITY city_record[];
slin77 2:d39a6a36e0c0 59 MISSILE missile_record[];
slin77 2:d39a6a36e0c0 60 ANTIMISSILE am[];
slin77 2:d39a6a36e0c0 61 EXPLOSION ex[];
slin77 2:d39a6a36e0c0 62
slin77 2:d39a6a36e0c0 63 int number_of_cities = 4;
arvahsu 0:532cb55d6136 64
arvahsu 0:532cb55d6136 65 /** Main() is where you start your implementation
arvahsu 0:532cb55d6136 66 @brief The hints of implementation are in the comments. <br>
arvahsu 0:532cb55d6136 67 @brief You are expected to implement your code in main.cpp and player.cpp. But you could modify any code if you want to make the game work better.
arvahsu 0:532cb55d6136 68 */
slin77 2:d39a6a36e0c0 69
slin77 2:d39a6a36e0c0 70
arvahsu 0:532cb55d6136 71 int main()
arvahsu 0:532cb55d6136 72 {
slin77 2:d39a6a36e0c0 73
arvahsu 0:532cb55d6136 74 setup_sequence();
slin77 2:d39a6a36e0c0 75 seg_driver_initialize();
slin77 2:d39a6a36e0c0 76 city_landscape_init(number_of_cities);
arvahsu 0:532cb55d6136 77 // Initialize the buttons
arvahsu 0:532cb55d6136 78 left_pb.mode(PullUp); // The variable left_pb will be zero when the pushbutton for moving the player left is pressed
arvahsu 0:532cb55d6136 79 right_pb.mode(PullUp); // The variable rightt_pb will be zero when the pushbutton for moving the player right is pressed
slin77 2:d39a6a36e0c0 80 fire_pb.mode(PullUp);
slin77 2:d39a6a36e0c0 81 fouth_pb.mode(PullUp); //the variable fouth_pb will be zero when the pushbutton for firing a missile is pressed
slin77 2:d39a6a36e0c0 82 player_init();//initalize the player
slin77 2:d39a6a36e0c0 83 antimissile_init();
slin77 2:d39a6a36e0c0 84 explosion_init();
slin77 2:d39a6a36e0c0 85 //display the game menu
slin77 2:d39a6a36e0c0 86 int k;
slin77 2:d39a6a36e0c0 87 while (1) {
slin77 2:d39a6a36e0c0 88 char str1[] = "Easy";
slin77 2:d39a6a36e0c0 89 char str2[] = "Medium";
slin77 2:d39a6a36e0c0 90 char str3[] = "hard";
slin77 2:d39a6a36e0c0 91 if (right_pb == 0) {
slin77 2:d39a6a36e0c0 92 k++;
slin77 2:d39a6a36e0c0 93 }
slin77 2:d39a6a36e0c0 94 k = k % 3;
slin77 2:d39a6a36e0c0 95 if(k == 1) {
slin77 2:d39a6a36e0c0 96 uLCD.text_string(str1, 3, 3, FONT_7X8, GREEN);
slin77 2:d39a6a36e0c0 97 } else {
slin77 2:d39a6a36e0c0 98 uLCD.text_string(str1,3, 3, FONT_7X8, WHITE);
slin77 2:d39a6a36e0c0 99 }
slin77 2:d39a6a36e0c0 100
slin77 2:d39a6a36e0c0 101 if(k == 2) {
slin77 2:d39a6a36e0c0 102 uLCD.text_string(str2, 3, 4, FONT_7X8, GREEN);
slin77 2:d39a6a36e0c0 103 } else {
slin77 2:d39a6a36e0c0 104 uLCD.text_string(str2, 3, 4, FONT_7X8, WHITE);
slin77 2:d39a6a36e0c0 105 }
slin77 2:d39a6a36e0c0 106
slin77 2:d39a6a36e0c0 107 if(k == 0) {
slin77 2:d39a6a36e0c0 108 uLCD.text_string(str3, 3, 5, FONT_7X8, GREEN);
slin77 2:d39a6a36e0c0 109 } else {
slin77 2:d39a6a36e0c0 110 uLCD.text_string(str3, 3, 5, FONT_7X8, WHITE);
slin77 2:d39a6a36e0c0 111 }
slin77 2:d39a6a36e0c0 112
slin77 2:d39a6a36e0c0 113 if (fire_pb == 0) {
slin77 2:d39a6a36e0c0 114 if (k == 0) {
slin77 2:d39a6a36e0c0 115 current_player.current_level = 3;
slin77 2:d39a6a36e0c0 116 } else {
slin77 2:d39a6a36e0c0 117 current_player.current_level = k;
slin77 2:d39a6a36e0c0 118 }
slin77 2:d39a6a36e0c0 119 set_missile_speed(5 - current_player.current_level);
slin77 2:d39a6a36e0c0 120 set_missile_interval(10 - current_player.current_level);
slin77 2:d39a6a36e0c0 121 uLCD.text_string(str1, 3, 3, FONT_7X8, BACKGROUND_COLOR);
slin77 2:d39a6a36e0c0 122 uLCD.text_string(str2, 3, 4, FONT_7X8, BACKGROUND_COLOR);
slin77 2:d39a6a36e0c0 123 uLCD.text_string(str3, 3, 5, FONT_7X8, BACKGROUND_COLOR);
slin77 2:d39a6a36e0c0 124 char go[] = "READY!";
slin77 2:d39a6a36e0c0 125 uLCD.text_string(go, 6, 6, FONT_7X8, GREEN);
slin77 4:0dc720aa3c71 126 playSound("/sd/wavfiles/BUZZER.wav");
slin77 2:d39a6a36e0c0 127 uLCD.text_string(go, 6, 6, FONT_7X8, BACKGROUND_COLOR);
slin77 2:d39a6a36e0c0 128 break;
slin77 2:d39a6a36e0c0 129 }
slin77 2:d39a6a36e0c0 130
slin77 2:d39a6a36e0c0 131
slin77 2:d39a6a36e0c0 132 }
slin77 2:d39a6a36e0c0 133
arvahsu 0:532cb55d6136 134 /// 2.Begin the game loop
arvahsu 0:532cb55d6136 135 while(1){
slin77 4:0dc720aa3c71 136 current_player.timer++;
slin77 2:d39a6a36e0c0 137 char str[] = {'s', 'c', 'o', 'r', 'e', ':', '0' + current_player.score};
slin77 2:d39a6a36e0c0 138 char life_str[] = {'l','i','f', 'e',':', '0' + current_player.life};
slin77 2:d39a6a36e0c0 139 char level_str[] = {'l', 'e', 'v', 'e', 'l' ,':','0' + current_player.current_level};
slin77 2:d39a6a36e0c0 140 uLCD.text_string(str, 11, 0, FONT_7X8, WHITE);
slin77 2:d39a6a36e0c0 141 uLCD.text_string(life_str, 0, 1, FONT_7X8, WHITE);
slin77 2:d39a6a36e0c0 142 uLCD.text_string(level_str, 0, 0, FONT_7X8, GREEN);
slin77 2:d39a6a36e0c0 143
slin77 2:d39a6a36e0c0 144 seg_driver(current_player.am_remain);
arvahsu 0:532cb55d6136 145 /// 3.Example of drawing the player
slin77 2:d39a6a36e0c0 146 player_draw(); // draws a player at the center of the screen
slin77 2:d39a6a36e0c0 147 draw_antimissiles();
arvahsu 0:532cb55d6136 148 /// 4.Example of calling the missile API.
arvahsu 0:532cb55d6136 149 missile_generator(); /// It updates all incoming missiles on the screen
slin77 2:d39a6a36e0c0 150 update_explosion();
slin77 2:d39a6a36e0c0 151 draw_explosion();
slin77 4:0dc720aa3c71 152 if (current_player.timer % 150 == 0 && current_player.life < 6) {
slin77 4:0dc720aa3c71 153 current_player.life++;
slin77 4:0dc720aa3c71 154 }
arvahsu 0:532cb55d6136 155 /// 5.Implement the code to get user input and update the player
arvahsu 0:532cb55d6136 156 /// -[Hint] You could see city_landscape.cpp to get some ideas about how to implement your player. <br>
arvahsu 0:532cb55d6136 157 if(left_pb == 0){
arvahsu 0:532cb55d6136 158 /// -[Hint] Implement the code to move player left <br>
slin77 2:d39a6a36e0c0 159 player_move_left();
arvahsu 0:532cb55d6136 160 }
arvahsu 0:532cb55d6136 161 if(right_pb == 0){
arvahsu 0:532cb55d6136 162 /// -[Hint] Implement the code to move player right <br>
slin77 2:d39a6a36e0c0 163 player_move_right();
arvahsu 0:532cb55d6136 164 }
arvahsu 0:532cb55d6136 165 if(fire_pb == 0){
arvahsu 0:532cb55d6136 166 /// -[Hint] Implement the code to fire player-missile <br>
slin77 2:d39a6a36e0c0 167 shoot();
arvahsu 0:532cb55d6136 168 // [Demo of play sound file]
slin77 2:d39a6a36e0c0 169 //playSound("/sd/wavfiles/BUZZER.wav");
arvahsu 0:532cb55d6136 170 }
slin77 2:d39a6a36e0c0 171 if(fouth_pb == 0 && current_player.protector_num > 0) {
slin77 2:d39a6a36e0c0 172 current_player.protector.is_active = 1;
slin77 2:d39a6a36e0c0 173 current_player.protector.timer = 0;
slin77 2:d39a6a36e0c0 174 current_player.protector_num--;
slin77 2:d39a6a36e0c0 175 }
slin77 5:3f356592ee9c 176 if(left_pb == 0 && right_pb == 0 && fouth_pb != 0 && fire_pb != 0) {
slin77 5:3f356592ee9c 177 big_shoot();
slin77 5:3f356592ee9c 178 }
slin77 2:d39a6a36e0c0 179 update_protector();
slin77 2:d39a6a36e0c0 180 update_antimissile_positions();
slin77 2:d39a6a36e0c0 181 check_interception();
slin77 2:d39a6a36e0c0 182 check_city_destruction();
arvahsu 0:532cb55d6136 183 /// 6.Implement the code to draw a user missile
arvahsu 0:532cb55d6136 184 /// -[Hint] You could see missile.cpp or missile_generator() for your reference <br>
slin77 4:0dc720aa3c71 185 if (current_player.score > 9 || (!left_pb && !right_pb && !fire_pb && !fouth_pb)) {
slin77 4:0dc720aa3c71 186 advance_level();
slin77 2:d39a6a36e0c0 187 //display_victory();
slin77 2:d39a6a36e0c0 188 } else if(!is_any_left()) {
slin77 2:d39a6a36e0c0 189 current_player.life--;
slin77 2:d39a6a36e0c0 190 city_landscape_init(number_of_cities);
slin77 2:d39a6a36e0c0 191
slin77 2:d39a6a36e0c0 192 } else if(current_player.current_level >= 4) {
slin77 2:d39a6a36e0c0 193 display_victory();
slin77 2:d39a6a36e0c0 194 break;
slin77 2:d39a6a36e0c0 195 }
arvahsu 0:532cb55d6136 196
slin77 2:d39a6a36e0c0 197 if (current_player.life == 0) {
slin77 2:d39a6a36e0c0 198 display_failure();
slin77 2:d39a6a36e0c0 199 break;
slin77 2:d39a6a36e0c0 200 }
slin77 2:d39a6a36e0c0 201
arvahsu 0:532cb55d6136 202 /// 7.Implement the code to detect the collision between missiles and cities
arvahsu 0:532cb55d6136 203 /// -[Hint] You could use city_get_info() and missile_get_info() <br>
arvahsu 0:532cb55d6136 204 /// -[Hint] You could use missile_set_exploded() to notify the missile module that the missile was exploded. <br>
arvahsu 1:3da29f1d84b4 205 /// -[Hint] You need to check which city was hit by the missile, and call city_destroy() to destroy it. <br>
arvahsu 0:532cb55d6136 206 /// -[Hint] You might also check whether the missile hit the land <br>
arvahsu 0:532cb55d6136 207
arvahsu 0:532cb55d6136 208 /// 8.Implement the code to detect a collision between player-missiles and incoming missiles
arvahsu 0:532cb55d6136 209 /// -[Hint] You could use missile_get_info() to get the position of incoming missile <br>
arvahsu 0:532cb55d6136 210 /// -[Hint] You could use missile_set_exploded() to notify the missile module that the missile was exploded. <br>
arvahsu 0:532cb55d6136 211 /// -[Hint] You might also check whether the missile hit the player <br>
arvahsu 0:532cb55d6136 212
arvahsu 0:532cb55d6136 213 /// 9.Implement the code to check the end of game
arvahsu 0:532cb55d6136 214 /// -[Hint] For example, if there is no more city, it should be gameover. <br>
arvahsu 0:532cb55d6136 215
arvahsu 0:532cb55d6136 216 }
arvahsu 0:532cb55d6136 217 }
arvahsu 0:532cb55d6136 218
arvahsu 0:532cb55d6136 219 // Example of implementation of your functions
arvahsu 0:532cb55d6136 220 void playSound(char * wav)
arvahsu 0:532cb55d6136 221 {
arvahsu 0:532cb55d6136 222 // open wav file
arvahsu 0:532cb55d6136 223 FILE *wave_file;
arvahsu 0:532cb55d6136 224 wave_file=fopen(wav,"r");
arvahsu 0:532cb55d6136 225
arvahsu 0:532cb55d6136 226 // play wav file
arvahsu 0:532cb55d6136 227 waver.play(wave_file);
arvahsu 0:532cb55d6136 228
arvahsu 0:532cb55d6136 229 // close wav file
arvahsu 0:532cb55d6136 230 fclose(wave_file);
arvahsu 0:532cb55d6136 231 }
slin77 2:d39a6a36e0c0 232
slin77 2:d39a6a36e0c0 233 void advance_level() {
slin77 4:0dc720aa3c71 234 current_player.timer = 0;
slin77 2:d39a6a36e0c0 235 current_player.current_level++;
slin77 2:d39a6a36e0c0 236 set_missile_speed(5 - current_player.current_level);
slin77 2:d39a6a36e0c0 237 set_missile_interval(10 - current_player.current_level);
slin77 2:d39a6a36e0c0 238 city_landscape_init(4);
slin77 2:d39a6a36e0c0 239 current_player.score = 0;
slin77 2:d39a6a36e0c0 240 current_player.protector_num = 3;
slin77 2:d39a6a36e0c0 241 char str[] = "Enter NEXT LEVEL";
slin77 2:d39a6a36e0c0 242 uLCD.text_string(str, 2, 6, FONT_7X8, WHITE);
slin77 2:d39a6a36e0c0 243 wait(1);
slin77 2:d39a6a36e0c0 244 uLCD.text_string(str, 2, 6, FONT_7X8, BACKGROUND_COLOR);
slin77 2:d39a6a36e0c0 245 int i;
slin77 2:d39a6a36e0c0 246 for (i = 0;i < MAX_NUM_MISSILE;i++) {
slin77 2:d39a6a36e0c0 247 missile_set_exploded(i);
slin77 2:d39a6a36e0c0 248 }
slin77 2:d39a6a36e0c0 249 }
slin77 2:d39a6a36e0c0 250 void check_interception() {
slin77 2:d39a6a36e0c0 251 int i,j,k;
slin77 2:d39a6a36e0c0 252 for (i = 0;i < MAX_NUM_MISSILE; i++) {
slin77 2:d39a6a36e0c0 253 for (j = 0; j < current_player.max_am; j++) {
slin77 2:d39a6a36e0c0 254 if (missile_record[i].status == MISSILE_ACTIVE && am[j].status == ACTIVE
slin77 2:d39a6a36e0c0 255 && within_range(missile_record[i], am[j])) {
slin77 2:d39a6a36e0c0 256 for (k = 0; k < current_player.max_am; k++) {
slin77 2:d39a6a36e0c0 257 if (ex[k].exploded == NO) {
slin77 2:d39a6a36e0c0 258 //find a unused explosion activate it
slin77 2:d39a6a36e0c0 259 ex[k].x = am[j].x;
slin77 2:d39a6a36e0c0 260 ex[k].y = am[j].y;
slin77 2:d39a6a36e0c0 261 ex[k].exploded = YES;
slin77 2:d39a6a36e0c0 262 ex[k].color = PLAYER_COLOR;
slin77 2:d39a6a36e0c0 263 break;
slin77 2:d39a6a36e0c0 264 }
slin77 2:d39a6a36e0c0 265 }
slin77 2:d39a6a36e0c0 266 //set both the missile and anti missile to DEACTIVE
slin77 2:d39a6a36e0c0 267 missile_record[i].status = MISSILE_EXPLODED;
slin77 2:d39a6a36e0c0 268 am[j].status = DEACTIVE;
slin77 2:d39a6a36e0c0 269 current_player.am_remain++;
slin77 2:d39a6a36e0c0 270 current_player.score++;
slin77 2:d39a6a36e0c0 271 }
slin77 2:d39a6a36e0c0 272 }
slin77 2:d39a6a36e0c0 273 }
slin77 2:d39a6a36e0c0 274
slin77 2:d39a6a36e0c0 275 }
slin77 2:d39a6a36e0c0 276
slin77 2:d39a6a36e0c0 277 void check_city_destruction() {
slin77 2:d39a6a36e0c0 278 int i,j,k;
slin77 2:d39a6a36e0c0 279 for (i = 0; i < MAX_NUM_MISSILE; i++) {
slin77 2:d39a6a36e0c0 280 for(j = 0;j < number_of_cities;j++) {
slin77 2:d39a6a36e0c0 281 if (missile_record[i].status == MISSILE_ACTIVE && city_get_info(j).status == EXIST && check_destruction_range(missile_record[i], city_get_info(j))) {
slin77 2:d39a6a36e0c0 282 for (k = 0; k < current_player.max_am; k++) {
slin77 2:d39a6a36e0c0 283 if (ex[k].exploded == NO) {
slin77 2:d39a6a36e0c0 284 //find a unused explosion activate it
slin77 2:d39a6a36e0c0 285 ex[k].x = missile_record[i].x;
slin77 2:d39a6a36e0c0 286 ex[k].y = missile_record[i].y;
slin77 2:d39a6a36e0c0 287 ex[k].exploded = YES;
slin77 2:d39a6a36e0c0 288 ex[k].color = LANDSCAPE_COLOR;
slin77 2:d39a6a36e0c0 289 break;
slin77 2:d39a6a36e0c0 290 }
slin77 2:d39a6a36e0c0 291 }
slin77 2:d39a6a36e0c0 292 missile_record[i].status = MISSILE_EXPLODED;
slin77 2:d39a6a36e0c0 293 city_destroy(j);
slin77 2:d39a6a36e0c0 294 }
slin77 2:d39a6a36e0c0 295 }
slin77 2:d39a6a36e0c0 296 }
slin77 2:d39a6a36e0c0 297
slin77 2:d39a6a36e0c0 298
slin77 2:d39a6a36e0c0 299 }
slin77 2:d39a6a36e0c0 300
slin77 2:d39a6a36e0c0 301 void display_victory() {
slin77 2:d39a6a36e0c0 302 uLCD.cls();
slin77 2:d39a6a36e0c0 303 char str[] = "You Are Winnner";
slin77 2:d39a6a36e0c0 304 uLCD.text_string(str, 2, 9, FONT_7X8, WHITE);
slin77 4:0dc720aa3c71 305 playSound("/sd/wavfiles/ding_dong.wav");
slin77 2:d39a6a36e0c0 306 }
slin77 2:d39a6a36e0c0 307
slin77 2:d39a6a36e0c0 308 void display_failure() {
slin77 2:d39a6a36e0c0 309 uLCD.cls();
slin77 2:d39a6a36e0c0 310 char str[] = "Game Over";
slin77 4:0dc720aa3c71 311 uLCD.text_string(str, 3, 9, FONT_7X8, WHITE);
slin77 4:0dc720aa3c71 312 playSound("/sd/wavfiles/ding_dong.wav");
slin77 2:d39a6a36e0c0 313 }
slin77 2:d39a6a36e0c0 314
slin77 2:d39a6a36e0c0 315
slin77 2:d39a6a36e0c0 316
slin77 2:d39a6a36e0c0 317
slin77 2:d39a6a36e0c0 318 int check_destruction_range(MISSILE m,CITY c) {
slin77 2:d39a6a36e0c0 319 if(c.x <= m.x
slin77 2:d39a6a36e0c0 320 && m.x <= c.x + c.width
slin77 2:d39a6a36e0c0 321 && c.y <= m.y
slin77 2:d39a6a36e0c0 322 && m.y <= c.y + c.height) {
slin77 2:d39a6a36e0c0 323 return 1;
slin77 2:d39a6a36e0c0 324 }
slin77 2:d39a6a36e0c0 325 return 0;
slin77 2:d39a6a36e0c0 326 }
slin77 2:d39a6a36e0c0 327
slin77 2:d39a6a36e0c0 328 int within_range(MISSILE m, ANTIMISSILE a) {
slin77 2:d39a6a36e0c0 329 if(m.x - 2 <=a.x
slin77 2:d39a6a36e0c0 330 && a.x <= m.x + 2
slin77 2:d39a6a36e0c0 331 && m.y - 2 <=a.y
slin77 2:d39a6a36e0c0 332 && a.y <= m.y + 2) {
slin77 2:d39a6a36e0c0 333 return 1;
slin77 2:d39a6a36e0c0 334 }
slin77 2:d39a6a36e0c0 335 return 0;
slin77 2:d39a6a36e0c0 336 }
slin77 2:d39a6a36e0c0 337