ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el19zf

Dependencies:   mbed

Revision:
3:b8fbaefc496c
Parent:
2:67b51ee7fc34
Child:
4:b12a49f0b730
--- a/People/People.cpp	Sun Apr 12 04:35:32 2020 +0000
+++ b/People/People.cpp	Sun Apr 12 12:56:49 2020 +0000
@@ -8,7 +8,7 @@
         {1,1,1,1},
         {0,1,1,0},
         {0,1,1,0},
-};//try to simulate a people, but for the operability of game, seems not good
+};//try to draw a people, but for the operability of game, seems not good..
 
 People::People() {
     
@@ -27,13 +27,7 @@
     
     //Draw sprite to represent a people
     lcd.drawSprite(_x,_y,4,4,(int*)people_sprite);
-    printf("drawSprite");
-}
-
-void People::update()
-{
-    _x += _velocity.x;
-    _y += _velocity.y;
+    // printf("drawSprite");
 }
 
 void People::set_pos(Vector2D p)
@@ -42,23 +36,60 @@
     _y = p.y;
 }
 
-void People::set_velocity(Vector2D v)
+void People::set_velocity(Direction d,float mag)
 {
-    _velocity.x = v.x;
-    _velocity.y = v.y;
+    _d = d;
+    _mag = mag;
 }
 
 Vector2D People::get_pos()
 {
     Vector2D p = {_x,_y};
+    //printf("Coord = %f,%f\n",p.x,p.y);
     return p;
 }
 
-Vector2D People::get_velocity()
+void People::update()
 {
-    Vector2D v = {_velocity.x,_velocity.y};
-    return v;
+    if (_d == S) {
+        if(_mag < 0.25f)        {   _x += 0;    _y += 1;} else
+        if(0.25f < _mag < 0.5f) {   _x += 0;    _y += 2;} else
+        if(0.5f < _mag < 0.75f) {   _x += 0;    _y += 3;} else 
+                                {   _x += 0;    _y += 4;}}
+    if (_d == SE) {
+        if(_mag < 0.25f)        {   _x += 1;    _y += 1;} else
+        if(0.25f < _mag < 0.5f) {   _x += 2;    _y += 2;} else
+        if(0.5f < _mag < 0.75f) {   _x += 3;    _y += 3;} else 
+                                {   _x += 4;    _y += 4;}}
+    if (_d == E) {              
+        if(_mag < 0.25f)        {   _x += 1;    _y += 0;} else
+        if(0.25f < _mag < 0.5f) {   _x += 2;    _y += 0;} else
+        if(0.5f < _mag < 0.75f) {   _x += 3;    _y += 0;} else 
+                                {   _x += 4;    _y += 0;}}  
+    if (_d == NE) {
+        if(_mag < 0.25f)        {   _x += 1;    _y -= 1;} else
+        if(0.25f < _mag < 0.5f) {   _x += 2;    _y -= 2;} else
+        if(0.5f < _mag < 0.75f) {   _x += 3;    _y -= 3;} else 
+                                {   _x += 4;    _y -= 4;}}
+    if (_d == N) {
+        if(_mag < 0.25f)        {   _x += 0;    _y -= 1;} else
+        if(0.25f < _mag < 0.5f) {   _x += 0;    _y -= 2;} else
+        if(0.5f < _mag < 0.75f) {   _x += 0;    _y -= 3;} else 
+                                {   _x += 0;    _y -= 4;}}
+    if (_d == NW) {
+        if(_mag < 0.25f)        {   _x -= 1;    _y -= 1;} else
+        if(0.25f < _mag < 0.5f) {   _x -= 2;    _y -= 2;} else
+        if(0.5f < _mag < 0.75f) {   _x -= 3;    _y -= 3;} else 
+                                {   _x -= 4;    _y -= 4;}}
+    if (_d == W) {
+        if(_mag < 0.25f)        {   _x -= 1;    _y -= 0;} else
+        if(0.25f < _mag < 0.5f) {   _x -= 2;    _y -= 0;} else
+        if(0.5f < _mag < 0.75f) {   _x -= 3;    _y -= 0;} else 
+                                {   _x -= 4;    _y -= 0;}}
+    if (_d == NW) {
+        if(_mag < 0.25f)        {   _x -= 1;    _y += 1;} else
+        if(0.25f < _mag < 0.5f) {   _x -= 2;    _y += 2;} else
+        if(0.5f < _mag < 0.75f) {   _x -= 3;    _y += 3;} else 
+                                {   _x -= 4;    _y += 4;}}
 }
-
-
     
\ No newline at end of file