2016-09-27 16:23:58 +00:00
|
|
|
#include "commands.hpp"
|
|
|
|
|
2016-09-27 18:13:09 +00:00
|
|
|
#include "trace.hpp"
|
|
|
|
|
2016-09-27 16:23:58 +00:00
|
|
|
namespace game {
|
|
|
|
void ShootCommand::apply(Player *player, State *state) const
|
|
|
|
{
|
|
|
|
//std::cout<<"apply command " << name() << std::endl;
|
|
|
|
|
2016-09-27 18:13:09 +00:00
|
|
|
// TODO: idea
|
|
|
|
// shoot multiple rockets at once or from different positions after
|
|
|
|
// level up / upgrade ...
|
|
|
|
Missile *missile = new Missile(player, player->ship->position, m_angle, m_speed);
|
|
|
|
|
|
|
|
Trace *trace = new Trace(missile);
|
|
|
|
missile->trace = trace;
|
|
|
|
|
2016-09-27 16:23:58 +00:00
|
|
|
player->energy -= m_speed;
|
2016-09-27 18:13:09 +00:00
|
|
|
player->missiles.push_back(missile);
|
|
|
|
|
|
|
|
state->addTrace(trace);
|
2016-09-27 16:23:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ShootCommand::allowed(const Player *player, const State *state) const
|
|
|
|
{
|
|
|
|
(void) state;
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
return player->alive && player->energy >= m_speed;
|
|
|
|
//return player->alive;
|
|
|
|
}
|
|
|
|
}
|