KlassischeKeplerKriege/game/state/missile.hpp
2016-09-28 00:13:03 +02:00

71 lines
1.8 KiB
C++

#pragma once
#include <glm/vec2.hpp>
#include <glm/vec3.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:
// missile advances to pos. if hit != Nothing, it hits something and
// stops existing afterwards.
class Event {
public:
Event(const glm::vec2 &pos)
: Event(pos, Hit::Nothing)
{
}
Event(const glm::vec2 &pos, Hit hit)
: hit(hit), position(pos)
{
}
Event(const glm::vec2 &pos, int planetId) : Event(pos, Hit::Planet)
{
this->planetId = planetId;
}
Event(const glm::vec2 &pos, int playerIdKiller, int playerIdVictim)
: Event(pos, Hit::Ship)
{
this->playerIdKiller = playerIdKiller;
this->playerIdVictim = playerIdVictim;
}
Hit hit;
glm::vec2 position;
// if a player was hit, these are valid.
int playerIdKiller;
int playerIdVictim;
// if a planet was hit, this is valid
int planetId;
};
Missile(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 position;
glm::vec2 velocity;
Trace *trace;
};
}