Missile Control Game with uLCD
Dependencies: 4DGL-uLCD-SE SDFileSystem mbed wave_player
Fork of missile_command by
main.cpp
- Committer:
- arvahsu
- Date:
- 2014-10-29
- Revision:
- 0:532cb55d6136
- Child:
- 1:3da29f1d84b4
File content as of revision 0:532cb55d6136:
/* Gatech ECE2035 2014 FALL missile command * Copyright (c) 2014 Gatech ECE2035 * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** @file main.cpp */ // Include header files for platform #include "mbed.h" #include "uLCD_4DGL.h" #include "wave_player.h" #include "SDFileSystem.h" #include "segment_display.h" // Include header files for missile command project #include "globals.h" #include "city_landscape_public.h" #include "missile_public.h" #include "player.h" // Platform initialization DigitalIn left_pb(p23); DigitalIn right_pb(p21); DigitalIn fire_pb(p22); uLCD_4DGL uLCD(p28,p27,p29); AnalogOut DACout(p18); wave_player waver(&DACout); SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, sck, cs // Example of the decleration of your implementation void playSound(char * wav); /** Main() is where you start your implementation @brief The hints of implementation are in the comments. <br> @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. */ int main() { // [Demo of 7-segment display] // 1.Initialize the segment display setup_sequence(); seg_driver_initialize(); // 2.show numbers int i; for(i=0;i<10;i++){ seg_driver(i); wait(0.2); } // [Demo of play sound file] playSound("/sd/wavfiles/BUZZER.wav"); /// [Example of missile command implementation] /// Here is a rough flow to implement the missile command: <br><br> /// 1.Initialize and draw the city landscape city_landscape_init(4); // Initialize the buttons left_pb.mode(PullUp); // The variable left_pb will be zero when the pushbutton for moving the player left is pressed right_pb.mode(PullUp); // The variable rightt_pb will be zero when the pushbutton for moving the player right is pressed fire_pb.mode(PullUp); //the variable fire_pb will be zero when the pushbutton for firing a missile is pressed /// 2.Begin the game loop while(1){ /// 3.Example of drawing the player player_draw(60,100); // draws a player at the center of the screen /// 4.Example of calling the missile API. missile_generator(); /// It updates all incoming missiles on the screen /// 5.Implement the code to get user input and update the player /// -[Hint] You could see city_landscape.cpp to get some ideas about how to implement your player. <br> if(left_pb == 0){ /// -[Hint] Implement the code to move player left <br> } if(right_pb == 0){ /// -[Hint] Implement the code to move player right <br> } if(fire_pb == 0){ /// -[Hint] Implement the code to fire player-missile <br> // [Demo of play sound file] playSound("/sd/wavfiles/BUZZER.wav"); } /// 6.Implement the code to draw a user missile /// -[Hint] You could see missile.cpp or missile_generator() for your reference <br> /// 7.Implement the code to detect the collision between missiles and cities /// -[Hint] You could use city_get_info() and missile_get_info() <br> /// -[Hint] You could use missile_set_exploded() to notify the missile module that the missile was exploded. <br> /// -[Hint] You need to check which city was hit by the missile, and call city_destory() to destroy it. <br> /// -[Hint] You might also check whether the missile hit the land <br> /// 8.Implement the code to detect a collision between player-missiles and incoming missiles /// -[Hint] You could use missile_get_info() to get the position of incoming missile <br> /// -[Hint] You could use missile_set_exploded() to notify the missile module that the missile was exploded. <br> /// -[Hint] You might also check whether the missile hit the player <br> /// 9.Implement the code to check the end of game /// -[Hint] For example, if there is no more city, it should be gameover. <br> } } // Example of implementation of your functions void playSound(char * wav) { // open wav file FILE *wave_file; wave_file=fopen(wav,"r"); // play wav file waver.play(wave_file); // close wav file fclose(wave_file); }