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.
Player/Player.cpp
- Committer:
- joebarhouch
- Date:
- 2020-05-18
- Revision:
- 3:e4e1cbf750b6
- Parent:
- 2:f22cb01c43bc
- Child:
- 4:cf5088ace087
File content as of revision 3:e4e1cbf750b6:
#include "Player.h"
#include "Sprites.h"
Player::Player()
{
}
Player::~Player()
{
}
void Player::init(int x,int y)
{
_playerX = x;
_playerY = y;
}
bool Player::jump(Gamepad &pad)
{
bool bttnA = pad.A_pressed();
_jmp = false;
// returns true when A is pressed for jump
if(bttnA == true) {
_jmp = true;
return _jmp;
} else {
_jmp = false;
}
return _jmp;
}
void Player::draw(N5110 &lcd)
{
if(_dir == E) {
Bitmap bit_player(s_player, 8, 9);
bit_player.render(lcd, _playerX, _playerY);
}
if(_dir == W) {
Bitmap bit_player_inv(s_player_inv, 8, 9);
bit_player_inv.render(lcd, _playerX, _playerY);
} else {
Bitmap bit_player(s_player, 8, 9);
bit_player.render(lcd, _playerX, _playerY);
}
}
void Player::update(Direction d, float mag)
{
int _vx = int(mag*4.0f);
if(d == E) {
_playerX = _playerX + _vx;
_dir = E;
}
if(d == W) {
_playerX = _playerX - _vx;
_dir = W;
}
if (_playerX > WIDTH - 8) {
_playerX = WIDTH - 8;
}
if(_playerX < 0) {
_playerX = 0;
}
}
Vector2D Player::get_pos()
{
Vector2D pos = {_playerX, _playerY};
return pos;
}