Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: PeopleEngine/People.cpp
- Revision:
- 9:62d6559f0d50
- Parent:
- 8:8287d2ef965d
- Child:
- 12:009895f6b6e4
diff -r 8287d2ef965d -r 62d6559f0d50 PeopleEngine/People.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PeopleEngine/People.cpp Sat May 09 08:27:07 2020 +0000 @@ -0,0 +1,100 @@ +#include "People.h" +#define INIT_x 1 +#define INIT_y 23 + + +const int people_sprite[4][4] = { + {0,1,1,0}, + {1,1,1,1}, + {0,1,1,0}, + {0,1,1,0}, +};//try to draw a people, but for the operability of game, seems not good.. + +People::People() { + +} + +People::~People() { + +} + +void People::init() { + + _x = INIT_x; + _y = INIT_y;//Set initial postion of people +} +void People::draw(N5110 &lcd) { + + //Draw sprite to represent a people + lcd.drawSprite(_x,_y,4,4,(int*)people_sprite); + // printf("drawSprite"); +} + +void People::set_pos(Vector2D p) +{ + _x = p.x; + _y = p.y; +} + +void People::set_velocity(Direction d,float mag) +{ + _d = d; + _mag = mag; +} + +Vector2D People::get_pos() +{ + Vector2D p = {_x,_y}; + //printf("Coord = %f,%f\n",p.x,p.y); + return p; +} + +void People::update() +{ + 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;}} + //without going off screen + if (_x < 1) { _x = 1;} else + if (_x > 79) { _x = 79;} else + if (_y < 1) {_y = 1;} else + if (_y > 43) {_y = 43;} +} + \ No newline at end of file