1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Missiles add spaceship vel; point in direction fired.

This issue was visible as crooked missiles when firing in a direction other
than that of travel, and being able to keep pace with fired missiles.
This commit is contained in:
Steve Dougherty 2012-05-26 14:15:06 -04:00 committed by Jonas 'Sortie' Termansen
parent a1c106ce1c
commit 46efe8923f

View file

@ -483,7 +483,7 @@ void AsteroidField::Think(float deltatime)
class Missile : public Actor class Missile : public Actor
{ {
public: public:
Missile(Vector pos, Vector vel, float ttl); Missile(Vector pos, Vector vel, Vector direction, float ttl);
virtual bool IsA(const char* classname) virtual bool IsA(const char* classname)
{ {
return !strcmp(classname, "Missile") || Actor::IsA(classname); return !strcmp(classname, "Missile") || Actor::IsA(classname);
@ -494,14 +494,16 @@ public:
private: private:
float ttl; float ttl;
Vector direction;
}; };
Missile::Missile(Vector pos, Vector vel, float ttl) Missile::Missile(Vector pos, Vector vel, Vector direction, float ttl)
{ {
this->pos = pos; this->pos = pos;
this->vel = vel; this->vel = vel;
this->ttl = ttl; this->ttl = ttl;
this->direction = direction;
} }
void Missile::Think(float deltatime) void Missile::Think(float deltatime)
@ -525,7 +527,7 @@ void Missile::Render()
uint32_t shipcolor = MakeColor(31, 255, 31); uint32_t shipcolor = MakeColor(31, 255, 31);
const float MISSILE_LEN = 5.0f; const float MISSILE_LEN = 5.0f;
Vector from = screenpos; Vector from = screenpos;
Vector to = screenpos + vel * (MISSILE_LEN / vel.Size()); Vector to = screenpos + direction * (MISSILE_LEN / direction.Size());
DrawLine(shipcolor, from.x, from.y, to.x, to.y); DrawLine(shipcolor, from.x, from.y, to.x, to.y);
} }
@ -609,7 +611,7 @@ void Spaceship::Think(float deltatime)
const Vector P3(16.0f, 0.0f); const Vector P3(16.0f, 0.0f);
Vector spawnpos = pos + P3.Rotate(shipangle) * 1.1; Vector spawnpos = pos + P3.Rotate(shipangle) * 1.1;
Vector spawnvel = Vector(speed, 0.0).Rotate(shipangle); Vector spawnvel = Vector(speed, 0.0).Rotate(shipangle);
new Missile(spawnpos, spawnvel, ttl); new Missile(spawnpos, vel + spawnvel, spawnvel, ttl);
} }
} }