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 13:15:34 2014 +0000
Revision:
2:d39a6a36e0c0
Parent:
1:3da29f1d84b4
Child:
4:0dc720aa3c71
first commit

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 2:d39a6a36e0c0 126 wait(1.5);
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
arvahsu 0:532cb55d6136 135 /// 2.Begin the game loop
arvahsu 0:532cb55d6136 136 while(1){
arvahsu 0:532cb55d6136 137
slin77 2:d39a6a36e0c0 138 char str[] = {'s', 'c', 'o', 'r', 'e', ':', '0' + current_player.score};
slin77 2:d39a6a36e0c0 139 char life_str[] = {'l','i','f', 'e',':', '0' + current_player.life};
slin77 2:d39a6a36e0c0 140 char level_str[] = {'l', 'e', 'v', 'e', 'l' ,':','0' + current_player.current_level};
slin77 2:d39a6a36e0c0 141 uLCD.text_string(str, 11, 0, FONT_7X8, WHITE);
slin77 2:d39a6a36e0c0 142 uLCD.text_string(life_str, 0, 1, FONT_7X8, WHITE);
slin77 2:d39a6a36e0c0 143 uLCD.text_string(level_str, 0, 0, FONT_7X8, GREEN);
slin77 2:d39a6a36e0c0 144
slin77 2:d39a6a36e0c0 145 seg_driver(current_player.am_remain);
arvahsu 0:532cb55d6136 146 /// 3.Example of drawing the player
slin77 2:d39a6a36e0c0 147 player_draw(); // draws a player at the center of the screen
slin77 2:d39a6a36e0c0 148 draw_antimissiles();
arvahsu 0:532cb55d6136 149 /// 4.Example of calling the missile API.
arvahsu 0:532cb55d6136 150 missile_generator(); /// It updates all incoming missiles on the screen
slin77 2:d39a6a36e0c0 151 update_explosion();
slin77 2:d39a6a36e0c0 152 draw_explosion();
arvahsu 0:532cb55d6136 153
arvahsu 0:532cb55d6136 154 /// 5.Implement the code to get user input and update the player
arvahsu 0:532cb55d6136 155 /// -[Hint] You could see city_landscape.cpp to get some ideas about how to implement your player. <br>
arvahsu 0:532cb55d6136 156 if(left_pb == 0){
arvahsu 0:532cb55d6136 157 /// -[Hint] Implement the code to move player left <br>
slin77 2:d39a6a36e0c0 158 player_move_left();
arvahsu 0:532cb55d6136 159 }
arvahsu 0:532cb55d6136 160 if(right_pb == 0){
arvahsu 0:532cb55d6136 161 /// -[Hint] Implement the code to move player right <br>
slin77 2:d39a6a36e0c0 162 player_move_right();
arvahsu 0:532cb55d6136 163 }
arvahsu 0:532cb55d6136 164 if(fire_pb == 0){
arvahsu 0:532cb55d6136 165 /// -[Hint] Implement the code to fire player-missile <br>
slin77 2:d39a6a36e0c0 166 shoot();
arvahsu 0:532cb55d6136 167 // [Demo of play sound file]
slin77 2:d39a6a36e0c0 168 //playSound("/sd/wavfiles/BUZZER.wav");
arvahsu 0:532cb55d6136 169 }
slin77 2:d39a6a36e0c0 170 if(fouth_pb == 0 && current_player.protector_num > 0) {
slin77 2:d39a6a36e0c0 171 current_player.protector.is_active = 1;
slin77 2:d39a6a36e0c0 172 current_player.protector.timer = 0;
slin77 2:d39a6a36e0c0 173 current_player.protector_num--;
slin77 2:d39a6a36e0c0 174 }
slin77 2:d39a6a36e0c0 175 update_protector();
slin77 2:d39a6a36e0c0 176 update_antimissile_positions();
slin77 2:d39a6a36e0c0 177 check_interception();
slin77 2:d39a6a36e0c0 178 check_city_destruction();
arvahsu 0:532cb55d6136 179 /// 6.Implement the code to draw a user missile
arvahsu 0:532cb55d6136 180 /// -[Hint] You could see missile.cpp or missile_generator() for your reference <br>
slin77 2:d39a6a36e0c0 181 if (current_player.score > 9 || (!left_pb && !right_pb)) {
slin77 2:d39a6a36e0c0 182 advance_level();
slin77 2:d39a6a36e0c0 183 //display_victory();
slin77 2:d39a6a36e0c0 184 } else if(!is_any_left()) {
slin77 2:d39a6a36e0c0 185 current_player.life--;
slin77 2:d39a6a36e0c0 186 city_landscape_init(number_of_cities);
slin77 2:d39a6a36e0c0 187
slin77 2:d39a6a36e0c0 188 } else if(current_player.current_level >= 4) {
slin77 2:d39a6a36e0c0 189 display_victory();
slin77 2:d39a6a36e0c0 190 break;
slin77 2:d39a6a36e0c0 191 }
arvahsu 0:532cb55d6136 192
slin77 2:d39a6a36e0c0 193 if (current_player.life == 0) {
slin77 2:d39a6a36e0c0 194 display_failure();
slin77 2:d39a6a36e0c0 195 break;
slin77 2:d39a6a36e0c0 196 }
slin77 2:d39a6a36e0c0 197
arvahsu 0:532cb55d6136 198 /// 7.Implement the code to detect the collision between missiles and cities
arvahsu 0:532cb55d6136 199 /// -[Hint] You could use city_get_info() and missile_get_info() <br>
arvahsu 0:532cb55d6136 200 /// -[Hint] You could use missile_set_exploded() to notify the missile module that the missile was exploded. <br>
arvahsu 1:3da29f1d84b4 201 /// -[Hint] You need to check which city was hit by the missile, and call city_destroy() to destroy it. <br>
arvahsu 0:532cb55d6136 202 /// -[Hint] You might also check whether the missile hit the land <br>
arvahsu 0:532cb55d6136 203
arvahsu 0:532cb55d6136 204 /// 8.Implement the code to detect a collision between player-missiles and incoming missiles
arvahsu 0:532cb55d6136 205 /// -[Hint] You could use missile_get_info() to get the position of incoming missile <br>
arvahsu 0:532cb55d6136 206 /// -[Hint] You could use missile_set_exploded() to notify the missile module that the missile was exploded. <br>
arvahsu 0:532cb55d6136 207 /// -[Hint] You might also check whether the missile hit the player <br>
arvahsu 0:532cb55d6136 208
arvahsu 0:532cb55d6136 209 /// 9.Implement the code to check the end of game
arvahsu 0:532cb55d6136 210 /// -[Hint] For example, if there is no more city, it should be gameover. <br>
arvahsu 0:532cb55d6136 211
arvahsu 0:532cb55d6136 212 }
arvahsu 0:532cb55d6136 213 }
arvahsu 0:532cb55d6136 214
arvahsu 0:532cb55d6136 215 // Example of implementation of your functions
arvahsu 0:532cb55d6136 216 void playSound(char * wav)
arvahsu 0:532cb55d6136 217 {
arvahsu 0:532cb55d6136 218 // open wav file
arvahsu 0:532cb55d6136 219 FILE *wave_file;
arvahsu 0:532cb55d6136 220 wave_file=fopen(wav,"r");
arvahsu 0:532cb55d6136 221
arvahsu 0:532cb55d6136 222 // play wav file
arvahsu 0:532cb55d6136 223 waver.play(wave_file);
arvahsu 0:532cb55d6136 224
arvahsu 0:532cb55d6136 225 // close wav file
arvahsu 0:532cb55d6136 226 fclose(wave_file);
arvahsu 0:532cb55d6136 227 }
slin77 2:d39a6a36e0c0 228
slin77 2:d39a6a36e0c0 229 void advance_level() {
slin77 2:d39a6a36e0c0 230 current_player.current_level++;
slin77 2:d39a6a36e0c0 231 set_missile_speed(5 - current_player.current_level);
slin77 2:d39a6a36e0c0 232 set_missile_interval(10 - current_player.current_level);
slin77 2:d39a6a36e0c0 233 city_landscape_init(4);
slin77 2:d39a6a36e0c0 234 current_player.score = 0;
slin77 2:d39a6a36e0c0 235 current_player.protector_num = 3;
slin77 2:d39a6a36e0c0 236 char str[] = "Enter NEXT LEVEL";
slin77 2:d39a6a36e0c0 237 uLCD.text_string(str, 2, 6, FONT_7X8, WHITE);
slin77 2:d39a6a36e0c0 238 wait(1);
slin77 2:d39a6a36e0c0 239 uLCD.text_string(str, 2, 6, FONT_7X8, BACKGROUND_COLOR);
slin77 2:d39a6a36e0c0 240 int i;
slin77 2:d39a6a36e0c0 241 for (i = 0;i < MAX_NUM_MISSILE;i++) {
slin77 2:d39a6a36e0c0 242 missile_set_exploded(i);
slin77 2:d39a6a36e0c0 243 }
slin77 2:d39a6a36e0c0 244 }
slin77 2:d39a6a36e0c0 245 void check_interception() {
slin77 2:d39a6a36e0c0 246 int i,j,k;
slin77 2:d39a6a36e0c0 247 for (i = 0;i < MAX_NUM_MISSILE; i++) {
slin77 2:d39a6a36e0c0 248 for (j = 0; j < current_player.max_am; j++) {
slin77 2:d39a6a36e0c0 249 if (missile_record[i].status == MISSILE_ACTIVE && am[j].status == ACTIVE
slin77 2:d39a6a36e0c0 250 && within_range(missile_record[i], am[j])) {
slin77 2:d39a6a36e0c0 251 for (k = 0; k < current_player.max_am; k++) {
slin77 2:d39a6a36e0c0 252 if (ex[k].exploded == NO) {
slin77 2:d39a6a36e0c0 253 //find a unused explosion activate it
slin77 2:d39a6a36e0c0 254 ex[k].x = am[j].x;
slin77 2:d39a6a36e0c0 255 ex[k].y = am[j].y;
slin77 2:d39a6a36e0c0 256 ex[k].exploded = YES;
slin77 2:d39a6a36e0c0 257 ex[k].color = PLAYER_COLOR;
slin77 2:d39a6a36e0c0 258 break;
slin77 2:d39a6a36e0c0 259 }
slin77 2:d39a6a36e0c0 260 }
slin77 2:d39a6a36e0c0 261 //set both the missile and anti missile to DEACTIVE
slin77 2:d39a6a36e0c0 262 missile_record[i].status = MISSILE_EXPLODED;
slin77 2:d39a6a36e0c0 263 am[j].status = DEACTIVE;
slin77 2:d39a6a36e0c0 264 current_player.am_remain++;
slin77 2:d39a6a36e0c0 265 current_player.score++;
slin77 2:d39a6a36e0c0 266 }
slin77 2:d39a6a36e0c0 267 }
slin77 2:d39a6a36e0c0 268 }
slin77 2:d39a6a36e0c0 269
slin77 2:d39a6a36e0c0 270 }
slin77 2:d39a6a36e0c0 271
slin77 2:d39a6a36e0c0 272 void check_city_destruction() {
slin77 2:d39a6a36e0c0 273 int i,j,k;
slin77 2:d39a6a36e0c0 274 for (i = 0; i < MAX_NUM_MISSILE; i++) {
slin77 2:d39a6a36e0c0 275 for(j = 0;j < number_of_cities;j++) {
slin77 2:d39a6a36e0c0 276 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 277 for (k = 0; k < current_player.max_am; k++) {
slin77 2:d39a6a36e0c0 278 if (ex[k].exploded == NO) {
slin77 2:d39a6a36e0c0 279 //find a unused explosion activate it
slin77 2:d39a6a36e0c0 280 ex[k].x = missile_record[i].x;
slin77 2:d39a6a36e0c0 281 ex[k].y = missile_record[i].y;
slin77 2:d39a6a36e0c0 282 ex[k].exploded = YES;
slin77 2:d39a6a36e0c0 283 ex[k].color = LANDSCAPE_COLOR;
slin77 2:d39a6a36e0c0 284 break;
slin77 2:d39a6a36e0c0 285 }
slin77 2:d39a6a36e0c0 286 }
slin77 2:d39a6a36e0c0 287 missile_record[i].status = MISSILE_EXPLODED;
slin77 2:d39a6a36e0c0 288 city_destroy(j);
slin77 2:d39a6a36e0c0 289 }
slin77 2:d39a6a36e0c0 290 }
slin77 2:d39a6a36e0c0 291 }
slin77 2:d39a6a36e0c0 292
slin77 2:d39a6a36e0c0 293
slin77 2:d39a6a36e0c0 294 }
slin77 2:d39a6a36e0c0 295
slin77 2:d39a6a36e0c0 296 void display_victory() {
slin77 2:d39a6a36e0c0 297 uLCD.cls();
slin77 2:d39a6a36e0c0 298 char str[] = "You Are Winnner";
slin77 2:d39a6a36e0c0 299 uLCD.text_string(str, 2, 9, FONT_7X8, WHITE);
slin77 2:d39a6a36e0c0 300 }
slin77 2:d39a6a36e0c0 301
slin77 2:d39a6a36e0c0 302 void display_failure() {
slin77 2:d39a6a36e0c0 303 uLCD.cls();
slin77 2:d39a6a36e0c0 304 char str[] = "Game Over";
slin77 2:d39a6a36e0c0 305 uLCD.text_string(str, 3, 9, FONT_7X8, WHITE);
slin77 2:d39a6a36e0c0 306 }
slin77 2:d39a6a36e0c0 307
slin77 2:d39a6a36e0c0 308
slin77 2:d39a6a36e0c0 309
slin77 2:d39a6a36e0c0 310
slin77 2:d39a6a36e0c0 311 int check_destruction_range(MISSILE m,CITY c) {
slin77 2:d39a6a36e0c0 312 if(c.x <= m.x
slin77 2:d39a6a36e0c0 313 && m.x <= c.x + c.width
slin77 2:d39a6a36e0c0 314 && c.y <= m.y
slin77 2:d39a6a36e0c0 315 && m.y <= c.y + c.height) {
slin77 2:d39a6a36e0c0 316 return 1;
slin77 2:d39a6a36e0c0 317 }
slin77 2:d39a6a36e0c0 318 return 0;
slin77 2:d39a6a36e0c0 319 }
slin77 2:d39a6a36e0c0 320
slin77 2:d39a6a36e0c0 321 int within_range(MISSILE m, ANTIMISSILE a) {
slin77 2:d39a6a36e0c0 322 if(m.x - 2 <=a.x
slin77 2:d39a6a36e0c0 323 && a.x <= m.x + 2
slin77 2:d39a6a36e0c0 324 && m.y - 2 <=a.y
slin77 2:d39a6a36e0c0 325 && a.y <= m.y + 2) {
slin77 2:d39a6a36e0c0 326 return 1;
slin77 2:d39a6a36e0c0 327 }
slin77 2:d39a6a36e0c0 328 return 0;
slin77 2:d39a6a36e0c0 329 }
slin77 2:d39a6a36e0c0 330