pocket tanks
Dependencies: 4DGL-uLCD-SE pockettanks SDFileSystem mbed wave_player
Fork of ECE2035_FroggerGame_SUM1025 by
Diff: main.cpp
- Revision:
- 3:8f68c00dd75a
- Parent:
- 1:172fbc00199c
--- 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;