pocket tanks
Dependencies: 4DGL-uLCD-SE pockettanks SDFileSystem mbed wave_player
Fork of ECE2035_FroggerGame_SUM1025 by
Revision 3:8f68c00dd75a, committed 2015-10-22
- Comitter:
- ece2035ta
- Date:
- Thu Oct 22 03:47:32 2015 +0000
- Parent:
- 2:25f099687458
- Commit message:
- hi
Changed in this revision
--- a/main.cpp Sun Oct 04 22:06:38 2015 +0000 +++ b/main.cpp Thu Oct 22 03:47:32 2015 +0000 @@ -54,8 +54,9 @@ 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(); - + uLCD.cls(); + + /////////////////////////////////////////////////////////////// // Initialize the timer /// [Example of time control implementation] /// Here is a rough example to implement the timer control <br><br> @@ -66,17 +67,18 @@ tick = timer.read_ms(); pre_tick = tick; - /// [Example of the game control implementation] /// Here is the example to initialize the game <br><br> uLCD.cls(); map_init(); double x_, y_, z_; - double x=0; - double y=1; + double x=3; + double y=0; + double a=3; + double b=11; double score=0; bool end=0; - + int p =4; /* uLCD.filled_rectangle(20, 20, 30, 30, RED); uLCD.filled_circle(20, 23, 1, BLACK); uLCD.filled_circle(20, 27, 1, BLACK); @@ -234,12 +236,14 @@ //////////////////////////////////////////newcode/////////////////////////////////////// - robot_init(x,y, score, end); +robot_init(x,y, score, end); +robot_init1(a,b, score, end); while (1) - { + { // move = right_pb; + 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. + 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); @@ -262,38 +266,7 @@ }*/ -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 + if(y_>0.8) { robot_clear(x,y); robot_clear(x+1, y); robot_clear(x+2, y); @@ -304,26 +277,64 @@ if (y!=0) { y=y-1; } else { - y=7; + y=4; } wait(0.1); - robot_init(x,y,score,end); - } else if(!down_pb) { //MOVE DOWN + robot_init(x,y,score,end); +} +else if(y_< -0.8) { 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); + 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) { + if(y!=4) { y=y+1; } else { y=0; } wait(0.1); robot_init(x,y,score,end); - } /*else if (!left_pb) { //MOVE LEFT +} + +/////////////////////////////////////////////tank 2 + + if(!up_pb) { +robot_clear1(a,b); +robot_clear1(a+1, b); +//robot_clear1(a+2, b); +robot_clear1(a, b+1); +robot_clear1(a+1,b+1); +//robot_clear1(a+2,b+1); + map_draw_grid(x,y); + if (b!=8) { + b=b-1; + } else { + b=12; + } + wait(0.1); + robot_init1(a,b,score,end); +} +else if(!down_pb) { +robot_clear1(a,b); +robot_clear1(a+1, b); +//robot_clear1(a+2, b); +robot_clear1(a, b+1); +robot_clear1(a+1,b+1); +//robot_clear1(a+2,b+1); + map_draw_grid(x,y); + if(b!=12) { + b=b+1; + } else { + b=8; + } + wait(0.1); + robot_init1(a,b,score,end); +} + + /*else if (!left_pb) { //MOVE LEFT robot_clear(x,y); map_draw_grid(x,y); if (x!=0) { @@ -336,12 +347,17 @@ robot_clear(x,y); map_draw_grid(x,y); if (x!=16) { - x+=1; + //x+=1; + uLCD.line(tank_x+10,tank_y + 5,tank_x + 15, tank_y+8 , BLACK); } wait(0.1); robot_init(x,y,score,end); }*/ - + + if (!right_pb && p <20){ + robot_shoot(x,y,p); + p++; + } } @@ -371,7 +387,7 @@ // pacman_draw(x, 0); - uLCD.locate(0,0); //locate "PACMAN" + uLCD.locate(2,0); //locate "Pocket Tanks" uLCD.text_height(1); uLCD.text_width(1); // uLCD.text_underline(ON); @@ -385,29 +401,29 @@ - uLCD.locate(2,2); + uLCD.locate(4,2); uLCD.printf("MENU"); uLCD.text_height(1); uLCD.text_width(1); - uLCD.locate(5,7); - uLCD.printf("1. EASY"); + uLCD.locate(2,7); + uLCD.printf("1. DUMMY MODE"); - uLCD.locate(5,9); - uLCD.printf("2. MEDIUM"); + uLCD.locate(2,9); + uLCD.printf("2. TWO PLAYER"); - uLCD.locate(5,11); - uLCD.printf("3. HARD"); + // uLCD.locate(5,11); + // uLCD.printf("3. HARD"); uLCD.textbackground_color(BLACK); -uLCD.locate(0,14); +uLCD.locate(3,14); uLCD.color(WHITE); uLCD.printf(" ECE 2035 "); - uLCD.filled_circle(10, 120, 2, 0xFF0000); //draw cherry + /* uLCD.filled_circle(10, 120, 2, 0xFF0000); //draw cherry uLCD.filled_circle(13, 121, 2, BLACK); uLCD.filled_circle(14, 121, 2, 0xFF0000); @@ -419,7 +435,7 @@ uLCD.filled_circle(14, 113, 1, 0xCCFF66); - uLCD.line(14,120, 14,111,0xCCFF66); //end cherry + uLCD.line(14,120, 14,111,0xCCFF66); */ //end cherry while(1) { if(!up_pb|| !down_pb || !right_pb || !left_pb) { break;
--- a/map/map_private.h Sun Oct 04 22:06:38 2015 +0000 +++ b/map/map_private.h Thu Oct 22 03:47:32 2015 +0000 @@ -35,7 +35,7 @@ // It defines the settings for drawing the map #define SIDE_WALK_COLOR_2 0x00ffdf //SKy blue #define SIDE_WALK_COLOR 0x198C19 // green -#define LINE_COLOR 0xE5E500 +#define LINE_COLOR 0x674529 #define CANDY_COLOR 0xFF7F7F #define CANDY_RADIUS 1 #define BIG_CANDY_RADIUS 2 @@ -47,11 +47,11 @@ #define MAP_ATTRIBUTE_SIDE_WALK 0 //side walk #define MAP_ATTRIBUTE_CANDY 1 //candy #define MAP_ATTRIBUTE_BIG_CANDY 2 //big candy -#define MAP_ATTRIBUTE_ROAD_L 3 -#define MAP_ATTRIBUTE_ROAD 4 +#define MAP_ATTRIBUTE_ROAD_L 4 +#define MAP_ATTRIBUTE_ROAD 3 #define MAP_ATTRIBUTE_ROAD_R 5 #define MAP_ATTRIBUTE_V_LINE 6 -#define MAP_ATTRIBUTE_SIDE_WALK_2 7 +#define MAP_ATTRIBUTE_SIDE_WALK_2 7 //green @@ -72,20 +72,38 @@ //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, 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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0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, \ +0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, \ +0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, \ +0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 7, 7, 7, 7, 7, 7, \ +0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 7, 7, 7, 7, 7, 7, \ +0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, \ +0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, \ +0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, \ +0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, \ +0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, \ +0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, \ +0, 0, 0, 7, 7, 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/robot/robot.cpp Sun Oct 04 22:06:38 2015 +0000 +++ b/robot/robot.cpp Thu Oct 22 03:47:32 2015 +0000 @@ -5,13 +5,48 @@ // 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 Robot, calculate the score ... etc. +/////////////////new/////////////////////// +/*DigitalIn right_pb(p21); // push bottom + int main() + { + right_pb.mode(PullUp); // The variable rightt_pb will be zero when the pushbutton for moving the player right is pressed + }*/ +////////////////////////////////////////////// void robot_init(int grid_x, int grid_y, double &score, bool& end){ 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_init1(int grid_a, int grid_b, double &score, bool& end){ + + map_eat_candy(grid_a,grid_b,score); //clear the cookie on the grid. + robot_draw(grid_a,grid_b); + + end = map_the_end(grid_a,grid_b); +} +void robot_shoot(int grid_x, int grid_y, int p){ + + GRID grid_info = map_get_grid_status(grid_x,grid_y); + // Calculate the actual position of the grid + int tank_x = grid_info.x + GRID_RADIUS; + int tank_y = grid_info.y + GRID_RADIUS; + //MOVE RIGHT + robot_clear(tank_x,tank_y); + map_draw_grid(tank_x,tank_y); + //x+=1; + + uLCD.line(tank_x+6,tank_y + 4,tank_x + 12, tank_y+p-1 , 0x00ffdf); + // p++; + uLCD.line(tank_x+7,tank_y + 4,tank_x + 12, tank_y+p , BLACK); + + + wait(0.1); + // robot_init(tank_x,tank_y,0,0,move); + + } void robot_draw(int grid_x, int grid_y){ @@ -19,26 +54,39 @@ // Calculate the actual position of the grid int tank_x = grid_info.x + GRID_RADIUS; int tank_y = grid_info.y + GRID_RADIUS; - // MAKE - /* - 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+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 + 6, tank_y +8, RED); + uLCD.filled_circle(tank_x, tank_y+2, 2, BLACK); + uLCD.filled_circle(tank_x, tank_y+5, 2, BLACK); + uLCD.line(tank_x+6,tank_y + 4,tank_x + 12, tank_y+4 , BLACK); +} + +void robot_draw1(int grid_a, int grid_b){ - 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); + GRID grid_info = map_get_grid_status(grid_a,grid_b); + // Calculate the actual position of the grid + int tank_a = grid_info.x + GRID_RADIUS; + int tank_b = grid_info.y + GRID_RADIUS; + + + uLCD.filled_rectangle(tank_a, tank_b, tank_a + 6, tank_b + 8, RED); + uLCD.filled_circle(tank_a, tank_b+2, 2, BLACK); + uLCD.filled_circle(tank_a, tank_b+5, 2, BLACK); + uLCD.line(tank_a+6,tank_b + 4,tank_a + 12, tank_b+4 , 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, 0x198C19); + uLCD.filled_rectangle(grid_info.x, grid_info.y, grid_info.x+GRID_SIZE-1, grid_info.y+GRID_SIZE-1, 0x00ffdf); } +void robot_clear1(int grid_a, int grid_b){ + + GRID grid_info = map_get_grid_status(grid_a,grid_b); + //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, 0x00ffdf); + +}
--- a/robot/robot.h Sun Oct 04 22:06:38 2015 +0000 +++ b/robot/robot.h Thu Oct 22 03:47:32 2015 +0000 @@ -2,7 +2,18 @@ #define ROBOT_H void robot_init(int grid_x, int grid_y, double&score, bool&end); +void robot_init1(int grid_a, int grid_b, double&score, bool&end); void robot_draw(int grid_x, int grid_y); +void robot_draw1(int grid_a, int grid_b); void robot_clear(int grid_x, int grid_y); +void robot_clear1(int grid_a, int grid_b); +void robot_shoot(int grid_x,int grid_y, int p); + +//Initialize struct with variables you want to update + +struct Tank +{ int tank_x; + int tank_y; +}; #endif \ No newline at end of file