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
Player/Player.cpp
- Committer:
- el15as
- Date:
- 2017-04-24
- Revision:
- 4:1f7f32f3e017
- Child:
- 5:158e2951654b
File content as of revision 4:1f7f32f3e017:
#include "Player.h"
Player::Player()
{
}
Player::~Player()
{
}
void Player::init(intVector2D XY)
{
_x = XY.x;
_y = XY.y;
_isDead = false;
Vector2D velocity = {0.0f, 0.0f};
_velocity = velocity;
intVector2D points[8] = {
{0,0}, {2,0}, // top
{0,2}, {2,2}, // bottom
{0,0}, {0,2}, // left
{2,0}, {2,2}, // right
};
for (int i = 0; i < 8; i++) {
collisionPoint[i] = points[i];
};
}
void Player::draw(N5110 &lcd)
{
// draw the player
lcd.drawRect(_x, _y, 3, 3, FILL_TRANSPARENT);
}
void Player::update(float jx, Serial &pc)
{
//_velocity.x = jx;
if (jx < 0) {
_velocity.x = int(jx*3.2f); // to make up for mechanical imbalance
} else {
_velocity.x = int(jx*3.0f);
}
// Jump if not already jumping and the jump key was pressed
if (_didReleaseJumpKey && !_isJumping && _didPressJump)
{
_isJumping = true;
_didReleaseJumpKey = false;
_velocity.y = JUMPSPEED;
}
// Jump key released
if (!_didPressJump)
_didReleaseJumpKey = true;
_velocity.y += GRAVITY; // apply gravity
}
intVector2D Player::get_pos() {
intVector2D p = {_x, _y};
return p;
}
void Player::set_pos(intVector2D p) {
_x = p.x;
_y = p.y;
}
Vector2D Player::get_velocity() {
Vector2D velocity = {_velocity.x, _velocity.y};
return velocity;
}
void Player::set_velocity(Vector2D v) {
_velocity = v;
}
void Player::reset_velocity()
{
_velocity.x = 0;
_velocity.y = 0;
}