ELEC2645 (2018/19) / Mbed 2 deprecated el17set_

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
S_Tingle
Date:
Wed May 08 15:01:45 2019 +0000
Parent:
17:ce6b54422113
Child:
19:1073cc64cb0b
Commit message:
new movement enemy1

Changed in this revision

Coin/Coin.cpp Show annotated file Show diff for this revision Revisions of this file
Enemy/Enemy1.cpp Show annotated file Show diff for this revision Revisions of this file
Enemy/Enemy1.h Show annotated file Show diff for this revision Revisions of this file
Game/Game.cpp Show annotated file Show diff for this revision Revisions of this file
Game/Game.h Show annotated file Show diff for this revision Revisions of this file
Menu/Menu.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Coin/Coin.cpp	Wed May 08 13:03:24 2019 +0000
+++ b/Coin/Coin.cpp	Wed May 08 15:01:45 2019 +0000
@@ -1,8 +1,6 @@
 #include "Coin.h"
 
 Coin::Coin(){
-    x_coin = 41;
-    y_coin = 42;
     _spawn = true;
 }
 
@@ -32,7 +30,6 @@
 }
 
 bool Coin::collidePlayer(int x, int y, Gamepad &pad) {
-
     for (int ix = 0; ix < 7; ix++) {
         for (int iy = 0; iy < 7; iy++) {
             if ( x + ix == x_coin - 1 &&
@@ -40,6 +37,21 @@
                 ++coin;
                 pad.tone(650,0.25);
                 return true;
+            } else if ( x + ix == x_coin + 2 &&
+                 y + iy == y_coin) {
+                ++coin;
+                pad.tone(650,0.25);
+                return true;
+            } else if ( x + ix == x_coin &&
+                 y + iy == y_coin - 1) {
+                ++coin;
+                pad.tone(650,0.25);
+                return true;
+            } else if ( x + ix == x_coin &&
+                 y + iy == y_coin + 2) {
+                ++coin;
+                pad.tone(650,0.25);
+                return true;
             }
         }       
     }
@@ -49,12 +61,8 @@
 void Coin::spawn(int x, int y, N5110 &lcd, Gamepad &pad) {
         drawSprite(lcd);
     if (collidePlayer(x,y,pad) == true) {
-        char buffer[14];
-        sprintf(buffer,"%2d",coins());
-        printf(buffer,77,40);
         x_coin = 100;
         y_coin = 100;
-
     } else {
 
     }
--- a/Enemy/Enemy1.cpp	Wed May 08 13:03:24 2019 +0000
+++ b/Enemy/Enemy1.cpp	Wed May 08 15:01:45 2019 +0000
@@ -28,20 +28,12 @@
 
 void Enemy1::movement(N5110 &lcd){
     accel = 1;
-    for (int i = 0; i < 60; i++) {
-        if (y_enem == 17 && x_enem < 50){
-            x_enem += accel;
-        }
-        if (y_enem < 24 && x_enem == 50){
-            y_enem += accel;
-        }
-        if (y_enem == 24 && x_enem > 27){
-            x_enem -= accel;
-        }
-        if (y_enem > 17 && x_enem == 27){
-            y_enem -= accel;
-        }
-    }
+    _incrementer_enem1++;
+    if ( _incrementer_enem1 == 62 ) { _incrementer_enem1 = 0; }
+    if ( _incrementer_enem1 >= 0 && _incrementer_enem1 <= 23) { x_enem++; }
+    else if ( _incrementer_enem1 >= 24 && _incrementer_enem1 <= 30) { y_enem++; }
+    else if ( _incrementer_enem1 >= 31 && _incrementer_enem1 <= 54) { x_enem--; }
+    else if ( _incrementer_enem1 >= 55 && _incrementer_enem1 <= 61) { y_enem--; }
 }
 
 bool Enemy1::northCollision(int x, int y, N5110 &lcd){
--- a/Enemy/Enemy1.h	Wed May 08 13:03:24 2019 +0000
+++ b/Enemy/Enemy1.h	Wed May 08 15:01:45 2019 +0000
@@ -40,6 +40,7 @@
     int x_enem;
     int y_enem;
     int accel;
+    int _incrementer_enem1;
      
 
 };
--- a/Game/Game.cpp	Wed May 08 13:03:24 2019 +0000
+++ b/Game/Game.cpp	Wed May 08 15:01:45 2019 +0000
@@ -10,7 +10,10 @@
 
 void Game::init(){
     smiley.init(x,y);
-    _lives = 1;
+    _lives = 3;
+    coin1.init(41, 42);
+    coin2.init(41, 23);
+    coin3.init(81, 42);
 }
 
 void Game::dirmag(Gamepad &pad){
@@ -22,7 +25,9 @@
     maze.drawSprite(lcd);
     enemy1.drawSprite(lcd);
     enemy2.drawSprite(lcd);
-    coin.drawSprite(lcd);
+    coin1.drawSprite(lcd);
+    coin2.drawSprite(lcd);
+    coin3.drawSprite(lcd);
     smiley.drawSprite(lcd);
 }
 
@@ -35,7 +40,7 @@
 void Game::collect(N5110 &lcd, Gamepad &pad){
     int x = smiley.get_x_char();
     int y = smiley.get_y_char();
-    coin.spawn(x, y, lcd, pad);
+    coin1.spawn(x, y, lcd, pad);
 }
 
 void Game::damage(N5110 &lcd, Gamepad &pad){
--- a/Game/Game.h	Wed May 08 13:03:24 2019 +0000
+++ b/Game/Game.h	Wed May 08 15:01:45 2019 +0000
@@ -22,6 +22,7 @@
     void drawSprite(N5110 &lcd);
     void collect(N5110 &lcd,  Gamepad &pad);
     void movement(Gamepad &pad,N5110 &lcd);
+    void position();
     void damage(N5110 &lcd,Gamepad &pad);
     void UI(Gamepad &pad,N5110 &lcd);
     void death(N5110 &lcd, Gamepad &pad);
@@ -33,7 +34,9 @@
     Maze maze;
     Enemy1 enemy1;
     Enemy2 enemy2;
-    Coin coin;
+    Coin coin1;
+    Coin coin2;
+    Coin coin3;
     Menu menu;
     Direction dir;
 
--- a/Menu/Menu.cpp	Wed May 08 13:03:24 2019 +0000
+++ b/Menu/Menu.cpp	Wed May 08 15:01:45 2019 +0000
@@ -63,10 +63,13 @@
         lcd.printString("TINGLE",10,4);
         lcd.refresh();
         if (pad.check_event(Gamepad::X_PRESSED) == true){
+            pad.check_event(Gamepad::L_PRESSED) == false;
         }
         if (pad.check_event(Gamepad::Y_PRESSED) == true){
+            pad.check_event(Gamepad::L_PRESSED) == false;
         }
         if (pad.check_event(Gamepad::B_PRESSED) == true){
+            pad.check_event(Gamepad::L_PRESSED) == false;
         }
     }
 }
\ No newline at end of file
--- a/main.cpp	Wed May 08 13:03:24 2019 +0000
+++ b/main.cpp	Wed May 08 15:01:45 2019 +0000
@@ -33,7 +33,7 @@
     wait(1.0f/fps);
     while (1) { 
         game.UI(pad,lcd); 
-        game.init();   
+        game.init();  
         int lives = game.get_lives();
         while (lives > 0) {
             render();