Stick_Runner
Dependencies: FXOS8700CQ Gamepad N5110 SDFileSystem mbed
Fork of Stick_Runner by
Character/Character.cpp
- Committer:
- el15ss
- Date:
- 2017-04-28
- Revision:
- 0:12cfe63faa6a
- Child:
- 1:db9ff66f67c8
File content as of revision 0:12cfe63faa6a:
#include "Character.h" Character::Character() { } Character::~Character() { } void Character::init() { _x = 42; _y = 75; _status = true; counter = 0; } void Character::draw(N5110 &lcd) { // draw Character in screen buffer. //lcd.drawRect(_x-4,_y-3,3,3,FILL_BLACK); //lcd.drawLine(_x-3, _y-3,_x-3,_y+1,1); lcd.setPixel(_x,_y); lcd.setPixel(_x-1,_y); lcd.setPixel(_x+1,_y); lcd.setPixel(_x,_y+1); lcd.setPixel(_x-1,_y+1); lcd.setPixel(_x+1,_y+1); lcd.setPixel(_x,_y+2); lcd.setPixel(_x-1,_y+2); lcd.setPixel(_x+1,_y+2); lcd.setPixel(_x,_y+3); lcd.setPixel(_x,_y+4); lcd.setPixel(_x,_y+5); lcd.setPixel(_x-1,_y+4); lcd.setPixel(_x+1,_y+4); lcd.setPixel(_x-2,_y+5); lcd.setPixel(_x+2,_y+5); lcd.setPixel(_x,_y+6); lcd.setPixel(_x-1,_y+7); lcd.setPixel(_x+1,_y+7); lcd.setPixel(_x-2,_y+8); lcd.setPixel(_x+2,_y+8); } void Character::Character_Status(Vector2D p) { if(((_x-5<p.x)&&(_x+5>p.x))&&((_y-5<p.y)&&(_y+5>p.y))){ _status = false; } } void Character::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 == NW) { _x-=_speed; _y-=_speed; } else if (d == NE) { _x+=_speed; _y-=_speed; }else if (d == S) { _y+=_speed; }else if (d == SW) { _x-=_speed; _y+=_speed; }else if (d == SE) { _x+=_speed; _y+=_speed; }else if (d == E) { _x+=_speed; }else if (d == W) { _x-=_speed; } // check the y origin to ensure that the Character doesn't go off screen if(_x-2<0) { _x = 2; } if(_x+2>WIDTH-1) { _x = WIDTH -5; } if (_y < 1) { _y = 1; } if (_y+8 > HEIGHT - 1) { _y = HEIGHT-10; } } Vector2D Character::get_pos() { Vector2D p = {_x,_y}; return p; } bool Character::get_status(){ return _status; }