Enemies melt when killed.

linux_template
sigonasr2 2 years ago
parent 062666753b
commit 0e091a856d
  1. 80
      Faceball2030/main.cpp
  2. 7
      Faceball2030/main.h

@ -31,6 +31,26 @@ bool Enemy::isDead() {
return health <= 0; return health <= 0;
} }
void Enemy::increaseDeathTimer(float fElapsedTime) {
deathTimer += fElapsedTime;
}
bool Enemy::deathAnimationOver() {
return deathTimer > 3.0f;
}
void Enemy::increaseColorFactor(float fElapsedTime) {
colorFactor += 50 * fElapsedTime;
}
float Enemy::getColorFactor() {
return colorFactor;
}
void Enemy::decreaseColorFactor() {
colorFactor--;
}
void FaceBall::InitializeEnemyData() { void FaceBall::InitializeEnemyData() {
enemyData[EnemyID::NONE] = { "VOID",undefined,BLACK }; enemyData[EnemyID::NONE] = { "VOID",undefined,BLACK };
enemyData[EXIT] = { "EXIT",undefined,GREEN }; enemyData[EXIT] = { "EXIT",undefined,GREEN };
@ -915,11 +935,10 @@ bool Bullet::Update(float fElapsedTime) {
int collided_enemy = FaceBall::CheckEnemyCollision(adjustedSpd, { pos.x,pos.z }, 0.1); int collided_enemy = FaceBall::CheckEnemyCollision(adjustedSpd, { pos.x,pos.z }, 0.1);
if (collided_enemy!=-1) { if (collided_enemy!=-1) {
Enemy& enemy = game->enemies[collided_enemy]; Enemy& enemy = game->enemies[collided_enemy];
enemy.Hurt(); if (!enemy.isDead()) {
if (enemy.isDead()) { enemy.Hurt();
game->enemies.erase(game->enemies.begin() + collided_enemy); return false;
} }
return false;
} }
} }
if (!FaceBall::CheckCollision(adjustedSpd, {pos.x,pos.z}, 0.05)) { if (!FaceBall::CheckCollision(adjustedSpd, {pos.x,pos.z}, 0.05)) {
@ -933,10 +952,55 @@ bool Bullet::Update(float fElapsedTime) {
} }
void FaceBall::RunEnemyAI(Enemy& e,float fElapsedTime) { void FaceBall::RunEnemyAI(Enemy& e,float fElapsedTime) {
switch (e.GetID()) { if (e.isDead()) {
case SHOOTME: { if (!e.deathAnimationOver()) {
e.rot += 0.5 * fElapsedTime; std::vector<Triangle>& tris = e.mesh.tris;
}break; uint8_t darkenAmt = 0;
while (e.getColorFactor() >= 1) {
darkenAmt++;
e.decreaseColorFactor();
}
for (Triangle& t : tris) {
if (t.p[0].y > 0.1) {
t.p[0].y = std::max(0.1f, t.p[0].y - 0.3f * fElapsedTime);
}
else {
float dir = std::atan2f(t.p[0].z, t.p[0].x);
t.p[0].x += std::cosf(dir)*0.04f*fElapsedTime;
t.p[0].z += std::sinf(dir) * 0.04f * fElapsedTime;
}
if (t.p[1].y > 0.1) {
t.p[1].y = std::max(0.1f, t.p[1].y - 0.3f * fElapsedTime);
}
else {
float dir = std::atan2f(t.p[1].z, t.p[1].x);
t.p[1].x += std::cosf(dir) * 0.06f * fElapsedTime;
t.p[1].z += std::sinf(dir) * 0.06f * fElapsedTime;
}
if (t.p[2].y > 0.1) {
t.p[2].y = std::max(0.1f, t.p[2].y - 0.3f * fElapsedTime);
}
else {
float dir = std::atan2f(t.p[2].z, t.p[2].x);
t.p[2].x += std::cosf(dir) * 0.05f * fElapsedTime;
t.p[2].z += std::sinf(dir) * 0.05f * fElapsedTime;
}
if (darkenAmt>0){
t.col[0] -= {darkenAmt, darkenAmt, darkenAmt};
t.col[1] -= {darkenAmt, darkenAmt, darkenAmt};
t.col[2] -= {darkenAmt, darkenAmt, darkenAmt};
}
}
e.increaseDeathTimer(fElapsedTime);
e.increaseColorFactor(fElapsedTime);
}
}
else {
switch (e.GetID()) {
case SHOOTME: {
e.rot += 0.5 * fElapsedTime;
}break;
}
} }
} }

@ -175,11 +175,18 @@ struct Enemy : Object {
int health=1; int health=1;
std::vector<float> shots; std::vector<float> shots;
float fireDelay=0; float fireDelay=0;
float deathTimer=0;
float colorFactor = 0;
public: public:
Enemy(EnemyID id, vec3d pos, float rot, float radius); Enemy(EnemyID id, vec3d pos, float rot, float radius);
EnemyID GetID(); EnemyID GetID();
void Hurt(); void Hurt();
bool isDead(); bool isDead();
void increaseDeathTimer(float fElapsedTime);
bool deathAnimationOver();
void increaseColorFactor(float fElapsedTime);
float getColorFactor();
void decreaseColorFactor();
}; };
class FaceBall : public PixelGameEngine class FaceBall : public PixelGameEngine

Loading…
Cancel
Save