KlassischeKeplerKriege/game/state/missile.hpp

74 lines
2.1 KiB
C++
Raw Normal View History

#pragma once
#include "object.hpp"
#include <glm/vec2.hpp>
#include "missile_hit_type.hpp"
namespace game {
class State;
class Ship;
class Planet;
class Player;
class State;
class Trace;
// missile belongs to a player and optionally fills a trace behind it.
// trace then belongs to the player.
class Missile : public Object {
public:
// missile advances to pos. if hit != Nothing, it hits something and
// stops existing afterwards.
class Event {
public:
Event(const glm::vec2 &pos, const glm::vec2 &missileVelocity)
: Event(pos, missileVelocity, Hit::Nothing)
{
}
Event(const glm::vec2 &pos, const glm::vec2 &missileVelocity, Hit hit)
: hit(hit), position(pos), missileVelocity(missileVelocity)
{
}
Event(const glm::vec2 &pos, const glm::vec2 &missileVelocity, size_t planetId)
: Event(pos, missileVelocity, Hit::Planet)
2016-09-27 22:13:03 +00:00
{
this->planetId = planetId;
}
Event(const glm::vec2 &pos, const glm::vec2 &missileVelocity, size_t playerIdKiller, size_t playerIdVictim)
: Event(pos, missileVelocity, Hit::Ship)
{
this->playerIdKiller = playerIdKiller;
this->playerIdVictim = playerIdVictim;
}
Hit hit;
glm::vec2 position;
glm::vec2 missileVelocity;
2016-09-27 22:13:03 +00:00
// if a player was hit, these are valid.
size_t playerIdKiller;
size_t playerIdVictim;
2016-09-27 22:13:03 +00:00
// if a planet was hit, this is valid
size_t planetId;
};
Missile(size_t id, Player *player, const glm::vec2 &pos, float angle, float speed);
~Missile();
// try to advance. if something will be hit, return the first hit in
// time.
Missile::Event advance(const game::State *state, float dt);
Player *player; // owner won't be hit by own missiles
glm::vec2 velocity;
Trace *trace;
};
}