Stick_Runner
Dependencies: FXOS8700CQ Gamepad N5110 SDFileSystem mbed
Fork of Stick_Runner by
Character/Character.cpp
- Committer:
- el15ss
- Date:
- 2017-05-02
- Revision:
- 2:98a41609c827
- Parent:
- 1:db9ff66f67c8
- Child:
- 3:0c690f1c04d8
File content as of revision 2:98a41609c827:
#include "Character.h" void Character::init() { charPosX = 42; charPosY = 75; charStatus = true; } void Character::draw(N5110 &lcd) { lcd.setPixel(charPosX,charPosY); lcd.setPixel(charPosX-1,charPosY); lcd.setPixel(charPosX+1,charPosY); lcd.setPixel(charPosX,charPosY+1); lcd.setPixel(charPosX-1,charPosY+1); lcd.setPixel(charPosX+1,charPosY+1); lcd.setPixel(charPosX,charPosY+2); lcd.setPixel(charPosX-1,charPosY+2); lcd.setPixel(charPosX+1,charPosY+2); lcd.setPixel(charPosX,charPosY+3); lcd.setPixel(charPosX,charPosY+4); lcd.setPixel(charPosX,charPosY+5); lcd.setPixel(charPosX-1,charPosY+4); lcd.setPixel(charPosX+1,charPosY+4); lcd.setPixel(charPosX-2,charPosY+5); lcd.setPixel(charPosX+2,charPosY+5); lcd.setPixel(charPosX,charPosY+6); lcd.setPixel(charPosX-1,charPosY+7); lcd.setPixel(charPosX+1,charPosY+7); lcd.setPixel(charPosX-2,charPosY+8); lcd.setPixel(charPosX+2,charPosY+8); } void Character::updateCharacter(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) { charPosY-=_speed; } else if (d == NW) { charPosX-=_speed; charPosY-=_speed; } else if (d == NE) { charPosX+=_speed; charPosY-=_speed; } else if (d == S) { charPosY+=_speed; } else if (d == SW) { charPosX-=_speed; charPosY+=_speed; } else if (d == SE) { charPosX+=_speed; charPosY+=_speed; } else if (d == E) { charPosX+=_speed; } else if (d == W) { charPosX-=_speed; } // check the y origin to ensure that the Character doesn't go off screen if(charPosX-2<0) { charPosX = 2; } if(charPosX+2>WIDTH-1) { charPosX = WIDTH -5; } if (charPosY < 1) { charPosY = 1; } if (charPosY+8 > HEIGHT - 1) { charPosY = HEIGHT-10; } } Vector2D Character::getCharacterPos() { Vector2D p = {charPosX,charPosY}; return p; } void Character::characterStatus(Vector2D p) { if(((charPosX-5<p.x)&&(charPosX+5>p.x))&&((charPosY-5<p.y)&&(charPosY+5>p.y))) { charStatus = false; } } bool Character::getCharacterStatus() { return charStatus; }