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