Ransom Conant / Mbed 2 deprecated MbedPacman

Dependencies:   4DGL-uLCD-SE mbed wave_player

Fork of PacMan_Skeleton_unlock by ECE 2035 TA

Revision:
0:be33a1fad8c0
Child:
1:fbda247b843b
diff -r 000000000000 -r be33a1fad8c0 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Feb 24 17:33:27 2017 +0000
@@ -0,0 +1,129 @@
+/* Gatech ECE2035 2015 SPRING PAC MAN
+ * Copyright (c) 2015 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 "wave_player.h"
+#include "SDFileSystem.h"
+
+// Include header files for pacman project
+#include "globals.h"
+#include "map_public.h"
+#include "pacman.h"
+#include "ghost.h"
+#include "MMA8452.h"
+#include "doubly_linked_list.h"
+
+// Platform initialization
+DigitalIn left_pb(p21);  // push bottem
+DigitalIn right_pb(p22); // push bottem
+DigitalIn up_pb(p23);    // push bottem
+DigitalIn down_pb(p24);  // push bottem
+uLCD_4DGL uLCD(p9,p10,p11); // LCD (serial tx, serial rx, reset pin;)
+Serial pc(USBTX,USBRX);     // used by Accelerometer
+MMA8452 acc(p28, p27, 100000); // Accelerometer
+AnalogOut DACout(p18);      // speaker
+wave_player waver(&DACout); // wav player
+SDFileSystem sd(p5, p6, p7, p8, "sd"); // SD card and filesystem (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 pacman.cpp. But you could modify any code if you want to make the game work better.
+*/
+int main()
+{   
+    // Initialize the timer
+    /// [Example of time control implementation]
+        /// Here is a rough example to implement the timer control <br><br>
+    int tick, pre_tick;
+    srand (time(NULL));
+    Timer timer;
+    timer.start();
+    tick = timer.read_ms();
+    pre_tick = tick;
+    
+    // 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        
+    up_pb.mode(PullUp);    //the variable fire_pb will be zero when the pushbutton for firing a missile is pressed
+    down_pb.mode(PullUp);  //the variable fire_pb will be zero when the pushbutton for firing a missile is pressed
+    
+    while(1)
+    {
+        /// [Example of the game control implementation]
+        /// Here is the example to initialize the game <br><br>
+        uLCD.cls();
+        map_init();
+        pacman_init(8,9); // Center of the map
+    
+        //Your code here
+        //Initiate & create & show the ghosts  
+    
+        //[Demo of play sound file]
+        //playSound("/sd/wavfiles/BUZZER.wav");
+    
+        /// 1. Begin the game loop
+        while(1){
+            tick = timer.read_ms(); // Read current time
+        
+            /// 2. Implement the code to get user input and update the Pacman
+            /// -[Hint] Implement the code to move Pacman. You could use either push-button or accelerometer. <br>
+            /// The accelerometer's function readXYZGravity() might be useful. 
+        
+            if((tick-pre_tick)>500){ // Time step control
+                 pre_tick = tick;
+            
+            /// 3. Update the Pacman on the screen
+            /// -[Hint] You could update the position of Pacman here based on the input at step 2. <br>
+            
+            }
+        
+        /// 4. Implement the code to check the end of game.
+        /// -[Hint] Check whether the ghost catch the Pacman. Make sure you could always detect that the ghost and Pacman meet on the screen.
+        /// 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).
+        /// Either at time t or t+1, you will see that the Pacman and the ghost are not on the same grid.
+        /// However, the Pacman should be caught by ghost with this movement.
+        /// -[Hint] Check whether Pacman win the game <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);
+}