|
|
@ -88,12 +88,24 @@ bool Enemy::isLastHitTimerActive() { |
|
|
|
return lastHitTime > 0.0f; |
|
|
|
return lastHitTime > 0.0f; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Enemy::isExplosive() { |
|
|
|
|
|
|
|
return game->enemyData[id].explosive; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Enemy::setExploded(bool exploded) { |
|
|
|
|
|
|
|
this->exploded = exploded; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Enemy::isBlinking() { |
|
|
|
|
|
|
|
return blinking; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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 }; |
|
|
|
enemyData[START] = { "SPAWN POSITION",undefined,{128,64,0} }; |
|
|
|
enemyData[START] = { "SPAWN POSITION",undefined,{128,64,0} }; |
|
|
|
enemyData[SHOOTME] = { "SHOOTME",enemy_ShootMe,YELLOW,1,1,PI / 8,2,1 }; |
|
|
|
enemyData[SHOOTME] = { "SHOOTME",enemy_ShootMe,YELLOW,1,1,PI / 8,2,1,0.2f,true }; |
|
|
|
enemyData[SHOOTME2] = { "SHOOTME2",enemy_IShoot,YELLOW,1,1,PI / 6,2,1,0.5f }; |
|
|
|
enemyData[SHOOTME2] = { "SHOOTME2",enemy_IShoot,YELLOW,1,1,PI / 6,2,1,0.3f,true }; |
|
|
|
enemyData[SONAR] = { "Sonar",enemy_Sonar,RED,5,1,PI / 8,2,1 }; |
|
|
|
enemyData[SONAR] = { "Sonar",enemy_Sonar,RED,5,1,PI / 8,2,1 }; |
|
|
|
enemyData[COIN] = { "Coin",undefined,BLUE }; |
|
|
|
enemyData[COIN] = { "Coin",undefined,BLUE }; |
|
|
|
enemyData[POWERUP_ARMOR] = { "Armor",undefined,{96,0,96} }; |
|
|
|
enemyData[POWERUP_ARMOR] = { "Armor",undefined,{96,0,96} }; |
|
|
@ -1066,10 +1078,24 @@ void FaceBall::HandleKeys(float fElapsedTime) { |
|
|
|
else { |
|
|
|
else { |
|
|
|
if (!CheckCollision({ vLeftStrafe.x,0,0 }, { player.GetPos().x,player.GetPos().z }, player.GetRadius())) { |
|
|
|
if (!CheckCollision({ vLeftStrafe.x,0,0 }, { player.GetPos().x,player.GetPos().z }, player.GetRadius())) { |
|
|
|
vec3d xMovement{ vLeftStrafe.x,0,0 }; |
|
|
|
vec3d xMovement{ vLeftStrafe.x,0,0 }; |
|
|
|
|
|
|
|
int enemyCollisionIndex = CheckExplosiveEnemyCollision(xMovement, { player.GetPos().x,player.GetPos().z }, player.GetRadius()); |
|
|
|
|
|
|
|
if (enemyCollisionIndex != -1) { |
|
|
|
|
|
|
|
Enemy& e = enemies[enemyCollisionIndex]; |
|
|
|
|
|
|
|
e.Hurt(999); |
|
|
|
|
|
|
|
e.setExploded(true); |
|
|
|
|
|
|
|
HurtPlayer(e.GetID(), 1, e.isBlinking()); |
|
|
|
|
|
|
|
} |
|
|
|
player.UpdatePos(Vector_Add(player.GetPos(), xMovement)); |
|
|
|
player.UpdatePos(Vector_Add(player.GetPos(), xMovement)); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!CheckCollision({ 0,0,vLeftStrafe.z }, { player.GetPos().x,player.GetPos().z }, player.GetRadius())) { |
|
|
|
if (!CheckCollision({ 0,0,vLeftStrafe.z }, { player.GetPos().x,player.GetPos().z }, player.GetRadius())) { |
|
|
|
vec3d zMovement{ 0,0,vLeftStrafe.z }; |
|
|
|
vec3d zMovement{ 0,0,vLeftStrafe.z }; |
|
|
|
|
|
|
|
int enemyCollisionIndex = CheckExplosiveEnemyCollision(zMovement, { player.GetPos().x,player.GetPos().z }, player.GetRadius()); |
|
|
|
|
|
|
|
if (enemyCollisionIndex != -1) { |
|
|
|
|
|
|
|
Enemy& e = enemies[enemyCollisionIndex]; |
|
|
|
|
|
|
|
e.Hurt(999); |
|
|
|
|
|
|
|
e.setExploded(true); |
|
|
|
|
|
|
|
HurtPlayer(e.GetID(), 1, e.isBlinking()); |
|
|
|
|
|
|
|
} |
|
|
|
player.UpdatePos(Vector_Add(player.GetPos(), zMovement)); |
|
|
|
player.UpdatePos(Vector_Add(player.GetPos(), zMovement)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -1084,10 +1110,24 @@ void FaceBall::HandleKeys(float fElapsedTime) { |
|
|
|
else { |
|
|
|
else { |
|
|
|
if (!CheckCollision({ vRightStrafe.x,0,0 }, { player.GetPos().x,player.GetPos().z }, player.GetRadius())) { |
|
|
|
if (!CheckCollision({ vRightStrafe.x,0,0 }, { player.GetPos().x,player.GetPos().z }, player.GetRadius())) { |
|
|
|
vec3d xMovement{ vRightStrafe.x,0,0 }; |
|
|
|
vec3d xMovement{ vRightStrafe.x,0,0 }; |
|
|
|
|
|
|
|
int enemyCollisionIndex = CheckExplosiveEnemyCollision(xMovement, { player.GetPos().x,player.GetPos().z }, player.GetRadius()); |
|
|
|
|
|
|
|
if (enemyCollisionIndex != -1) { |
|
|
|
|
|
|
|
Enemy& e = enemies[enemyCollisionIndex]; |
|
|
|
|
|
|
|
e.Hurt(999); |
|
|
|
|
|
|
|
e.setExploded(true); |
|
|
|
|
|
|
|
HurtPlayer(e.GetID(), 1, e.isBlinking()); |
|
|
|
|
|
|
|
} |
|
|
|
player.UpdatePos(Vector_Add(player.GetPos(), xMovement)); |
|
|
|
player.UpdatePos(Vector_Add(player.GetPos(), xMovement)); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!CheckCollision({ 0,0,vRightStrafe.z }, { player.GetPos().x,player.GetPos().z }, player.GetRadius())) { |
|
|
|
if (!CheckCollision({ 0,0,vRightStrafe.z }, { player.GetPos().x,player.GetPos().z }, player.GetRadius())) { |
|
|
|
vec3d zMovement{ 0,0,vRightStrafe.z }; |
|
|
|
vec3d zMovement{ 0,0,vRightStrafe.z }; |
|
|
|
|
|
|
|
int enemyCollisionIndex = CheckExplosiveEnemyCollision(zMovement, { player.GetPos().x,player.GetPos().z }, player.GetRadius()); |
|
|
|
|
|
|
|
if (enemyCollisionIndex != -1) { |
|
|
|
|
|
|
|
Enemy& e = enemies[enemyCollisionIndex]; |
|
|
|
|
|
|
|
e.Hurt(999); |
|
|
|
|
|
|
|
e.setExploded(true); |
|
|
|
|
|
|
|
HurtPlayer(e.GetID(), 1, e.isBlinking()); |
|
|
|
|
|
|
|
} |
|
|
|
player.UpdatePos(Vector_Add(player.GetPos(), zMovement)); |
|
|
|
player.UpdatePos(Vector_Add(player.GetPos(), zMovement)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -1099,10 +1139,24 @@ void FaceBall::HandleKeys(float fElapsedTime) { |
|
|
|
else { |
|
|
|
else { |
|
|
|
if (!CheckCollision({ vForward.x,0,0 }, {player.GetPos().x,player.GetPos().z},player.GetRadius())) { |
|
|
|
if (!CheckCollision({ vForward.x,0,0 }, {player.GetPos().x,player.GetPos().z},player.GetRadius())) { |
|
|
|
vec3d xMovement{ vForward.x,0,0 }; |
|
|
|
vec3d xMovement{ vForward.x,0,0 }; |
|
|
|
|
|
|
|
int enemyCollisionIndex = CheckExplosiveEnemyCollision(xMovement, { player.GetPos().x,player.GetPos().z }, player.GetRadius()); |
|
|
|
|
|
|
|
if (enemyCollisionIndex != -1) { |
|
|
|
|
|
|
|
Enemy& e = enemies[enemyCollisionIndex]; |
|
|
|
|
|
|
|
e.Hurt(999); |
|
|
|
|
|
|
|
e.setExploded(true); |
|
|
|
|
|
|
|
HurtPlayer(e.GetID(), 1, e.isBlinking()); |
|
|
|
|
|
|
|
} |
|
|
|
player.UpdatePos(Vector_Add(player.GetPos(), xMovement)); |
|
|
|
player.UpdatePos(Vector_Add(player.GetPos(), xMovement)); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!CheckCollision({ 0,0,vForward.z }, { player.GetPos().x,player.GetPos().z }, player.GetRadius())) { |
|
|
|
if (!CheckCollision({ 0,0,vForward.z }, { player.GetPos().x,player.GetPos().z }, player.GetRadius())) { |
|
|
|
vec3d zMovement{ 0,0,vForward.z }; |
|
|
|
vec3d zMovement{ 0,0,vForward.z }; |
|
|
|
|
|
|
|
int enemyCollisionIndex = CheckExplosiveEnemyCollision(zMovement, { player.GetPos().x,player.GetPos().z }, player.GetRadius()); |
|
|
|
|
|
|
|
if (enemyCollisionIndex != -1) { |
|
|
|
|
|
|
|
Enemy& e = enemies[enemyCollisionIndex]; |
|
|
|
|
|
|
|
e.Hurt(999); |
|
|
|
|
|
|
|
e.setExploded(true); |
|
|
|
|
|
|
|
HurtPlayer(e.GetID(), 1, e.isBlinking()); |
|
|
|
|
|
|
|
} |
|
|
|
player.UpdatePos(Vector_Add(player.GetPos(), zMovement)); |
|
|
|
player.UpdatePos(Vector_Add(player.GetPos(), zMovement)); |
|
|
|
} |
|
|
|
} |
|
|
|
float distanceToExit = std::sqrtf(std::powf(player.GetPos().x - exit.pos.x, 2) + std::powf(player.GetPos().z - exit.pos.z, 2)); |
|
|
|
float distanceToExit = std::sqrtf(std::powf(player.GetPos().x - exit.pos.x, 2) + std::powf(player.GetPos().z - exit.pos.z, 2)); |
|
|
@ -1119,10 +1173,24 @@ void FaceBall::HandleKeys(float fElapsedTime) { |
|
|
|
else { |
|
|
|
else { |
|
|
|
if (!CheckCollision({ vReverse.x,0,0 }, { player.GetPos().x,player.GetPos().z }, player.GetRadius())) { |
|
|
|
if (!CheckCollision({ vReverse.x,0,0 }, { player.GetPos().x,player.GetPos().z }, player.GetRadius())) { |
|
|
|
vec3d xMovement{ vReverse.x,0,0 }; |
|
|
|
vec3d xMovement{ vReverse.x,0,0 }; |
|
|
|
|
|
|
|
int enemyCollisionIndex = CheckExplosiveEnemyCollision(xMovement, { player.GetPos().x,player.GetPos().z }, player.GetRadius()); |
|
|
|
|
|
|
|
if (enemyCollisionIndex != -1) { |
|
|
|
|
|
|
|
Enemy& e = enemies[enemyCollisionIndex]; |
|
|
|
|
|
|
|
e.Hurt(999); |
|
|
|
|
|
|
|
e.setExploded(true); |
|
|
|
|
|
|
|
HurtPlayer(e.GetID(), 1, e.isBlinking()); |
|
|
|
|
|
|
|
} |
|
|
|
player.UpdatePos(Vector_Add(player.GetPos(), xMovement)); |
|
|
|
player.UpdatePos(Vector_Add(player.GetPos(), xMovement)); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!CheckCollision({ 0,0,vReverse.z }, { player.GetPos().x,player.GetPos().z }, player.GetRadius())) { |
|
|
|
if (!CheckCollision({ 0,0,vReverse.z }, { player.GetPos().x,player.GetPos().z }, player.GetRadius())) { |
|
|
|
vec3d zMovement{ 0,0,vReverse.z }; |
|
|
|
vec3d zMovement{ 0,0,vReverse.z }; |
|
|
|
|
|
|
|
int enemyCollisionIndex = CheckExplosiveEnemyCollision(zMovement, { player.GetPos().x,player.GetPos().z }, player.GetRadius()); |
|
|
|
|
|
|
|
if (enemyCollisionIndex != -1) { |
|
|
|
|
|
|
|
Enemy& e = enemies[enemyCollisionIndex]; |
|
|
|
|
|
|
|
e.Hurt(999); |
|
|
|
|
|
|
|
e.setExploded(true); |
|
|
|
|
|
|
|
HurtPlayer(e.GetID(), 1, e.isBlinking()); |
|
|
|
|
|
|
|
} |
|
|
|
player.UpdatePos(Vector_Add(player.GetPos(), zMovement)); |
|
|
|
player.UpdatePos(Vector_Add(player.GetPos(), zMovement)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -1245,6 +1313,25 @@ int FaceBall::CheckEnemyCollision(vec3d movementVector, vf2d pos, float radius,i |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//This returns the index of only explosive enemies that collided (Or -1 if nothing was collided with).
|
|
|
|
|
|
|
|
//Collisions will not occur if the enemy is dead.
|
|
|
|
|
|
|
|
int FaceBall::CheckExplosiveEnemyCollision(vec3d movementVector, vf2d pos, float radius, int ignoreIndex) { |
|
|
|
|
|
|
|
vf2d newpos = { pos.x + movementVector.x,pos.y + movementVector.z }; |
|
|
|
|
|
|
|
for (int i = 0; i < game->enemies.size(); i++) { |
|
|
|
|
|
|
|
if (i != ignoreIndex) { |
|
|
|
|
|
|
|
Enemy& e = game->enemies[i]; |
|
|
|
|
|
|
|
if (e.isExplosive()&&!e.isDead()) { |
|
|
|
|
|
|
|
float dist = std::sqrtf(std::powf(newpos.x - e.pos.x, 2) + std::powf(newpos.y - e.pos.z, 2)); |
|
|
|
|
|
|
|
if (dist < radius + e.radius) { |
|
|
|
|
|
|
|
return i; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return -1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Bullet::Update(float fElapsedTime) { |
|
|
|
bool Bullet::Update(float fElapsedTime) { |
|
|
|
vec3d adjustedSpd = { spd.x * fElapsedTime,0,spd.y * fElapsedTime }; |
|
|
|
vec3d adjustedSpd = { spd.x * fElapsedTime,0,spd.y * fElapsedTime }; |
|
|
|
if (friendly) { |
|
|
|
if (friendly) { |
|
|
|