|
|
|
@ -31,6 +31,26 @@ bool Enemy::isDead() { |
|
|
|
|
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() { |
|
|
|
|
enemyData[EnemyID::NONE] = { "VOID",undefined,BLACK }; |
|
|
|
|
enemyData[EXIT] = { "EXIT",undefined,GREEN }; |
|
|
|
@ -915,13 +935,12 @@ bool Bullet::Update(float fElapsedTime) { |
|
|
|
|
int collided_enemy = FaceBall::CheckEnemyCollision(adjustedSpd, { pos.x,pos.z }, 0.1); |
|
|
|
|
if (collided_enemy!=-1) { |
|
|
|
|
Enemy& enemy = game->enemies[collided_enemy]; |
|
|
|
|
if (!enemy.isDead()) { |
|
|
|
|
enemy.Hurt(); |
|
|
|
|
if (enemy.isDead()) { |
|
|
|
|
game->enemies.erase(game->enemies.begin() + collided_enemy); |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (!FaceBall::CheckCollision(adjustedSpd, {pos.x,pos.z}, 0.05)) { |
|
|
|
|
pos.x += adjustedSpd.x; |
|
|
|
|
pos.z += adjustedSpd.z; |
|
|
|
@ -933,11 +952,56 @@ bool Bullet::Update(float fElapsedTime) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void FaceBall::RunEnemyAI(Enemy& e,float fElapsedTime) { |
|
|
|
|
if (e.isDead()) { |
|
|
|
|
if (!e.deathAnimationOver()) { |
|
|
|
|
std::vector<Triangle>& tris = e.mesh.tris; |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool FaceBall::OnUserUpdate(float fElapsedTime) |
|
|
|
|