ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18jgb

Dependencies:   mbed

Revision:
5:c37f4ed2cad3
Parent:
4:6f898b000797
Child:
6:d560ecc21ae6
--- a/Eng.cpp	Thu May 14 16:16:49 2020 +0000
+++ b/Eng.cpp	Sun May 17 13:11:55 2020 +0000
@@ -1,8 +1,5 @@
-#include "Aim.h"
-#include "mbed.h"
-#include "N5110.h"
-#include "Gamepad.h"
-#include "Heston.h"
+
+#include "Eng.h"
 Eng::Eng()
 {
 
@@ -13,35 +10,50 @@
 
 }
 // objects
-Gamepad pad;
-N5110 lcd;
-Aim Aim;
+//Gamepad pad;
+//N5110 lcd;
+Aim aim;
 Heston heston;
 
-InterruptIn buttonA(PTC7);
-InterruptIn buttonB(PTC9);
-InterruptIn buttonX(PTC5);
-InterruptIn buttonY(PTC0);
 
-DigitalOut led1(PTA2);
-DigitalOut led2(PTC2);
-DigitalOut led3(PTC3);
-DigitalOut led4(PTA1);
+void Eng::init()
+{
+    
+    aim.init();
+    heston.init();
 
-void init()
+
+}
+
+//void Eng::read_input(Gamepad &pad);
+void Eng::update(Gamepad &pad)
 {
-    buttonA.mode(PullUp); // turn on internal pull-up resistor
-    // pin will be 1 (3.3 V) when not pressed and 0 (0 V) when pressed
-    buttonB.mode(PullUp);
-    buttonY.mode(PullUp);
-    buttonX.mode(PullUp);
-    // We therefore need to look for a falling edge on the pin to fire the interrupt
-    // when the button is pressed
-    buttonA.fall(&buttonA_isr);
-    buttonB.fall(&buttonB_isr);
-    buttonX.fall(&buttonX_isr);
-    buttonY.fall(&buttonY_isr);
+        check_hit(pad);
+        
+        heston.update(pad);
+        aim.update(pad);
+
+
+}
+
+void Eng::draw(N5110 &lcd)
+{
+    heston.draw(lcd);
+    aim.draw(lcd);
 }
-void read_input(Gamepad &pad);
-void update(Gamepad &pad);
-void draw(N5110 &lcd);
+
+void Eng::check_hit(Gamepad &pad)
+{
+    Vector2D aim_pos = aim.get_pos();
+    Vector2D h1_pos = heston.get_pos();
+    
+    if (
+        (aim_pos.y >= h1_pos.y) && //top
+        (aim_pos.y <= h1_pos.y + 12) && //bottom
+        (aim_pos.x >= h1_pos.x) && //left
+        (aim_pos.x <= h1_pos.x + 11)  //right
+    ) {
+        heston.hit(pad);
+}
+
+}