Missile Control Game with uLCD
Dependencies: 4DGL-uLCD-SE SDFileSystem mbed wave_player
Fork of missile_command by
main.cpp@1:3da29f1d84b4, 2014-10-29 (annotated)
- Committer:
- arvahsu
- Date:
- Wed Oct 29 02:58:53 2014 +0000
- Revision:
- 1:3da29f1d84b4
- Parent:
- 0:532cb55d6136
- Child:
- 2:eba4ed0263a4
fix typo
Who changed what in which revision?
User | Revision | Line number | New 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" |
arvahsu | 0:532cb55d6136 | 35 | |
arvahsu | 0:532cb55d6136 | 36 | // Platform initialization |
arvahsu | 0:532cb55d6136 | 37 | DigitalIn left_pb(p23); DigitalIn right_pb(p21); DigitalIn fire_pb(p22); |
arvahsu | 0:532cb55d6136 | 38 | uLCD_4DGL uLCD(p28,p27,p29); |
arvahsu | 0:532cb55d6136 | 39 | AnalogOut DACout(p18); |
arvahsu | 0:532cb55d6136 | 40 | wave_player waver(&DACout); |
arvahsu | 0:532cb55d6136 | 41 | SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, sck, cs |
arvahsu | 0:532cb55d6136 | 42 | |
arvahsu | 0:532cb55d6136 | 43 | // Example of the decleration of your implementation |
arvahsu | 0:532cb55d6136 | 44 | void playSound(char * wav); |
arvahsu | 0:532cb55d6136 | 45 | |
arvahsu | 0:532cb55d6136 | 46 | /** Main() is where you start your implementation |
arvahsu | 0:532cb55d6136 | 47 | @brief The hints of implementation are in the comments. <br> |
arvahsu | 0:532cb55d6136 | 48 | @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 | 49 | */ |
arvahsu | 0:532cb55d6136 | 50 | int main() |
arvahsu | 0:532cb55d6136 | 51 | { |
arvahsu | 0:532cb55d6136 | 52 | // [Demo of 7-segment display] |
arvahsu | 0:532cb55d6136 | 53 | // 1.Initialize the segment display |
arvahsu | 0:532cb55d6136 | 54 | setup_sequence(); |
arvahsu | 0:532cb55d6136 | 55 | seg_driver_initialize(); |
arvahsu | 0:532cb55d6136 | 56 | // 2.show numbers |
arvahsu | 0:532cb55d6136 | 57 | int i; |
arvahsu | 0:532cb55d6136 | 58 | for(i=0;i<10;i++){ |
arvahsu | 0:532cb55d6136 | 59 | seg_driver(i); |
arvahsu | 0:532cb55d6136 | 60 | wait(0.2); |
arvahsu | 0:532cb55d6136 | 61 | } |
arvahsu | 0:532cb55d6136 | 62 | |
arvahsu | 0:532cb55d6136 | 63 | // [Demo of play sound file] |
arvahsu | 0:532cb55d6136 | 64 | playSound("/sd/wavfiles/BUZZER.wav"); |
arvahsu | 0:532cb55d6136 | 65 | |
arvahsu | 0:532cb55d6136 | 66 | /// [Example of missile command implementation] |
arvahsu | 0:532cb55d6136 | 67 | /// Here is a rough flow to implement the missile command: <br><br> |
arvahsu | 0:532cb55d6136 | 68 | |
arvahsu | 0:532cb55d6136 | 69 | /// 1.Initialize and draw the city landscape |
arvahsu | 0:532cb55d6136 | 70 | city_landscape_init(4); |
arvahsu | 0:532cb55d6136 | 71 | // Initialize the buttons |
arvahsu | 0:532cb55d6136 | 72 | left_pb.mode(PullUp); // The variable left_pb will be zero when the pushbutton for moving the player left is pressed |
arvahsu | 0:532cb55d6136 | 73 | right_pb.mode(PullUp); // The variable rightt_pb will be zero when the pushbutton for moving the player right is pressed |
arvahsu | 0:532cb55d6136 | 74 | fire_pb.mode(PullUp); //the variable fire_pb will be zero when the pushbutton for firing a missile is pressed |
arvahsu | 0:532cb55d6136 | 75 | |
arvahsu | 0:532cb55d6136 | 76 | /// 2.Begin the game loop |
arvahsu | 0:532cb55d6136 | 77 | while(1){ |
arvahsu | 0:532cb55d6136 | 78 | |
arvahsu | 0:532cb55d6136 | 79 | /// 3.Example of drawing the player |
arvahsu | 0:532cb55d6136 | 80 | player_draw(60,100); // draws a player at the center of the screen |
arvahsu | 0:532cb55d6136 | 81 | |
arvahsu | 0:532cb55d6136 | 82 | /// 4.Example of calling the missile API. |
arvahsu | 0:532cb55d6136 | 83 | missile_generator(); /// It updates all incoming missiles on the screen |
arvahsu | 0:532cb55d6136 | 84 | |
arvahsu | 0:532cb55d6136 | 85 | /// 5.Implement the code to get user input and update the player |
arvahsu | 0:532cb55d6136 | 86 | /// -[Hint] You could see city_landscape.cpp to get some ideas about how to implement your player. <br> |
arvahsu | 0:532cb55d6136 | 87 | if(left_pb == 0){ |
arvahsu | 0:532cb55d6136 | 88 | /// -[Hint] Implement the code to move player left <br> |
arvahsu | 0:532cb55d6136 | 89 | } |
arvahsu | 0:532cb55d6136 | 90 | if(right_pb == 0){ |
arvahsu | 0:532cb55d6136 | 91 | /// -[Hint] Implement the code to move player right <br> |
arvahsu | 0:532cb55d6136 | 92 | } |
arvahsu | 0:532cb55d6136 | 93 | if(fire_pb == 0){ |
arvahsu | 0:532cb55d6136 | 94 | /// -[Hint] Implement the code to fire player-missile <br> |
arvahsu | 0:532cb55d6136 | 95 | |
arvahsu | 0:532cb55d6136 | 96 | // [Demo of play sound file] |
arvahsu | 0:532cb55d6136 | 97 | playSound("/sd/wavfiles/BUZZER.wav"); |
arvahsu | 0:532cb55d6136 | 98 | } |
arvahsu | 0:532cb55d6136 | 99 | |
arvahsu | 0:532cb55d6136 | 100 | /// 6.Implement the code to draw a user missile |
arvahsu | 0:532cb55d6136 | 101 | /// -[Hint] You could see missile.cpp or missile_generator() for your reference <br> |
arvahsu | 0:532cb55d6136 | 102 | |
arvahsu | 0:532cb55d6136 | 103 | /// 7.Implement the code to detect the collision between missiles and cities |
arvahsu | 0:532cb55d6136 | 104 | /// -[Hint] You could use city_get_info() and missile_get_info() <br> |
arvahsu | 0:532cb55d6136 | 105 | /// -[Hint] You could use missile_set_exploded() to notify the missile module that the missile was exploded. <br> |
arvahsu | 1:3da29f1d84b4 | 106 | /// -[Hint] You need to check which city was hit by the missile, and call city_destroy() to destroy it. <br> |
arvahsu | 0:532cb55d6136 | 107 | /// -[Hint] You might also check whether the missile hit the land <br> |
arvahsu | 0:532cb55d6136 | 108 | |
arvahsu | 0:532cb55d6136 | 109 | /// 8.Implement the code to detect a collision between player-missiles and incoming missiles |
arvahsu | 0:532cb55d6136 | 110 | /// -[Hint] You could use missile_get_info() to get the position of incoming missile <br> |
arvahsu | 0:532cb55d6136 | 111 | /// -[Hint] You could use missile_set_exploded() to notify the missile module that the missile was exploded. <br> |
arvahsu | 0:532cb55d6136 | 112 | /// -[Hint] You might also check whether the missile hit the player <br> |
arvahsu | 0:532cb55d6136 | 113 | |
arvahsu | 0:532cb55d6136 | 114 | /// 9.Implement the code to check the end of game |
arvahsu | 0:532cb55d6136 | 115 | /// -[Hint] For example, if there is no more city, it should be gameover. <br> |
arvahsu | 0:532cb55d6136 | 116 | |
arvahsu | 0:532cb55d6136 | 117 | } |
arvahsu | 0:532cb55d6136 | 118 | } |
arvahsu | 0:532cb55d6136 | 119 | |
arvahsu | 0:532cb55d6136 | 120 | // Example of implementation of your functions |
arvahsu | 0:532cb55d6136 | 121 | void playSound(char * wav) |
arvahsu | 0:532cb55d6136 | 122 | { |
arvahsu | 0:532cb55d6136 | 123 | // open wav file |
arvahsu | 0:532cb55d6136 | 124 | FILE *wave_file; |
arvahsu | 0:532cb55d6136 | 125 | wave_file=fopen(wav,"r"); |
arvahsu | 0:532cb55d6136 | 126 | |
arvahsu | 0:532cb55d6136 | 127 | // play wav file |
arvahsu | 0:532cb55d6136 | 128 | waver.play(wave_file); |
arvahsu | 0:532cb55d6136 | 129 | |
arvahsu | 0:532cb55d6136 | 130 | // close wav file |
arvahsu | 0:532cb55d6136 | 131 | fclose(wave_file); |
arvahsu | 0:532cb55d6136 | 132 | } |