ELEC2645 (2018/19) / Mbed 2 deprecated el17ttds

Dependencies:   mbed N5110_tf

Revision:
9:3a0194c87afe
Parent:
8:d1c04f0e4890
--- a/Enemy/Enemy.cpp	Sat May 11 08:23:54 2019 +0000
+++ b/Enemy/Enemy.cpp	Sun May 12 16:21:08 2019 +0000
@@ -27,10 +27,10 @@
 }
 
 bool Enemy::check_collision() {
-  if ( (_x >= 29) &&  // Hero centrepoint - radius - enemyRadius
-    (_x <= 55) &&
-    (_y >= 11) &&
-    (_y <= 37) ) {
+  if ( (_x + 19 >= 37) &&  // Hero centrepoint - radius - enemyRadius
+    (_x <= 48) &&
+    (_y + 19 >= 19) &&
+    (_y <= 27) ) {
     return 1;
   } else {
     return 0;
@@ -39,46 +39,45 @@
 
 void Enemy::random_position() { // finds random postion for enemy out of 50 options
   _col = rand() % 5;
-  _row = rand() % 10;
+  _row = rand() % 5;
   _x = _map_x + 42 + _col * 20;
-  _y = _map_y + 24 + _row * 10;
+  _y = _map_y + 24 + _row * 20;
   valid_position();
   // spacesi = _row * 5 + _col; :: int Shows space 0 - 49. Could be useful.
 }
 
 void Enemy::valid_position() { // if enemy spawns too close to hero, re write enemy
-  if ((_x >= 24) && (_x <= 50) && (_y >= 6) && (_y <= 42)) {
+  if ((_x >= 14) && (_x <= 60) && (_y >= 0) && (_y <= 52) ) {
     random_position();
   }
 }
 
 void Enemy::draw(N5110 &lcd) {
-  lcd.drawCircle( _x, _y, 10, FILL_BLACK);
-  /*
-  int enemy[10][20] = {  CHANGE VALID POSITION DIMENSIONS AND COLLISION MECHANIC
-    {0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0},
-    {0,0,0,0,0,0,1,1,1,0,0,1,1,1,0,0,0,0,0,0},
-    {0,0,0,0,1,1,1,0,1,0,0,1,0,1,1,1,0,0,0,0},
-    {0,0,1,1,1,0,0,1,0,1,1,0,1,0,0,1,1,1,0,0},
-    {1,1,1,0,0,0,1,0,1,1,1,1,0,1,0,0,0,1,1,1},
-    {1,1,1,0,0,0,1,0,1,1,1,1,0,1,0,0,0,1,1,1},
-    {0,0,1,1,1,0,0,1,0,1,1,0,1,0,0,1,1,1,0,0},
-    {0,0,0,0,1,1,1,0,1,0,0,1,0,1,1,1,0,0,0,0},
-    {0,0,0,0,0,0,1,1,1,0,0,1,1,1,0,0,0,0,0,0},
-    {0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0},
+  // lcd.drawCircle( _x, _y, 10, FILL_BLACK);
+  int const enemy[21][21] = {
+    {0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0},
+    {0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0},
+    {0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0},
+    {0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0},
+    {0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
+    {0,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,0},
+    {0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0},
+    {1,1,1,1,1,0,0,0,0,1,1,1,0,0,0,0,1,1,1,1,1},
+    {1,1,1,1,0,0,0,0,1,1,1,1,1,0,0,0,0,1,1,1,1},
+    {1,1,1,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,1,1,1},
+    {1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1},
+    {1,1,1,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,1,1,1},
+    {1,1,1,1,0,0,0,0,1,1,1,1,1,0,0,0,0,1,1,1,1},
+    {1,1,1,1,1,0,0,0,0,1,1,1,0,0,0,0,1,1,1,1,1},
+    {0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0},
+    {0,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,0},
+    {0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
+    {0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0},
+    {0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0},
+    {0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0},
+    {0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0},
   };
-  for (_n = 0; _n < 10; _n++) { // Bitmap library encountered errors with lcd.drawSprite
-    for (_m = 0; _m < 20; _m++) {
-      if (enemy[_m][_n] == 1) {
-        lcd.setPixel(_x, _y);
-      } else {
-        lcd.clearPixel(_x, _y);
-      }
-      _x++;
-    }
-    _y++;
-  }
-  */
+  lcd.drawSprite(_x, _y, 21, 21, (int *)enemy);
 }
 
 int Enemy::get_x() {