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
PeopleEngine/People.cpp
- Committer:
- el19zf
- Date:
- 2020-05-09
- Revision:
- 9:62d6559f0d50
- Parent:
- People/People.cpp@ 8:8287d2ef965d
- Child:
- 12:009895f6b6e4
File content as of revision 9:62d6559f0d50:
#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;} }