feat: Aircraft trails
This commit is contained in:
@@ -4,14 +4,14 @@ void dxd::sim::AFSpawner::tick(float timestep, World *world)
|
||||
{
|
||||
(void)timestep;
|
||||
|
||||
if (_next_spawn-- != 0)
|
||||
if (--_next_spawn != 0)
|
||||
return;
|
||||
|
||||
_next_spawn = 60 + SDL_rand(120);
|
||||
_next_spawn = _MIN_SPAWN_DELAY + SDL_rand(_MAX_SPAWN_DELAY);
|
||||
|
||||
//Pos should spawn in a grid, check if free, and offset random from grid coord to look natural
|
||||
vec2 pos = {(SDL_randf()-.5f)*2*60.0f, (SDL_randf()-.5f)*2*60.0f};
|
||||
Airfield *af = new Airfield(pos, 180 + SDL_rand(600));
|
||||
Airfield *af = new Airfield(pos, _MIN_AF_TTL + SDL_rand(_MAX_AF_TTL));
|
||||
world->add_obj(af);
|
||||
_airfields.push_back(af);
|
||||
}
|
||||
|
||||
@@ -15,11 +15,16 @@ private:
|
||||
std::vector<Airfield*> _airfields;
|
||||
int _next_spawn;
|
||||
|
||||
const int _MIN_SPAWN_DELAY = 450;
|
||||
const int _MAX_SPAWN_DELAY = 3000;
|
||||
const int _MIN_AF_TTL = 1200;
|
||||
const int _MAX_AF_TTL = 6000;
|
||||
|
||||
public:
|
||||
AFSpawner()
|
||||
{
|
||||
_airfields = std::vector<Airfield*>();
|
||||
_next_spawn = 0;
|
||||
_next_spawn = 1;
|
||||
}
|
||||
|
||||
void tick(float timestep, World *world) override;
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
#include "aircraft.hpp"
|
||||
#include "aircraft_trail.hpp"
|
||||
|
||||
void dxd::sim::Aircraft::tick(float timestep, World *world)
|
||||
{
|
||||
(void)world;
|
||||
|
||||
_position = _position + polar_to_vec2(_direction, _speed) * timestep;
|
||||
|
||||
if (--_trail_cooldown == 0)
|
||||
{
|
||||
world->add_obj(new AircraftTrail(_position, _TRAIL_DURATION));
|
||||
_trail_cooldown = _TRAIL_DELAY;
|
||||
}
|
||||
}
|
||||
|
||||
void dxd::sim::Aircraft::draw(Renderer *rend)
|
||||
|
||||
@@ -12,10 +12,17 @@ private:
|
||||
vec2 _position;
|
||||
float _direction;
|
||||
float _speed;
|
||||
int _trail_cooldown;
|
||||
|
||||
const int _TRAIL_DELAY = 60;
|
||||
const int _TRAIL_DURATION = 420;
|
||||
|
||||
public:
|
||||
Aircraft(vec2 position, float direction, float speed)
|
||||
: _position(position), _direction(direction), _speed(speed) {}
|
||||
: _position(position), _direction(direction), _speed(speed)
|
||||
{
|
||||
_trail_cooldown = _TRAIL_DELAY;
|
||||
}
|
||||
|
||||
void tick(float timestep, World *world) override;
|
||||
void draw(Renderer *rend) override;
|
||||
|
||||
18
src/sim/aircraft_trail.cpp
Normal file
18
src/sim/aircraft_trail.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "aircraft_trail.hpp"
|
||||
|
||||
void dxd::sim::AircraftTrail::tick(float timestep, World *world)
|
||||
{
|
||||
(void)timestep;
|
||||
|
||||
if (--_ttl == 0)
|
||||
{
|
||||
world->remove_obj(this);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void dxd::sim::AircraftTrail::draw(Renderer *rend)
|
||||
{
|
||||
rend->color(128, 128, 128, 255);
|
||||
rend->box(_position, .5);
|
||||
}
|
||||
22
src/sim/aircraft_trail.hpp
Normal file
22
src/sim/aircraft_trail.hpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "../math.hpp"
|
||||
#include "world_object.hpp"
|
||||
|
||||
namespace dxd::sim
|
||||
{
|
||||
|
||||
class AircraftTrail : public WorldObject
|
||||
{
|
||||
private:
|
||||
vec2 _position;
|
||||
int _ttl;
|
||||
|
||||
public:
|
||||
AircraftTrail(vec2 position, int ttl) : _position(position), _ttl(ttl) {}
|
||||
|
||||
void tick(float timestep, World *world) override;
|
||||
void draw(Renderer *rend) override;
|
||||
};
|
||||
|
||||
} // namespace dxd::sim
|
||||
@@ -13,9 +13,9 @@ void dxd::sim::Airfield::tick(float timestep, World *world)
|
||||
|
||||
if (--_next_spawn == 0)
|
||||
{
|
||||
Aircraft *af = new Aircraft(_position, SDL_randf() * M_PIf, 5.0f);
|
||||
Aircraft *af = new Aircraft(_position, SDL_randf() * 2 * M_PIf, 5.0f);
|
||||
world->add_obj(af);
|
||||
_next_spawn = 60 + SDL_rand(240);
|
||||
_next_spawn = _MIN_TAKEOFF_DELAY + SDL_rand(_MAX_TAKEOFF_DELAY - _MIN_TAKEOFF_DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,9 @@ private:
|
||||
int _ttl;
|
||||
int _next_spawn;
|
||||
|
||||
const int _MIN_TAKEOFF_DELAY = 240;
|
||||
const int _MAX_TAKEOFF_DELAY = 600;
|
||||
|
||||
public:
|
||||
Airfield(vec2 position, int ttl) : _position(position), _ttl(ttl)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user