ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18jgb

Dependencies:   mbed

Revision:
13:cfdfe60a2327
Parent:
10:6c574b8524df
Child:
17:18ae81180853
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Spikes/Spikes.cpp	Mon May 18 15:46:04 2020 +0000
@@ -0,0 +1,67 @@
+#include "Spikes.h"
+
+const int spike [5][5] = 
+{
+    {0,0,1,0,0},
+    {0,0,1,0,0},
+    {1,1,1,1,1},
+    {0,1,1,1,0},
+    {0,0,1,0,0},
+};
+
+Spikes::Spikes()
+{
+
+}
+
+Spikes::~Spikes()
+{
+
+}
+
+void Spikes::init(){
+    _x = 0;
+    _y = 0;
+    _height = 5;
+    _width = 5;
+    
+    _speed = 3;
+}
+
+
+void Spikes::draw(N5110 &lcd)
+{
+    // draw spike 
+    lcd.drawSprite(_x,_y,5,5,(int*)spike);
+
+}
+
+void Spikes::position(int x)
+{
+    if (x == 1){
+        _x = rand() % 37 + 1;
+        _y = 1;
+    }
+    if (x == 2){
+        _x = rand() % 37 + 42;
+        _y = 1;
+    }
+}
+
+void Spikes::update()
+{
+    _y = _y + 3;
+}
+
+Vector2D Spikes::get_pos() {
+    Vector2D p = {_x,_y};
+    return p;    
+}
+
+void Spikes::hit(Gamepad &pad)
+{
+    pad.led(1,1);
+    pad.led(4,1);
+}
+
+    
\ No newline at end of file