danmaku/player.cpp

58 lines
1.7 KiB
C++
Raw Normal View History

2021-01-09 11:41:58 +01:00
#include "player.h"
#include "command.h"
#include "enemy.h"
Player::Player() :
player_speed(45.f)
{
map_key_bindings[sf::Keyboard::Left] = Action::MoveLeft;
map_key_bindings[sf::Keyboard::Right] = Action::MoveRight;
map_key_bindings[sf::Keyboard::Up] = Action::MoveUp;
map_key_bindings[sf::Keyboard::Down] = Action::MoveDown;
map_action_bindings[Action::MoveLeft].action =
[&] (SceneNode& node, const sf::Time& time)
{
node.move(-player_speed * time.asSeconds(), 0.f);
};
map_action_bindings[Action::MoveRight].action =
[&] (SceneNode& node, const sf::Time& time)
{
node.move(player_speed * time.asSeconds(), 0.f);
};
map_action_bindings[Action::MoveUp].action =
[&] (SceneNode& node, const sf::Time& time)
{
node.move(0.f, -player_speed * time.asSeconds());
};
map_action_bindings[Action::MoveDown].action =
[&] (SceneNode& node, const sf::Time& time)
{
node.move(0.f, player_speed * time.asSeconds());
};
for (auto& pair : map_action_bindings)
pair.second.category = Category::Enemy;
}
void Player::handleRealtimeInput(std::queue<Command>& queue)
{
for (const auto& pair : map_key_bindings)
if (sf::Keyboard::isKeyPressed(pair.first) && isRealtime(pair.second))
queue.push(map_action_bindings[pair.second]);
}
void Player::handleEvent(const sf::Event &event, std::queue<Command> &queue)
{
switch (event.type)
{
case sf::Event::KeyPressed:
break;
default:
break;
}
}