pocket tanks
Dependencies: 4DGL-uLCD-SE pockettanks SDFileSystem mbed wave_player
Fork of ECE2035_FroggerGame_SUM1025 by
Revision 1:172fbc00199c, committed 2015-10-04
- Comitter:
- ece2035ta
- Date:
- Sun Oct 04 22:05:25 2015 +0000
- Parent:
- 0:7fe3c940e4b5
- Child:
- 2:25f099687458
- Commit message:
- pocket tanks;
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MMA8452.lib Sun Oct 04 22:05:25 2015 +0000 @@ -0,0 +1,1 @@ +MMA8452#fccb20977af0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cars/cars.cpp Sun Oct 04 22:05:25 2015 +0000 @@ -0,0 +1,118 @@ +#include "cars.h" +//#include "mbed.h" +//#include "globals.h" +//#include "map_public.h" + + +//======================================================================= +//Private Functions +void collision() { + uLCD.cls(); + uLCD.locate(6,8); + uLCD.printf("GAME OVER"); + + while(1) { } + } +void car_up(car_t * g) +{ + //Need if statement to loop around + if (g->car_blk_y == 0) + { + car_move(g,g->car_blk_x, 13); + return; + } + + car_move(g, g->car_blk_x, g->car_blk_y-1); + return; +} + +//Function to choose car direction +//This can probably be merged with drive function +void car_down(car_t * g) +{ + + car_move(g, g->car_blk_x, g->car_blk_y+1); + return; +} + +void clean_blk(unsigned int blk_x, unsigned int blk_y) +{ + GRID grid_info = map_get_grid_status(blk_x,blk_y); + uLCD.filled_rectangle(grid_info.x, grid_info.y, grid_info.x+GRID_SIZE-1, grid_info.y+GRID_SIZE+1, BACKGROUND_COLOR); + return; +} + +void drawCar(car_t * g, int grid_x, int grid_y) +{ + GRID grid_info = map_get_grid_status(grid_x,grid_y); + int pos_x = grid_info.x + GRID_RADIUS; + int pos_y = grid_info.y + GRID_RADIUS; + uLCD.filled_rectangle(pos_x-GRID_RADIUS, pos_y, pos_x+GRID_RADIUS-2,pos_y+GRID_RADIUS+2,g->car_color); + return; + +} +//This moves the car from tile to tile + +void car_move(car_t * g, unsigned int new_blk_x, unsigned int new_blk_y) +{ + // clean up ghost at old position + clean_blk(g->car_blk_x, g->car_blk_y); + // clean the block at new position + clean_blk(new_blk_x, new_blk_y); + // draw the ghost at new position + drawCar(g, new_blk_x, new_blk_y); + + // recover map component + map_draw_grid(g->car_blk_x, g->car_blk_y); + + g->car_blk_x = new_blk_x; + g->car_blk_y = new_blk_y; + return; +} + + +//============================================================================== +//Public Functions + + +void car_init(car_t * g) { + if(g->lane == 1) + { g->car_blk_x = 4; + g->car_blk_y = 0; + drawCar(g, 7, 0); + return; + } + if (g->lane == 2) + { + g->car_blk_x = 7; + g->car_blk_y = 0; + drawCar(g, 7, 0); + return; + } + + if (g->lane == 3) + { + g->car_blk_x = 10; + g->car_blk_y = 0; + drawCar(g, 10, 0); + return; + } + +return; +} + +void drive(car_t * g) +{ + + switch (g->car_motion) { + case CAR_UP: + car_up(g); + break; + case CAR_DOWN: + car_down(g); + break; + default: + break; + } + return; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cars/cars.h Sun Oct 04 22:05:25 2015 +0000 @@ -0,0 +1,31 @@ +#include "mbed.h" +//#include "cars.h" +#include "map_public.h" +#include "globals.h" + + +//void clearCar(int lane); +//void moveCar(int whichOne); // 1 -> lane 1. 2 -> lane 2 etc + + + +/// The enum defines the motion of the car +typedef enum { + CAR_UP=0, ///< move up + CAR_DOWN, ///< move down +} CAR_MOTION; + +typedef struct +{ + unsigned int car_blk_x; ///< horizontal position in the grid + unsigned int car_blk_y; ///< vertical position in the grid + unsigned int car_color; ///< color of the car + unsigned int lane; //car lane + CAR_MOTION car_motion; ///< the motion of the car +} car_t; + +void car_move(car_t * g, unsigned int new_blk_x, unsigned int new_blk_y); //A function to move the car +//void drawCar(car_t * g, int grid_x, int grid_y); // @param lane @param color I don't think this function needs to be public +void car_init(car_t * g); // Initialize a car +void drive(car_t*); +void collision();
--- a/globals.h Thu Jun 25 14:35:52 2015 +0000 +++ b/globals.h Sun Oct 04 22:05:25 2015 +0000 @@ -34,10 +34,12 @@ // === [global settings] === #define BACKGROUND_COLOR 0x000000 #define GRID_RADIUS 3 -#define GRID_SIZE 7 //(GRID_RADIUS*2+1) -#define NUM_GRID_X 17 -#define NUM_GRID_Y 16 -#define NUM_GRID 272 //(NUM_GRID_X*NUM_GRID_Y) +//I changed this +#define GRID_SIZE 8 //(GRID_RADIUS*2+1) +#define NUM_GRID_X 15 +#define NUM_GRID_Y 14 +#define NUM_GRID 210 //(NUM_GRID_X*NUM_GRID_Y) +//end of change
--- a/main.cpp Thu Jun 25 14:35:52 2015 +0000 +++ b/main.cpp Sun Oct 04 22:05:25 2015 +0000 @@ -4,11 +4,13 @@ #include "SDFileSystem.h" #include "Shiftbrite.h" #include <vector> +#include "MMA8452.h" // for accelerometer -// Include header files for pacman project +// Include header files for robot project #include "globals.h" #include "map_public.h" #include "robot.h" +#include "cars.h" //Platform initialization DigitalIn left_pb(p24); // push bottom @@ -16,11 +18,44 @@ 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;) +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) +Serial pc(USBTX,USBRX); // used by Accelerometer +MMA8452 acc(p28, p27, 100000); // Accelerometer +DigitalOut myled(LED1); +void gameMenu(); +void playSound(char * wav) +{ + // open wav file + FILE *wave_file; + wave_file=fopen(wav,"r"); -DigitalOut myled(LED1); + if(wave_file == NULL) { + uLCD.locate(9,0); + uLCD.printf("ERROR_SD"); + uLCD.cls(); + return; + } + + // play wav file + waver.play(wave_file); + + // close wav file + fclose(wave_file); +} int main() { + // 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 + gameMenu(); + uLCD.background_color(BLACK); + uLCD.cls(); + // Initialize the timer /// [Example of time control implementation] /// Here is a rough example to implement the timer control <br><br> @@ -31,32 +66,114 @@ 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; + double y=1; + double score=0; + bool end=0; + + /* uLCD.filled_rectangle(20, 20, 30, 30, RED); + uLCD.filled_circle(20, 23, 1, BLACK); + uLCD.filled_circle(20, 27, 1, BLACK); + uLCD.line(30,25,35,25, BLACK);*/ + //robot_init(x,y,score,end); + // Init car 1 + /* car_t car1; + car_t * redcar = &car1; + redcar -> car_color = RED; + redcar -> lane = 1; + redcar -> car_motion = (CAR_MOTION) 0; + + car_init(redcar); + drive(redcar); + //Init Car 2 + car_t car2; + car_t * bluecar = &car2; + bluecar -> car_color = BLUE; + bluecar -> lane = 2; + bluecar -> car_motion = (CAR_MOTION) 0; + + car_init(bluecar); + drive(bluecar); + + //Init Car 3 + + car_t car3; + car_t * whitecar = &car3; + whitecar -> car_color = WHITE; + whitecar -> lane = 3; + whitecar -> car_motion = (CAR_MOTION) 0; + + car_init(whitecar); + drive(whitecar); + + //begin sound + playSound("/sd/wavfiles/BUZZER.wav"); /// 1. Begin the game loop while(1) { + if((whitecar -> car_blk_x == x && whitecar -> car_blk_y == y) + || (redcar -> car_blk_x == x && redcar -> car_blk_y == y) + || (bluecar -> car_blk_x == x && bluecar -> car_blk_y == y) ) { + collision(); + } + acc.readXYZGravity(&x_,&y_,&z_); //read accelerometer + uLCD.locate(0,0); + uLCD.printf("sensor x%4.1f y%4.1f\n",x_,y_); //You could remove this code if you already make the accelerometer work. + if(x_>=0.3){ //READING INPUTS FROM ACCELEROMETER + robot_clear(x,y); + map_draw_grid(x,y); + if (x!=0) { + x+=1; + } + wait(0.1); + robot_init(x,y,score,end); +} +else if(x_<=-0.3) { +robot_clear(x,y); + map_draw_grid(x,y); + if (x!=0) { + x-=1; + } + wait(0.1); + robot_init(x,y,score,end); +} +else if(y_>0.3) { +robot_clear(x,y); + map_draw_grid(x,y); + if (x!=16) { + x+=1; + } + wait(0.1); + robot_init(x,y,score,end); +} +else if(y_< -0.3) { +robot_clear(x,y); + map_draw_grid(x,y); + if(y!=15) { + y=y+1; + } else { + y=0; + } + wait(0.1); + robot_init(x,y,score,end); +} + 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> - - // [Some hints for user-input detection] + if (!end){ + uLCD.locate(0,1); + // uLCD.printf("Score x%4.1f ",score); + } else { + uLCD.locate(0,1); + uLCD.printf("YOU WIN!!!!!"); + } //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. + //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> @@ -64,7 +181,13 @@ if((tick-pre_tick)>500) { // Time step control pre_tick = tick; // update the previous tick - + + + //Move car? + + drive(redcar); + drive(bluecar); + drive(whitecar); /// 3. Update the Pacman on the screen /// -[Hint] You could update the position of Pacman (draw it on the screen) here based on the user-input at step 2. <br> if (!up_pb) { //MOVE UP @@ -76,7 +199,7 @@ y=15; } wait(0.1); - robot_init(x,y); + robot_init(x,y,score,end); } else if(!down_pb) { //MOVE DOWN robot_clear(x,y); map_draw_grid(x,y); @@ -86,7 +209,7 @@ y=0; } wait(0.1); - robot_init(x,y); + robot_init(x,y,score,end); } else if (!left_pb) { //MOVE LEFT robot_clear(x,y); map_draw_grid(x,y); @@ -94,7 +217,7 @@ x-=1; } wait(0.1); - robot_init(x,y); + robot_init(x,y,score,end); } else if(!right_pb) { //MOVE RIGHT robot_clear(x,y); @@ -103,13 +226,204 @@ x+=1; } wait(0.1); - robot_init(x,y); + robot_init(x,y,score,end); } - + + } + }*/ + + +//////////////////////////////////////////newcode/////////////////////////////////////// + robot_init(x,y, score, end); + while (1) + { + acc.readXYZGravity(&x_,&y_,&z_); //read accelerometer + uLCD.locate(0,0); + uLCD.printf("sensor x%4.1f y%4.1f\n",x_,y_); //You could remove this code if you already make the accelerometer work. + /* if(x_>=0.3){ //READING INPUTS FROM ACCELEROMETER + robot_clear(x,y); + robot_clear(x+1, y); + map_draw_grid(x,y); + if (x!=0) { + x+=1; + } + wait(0.1); + robot_init(x,y,score,end); +} +else if(x_<=-0.3) { +robot_clear(x,y); +robot_clear(x+1, y); + map_draw_grid(x,y); + if (x!=0) { + x-=1; + } + wait(0.1); + robot_init(x,y,score,end); +}*/ - /// 4. Implement the code to check the end of game. +if(y_>0.3) { +robot_clear(x,y); +robot_clear(x+1, y); +robot_clear(x+2, y); +robot_clear(x, y+1); +robot_clear(x+1, y+1); +robot_clear(x+2, y+1); + map_draw_grid(x,y); + if (x!=16) { + x+=1; + } + wait(0.1); + robot_init(x,y,score,end); +} +else if(y_< -0.3) { +robot_clear(x,y); +robot_clear(x+1, y); +robot_clear(x+2, y); +robot_clear(x, y+1); +robot_clear(x+1, y+1); +robot_clear(x+2, y+1); + map_draw_grid(x,y); + if(y!=7) { + y=y+1; + } else { + y=0; + } + wait(0.1); + robot_init(x,y,score,end); +} + + if (!up_pb) { //MOVE UP +robot_clear(x,y); +robot_clear(x+1, y); +robot_clear(x+2, y); +robot_clear(x, y+1); +robot_clear(x+1, y+1); +robot_clear(x+2, y+1); + map_draw_grid(x,y); + if (y!=0) { + y=y-1; + } else { + y=7; + } + wait(0.1); + robot_init(x,y,score,end); + } else if(!down_pb) { //MOVE DOWN + robot_clear(x,y); +robot_clear(x+1, y); +robot_clear(x+2, y); +robot_clear(x, y+1); +robot_clear(x+1, y+1); +robot_clear(x+2, y+1); + map_draw_grid(x,y); + if(y!=7) { + y=y+1; + } else { + y=0; + } + wait(0.1); + robot_init(x,y,score,end); + } /*else if (!left_pb) { //MOVE LEFT + robot_clear(x,y); + map_draw_grid(x,y); + if (x!=0) { + x-=1; + } + wait(0.1); + robot_init(x,y,score,end); + + } else if(!right_pb) { //MOVE RIGHT + robot_clear(x,y); + map_draw_grid(x,y); + if (x!=16) { + x+=1; + } + wait(0.1); + robot_init(x,y,score,end); + }*/ } - } -} \ No newline at end of file + + + tick = timer.read_ms(); // Read current time + if (!end){ + uLCD.locate(0,1); + // uLCD.printf("Score x%4.1f ",score); + } else { + uLCD.locate(0,1); + uLCD.printf("YOU WIN!!!!!"); + } + //acc.readXYZGravity(&x,&y,&z); //read accelerometer + //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> + + + + } + + +void gameMenu(){ + +uLCD.background_color(RED); + uLCD.cls(); + + // pacman_draw(x, 0); + + uLCD.locate(0,0); //locate "PACMAN" + uLCD.text_height(1); + uLCD.text_width(1); + // uLCD.text_underline(ON); + uLCD.printf(" Pocket Tanks "); + // uLCD.text_underline(OFF); + + uLCD.color(BLACK); + uLCD.textbackground_color(RED); + + + + + + uLCD.locate(2,2); + uLCD.printf("MENU"); + + uLCD.text_height(1); + uLCD.text_width(1); + + uLCD.locate(5,7); + uLCD.printf("1. EASY"); + + uLCD.locate(5,9); + uLCD.printf("2. MEDIUM"); + + uLCD.locate(5,11); + uLCD.printf("3. HARD"); + + + uLCD.textbackground_color(BLACK); + +uLCD.locate(0,14); +uLCD.color(WHITE); + uLCD.printf(" ECE 2035 "); + + uLCD.filled_circle(10, 120, 2, 0xFF0000); //draw cherry + uLCD.filled_circle(13, 121, 2, BLACK); + uLCD.filled_circle(14, 121, 2, 0xFF0000); + + uLCD.pixel(10,117, 0xCCFF66); + uLCD.pixel(11,116,0xCCFF66); + uLCD.pixel(12,115,0xCCFF66); + uLCD.pixel(13,114,0xCCFF66); + uLCD.pixel(14,113,0xCCFF66); + + uLCD.filled_circle(14, 113, 1, 0xCCFF66); + + uLCD.line(14,120, 14,111,0xCCFF66); //end cherry + while(1) { + if(!up_pb|| !down_pb || !right_pb || !left_pb) { + break; + } + + } + } \ No newline at end of file
--- a/map/map.cpp Thu Jun 25 14:35:52 2015 +0000 +++ b/map/map.cpp Sun Oct 04 22:05:25 2015 +0000 @@ -85,12 +85,12 @@ } else if(map[i].status==GRID_BIG_CANDY) { uLCD.filled_circle(map[i].x+GRID_RADIUS, map[i].y+GRID_RADIUS, BIG_CANDY_RADIUS, CANDY_COLOR); } else if(map[i].status==GRID_ROAD_L) { - if ((grid_x!=4)and ((grid_y%3)!=2)) { + if ((grid_x!=3)and ((grid_y%3)!=2)) { //draw line on the LEFT uLCD.filled_rectangle(map[i].x, map[i].y, map[i].x+1, map[i].y+GRID_SIZE-1, LINE_COLOR); } } else if(map[i].status==GRID_ROAD_R) { - if ((grid_x!=12)and ((grid_y%3)!=2)) { + if ((grid_x!=11)and ((grid_y%3)!=2)) { //draw line on the RIGHT uLCD.filled_rectangle(map[i].x+GRID_SIZE-1, map[i].y, map[i].x+GRID_SIZE, map[i].y+GRID_SIZE-1, LINE_COLOR); } @@ -105,18 +105,31 @@ return map[XY2IDX(grid_x,grid_y)]; } -bool map_eat_candy(int grid_x, int grid_y){ +bool map_the_end(int grid_x, int grid_y){ int idx=XY2IDX(grid_x,grid_y); - - if(map[idx].status==GRID_CANDY || map[idx].status==GRID_BIG_CANDY){ - map[idx].status = GRID_ROAD; - num_candy--; + if (map[idx].status==GRID_V_LINE){ return 1; } return 0; } +bool map_eat_candy(int grid_x, int grid_y, double &score){ + int idx=XY2IDX(grid_x,grid_y); + + if(map[idx].status==GRID_CANDY || map[idx].status==GRID_BIG_CANDY) { + map[idx].status = GRID_ROAD; + num_candy--; + if(map[idx].status==GRID_CANDY){ + score+=1; + } + else if (map[idx].status==GRID_BIG_CANDY) { + score+=2.5; + return 1; + } + } + return 0; +} int map_remaining_candy(void){ - return num_candy; + return num_candy; }
--- a/map/map_private.h Thu Jun 25 14:35:52 2015 +0000 +++ b/map/map_private.h Sun Oct 04 22:05:25 2015 +0000 @@ -33,8 +33,8 @@ #include "map_public.h" // It defines the settings for drawing the map -#define SIDE_WALK_COLOR_2 0x999999 -#define SIDE_WALK_COLOR 0x198C19 +#define SIDE_WALK_COLOR_2 0x00ffdf //SKy blue +#define SIDE_WALK_COLOR 0x198C19 // green #define LINE_COLOR 0xE5E500 #define CANDY_COLOR 0xFF7F7F #define CANDY_RADIUS 1 @@ -54,24 +54,38 @@ #define MAP_ATTRIBUTE_SIDE_WALK_2 7 + +//0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ +//0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ +//0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ +//0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ +//0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ +//0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ +//0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ +//0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ +//0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ +//0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ +//0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ +//7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, \ +//7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, \ +//7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, \ +//7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, \ +//7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, } #define DEFAULT_MAP {\ -0, 0, 0, 7, 3, 4, 5, 3, 4, 5, 3, 4, 5, 7, 6, 6, 6, \ -0, 0, 0, 7, 3, 4, 5, 3, 4, 5, 3, 4, 5, 7, 6, 6, 6, \ -0, 0, 0, 7, 3, 1, 5, 3, 4, 5, 3, 4, 5, 7, 6, 6, 6, \ -0, 0, 0, 7, 3, 4, 5, 3, 4, 5, 3, 4, 5, 7, 6, 6, 6, \ -0, 0, 0, 7, 3, 4, 5, 3, 4, 5, 3, 4, 5, 7, 6, 6, 6, \ -0, 0, 0, 7, 3, 2, 5, 3, 4, 5, 3, 4, 5, 7, 6, 6, 6, \ -0, 0, 0, 7, 3, 4, 5, 3, 4, 5, 3, 4, 5, 7, 6, 6, 6, \ -0, 0, 0, 7, 3, 4, 5, 3, 4, 5, 3, 4, 5, 7, 6, 6, 6, \ -0, 0, 0, 7, 3, 4, 5, 3, 4, 5, 3, 4, 5, 7, 6, 6, 6, \ -0, 0, 0, 7, 3, 4, 5, 3, 4, 5, 3, 4, 5, 7, 6, 6, 6, \ -0, 0, 0, 7, 3, 1, 5, 3, 4, 5, 3, 4, 5, 7, 6, 6, 6, \ -0, 0, 0, 7, 3, 4, 5, 3, 4, 5, 3, 4, 5, 7, 6, 6, 6, \ -0, 0, 0, 7, 3, 4, 5, 3, 4, 5, 3, 4, 5, 7, 6, 6, 6, \ -0, 0, 0, 7, 3, 4, 5, 3, 4, 5, 3, 4, 5, 7, 6, 6, 6, \ -0, 0, 0, 7, 3, 4, 5, 3, 4, 5, 3, 4, 5, 7, 6, 6, 6, \ -0, 0, 0, 7, 3, 4, 5, 3, 4, 5, 3, 4, 5, 7, 6, 6, 6, } - +0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, \ +0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, \ +0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, \ +0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, \ +0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, \ +0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, \ +0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, \ +0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, \ +0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, \ +0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, \ +0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, \ +0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, \ +0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, \ +0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, } // Here defines some useful macros #define IDX2X(idx) (idx%NUM_GRID_X) #define IDX2Y(idx) (idx/NUM_GRID_X)
--- a/map/map_public.h Thu Jun 25 14:35:52 2015 +0000 +++ b/map/map_public.h Sun Oct 04 22:05:25 2015 +0000 @@ -53,13 +53,15 @@ @param grid_y The vertical position in the grid. @return 1:There is a cookie be eaten. 0:The is no cookie at the grid. */ -bool map_eat_candy(int grid_x, int grid_y); +bool map_eat_candy(int grid_x, int grid_y, double& score); /** Get the information about the grid @param grid_x The horizontal position in the grid. @param grid_y The vertical position in the grid. @return The data structure of the grid. You could access the contents by using the_grid.x , the_grid.status ... etc. */ +bool map_the_end(int grid_x, int grid_y); + GRID map_get_grid_status(int grid_x, int grid_y); /** Draw the grid @@ -72,6 +74,6 @@ @brief The game should be ended when there is no cookie. @return The number of remaining cookie. */ -int map_remaining_candy(void); +int map_remaining_candy(void); #endif //MAP_H \ No newline at end of file
--- a/robot/robot.cpp Thu Jun 25 14:35:52 2015 +0000 +++ b/robot/robot.cpp Sun Oct 04 22:05:25 2015 +0000 @@ -4,35 +4,41 @@ #include "robot.h" // Following code will only draw the Robot on the screen. You are expected to modify most of the functions here. -// All other necessary functions will be implemented by you. Ex: the movement of Pacman, calculate the score ... etc. +// All other necessary functions will be implemented by you. Ex: the movement of Robot, calculate the score ... etc. -void robot_init(int grid_x, int grid_y){ +void robot_init(int grid_x, int grid_y, double &score, bool& end){ - map_eat_candy(grid_x,grid_y); //clear the cookie on the grid. + map_eat_candy(grid_x,grid_y,score); //clear the cookie on the grid. robot_draw(grid_x,grid_y); - + end = map_the_end(grid_x,grid_y); } void robot_draw(int grid_x, int grid_y){ GRID grid_info = map_get_grid_status(grid_x,grid_y); // Calculate the actual position of the grid - int frog_x = grid_info.x + GRID_RADIUS; - int frog_y = grid_info.y + GRID_RADIUS; - + int tank_x = grid_info.x + GRID_RADIUS; + int tank_y = grid_info.y + GRID_RADIUS; // MAKE - uLCD.filled_circle(frog_x, frog_y, 3, 0x909090); - uLCD.filled_rectangle(frog_x-3,frog_y+1,frog_x+3,frog_y+3,0x33FF66); + /* + uLCD.filled_circle(frog_x, frog_y, 2, 0xCC0066); + uLCD.filled_rectangle(frog_x-2,frog_y+1,frog_x+2,frog_y+3,0x33FF66); uLCD.line(frog_x-1, frog_y+4,frog_x-1, frog_y+5, 0xFF0000);//legs uLCD.line(frog_x+2, frog_y+4,frog_x+2, frog_y+5, 0xFF0000); - uLCD.line(frog_x+4, frog_y+1,frog_x+5, frog_y+1, 0xFF0000);//hands - uLCD.line(frog_x-4, frog_y+1,frog_x-5, frog_y+1, 0xFF0000); + uLCD.line(frog_x+2, frog_y+1,frog_x+4, frog_y+1, 0xFF0000);//hands + uLCD.line(frog_x-2, frog_y+1,frog_x-4, frog_y+1, 0xFF0000); + */ + + uLCD.filled_rectangle(tank_x, tank_y, tank_x + 10, tank_y +10, RED); + uLCD.filled_circle(tank_x, tank_y+3, 1, BLACK); + uLCD.filled_circle(tank_x, tank_y+7, 1, BLACK); + uLCD.line(tank_x+10,tank_y + 5,tank_x + 15, tank_y+5 , BLACK); } void robot_clear(int grid_x, int grid_y){ GRID grid_info = map_get_grid_status(grid_x,grid_y); //Fill the grid (a rectangle) with BACKGROUND_COLOR to clear the pacman - uLCD.filled_rectangle(grid_info.x, grid_info.y, grid_info.x+GRID_SIZE-1, grid_info.y+GRID_SIZE-1, BACKGROUND_COLOR); + uLCD.filled_rectangle(grid_info.x, grid_info.y, grid_info.x+GRID_SIZE-1, grid_info.y+GRID_SIZE-1, 0x198C19); }
--- a/robot/robot.h Thu Jun 25 14:35:52 2015 +0000 +++ b/robot/robot.h Sun Oct 04 22:05:25 2015 +0000 @@ -1,9 +1,7 @@ #ifndef ROBOT_H #define ROBOT_H -#define ROBOT_COLOR 0xFFFFFF - -void robot_init(int grid_x, int grid_y); +void robot_init(int grid_x, int grid_y, double&score, bool&end); void robot_draw(int grid_x, int grid_y); void robot_clear(int grid_x, int grid_y);