open and closing of powerup capsule.
This commit is contained in:
parent
5e9fed6992
commit
78b7aef32f
@ -158,6 +158,7 @@ bool Powerup::Update(float fElapsedTime) {
|
|||||||
aliveTime += fElapsedTime;
|
aliveTime += fElapsedTime;
|
||||||
colorCycle = std::sinf(10 * aliveTime);
|
colorCycle = std::sinf(10 * aliveTime);
|
||||||
col = game->powerupColorData[type] * colorCycle;
|
col = game->powerupColorData[type] * colorCycle;
|
||||||
|
opened = false; //Open state is false until a player causes it to open.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,6 +189,7 @@ void FaceBall::LoadLevel(int level)
|
|||||||
objects.clear();
|
objects.clear();
|
||||||
bullets.clear();
|
bullets.clear();
|
||||||
enemies.clear();
|
enemies.clear();
|
||||||
|
powerups.clear();
|
||||||
exitCoords = { 0,0 };
|
exitCoords = { 0,0 };
|
||||||
for (int y = 0; y < MAP_SIZE.y; y++) {
|
for (int y = 0; y < MAP_SIZE.y; y++) {
|
||||||
std::vector<MapSquare>row;
|
std::vector<MapSquare>row;
|
||||||
@ -835,7 +837,7 @@ void FaceBall::RenderPowerupMesh(mat4x4& matView, std::vector<Triangle>& vecTria
|
|||||||
rotMat = Matrix_MultiplyMatrix(rotMat, flipMat);
|
rotMat = Matrix_MultiplyMatrix(rotMat, flipMat);
|
||||||
}
|
}
|
||||||
localMat = Matrix_MultiplyMatrix(localMat, rotMat);
|
localMat = Matrix_MultiplyMatrix(localMat, rotMat);
|
||||||
mat4x4 matTrans = Matrix_MakeTranslation(p.pos.x, p.pos.y+(i?0.375f:0), p.pos.z);
|
mat4x4 matTrans = Matrix_MakeTranslation(p.pos.x, p.pos.y+(i?p.opened?0.65f:0.375f:p.opened?-0.125f:0), p.pos.z);
|
||||||
localMat = Matrix_MultiplyMatrix(localMat, matTrans);
|
localMat = Matrix_MultiplyMatrix(localMat, matTrans);
|
||||||
|
|
||||||
triTransformed.p[0] = Matrix_MultiplyVector(localMat, tri.p[0]);
|
triTransformed.p[0] = Matrix_MultiplyVector(localMat, tri.p[0]);
|
||||||
@ -1292,7 +1294,8 @@ void FaceBall::HandleKeys(float fElapsedTime) {
|
|||||||
freeRoamCamera = Vector_Add(freeRoamCamera, vLeftStrafe);
|
freeRoamCamera = Vector_Add(freeRoamCamera, vLeftStrafe);
|
||||||
}
|
}
|
||||||
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())&&
|
||||||
|
CheckPowerupCollision({ vLeftStrafe.x,0,0 }, { player.GetPos().x,player.GetPos().z }, player.GetRadius())==-1) {
|
||||||
vec3d xMovement{ vLeftStrafe.x,0,0 };
|
vec3d xMovement{ vLeftStrafe.x,0,0 };
|
||||||
int enemyCollisionIndex = CheckExplosiveEnemyCollision(xMovement, { player.GetPos().x,player.GetPos().z }, player.GetRadius());
|
int enemyCollisionIndex = CheckExplosiveEnemyCollision(xMovement, { player.GetPos().x,player.GetPos().z }, player.GetRadius());
|
||||||
if (enemyCollisionIndex != -1) {
|
if (enemyCollisionIndex != -1) {
|
||||||
@ -1304,7 +1307,8 @@ void FaceBall::HandleKeys(float fElapsedTime) {
|
|||||||
}
|
}
|
||||||
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()) &&
|
||||||
|
CheckPowerupCollision({ 0,0,vLeftStrafe.z }, { player.GetPos().x,player.GetPos().z }, player.GetRadius()) == -1) {
|
||||||
vec3d zMovement{ 0,0,vLeftStrafe.z };
|
vec3d zMovement{ 0,0,vLeftStrafe.z };
|
||||||
int enemyCollisionIndex = CheckExplosiveEnemyCollision(zMovement, { player.GetPos().x,player.GetPos().z }, player.GetRadius());
|
int enemyCollisionIndex = CheckExplosiveEnemyCollision(zMovement, { player.GetPos().x,player.GetPos().z }, player.GetRadius());
|
||||||
if (enemyCollisionIndex != -1) {
|
if (enemyCollisionIndex != -1) {
|
||||||
@ -1326,7 +1330,8 @@ void FaceBall::HandleKeys(float fElapsedTime) {
|
|||||||
freeRoamCamera = Vector_Add(freeRoamCamera, vRightStrafe);
|
freeRoamCamera = Vector_Add(freeRoamCamera, vRightStrafe);
|
||||||
}
|
}
|
||||||
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()) &&
|
||||||
|
CheckPowerupCollision({ vRightStrafe.x,0,0 }, { player.GetPos().x,player.GetPos().z }, player.GetRadius()) == -1) {
|
||||||
vec3d xMovement{ vRightStrafe.x,0,0 };
|
vec3d xMovement{ vRightStrafe.x,0,0 };
|
||||||
int enemyCollisionIndex = CheckExplosiveEnemyCollision(xMovement, { player.GetPos().x,player.GetPos().z }, player.GetRadius());
|
int enemyCollisionIndex = CheckExplosiveEnemyCollision(xMovement, { player.GetPos().x,player.GetPos().z }, player.GetRadius());
|
||||||
if (enemyCollisionIndex != -1) {
|
if (enemyCollisionIndex != -1) {
|
||||||
@ -1338,7 +1343,8 @@ void FaceBall::HandleKeys(float fElapsedTime) {
|
|||||||
}
|
}
|
||||||
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()) &&
|
||||||
|
CheckPowerupCollision({ 0,0,vRightStrafe.z }, { player.GetPos().x,player.GetPos().z }, player.GetRadius()) == -1) {
|
||||||
vec3d zMovement{ 0,0,vRightStrafe.z };
|
vec3d zMovement{ 0,0,vRightStrafe.z };
|
||||||
int enemyCollisionIndex = CheckExplosiveEnemyCollision(zMovement, { player.GetPos().x,player.GetPos().z }, player.GetRadius());
|
int enemyCollisionIndex = CheckExplosiveEnemyCollision(zMovement, { player.GetPos().x,player.GetPos().z }, player.GetRadius());
|
||||||
if (enemyCollisionIndex != -1) {
|
if (enemyCollisionIndex != -1) {
|
||||||
@ -1357,7 +1363,8 @@ void FaceBall::HandleKeys(float fElapsedTime) {
|
|||||||
freeRoamCamera = Vector_Add(freeRoamCamera, vForward);
|
freeRoamCamera = Vector_Add(freeRoamCamera, vForward);
|
||||||
}
|
}
|
||||||
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()) &&
|
||||||
|
CheckPowerupCollision({ vForward.x,0,0 }, { player.GetPos().x,player.GetPos().z }, player.GetRadius()) == -1) {
|
||||||
vec3d xMovement{ vForward.x,0,0 };
|
vec3d xMovement{ vForward.x,0,0 };
|
||||||
int enemyCollisionIndex = CheckExplosiveEnemyCollision(xMovement, { player.GetPos().x,player.GetPos().z }, player.GetRadius());
|
int enemyCollisionIndex = CheckExplosiveEnemyCollision(xMovement, { player.GetPos().x,player.GetPos().z }, player.GetRadius());
|
||||||
if (enemyCollisionIndex != -1) {
|
if (enemyCollisionIndex != -1) {
|
||||||
@ -1369,7 +1376,8 @@ void FaceBall::HandleKeys(float fElapsedTime) {
|
|||||||
}
|
}
|
||||||
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()) &&
|
||||||
|
CheckPowerupCollision({ 0,0,vForward.z }, { player.GetPos().x,player.GetPos().z }, player.GetRadius()) == -1) {
|
||||||
vec3d zMovement{ 0,0,vForward.z };
|
vec3d zMovement{ 0,0,vForward.z };
|
||||||
int enemyCollisionIndex = CheckExplosiveEnemyCollision(zMovement, { player.GetPos().x,player.GetPos().z }, player.GetRadius());
|
int enemyCollisionIndex = CheckExplosiveEnemyCollision(zMovement, { player.GetPos().x,player.GetPos().z }, player.GetRadius());
|
||||||
if (enemyCollisionIndex != -1) {
|
if (enemyCollisionIndex != -1) {
|
||||||
@ -1393,7 +1401,8 @@ void FaceBall::HandleKeys(float fElapsedTime) {
|
|||||||
freeRoamCamera = Vector_Add(freeRoamCamera, vReverse);
|
freeRoamCamera = Vector_Add(freeRoamCamera, vReverse);
|
||||||
}
|
}
|
||||||
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()) &&
|
||||||
|
CheckPowerupCollision({ vReverse.x,0,0 }, { player.GetPos().x,player.GetPos().z }, player.GetRadius()) == -1) {
|
||||||
vec3d xMovement{ vReverse.x,0,0 };
|
vec3d xMovement{ vReverse.x,0,0 };
|
||||||
int enemyCollisionIndex = CheckExplosiveEnemyCollision(xMovement, { player.GetPos().x,player.GetPos().z }, player.GetRadius());
|
int enemyCollisionIndex = CheckExplosiveEnemyCollision(xMovement, { player.GetPos().x,player.GetPos().z }, player.GetRadius());
|
||||||
if (enemyCollisionIndex != -1) {
|
if (enemyCollisionIndex != -1) {
|
||||||
@ -1405,7 +1414,8 @@ void FaceBall::HandleKeys(float fElapsedTime) {
|
|||||||
}
|
}
|
||||||
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()) &&
|
||||||
|
CheckPowerupCollision({ 0,0,vReverse.z }, { player.GetPos().x,player.GetPos().z }, player.GetRadius()) == -1) {
|
||||||
vec3d zMovement{ 0,0,vReverse.z };
|
vec3d zMovement{ 0,0,vReverse.z };
|
||||||
int enemyCollisionIndex = CheckExplosiveEnemyCollision(zMovement, { player.GetPos().x,player.GetPos().z }, player.GetRadius());
|
int enemyCollisionIndex = CheckExplosiveEnemyCollision(zMovement, { player.GetPos().x,player.GetPos().z }, player.GetRadius());
|
||||||
if (enemyCollisionIndex != -1) {
|
if (enemyCollisionIndex != -1) {
|
||||||
@ -1516,6 +1526,19 @@ bool FaceBall::OnUserCreate()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int FaceBall::CheckPowerupCollision(vec3d movementVector, vf2d pos, float radius) {
|
||||||
|
vf2d newpos = { pos.x + movementVector.x,pos.y + movementVector.z };
|
||||||
|
for (int i = 0; i < game->powerups.size(); i++) {
|
||||||
|
Powerup& p = game->powerups[i];
|
||||||
|
float dist = std::sqrtf(std::powf(newpos.x - p.pos.x, 2) + std::powf(newpos.y - p.pos.z, 2));
|
||||||
|
if (dist < radius + p.radius) {
|
||||||
|
lastPowerupCollidedWith = i; //This function is only meant for the player to collide with things. If this is needed for other things, we will have to refactor/reconsider this line as they would modify the player's last powerup touched variable which is a no-no.
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
//Collisions will not occur if the player is dead.
|
//Collisions will not occur if the player is dead.
|
||||||
bool FaceBall::CheckPlayerCollision(vec3d movementVector, vf2d pos, float radius) {
|
bool FaceBall::CheckPlayerCollision(vec3d movementVector, vf2d pos, float radius) {
|
||||||
if (game->hp <= 0) { return false; }
|
if (game->hp <= 0) { return false; }
|
||||||
@ -2003,34 +2026,40 @@ void FaceBall::RunEnemyAI(Enemy& e,float fElapsedTime,int myIndex) {
|
|||||||
bool FaceBall::OnUserUpdate(float fElapsedTime)
|
bool FaceBall::OnUserUpdate(float fElapsedTime)
|
||||||
{
|
{
|
||||||
gameTimer += fElapsedTime;
|
gameTimer += fElapsedTime;
|
||||||
for (std::vector<Bullet>::iterator it = bullets.begin(); it != bullets.end();) {
|
|
||||||
Bullet& b = *it;
|
|
||||||
if (!b.Update(fElapsedTime)) {
|
|
||||||
it=bullets.erase(it);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
it++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (int i = 0; i < enemies.size(); i++) {
|
|
||||||
Enemy& e = enemies[i];
|
|
||||||
e.Update(fElapsedTime);
|
|
||||||
if (e.isLastHitTimerActive()) {
|
|
||||||
e.reduceLastHitTimer(fElapsedTime);
|
|
||||||
}
|
|
||||||
RunEnemyAI(e, fElapsedTime,i);
|
|
||||||
}
|
|
||||||
for (std::vector<Powerup>::iterator it = powerups.begin(); it != powerups.end();) {
|
|
||||||
Powerup& p = *it;
|
|
||||||
if (!p.Update(fElapsedTime)) {
|
|
||||||
it = powerups.erase(it);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
it++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case GAME: {
|
case GAME: {
|
||||||
|
for (std::vector<Bullet>::iterator it = bullets.begin(); it != bullets.end();) {
|
||||||
|
Bullet& b = *it;
|
||||||
|
if (!b.Update(fElapsedTime)) {
|
||||||
|
it = bullets.erase(it);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < enemies.size(); i++) {
|
||||||
|
Enemy& e = enemies[i];
|
||||||
|
e.Update(fElapsedTime);
|
||||||
|
if (e.isLastHitTimerActive()) {
|
||||||
|
e.reduceLastHitTimer(fElapsedTime);
|
||||||
|
}
|
||||||
|
RunEnemyAI(e, fElapsedTime, i);
|
||||||
|
}
|
||||||
|
for (std::vector<Powerup>::iterator it = powerups.begin(); it != powerups.end();) {
|
||||||
|
Powerup& p = *it;
|
||||||
|
if (!p.Update(fElapsedTime)) {
|
||||||
|
it = powerups.erase(it);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (lastPowerupCollidedWith != -1) {
|
||||||
|
vec3d vForward = Vector_Mul(vLookDir, std::min(player.GetRadius() - 0.00001f, moveSpd * fElapsedTime));
|
||||||
|
if (CheckPowerupCollision({ vForward.x,0,vForward.z }, { player.GetPos().x,player.GetPos().z }, player.GetRadius() * 1.25) != -1) {
|
||||||
|
powerups[lastPowerupCollidedWith].opened = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (hp > 0) {
|
if (hp > 0) {
|
||||||
HandleKeys(fElapsedTime);
|
HandleKeys(fElapsedTime);
|
||||||
RenderWorld();
|
RenderWorld();
|
||||||
|
@ -174,6 +174,7 @@ struct Powerup : Object {
|
|||||||
Pixel col;
|
Pixel col;
|
||||||
float colorCycle=1;
|
float colorCycle=1;
|
||||||
float aliveTime=0;
|
float aliveTime=0;
|
||||||
|
bool opened = false;
|
||||||
bool Update(float fElapsedTime);
|
bool Update(float fElapsedTime);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -278,6 +279,7 @@ class FaceBall : public PixelGameEngine
|
|||||||
int tagsRemaining = 10;
|
int tagsRemaining = 10;
|
||||||
int lives = 3;
|
int lives = 3;
|
||||||
double gameTimer = 0;
|
double gameTimer = 0;
|
||||||
|
int lastPowerupCollidedWith = -1;
|
||||||
|
|
||||||
mat4x4 matProj;
|
mat4x4 matProj;
|
||||||
|
|
||||||
@ -374,6 +376,7 @@ class FaceBall : public PixelGameEngine
|
|||||||
void RenderHud(float fElapsedTime);
|
void RenderHud(float fElapsedTime);
|
||||||
void ConvertBulletColor(Mesh& bullet, Pixel col);
|
void ConvertBulletColor(Mesh& bullet, Pixel col);
|
||||||
void Display3DKillerModel();
|
void Display3DKillerModel();
|
||||||
|
int CheckPowerupCollision(vec3d movementVector, vf2d pos, float radius);
|
||||||
public:
|
public:
|
||||||
vi2d MAP_SIZE;
|
vi2d MAP_SIZE;
|
||||||
float restingTriangleYDepth = 0.f;
|
float restingTriangleYDepth = 0.f;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user