|
|
@ -11,7 +11,7 @@ using namespace olc; |
|
|
|
FaceBall* game; |
|
|
|
FaceBall* game; |
|
|
|
|
|
|
|
|
|
|
|
Enemy::Enemy(EnemyID id,vec3d pos,float rot,float radius) |
|
|
|
Enemy::Enemy(EnemyID id,vec3d pos,float rot,float radius) |
|
|
|
:id(id), health(game->enemyData[id].health), fireDelay(0), |
|
|
|
:id(id), health(game->enemyData[id].health), fireDelay(0), blinking(game->enemyData[id].blinking), |
|
|
|
Object({game->enemyData[id].mesh,pos,rot,radius}) {} |
|
|
|
Object({game->enemyData[id].mesh,pos,rot,radius}) {} |
|
|
|
|
|
|
|
|
|
|
|
EnemyID Enemy::GetID() { |
|
|
|
EnemyID Enemy::GetID() { |
|
|
@ -104,12 +104,31 @@ bool Enemy::isExploded() { |
|
|
|
return exploded; |
|
|
|
return exploded; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Enemy::Update(float fElapsedTime) { |
|
|
|
|
|
|
|
if (!isDead()) { |
|
|
|
|
|
|
|
aliveTime += fElapsedTime; |
|
|
|
|
|
|
|
if (isBlinking()) { |
|
|
|
|
|
|
|
blinkingAmt = std::sinf(30 * aliveTime); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Enemy::OnDeathEvent() { |
|
|
|
|
|
|
|
game->SubtractTag(); |
|
|
|
|
|
|
|
if (game->enemyData[id].powerupDrop != PowerupType::NONE) { |
|
|
|
|
|
|
|
game->SpawnPowerup(game->enemyData[id].powerupDrop, pos); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
blinkingAmt = 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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,0.2f,true }; |
|
|
|
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.3f,true }; |
|
|
|
enemyData[SHOOTME2] = { "SHOOTME2",enemy_IShoot,YELLOW,1,1,PI / 6,2,1,0.3f,true }; |
|
|
|
|
|
|
|
enemyData[SHOOTME_ARMOR] = { "SHOOTME_ARMOR",enemy_ShootMe,YELLOW,6,1,PI / 6,2,1,0.3f,true,PowerupType::ARMOR,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} }; |
|
|
@ -121,6 +140,32 @@ void FaceBall::InitializeEnemyData() { |
|
|
|
enemyData[AREA_MAP] = { "Map",undefined,GREEN }; |
|
|
|
enemyData[AREA_MAP] = { "Map",undefined,GREEN }; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FaceBall::InitializePowerupColors() { |
|
|
|
|
|
|
|
powerupColorData[PowerupType::ARMOR] = DARK_GREEN; |
|
|
|
|
|
|
|
powerupColorData[PowerupType::SPEED] = DARK_BLUE; |
|
|
|
|
|
|
|
powerupColorData[PowerupType::SHOTS] = DARK_RED; |
|
|
|
|
|
|
|
powerupColorData[PowerupType::STOP] = RED; |
|
|
|
|
|
|
|
powerupColorData[PowerupType::SHIELD] = CYAN; |
|
|
|
|
|
|
|
powerupColorData[PowerupType::CAMO] = MAGENTA; |
|
|
|
|
|
|
|
powerupColorData[PowerupType::MAP] = GREEN; |
|
|
|
|
|
|
|
powerupColorData[PowerupType::COIN] = BLUE; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Powerup::Powerup(Mesh mesh, vec3d pos, float rot, PowerupType type)
|
|
|
|
|
|
|
|
: type(type), col(game->powerupColorData[type]), Object{ mesh,pos,rot,0.375f } {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Powerup::Update(float fElapsedTime) { |
|
|
|
|
|
|
|
aliveTime += fElapsedTime; |
|
|
|
|
|
|
|
colorCycle = std::sinf(10 * aliveTime); |
|
|
|
|
|
|
|
col = game->powerupColorData[type] * colorCycle; |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FaceBall::SpawnPowerup(PowerupType type, vec3d pos) { |
|
|
|
|
|
|
|
Mesh& mesh = (type <= PowerupType::SHOTS) ? powerup : powerup2; |
|
|
|
|
|
|
|
powerups.push_back({ mesh,pos,0,type }); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void FaceBall::ConvertBulletColor(Mesh& bullet, Pixel col) { |
|
|
|
void FaceBall::ConvertBulletColor(Mesh& bullet, Pixel col) { |
|
|
|
for (Triangle& t : bullet.tris) { |
|
|
|
for (Triangle& t : bullet.tris) { |
|
|
|
t.col[0] = col; |
|
|
|
t.col[0] = col; |
|
|
@ -494,6 +539,8 @@ int FaceBall::Triangle_ClipAgainstPlane(vec3d plane_p, vec3d plane_n, Triangle& |
|
|
|
vec3d* outside_points[3]; int nOutsidePointCount = 0; |
|
|
|
vec3d* outside_points[3]; int nOutsidePointCount = 0; |
|
|
|
vec2d* inside_tex[3]; int nInsideTexCount = 0; |
|
|
|
vec2d* inside_tex[3]; int nInsideTexCount = 0; |
|
|
|
vec2d* outside_tex[3]; int nOutsideTexCount = 0; |
|
|
|
vec2d* outside_tex[3]; int nOutsideTexCount = 0; |
|
|
|
|
|
|
|
Pixel* inside_col[3]; int nInsideColCount = 0; |
|
|
|
|
|
|
|
Pixel* outside_col[3]; int nOutsideColCount = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get signed distance of each point in triangle to plane
|
|
|
|
// Get signed distance of each point in triangle to plane
|
|
|
@ -501,21 +548,21 @@ int FaceBall::Triangle_ClipAgainstPlane(vec3d plane_p, vec3d plane_n, Triangle& |
|
|
|
float d1 = dist(in_tri.p[1]); |
|
|
|
float d1 = dist(in_tri.p[1]); |
|
|
|
float d2 = dist(in_tri.p[2]); |
|
|
|
float d2 = dist(in_tri.p[2]); |
|
|
|
|
|
|
|
|
|
|
|
if (d0 >= 0) { inside_points[nInsidePointCount++] = &in_tri.p[0]; inside_tex[nInsideTexCount++] = &in_tri.uv[0]; } |
|
|
|
if (d0 >= 0) { inside_points[nInsidePointCount++] = &in_tri.p[0]; inside_tex[nInsideTexCount++] = &in_tri.uv[0]; inside_col[nInsideColCount++] = &in_tri.col[0]; } |
|
|
|
else { |
|
|
|
else { |
|
|
|
outside_points[nOutsidePointCount++] = &in_tri.p[0]; outside_tex[nOutsideTexCount++] = &in_tri.uv[0]; |
|
|
|
outside_points[nOutsidePointCount++] = &in_tri.p[0]; outside_tex[nOutsideTexCount++] = &in_tri.uv[0]; outside_col[nOutsideColCount++] = &in_tri.col[0]; |
|
|
|
} |
|
|
|
} |
|
|
|
if (d1 >= 0) { |
|
|
|
if (d1 >= 0) { |
|
|
|
inside_points[nInsidePointCount++] = &in_tri.p[1]; inside_tex[nInsideTexCount++] = &in_tri.uv[1]; |
|
|
|
inside_points[nInsidePointCount++] = &in_tri.p[1]; inside_tex[nInsideTexCount++] = &in_tri.uv[1]; inside_col[nInsideColCount++] = &in_tri.col[1]; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
outside_points[nOutsidePointCount++] = &in_tri.p[1]; outside_tex[nOutsideTexCount++] = &in_tri.uv[1]; |
|
|
|
outside_points[nOutsidePointCount++] = &in_tri.p[1]; outside_tex[nOutsideTexCount++] = &in_tri.uv[1]; outside_col[nOutsideColCount++] = &in_tri.col[1]; |
|
|
|
} |
|
|
|
} |
|
|
|
if (d2 >= 0) { |
|
|
|
if (d2 >= 0) { |
|
|
|
inside_points[nInsidePointCount++] = &in_tri.p[2]; inside_tex[nInsideTexCount++] = &in_tri.uv[2]; |
|
|
|
inside_points[nInsidePointCount++] = &in_tri.p[2]; inside_tex[nInsideTexCount++] = &in_tri.uv[2]; inside_col[nInsideColCount++] = &in_tri.col[2]; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
outside_points[nOutsidePointCount++] = &in_tri.p[2]; outside_tex[nOutsideTexCount++] = &in_tri.uv[2]; |
|
|
|
outside_points[nOutsidePointCount++] = &in_tri.p[2]; outside_tex[nOutsideTexCount++] = &in_tri.uv[2]; outside_col[nOutsideColCount++] = &in_tri.col[2]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Now classify triangle points, and break the input triangle into
|
|
|
|
// Now classify triangle points, and break the input triangle into
|
|
|
@ -553,6 +600,7 @@ int FaceBall::Triangle_ClipAgainstPlane(vec3d plane_p, vec3d plane_n, Triangle& |
|
|
|
// The inside point is valid, so keep that...
|
|
|
|
// The inside point is valid, so keep that...
|
|
|
|
out_tri1.p[0] = *inside_points[0]; |
|
|
|
out_tri1.p[0] = *inside_points[0]; |
|
|
|
out_tri1.uv[0] = *inside_tex[0]; |
|
|
|
out_tri1.uv[0] = *inside_tex[0]; |
|
|
|
|
|
|
|
out_tri1.col[0] = *inside_col[0]; |
|
|
|
|
|
|
|
|
|
|
|
// but the two new points are at the locations where the
|
|
|
|
// but the two new points are at the locations where the
|
|
|
|
// original sides of the triangle (lines) intersect with the plane
|
|
|
|
// original sides of the triangle (lines) intersect with the plane
|
|
|
@ -560,11 +608,19 @@ int FaceBall::Triangle_ClipAgainstPlane(vec3d plane_p, vec3d plane_n, Triangle& |
|
|
|
out_tri1.p[1] = Vector_IntersectPlane(plane_p, plane_n, *inside_points[0], *outside_points[0], t); |
|
|
|
out_tri1.p[1] = Vector_IntersectPlane(plane_p, plane_n, *inside_points[0], *outside_points[0], t); |
|
|
|
out_tri1.uv[1].u = t * (outside_tex[0]->u - inside_tex[0]->u) + inside_tex[0]->u; |
|
|
|
out_tri1.uv[1].u = t * (outside_tex[0]->u - inside_tex[0]->u) + inside_tex[0]->u; |
|
|
|
out_tri1.uv[1].v = t * (outside_tex[0]->v - inside_tex[0]->v) + inside_tex[0]->v; |
|
|
|
out_tri1.uv[1].v = t * (outside_tex[0]->v - inside_tex[0]->v) + inside_tex[0]->v; |
|
|
|
|
|
|
|
out_tri1.col[1].r = t * (outside_col[0]->r - inside_col[0]->r) + inside_col[0]->r; |
|
|
|
|
|
|
|
out_tri1.col[1].g = t * (outside_col[0]->g - inside_col[0]->g) + inside_col[0]->g; |
|
|
|
|
|
|
|
out_tri1.col[1].b = t * (outside_col[0]->b - inside_col[0]->b) + inside_col[0]->b; |
|
|
|
|
|
|
|
//out_tri1.col[1].a = t * (outside_col[0]->a - inside_col[0]->a) + inside_col[0]->a;
|
|
|
|
out_tri1.uv[1].w = t * (outside_tex[0]->w - inside_tex[0]->w) + inside_tex[0]->w; |
|
|
|
out_tri1.uv[1].w = t * (outside_tex[0]->w - inside_tex[0]->w) + inside_tex[0]->w; |
|
|
|
|
|
|
|
|
|
|
|
out_tri1.p[2] = Vector_IntersectPlane(plane_p, plane_n, *inside_points[0], *outside_points[1], t); |
|
|
|
out_tri1.p[2] = Vector_IntersectPlane(plane_p, plane_n, *inside_points[0], *outside_points[1], t); |
|
|
|
out_tri1.uv[2].u = t * (outside_tex[1]->u - inside_tex[0]->u) + inside_tex[0]->u; |
|
|
|
out_tri1.uv[2].u = t * (outside_tex[1]->u - inside_tex[0]->u) + inside_tex[0]->u; |
|
|
|
out_tri1.uv[2].v = t * (outside_tex[1]->v - inside_tex[0]->v) + inside_tex[0]->v; |
|
|
|
out_tri1.uv[2].v = t * (outside_tex[1]->v - inside_tex[0]->v) + inside_tex[0]->v; |
|
|
|
|
|
|
|
out_tri1.col[2].r = t * (outside_col[1]->r - inside_col[0]->r) + inside_col[0]->r; |
|
|
|
|
|
|
|
out_tri1.col[2].g = t * (outside_col[1]->g - inside_col[0]->g) + inside_col[0]->g; |
|
|
|
|
|
|
|
out_tri1.col[2].b = t * (outside_col[1]->b - inside_col[0]->b) + inside_col[0]->b; |
|
|
|
|
|
|
|
//out_tri1.col[2].a = t * (outside_col[1]->a - inside_col[0]->a) + inside_col[0]->a;
|
|
|
|
out_tri1.uv[2].w = t * (outside_tex[1]->w - inside_tex[0]->w) + inside_tex[0]->w; |
|
|
|
out_tri1.uv[2].w = t * (outside_tex[1]->w - inside_tex[0]->w) + inside_tex[0]->w; |
|
|
|
|
|
|
|
|
|
|
|
return 1; // Return the newly formed single triangle
|
|
|
|
return 1; // Return the newly formed single triangle
|
|
|
@ -593,11 +649,17 @@ int FaceBall::Triangle_ClipAgainstPlane(vec3d plane_p, vec3d plane_n, Triangle& |
|
|
|
out_tri1.p[1] = *inside_points[1]; |
|
|
|
out_tri1.p[1] = *inside_points[1]; |
|
|
|
out_tri1.uv[0] = *inside_tex[0]; |
|
|
|
out_tri1.uv[0] = *inside_tex[0]; |
|
|
|
out_tri1.uv[1] = *inside_tex[1]; |
|
|
|
out_tri1.uv[1] = *inside_tex[1]; |
|
|
|
|
|
|
|
out_tri1.col[0] = *inside_col[0]; |
|
|
|
|
|
|
|
out_tri1.col[1] = *inside_col[1]; |
|
|
|
|
|
|
|
|
|
|
|
float t; |
|
|
|
float t; |
|
|
|
out_tri1.p[2] = Vector_IntersectPlane(plane_p, plane_n, *inside_points[0], *outside_points[0], t); |
|
|
|
out_tri1.p[2] = Vector_IntersectPlane(plane_p, plane_n, *inside_points[0], *outside_points[0], t); |
|
|
|
out_tri1.uv[2].u = t * (outside_tex[0]->u - inside_tex[0]->u) + inside_tex[0]->u; |
|
|
|
out_tri1.uv[2].u = t * (outside_tex[0]->u - inside_tex[0]->u) + inside_tex[0]->u; |
|
|
|
out_tri1.uv[2].v = t * (outside_tex[0]->v - inside_tex[0]->v) + inside_tex[0]->v; |
|
|
|
out_tri1.uv[2].v = t * (outside_tex[0]->v - inside_tex[0]->v) + inside_tex[0]->v; |
|
|
|
|
|
|
|
out_tri1.col[2].r = t * (outside_col[0]->r - inside_col[0]->r) + inside_col[0]->r; |
|
|
|
|
|
|
|
out_tri1.col[2].g = t * (outside_col[0]->g - inside_col[0]->g) + inside_col[0]->g; |
|
|
|
|
|
|
|
out_tri1.col[2].b = t * (outside_col[0]->b - inside_col[0]->b) + inside_col[0]->b; |
|
|
|
|
|
|
|
//out_tri1.col[2].a = t * (outside_col[0]->a - inside_col[0]->a) + inside_col[0]->a;
|
|
|
|
out_tri1.uv[2].w = t * (outside_tex[0]->w - inside_tex[0]->w) + inside_tex[0]->w; |
|
|
|
out_tri1.uv[2].w = t * (outside_tex[0]->w - inside_tex[0]->w) + inside_tex[0]->w; |
|
|
|
|
|
|
|
|
|
|
|
// The second triangle is composed of one of he inside points, a
|
|
|
|
// The second triangle is composed of one of he inside points, a
|
|
|
@ -605,11 +667,17 @@ int FaceBall::Triangle_ClipAgainstPlane(vec3d plane_p, vec3d plane_n, Triangle& |
|
|
|
// triangle and the plane, and the newly created point above
|
|
|
|
// triangle and the plane, and the newly created point above
|
|
|
|
out_tri2.p[0] = *inside_points[1]; |
|
|
|
out_tri2.p[0] = *inside_points[1]; |
|
|
|
out_tri2.uv[0] = *inside_tex[1]; |
|
|
|
out_tri2.uv[0] = *inside_tex[1]; |
|
|
|
|
|
|
|
out_tri2.col[0] = *inside_col[1]; |
|
|
|
out_tri2.p[1] = out_tri1.p[2]; |
|
|
|
out_tri2.p[1] = out_tri1.p[2]; |
|
|
|
out_tri2.uv[1] = out_tri1.uv[2]; |
|
|
|
out_tri2.uv[1] = out_tri1.uv[2]; |
|
|
|
|
|
|
|
out_tri2.col[1] = out_tri1.col[2]; |
|
|
|
out_tri2.p[2] = Vector_IntersectPlane(plane_p, plane_n, *inside_points[1], *outside_points[0], t); |
|
|
|
out_tri2.p[2] = Vector_IntersectPlane(plane_p, plane_n, *inside_points[1], *outside_points[0], t); |
|
|
|
out_tri2.uv[2].u = t * (outside_tex[0]->u - inside_tex[1]->u) + inside_tex[1]->u; |
|
|
|
out_tri2.uv[2].u = t * (outside_tex[0]->u - inside_tex[1]->u) + inside_tex[1]->u; |
|
|
|
out_tri2.uv[2].v = t * (outside_tex[0]->v - inside_tex[1]->v) + inside_tex[1]->v; |
|
|
|
out_tri2.uv[2].v = t * (outside_tex[0]->v - inside_tex[1]->v) + inside_tex[1]->v; |
|
|
|
|
|
|
|
out_tri1.col[2].r = t * (outside_col[0]->r - inside_col[1]->r) + inside_col[1]->r; |
|
|
|
|
|
|
|
out_tri1.col[2].g = t * (outside_col[0]->g - inside_col[1]->g) + inside_col[1]->g; |
|
|
|
|
|
|
|
out_tri1.col[2].b = t * (outside_col[0]->b - inside_col[1]->b) + inside_col[1]->b; |
|
|
|
|
|
|
|
//out_tri1.col[2].a = t * (outside_col[0]->a - inside_col[1]->a) + inside_col[1]->a;
|
|
|
|
out_tri2.uv[2].w = t * (outside_tex[0]->w - inside_tex[1]->w) + inside_tex[1]->w; |
|
|
|
out_tri2.uv[2].w = t * (outside_tex[0]->w - inside_tex[1]->w) + inside_tex[1]->w; |
|
|
|
return 2; // Return two newly formed triangles which form a quad
|
|
|
|
return 2; // Return two newly formed triangles which form a quad
|
|
|
|
} |
|
|
|
} |
|
|
@ -914,8 +982,13 @@ void FaceBall::RenderWorld() { |
|
|
|
t.col[0] = t.col[1] = t.col[2] = {0,(uint8_t)(std::abs(std::sinf(2*PI*gameTimer)) * 255),0}; |
|
|
|
t.col[0] = t.col[1] = t.col[2] = {0,(uint8_t)(std::abs(std::sinf(2*PI*gameTimer)) * 255),0}; |
|
|
|
} |
|
|
|
} |
|
|
|
for (auto& enemy : enemies) { |
|
|
|
for (auto& enemy : enemies) { |
|
|
|
|
|
|
|
if (enemy.blinkingAmt > 0.4f) { |
|
|
|
RenderMesh(matView, vecTrianglesToRaster, enemy); |
|
|
|
RenderMesh(matView, vecTrianglesToRaster, enemy); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for (auto& powerup : powerups) { |
|
|
|
|
|
|
|
RenderMesh(matView, vecTrianglesToRaster, powerup); |
|
|
|
|
|
|
|
} |
|
|
|
for (auto& bullet : bullets) { |
|
|
|
for (auto& bullet : bullets) { |
|
|
|
RenderBulletMesh(matView, vecTrianglesToRasterTranslucent, bullet); |
|
|
|
RenderBulletMesh(matView, vecTrianglesToRasterTranslucent, bullet); |
|
|
|
} |
|
|
|
} |
|
|
@ -1286,11 +1359,15 @@ bool FaceBall::OnUserCreate() |
|
|
|
life1 = new Decal(new Sprite("assets/life1.png")); |
|
|
|
life1 = new Decal(new Sprite("assets/life1.png")); |
|
|
|
crosshair = new Decal(new Sprite("assets/crosshair.png")); |
|
|
|
crosshair = new Decal(new Sprite("assets/crosshair.png")); |
|
|
|
hudmeter = new Decal(new Sprite("assets/hudmeter.png")); |
|
|
|
hudmeter = new Decal(new Sprite("assets/hudmeter.png")); |
|
|
|
|
|
|
|
powerup_tex = new Decal(new Sprite("assets/powerup.png")); |
|
|
|
|
|
|
|
powerup2_tex = new Decal(new Sprite("assets/powerup2.png")); |
|
|
|
|
|
|
|
|
|
|
|
enemy_ShootMe = { "assets/enemies/ShootMe.obj", enemy_ShootMe_tex }; |
|
|
|
enemy_ShootMe = { "assets/enemies/ShootMe.obj", enemy_ShootMe_tex }; |
|
|
|
enemy_IShoot = { "assets/enemies/IShoot.obj", enemy_IShoot_tex }; |
|
|
|
enemy_IShoot = { "assets/enemies/IShoot.obj", enemy_IShoot_tex }; |
|
|
|
enemy_Sonar = { "assets/enemies/Sonar.obj", enemy_Sonar_tex }; |
|
|
|
enemy_Sonar = { "assets/enemies/Sonar.obj", enemy_Sonar_tex }; |
|
|
|
bullet = { "assets/enemies/bullet.obj",bullet_tex }; |
|
|
|
bullet = { "assets/enemies/bullet.obj",bullet_tex }; |
|
|
|
|
|
|
|
powerup = { "assets/Powerup.obj",powerup_tex}; |
|
|
|
|
|
|
|
powerup2 = { "assets/Powerup2.obj",powerup2_tex }; |
|
|
|
mapExit = { "assets/Exit.obj",dot }; |
|
|
|
mapExit = { "assets/Exit.obj",dot }; |
|
|
|
mapWalls.texture = wall_tex; |
|
|
|
mapWalls.texture = wall_tex; |
|
|
|
mapFloor.texture = floor_tex; |
|
|
|
mapFloor.texture = floor_tex; |
|
|
@ -1356,7 +1433,7 @@ bool Bullet::Update(float fElapsedTime) { |
|
|
|
Enemy& enemy = game->enemies[collided_enemy]; |
|
|
|
Enemy& enemy = game->enemies[collided_enemy]; |
|
|
|
enemy.Hurt(); |
|
|
|
enemy.Hurt(); |
|
|
|
if (enemy.isDead()) { |
|
|
|
if (enemy.isDead()) { |
|
|
|
game->SubtractTag(); |
|
|
|
enemy.OnDeathEvent(); |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
@ -1396,22 +1473,7 @@ void FaceBall::HurtPlayer(EnemyID id,int damage,bool blinking) { |
|
|
|
screenCol = enemyData[lastHitBy].col; |
|
|
|
screenCol = enemyData[lastHitBy].col; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void FaceBall::RenderHud(float fElapsedTime) { |
|
|
|
void FaceBall::Display3DKillerModel() { |
|
|
|
if (hudShakeTime > 0) { |
|
|
|
|
|
|
|
hudShakeTime -= fElapsedTime; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!GetKey(olc::D).bHeld && !GetKey(olc::A).bHeld) { |
|
|
|
|
|
|
|
hudOffsetAcc += 20 * fElapsedTime; |
|
|
|
|
|
|
|
while (hudOffsetAcc >= 1) { |
|
|
|
|
|
|
|
hudOffset /= 2; |
|
|
|
|
|
|
|
hudOffsetAcc--; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
SetDecalMode(DecalMode::NORMAL); |
|
|
|
|
|
|
|
if (hp <= 0) { |
|
|
|
|
|
|
|
FillRectDecal({ 0,0 }, { float(ScreenWidth()),float(ScreenHeight()) }); |
|
|
|
|
|
|
|
std::string topText = enemyData[lastHitBy].name + " SAYS"; |
|
|
|
|
|
|
|
std::string bottomText = "HAVE A NICE DAY !"; |
|
|
|
|
|
|
|
// Set up rotation matrices
|
|
|
|
// Set up rotation matrices
|
|
|
|
mat4x4 matRotZ, matRotX, matWorld; |
|
|
|
mat4x4 matRotZ, matRotX, matWorld; |
|
|
|
|
|
|
|
|
|
|
@ -1502,6 +1564,25 @@ void FaceBall::RenderHud(float fElapsedTime) { |
|
|
|
triRenderCount++; |
|
|
|
triRenderCount++; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FaceBall::RenderHud(float fElapsedTime) { |
|
|
|
|
|
|
|
if (hudShakeTime > 0) { |
|
|
|
|
|
|
|
hudShakeTime -= fElapsedTime; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!GetKey(olc::D).bHeld && !GetKey(olc::A).bHeld) { |
|
|
|
|
|
|
|
hudOffsetAcc += 20 * fElapsedTime; |
|
|
|
|
|
|
|
while (hudOffsetAcc >= 1) { |
|
|
|
|
|
|
|
hudOffset /= 2; |
|
|
|
|
|
|
|
hudOffsetAcc--; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
SetDecalMode(DecalMode::NORMAL); |
|
|
|
|
|
|
|
if (hp <= 0) { |
|
|
|
|
|
|
|
FillRectDecal({ 0,0 }, { float(ScreenWidth()),float(ScreenHeight()) }); |
|
|
|
|
|
|
|
std::string topText = enemyData[lastHitBy].name + " SAYS"; |
|
|
|
|
|
|
|
std::string bottomText = "HAVE A NICE DAY !"; |
|
|
|
|
|
|
|
Display3DKillerModel(); |
|
|
|
DrawStringDecal({ (float)(ScreenWidth() / 2 - GetTextSize(topText).x / 2 * 3),140.f }, topText, { 96,96,255 }, { 3,6 }); |
|
|
|
DrawStringDecal({ (float)(ScreenWidth() / 2 - GetTextSize(topText).x / 2 * 3),140.f }, topText, { 96,96,255 }, { 3,6 }); |
|
|
|
DrawStringDecal({ float(ScreenWidth() / 2 - GetTextSize(bottomText).x / 2 * 3),float(ScreenHeight() - 140.f) }, bottomText, { 96,96,255 }, { 3,6 }); |
|
|
|
DrawStringDecal({ float(ScreenWidth() / 2 - GetTextSize(bottomText).x / 2 * 3),float(ScreenHeight() - 140.f) }, bottomText, { 96,96,255 }, { 3,6 }); |
|
|
|
} |
|
|
|
} |
|
|
@ -1785,22 +1866,26 @@ 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(); ++it) { |
|
|
|
for (std::vector<Bullet>::iterator it = bullets.end(); it != bullets.begin();) { |
|
|
|
Bullet& b = *it; |
|
|
|
Bullet& b = *--it; |
|
|
|
if (!b.Update(fElapsedTime)) { |
|
|
|
if (!b.Update(fElapsedTime)) { |
|
|
|
it=bullets.erase(it); |
|
|
|
it=bullets.erase(it); |
|
|
|
if (it == bullets.end()) { |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
for (int i = 0; i < enemies.size(); i++) { |
|
|
|
for (int i = 0; i < enemies.size(); i++) { |
|
|
|
Enemy& e = enemies[i]; |
|
|
|
Enemy& e = enemies[i]; |
|
|
|
|
|
|
|
e.Update(fElapsedTime); |
|
|
|
if (e.isLastHitTimerActive()) { |
|
|
|
if (e.isLastHitTimerActive()) { |
|
|
|
e.reduceLastHitTimer(fElapsedTime); |
|
|
|
e.reduceLastHitTimer(fElapsedTime); |
|
|
|
} |
|
|
|
} |
|
|
|
RunEnemyAI(e, fElapsedTime,i); |
|
|
|
RunEnemyAI(e, fElapsedTime,i); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for (std::vector<Powerup>::iterator it = powerups.end(); it != powerups.begin();) { |
|
|
|
|
|
|
|
Powerup& p = *--it; |
|
|
|
|
|
|
|
if (!p.Update(fElapsedTime)) { |
|
|
|
|
|
|
|
it = powerups.erase(it); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
switch (mode) { |
|
|
|
switch (mode) { |
|
|
|
case GAME: { |
|
|
|
case GAME: { |
|
|
|
if (hp > 0) { |
|
|
|
if (hp > 0) { |
|
|
|