Ransom Conant / Mbed 2 deprecated MbedPacman

Dependencies:   4DGL-uLCD-SE mbed wave_player

Fork of PacMan_Skeleton_unlock by ECE 2035 TA

Committer:
conantina
Date:
Fri Feb 24 17:33:27 2017 +0000
Revision:
0:be33a1fad8c0
Child:
1:fbda247b843b
PacMan_Skeleton for student

Who changed what in which revision?

UserRevisionLine numberNew contents of line
conantina 0:be33a1fad8c0 1 /* Gatech ECE2035 2015 SPRING PAC MAN
conantina 0:be33a1fad8c0 2 * Copyright (c) 2015 Gatech ECE2035
conantina 0:be33a1fad8c0 3 *
conantina 0:be33a1fad8c0 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
conantina 0:be33a1fad8c0 5 * of this software and associated documentation files (the "Software"), to deal
conantina 0:be33a1fad8c0 6 * in the Software without restriction, including without limitation the rights
conantina 0:be33a1fad8c0 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
conantina 0:be33a1fad8c0 8 * copies of the Software, and to permit persons to whom the Software is
conantina 0:be33a1fad8c0 9 * furnished to do so, subject to the following conditions:
conantina 0:be33a1fad8c0 10 *
conantina 0:be33a1fad8c0 11 * The above copyright notice and this permission notice shall be included in
conantina 0:be33a1fad8c0 12 * all copies or substantial portions of the Software.
conantina 0:be33a1fad8c0 13 *
conantina 0:be33a1fad8c0 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
conantina 0:be33a1fad8c0 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
conantina 0:be33a1fad8c0 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
conantina 0:be33a1fad8c0 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
conantina 0:be33a1fad8c0 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
conantina 0:be33a1fad8c0 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
conantina 0:be33a1fad8c0 20 * SOFTWARE.
conantina 0:be33a1fad8c0 21 */
conantina 0:be33a1fad8c0 22 /** @file main.cpp */
conantina 0:be33a1fad8c0 23 // Include header files for platform
conantina 0:be33a1fad8c0 24 #include "mbed.h"
conantina 0:be33a1fad8c0 25 #include "wave_player.h"
conantina 0:be33a1fad8c0 26 #include "SDFileSystem.h"
conantina 0:be33a1fad8c0 27
conantina 0:be33a1fad8c0 28 // Include header files for pacman project
conantina 0:be33a1fad8c0 29 #include "globals.h"
conantina 0:be33a1fad8c0 30 #include "map_public.h"
conantina 0:be33a1fad8c0 31 #include "pacman.h"
conantina 0:be33a1fad8c0 32 #include "ghost.h"
conantina 0:be33a1fad8c0 33 #include "MMA8452.h"
conantina 0:be33a1fad8c0 34 #include "doubly_linked_list.h"
conantina 0:be33a1fad8c0 35
conantina 0:be33a1fad8c0 36 // Platform initialization
conantina 0:be33a1fad8c0 37 DigitalIn left_pb(p21); // push bottem
conantina 0:be33a1fad8c0 38 DigitalIn right_pb(p22); // push bottem
conantina 0:be33a1fad8c0 39 DigitalIn up_pb(p23); // push bottem
conantina 0:be33a1fad8c0 40 DigitalIn down_pb(p24); // push bottem
conantina 0:be33a1fad8c0 41 uLCD_4DGL uLCD(p9,p10,p11); // LCD (serial tx, serial rx, reset pin;)
conantina 0:be33a1fad8c0 42 Serial pc(USBTX,USBRX); // used by Accelerometer
conantina 0:be33a1fad8c0 43 MMA8452 acc(p28, p27, 100000); // Accelerometer
conantina 0:be33a1fad8c0 44 AnalogOut DACout(p18); // speaker
conantina 0:be33a1fad8c0 45 wave_player waver(&DACout); // wav player
conantina 0:be33a1fad8c0 46 SDFileSystem sd(p5, p6, p7, p8, "sd"); // SD card and filesystem (mosi, miso, sck, cs)
conantina 0:be33a1fad8c0 47
conantina 0:be33a1fad8c0 48 // Example of the decleration of your implementation
conantina 0:be33a1fad8c0 49 void playSound(char * wav);
conantina 0:be33a1fad8c0 50
conantina 0:be33a1fad8c0 51
conantina 0:be33a1fad8c0 52 /** Main() is where you start your implementation
conantina 0:be33a1fad8c0 53 @brief The hints of implementation are in the comments. <br>
conantina 0:be33a1fad8c0 54 @brief You are expected to implement your code in main.cpp and pacman.cpp. But you could modify any code if you want to make the game work better.
conantina 0:be33a1fad8c0 55 */
conantina 0:be33a1fad8c0 56 int main()
conantina 0:be33a1fad8c0 57 {
conantina 0:be33a1fad8c0 58 // Initialize the timer
conantina 0:be33a1fad8c0 59 /// [Example of time control implementation]
conantina 0:be33a1fad8c0 60 /// Here is a rough example to implement the timer control <br><br>
conantina 0:be33a1fad8c0 61 int tick, pre_tick;
conantina 0:be33a1fad8c0 62 srand (time(NULL));
conantina 0:be33a1fad8c0 63 Timer timer;
conantina 0:be33a1fad8c0 64 timer.start();
conantina 0:be33a1fad8c0 65 tick = timer.read_ms();
conantina 0:be33a1fad8c0 66 pre_tick = tick;
conantina 0:be33a1fad8c0 67
conantina 0:be33a1fad8c0 68 // Initialize the buttons
conantina 0:be33a1fad8c0 69 left_pb.mode(PullUp); // The variable left_pb will be zero when the pushbutton for moving the player left is pressed
conantina 0:be33a1fad8c0 70 right_pb.mode(PullUp); // The variable rightt_pb will be zero when the pushbutton for moving the player right is pressed
conantina 0:be33a1fad8c0 71 up_pb.mode(PullUp); //the variable fire_pb will be zero when the pushbutton for firing a missile is pressed
conantina 0:be33a1fad8c0 72 down_pb.mode(PullUp); //the variable fire_pb will be zero when the pushbutton for firing a missile is pressed
conantina 0:be33a1fad8c0 73
conantina 0:be33a1fad8c0 74 while(1)
conantina 0:be33a1fad8c0 75 {
conantina 0:be33a1fad8c0 76 /// [Example of the game control implementation]
conantina 0:be33a1fad8c0 77 /// Here is the example to initialize the game <br><br>
conantina 0:be33a1fad8c0 78 uLCD.cls();
conantina 0:be33a1fad8c0 79 map_init();
conantina 0:be33a1fad8c0 80 pacman_init(8,9); // Center of the map
conantina 0:be33a1fad8c0 81
conantina 0:be33a1fad8c0 82 //Your code here
conantina 0:be33a1fad8c0 83 //Initiate & create & show the ghosts
conantina 0:be33a1fad8c0 84
conantina 0:be33a1fad8c0 85 //[Demo of play sound file]
conantina 0:be33a1fad8c0 86 //playSound("/sd/wavfiles/BUZZER.wav");
conantina 0:be33a1fad8c0 87
conantina 0:be33a1fad8c0 88 /// 1. Begin the game loop
conantina 0:be33a1fad8c0 89 while(1){
conantina 0:be33a1fad8c0 90 tick = timer.read_ms(); // Read current time
conantina 0:be33a1fad8c0 91
conantina 0:be33a1fad8c0 92 /// 2. Implement the code to get user input and update the Pacman
conantina 0:be33a1fad8c0 93 /// -[Hint] Implement the code to move Pacman. You could use either push-button or accelerometer. <br>
conantina 0:be33a1fad8c0 94 /// The accelerometer's function readXYZGravity() might be useful.
conantina 0:be33a1fad8c0 95
conantina 0:be33a1fad8c0 96 if((tick-pre_tick)>500){ // Time step control
conantina 0:be33a1fad8c0 97 pre_tick = tick;
conantina 0:be33a1fad8c0 98
conantina 0:be33a1fad8c0 99 /// 3. Update the Pacman on the screen
conantina 0:be33a1fad8c0 100 /// -[Hint] You could update the position of Pacman here based on the input at step 2. <br>
conantina 0:be33a1fad8c0 101
conantina 0:be33a1fad8c0 102 }
conantina 0:be33a1fad8c0 103
conantina 0:be33a1fad8c0 104 /// 4. Implement the code to check the end of game.
conantina 0:be33a1fad8c0 105 /// -[Hint] Check whether the ghost catch the Pacman. Make sure you could always detect that the ghost and Pacman meet on the screen.
conantina 0:be33a1fad8c0 106 /// One tricky scenario is that: Pacman is at grid (3,3) and is heading to (3,4), while the ghost is at grid (3,4) and is heading to (3,3).
conantina 0:be33a1fad8c0 107 /// Either at time t or t+1, you will see that the Pacman and the ghost are not on the same grid.
conantina 0:be33a1fad8c0 108 /// However, the Pacman should be caught by ghost with this movement.
conantina 0:be33a1fad8c0 109 /// -[Hint] Check whether Pacman win the game <br>
conantina 0:be33a1fad8c0 110
conantina 0:be33a1fad8c0 111 }
conantina 0:be33a1fad8c0 112 }
conantina 0:be33a1fad8c0 113 }
conantina 0:be33a1fad8c0 114
conantina 0:be33a1fad8c0 115
conantina 0:be33a1fad8c0 116
conantina 0:be33a1fad8c0 117 // Example of implementation of your functions
conantina 0:be33a1fad8c0 118 void playSound(char * wav)
conantina 0:be33a1fad8c0 119 {
conantina 0:be33a1fad8c0 120 // open wav file
conantina 0:be33a1fad8c0 121 FILE *wave_file;
conantina 0:be33a1fad8c0 122 wave_file=fopen(wav,"r");
conantina 0:be33a1fad8c0 123
conantina 0:be33a1fad8c0 124 // play wav file
conantina 0:be33a1fad8c0 125 waver.play(wave_file);
conantina 0:be33a1fad8c0 126
conantina 0:be33a1fad8c0 127 // close wav file
conantina 0:be33a1fad8c0 128 fclose(wave_file);
conantina 0:be33a1fad8c0 129 }