frogger game revision
Dependencies: 4DGL-uLCD-SE MMA8452 SDFileSystem mbed wave_player
Fork of ECE2035_FroggerGame_SUM2015 by
main.cpp
- Committer:
- ece2035ta
- Date:
- 2015-07-05
- Revision:
- 4:3fb1d198e9d6
- Parent:
- 3:3856a3dccf6d
- Child:
- 5:52a01054e275
File content as of revision 4:3fb1d198e9d6:
// Include header files for platform #include "mbed.h" #include "wave_player.h" #include "SDFileSystem.h" #include "Shiftbrite.h" #include <vector> #include "MMA8452.h" // Include header files for pacman project #include "globals.h" #include "map_public.h" #include "robot.h" //Platform initialization DigitalIn right_pb(p24); // push bottom DigitalIn left_pb(p21); // push bottom DigitalIn up_pb(p22); // push bottom DigitalIn down_pb(p23); // push bottom 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 DigitalOut myled(LED1); 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 /// [Example of the game control implementation] /// Here is the example to initialize the game <br><br> uLCD.cls(); map_init(); robot_init(0,8); double x_, y_, z_; double x=0; double y=8; /// 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 RoboFrogger. You could use either push-button or accelerometer. <br> // [Some hints for user-input detection] acc.readXYZGravity(&x_,&y_,&z_); //read accelerometer uLCD.locate(0,1); uLCD.printf("Score x%4.1f ",1); //You could remove this code if you already make the accelerometer work. /// -[Hint] Here is a simple way to utilize the readings of accelerometer: /// If x is larger than certain value (ex:0.3), then make the Pacman move right. /// If x<-0.3, then make it move left. <br> if((tick-pre_tick)>500) { // Time step control pre_tick = tick; // update the previous tick /// 3. Update the RoboFrogger on the screen /// -[Hint] You could update the position of RoboFrogger (draw it on the screen) here based on the user-input at step 2. <br> /// 4. Implement the code to check the end of game. } } }