Simple 2D RPG made in C++ and SFML
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.1 KiB

#include "player.h"
Player::Player(EntityManager* entityManager, Map *map, Camera *camera, float x, float y) {
this->entityManager = entityManager;
this->map = map;
this->camera = camera;
this->Load("data/gfx/player.png");
this->setPosition(x, y);
this->speed = 0.00015f;
}
void Player::Update(sf::RenderWindow* window, InputManager inputManager, int timeElapsed) {
float speed = this->speed * timeElapsed;
// Update player velocity
this->velocity.x = inputManager.IsPressed(InputManager::Right) * speed -
inputManager.IsPressed(InputManager::Left) * speed;
this->velocity.y = inputManager.IsPressed(InputManager::Down) * speed -
inputManager.IsPressed(InputManager::Up) * speed;
// Set correct speed on diagonal movement
if((this->velocity.x == speed || this->velocity.x == -speed)
&& (this->velocity.y == speed || this->velocity.y == -speed)) {
this->velocity.x *= .75;
this->velocity.y *= .75;
}
}
float Player::GetSpeed() {
return this->speed;
}
Player::~Player()
{
}