ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18zc2

Dependencies:   mbed

Revision:
4:e46c295d4baf
Parent:
3:20bd321071ef
--- a/Fighter/Fighter.cpp	Sat May 23 06:21:49 2020 +0000
+++ b/Fighter/Fighter.cpp	Sat May 23 18:12:03 2020 +0000
@@ -0,0 +1,97 @@
+#include "Fighter.h"
+
+// nothing doing in the constructor and destructor
+fighter::fighter()
+{
+
+}
+
+fighter::~fighter()
+{
+
+}
+
+void fighter::init(int x,int y,int height,int width)
+{
+    _x=WIDTH/2-width/2 ; // horizontal coordinate of fighter
+    _y=HEIGHT/2-height/2 ; // vertical coordinate of fighte
+    _height =height;
+    _width = width;
+    _speed = 1;  // default speed
+    _score = 0;
+    
+    
+    }
+    void fighter::draw(N5110 &lcd);
+    {
+        lcd.drawRect(_x+(_height/2)-(_width/2),_y,_width,_height,FILL_BLACK);
+        lcd.drawRect(_x,_y,_height,_width,FILL_BLACK);
+        
+    }
+        void fighter::update(Direction d,float mag)
+        {
+            speed = int(mag*10.0f);  // scale is arbitrary, could be changed in future
+
+    // update y value depending on direction of movement
+    // North is decrement as origin is at the top-left so decreasing moves up
+            if (d == N) 
+            {
+                _y-=_speed;
+            }else if (d == S) 
+            {
+                _y+=_speed;
+            }else if(d == W)
+            {
+                _x-=_speed;
+            }else if(d == E)
+            {
+                _x+=_speed;
+            }else if(d == NE)
+            {
+                _y+=_speed;
+                _x+=_speed;
+            }else if(d == NW)
+            {
+                _y+=_speed;
+                _x-=_speed;
+            }else if(d == SE)
+            {
+                _y-=_speed;
+                _x+=_speed;
+            }else if(d == SW)
+            {
+                _y-=_speed;
+                _x-=_speed;
+            }
+            if (_y < 1) 
+            {
+                _y = 1;
+            }
+            if (_y > HEIGHT - _height - 1)
+            {
+                _y = HEIGHT - _height - 1;
+            }
+             if (_x < 1) 
+            {
+                _x = 1;
+            }
+            if (_x > WIDTH - _width - 1)
+            {
+                _x = WIDTH - _width - 1;
+            }
+}
+            void fighter::add_score()
+            {
+                 _score++;
+            }
+            int fighter::get_score()
+            {
+                return _score;
+            }
+
+            Vector2D fighter::get_pos() 
+            {
+                 Vector2D p = {_x,_y};
+                 return p;    
+            }
+            
\ No newline at end of file