Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 6:5d57c758c31d
- Parent:
- 5:8a2e96f7fb4d
- Child:
- 7:a3ccabdebe2e
diff -r 8a2e96f7fb4d -r 5d57c758c31d main.cpp
--- a/main.cpp Wed Apr 03 12:38:12 2019 +0000
+++ b/main.cpp Wed Apr 03 14:47:21 2019 +0000
@@ -47,15 +47,18 @@
int main()
{
int tank_hb[40];
+ int proj_hb[25];
lcd.init();
// welcome(); // display welcome message
while(1) { // infinite loop
- srand(time(NULL));
- char buffer[14];
- int t_pos_x = rand() % 77;
- int t_pos_y = rand() % 37;
+ srand(time(NULL));
+ int t_pos_x = rand() % (84-1-10); // Tank position
+ int t_pos_y = rand() % (48-1-6);
+
+ int p_pos_x = rand() % (84-1-5); // projectile position
+ int p_pos_y = rand() % (48-1-5);
//Takes the tanks x and y position (of its bottom left pixel of sprite) and
//determines the area it cover in terms of grid values.
@@ -67,31 +70,41 @@
i++;
}
}
-
- lcd.clear();
- sprintf(buffer," %d ",tank_hb[0] );
- lcd.printString(buffer,0,1);
- lcd.refresh();
- wait(1.5);
- lcd.clear();
- sprintf(buffer," %d ",tank_hb[39] );
- lcd.printString(buffer,0,1);
- lcd.refresh();
- wait(1.5);
- lcd.clear();
+
+ i = 0;
+
+ for (int i0 = 0; i0 < 5; i0++) {
- /*
- int p_pos_x = rand() % 84;
- int p_pos_y = rand() % 48;
- int proj_hb = p_pos_y * 84 + p_pos_x + 1;
-
- //sprintf(buffer,"t_pos_x = %d ",t_pos_x);
+ for (int i1 = 1; i1 < 6; i1++) {
+ proj_hb[i] = (i0 + p_pos_y) * 84 + p_pos_x + i1;
+ i++;
+ }
+ }
+
+ bool hit = false;
+ for (int i0 = 0; i0 < 25; i0++) {
+ for (int i1 = 0; i1 < 40; i1++) {
+ if (proj_hb[i0] == tank_hb[i1]) {hit = true;}
+ }
+ if(hit == true) {break;}
+ }
+
+// bool hit = false;
lcd.clear();
lcd.drawSprite(t_pos_x,42 - t_pos_y,6,10,(int *)tank_left);
- lcd.drawSprite(p_pos_x - 2 ,44 - p_pos_y,5,5,(int *)proj);
- lcd.printString(buffer,0,1);
- lcd.refresh();*/
- wait(1);
- // }
+ lcd.drawSprite(p_pos_x,43 - p_pos_y,5,5,(int *)proj);
+ lcd.refresh();
+ wait(0.5);
+ if (hit == true){
+ lcd.clear();
+ lcd.printString("HIT",0,1);
+ lcd.refresh();
+ wait(2.0);
+ }
+ }
}
-
+/*
+ char buffer[14];
+ sprintf(buffer,"t_pos_x = %d ",t_pos_x);
+ lcd.printString(buffer,0,1);
+ */
\ No newline at end of file