ELEC2645 (2018/19) / Mbed 2 deprecated EL17MCD

Dependencies:   mbed

Revision:
4:3b3a7f102250
Parent:
3:087b28bf8b96
Child:
5:8a2e96f7fb4d
--- a/main.cpp	Tue Apr 02 16:46:24 2019 +0000
+++ b/main.cpp	Tue Apr 02 19:00:18 2019 +0000
@@ -23,7 +23,15 @@
     { 1,0,1,0,1,0,1,0,1,0 },
     { 0,1,0,1,0,1,0,1,0,0 },                                                                
 };
-
+const int proj[5][5] =   {
+    { 0,0,1,0,0 },
+    { 0,0,1,0,0 },
+    { 1,1,1,1,1 },
+    { 0,0,1,0,0 },
+    { 0,0,1,0,0 },                                                               
+};
+// Spawning tank and projectile at random position
+// with visual feedback to build grid and hitbox system
 void welcome()
 {
     lcd.clear();
@@ -38,17 +46,37 @@
 
 int main()
 {
-  int pos_x = rand() % 84;
-  
+    int tank_hb[40];
     lcd.init();
    // welcome();  // display welcome message 
 
-    while(1) {  // infinite loop
-    
-    lcd.clear();
-  //  lcd.drawSprite(0,48-6,6,10,(int *)tank_left);
-    lcd.refresh();
-    wait_ms(250);
-    } */
+  //  while(1) {  // infinite loop
+        
+        srand(time(NULL)); 
+        char buffer[14];
+        int t_pos_x = rand() % 77;
+        int t_pos_y = rand() % 37;
+        int i = 0;
+        
+        for (int i0 = 0; i0 < 6; i0++) {
+        
+            for (int i1 = 1; i1 < 11; i1++) {
+            tank_hb[i] = (i0 + t_pos_y) * 84 + t_pos_x + i1;
+             i++;
+            }
+        }
+        
+        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);
+        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);
+  //  } 
 }