Add powerup model, clipping triangle colors (mostly) fixed, and applied blinking state to enemies

linux_template
sigonasr2 2 years ago
parent 9b725bf02a
commit 0291b3ab43
  1. 1
      Faceball2030/Editor.h
  2. 2
      Faceball2030/MapFormat.txt
  3. 11
      Faceball2030/assets/Powerup.mtl
  4. BIN
      Faceball2030/assets/Powerup.wings
  5. 11
      Faceball2030/assets/Powerup2.mtl
  6. BIN
      Faceball2030/assets/Powerup2.wings
  7. 2
      Faceball2030/assets/map/map1.map
  8. BIN
      Faceball2030/assets/octahedron3_auv.png
  9. BIN
      Faceball2030/assets/powerup.png
  10. BIN
      Faceball2030/assets/powerup2.png
  11. BIN
      Faceball2030/assets/sphere1_auv2.png
  12. 143
      Faceball2030/main.cpp
  13. 38
      Faceball2030/main.h

@ -14,6 +14,7 @@ enum EnemyID {
SHOOTME2, SHOOTME2,
ISHOOT, ISHOOT,
ISHOOT2, ISHOOT2,
SHOOTME_ARMOR,
SONAR, SONAR,
COIN = 56, COIN = 56,
POWERUP_ARMOR = 57, POWERUP_ARMOR = 57,

@ -12,7 +12,7 @@ Width*Height 16-bit values
^ ^ En ID^ ^^^^ ^ ^ En ID^ ^^^^
| ^^^ NESW | ^^^ NESW
| Wave 321 | Wave 321
Blink Blink (UNUSED! Changed our minds)
Armor Armor
Speed Speed

@ -0,0 +1,11 @@
# Exported from Wings 3D 2.2.9
newmtl sphere1_auv
Ns 19.999999999999996
d 1.0
illum 2
Kd 1.0 1.0 1.0
Ka 0.0 0.0 0.0
Ks 0.19 0.19 0.19
Ke 0.0 0.0 0.0
map_Kd sphere1_auv2.png

Binary file not shown.

@ -0,0 +1,11 @@
# Exported from Wings 3D 2.2.9
newmtl octahedron3_auv
Ns 19.999999999999996
d 1.0
illum 2
Kd 1.0 1.0 1.0
Ka 0.0 0.0 0.0
Ks 0.19 0.19 0.19
Ke 0.0 0.0 0.0
map_Kd octahedron3_auv.png

@ -20,7 +20,7 @@
8196 8196
8193 8193
2 2
24580 25492
8201 8201
8204 8204
8197 8197

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

@ -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) {

@ -156,6 +156,27 @@ struct Bullet : Object{
bool Update(float fElapsedTime); bool Update(float fElapsedTime);
}; };
enum class PowerupType {
NONE,
ARMOR,
SPEED,
SHOTS,
STOP,
SHIELD,
CAMO,
MAP,
COIN
};
struct Powerup : Object {
PowerupType type;
Powerup(Mesh mesh, vec3d pos, float rot, PowerupType type);
Pixel col;
float colorCycle=1;
float aliveTime=0;
bool Update(float fElapsedTime);
};
struct EnemyData { struct EnemyData {
std::string name; std::string name;
Mesh mesh; Mesh mesh;
@ -167,6 +188,8 @@ struct EnemyData {
float fireDelay = 1; float fireDelay = 1;
float radius = 0.2f; float radius = 0.2f;
bool explosive = false; //Explodes on contact. bool explosive = false; //Explodes on contact.
PowerupType powerupDrop=PowerupType::NONE;
bool blinking = false;
}; };
struct mat4x4 struct mat4x4
@ -189,12 +212,14 @@ struct Enemy : public Object {
bool exploded = false; //If contacted and explosive, then explosion flag is set instead. bool exploded = false; //If contacted and explosive, then explosion flag is set instead.
float colorFactor = 0; float colorFactor = 0;
Phase phase=Phase::DEFAULT; Phase phase=Phase::DEFAULT;
bool blinking = false; //TODO TO BE IMPLEMENTED.
float lastHitTime = 0; float lastHitTime = 0;
bool blinking = false;
float aliveTime = 0;
public: public:
float turnAmt = 0; float turnAmt = 0;
bool flippedTriangles = false; bool flippedTriangles = false;
bool finishedAnimation = false; bool finishedAnimation = false;
float blinkingAmt = 1; //>0.5 the enemy is visible.
Enemy(EnemyID id, vec3d pos, float rot, float radius); Enemy(EnemyID id, vec3d pos, float rot, float radius);
EnemyID GetID(); EnemyID GetID();
//Can set the damage to 0 to cause just a visual hit. //Can set the damage to 0 to cause just a visual hit.
@ -216,6 +241,8 @@ struct Enemy : public Object {
void setExploded(bool exploded); void setExploded(bool exploded);
bool isBlinking(); bool isBlinking();
bool isExploded(); bool isExploded();
bool Update(float fElapsedTime);
void OnDeathEvent();
}; };
class FaceBall : public PixelGameEngine class FaceBall : public PixelGameEngine
@ -230,14 +257,16 @@ class FaceBall : public PixelGameEngine
EnemyData GetData(EnemyID id); EnemyData GetData(EnemyID id);
Decal* circle,*arrow,*YAZAWA; Decal* circle,*arrow,*YAZAWA;
std::map<EnemyID, EnemyData>enemyData; std::map<EnemyID, EnemyData>enemyData;
std::map<PowerupType, Pixel>powerupColorData;
std::vector<Enemy>enemies; std::vector<Enemy>enemies;
std::vector<Powerup>powerups;
private: private:
Mesh mapWalls,mapFloor,enemy_ShootMe,undefined, Mesh mapWalls,mapFloor,enemy_ShootMe,undefined,
enemy_Sonar, mapExit,enemy_IShoot; enemy_Sonar, mapExit,enemy_IShoot,powerup,powerup2;
Decal* dot, * enemy_ShootMe_tex,*bullet_tex,*wall_tex,*floor_tex, Decal* dot, * enemy_ShootMe_tex,*bullet_tex,*wall_tex,*floor_tex,
*enemy_Sonar_tex,*hud,*exit_wall_tex,*enemy_IShoot_tex, *enemy_Sonar_tex,*hud,*exit_wall_tex,*enemy_IShoot_tex,
*life4,*life3,*life2,*life1,*crosshair,*hudmeter; *life4,*life3,*life2,*life1,*crosshair,*hudmeter,*powerup_tex,*powerup2_tex;
vi2d MAP_SIZE; vi2d MAP_SIZE;
vi2d exitCoords = { 0,0 }; vi2d exitCoords = { 0,0 };
std::vector<std::vector<MapSquare>>map; std::vector<std::vector<MapSquare>>map;
@ -336,6 +365,7 @@ class FaceBall : public PixelGameEngine
void OnTextEntryComplete(const std::string& sText) override; void OnTextEntryComplete(const std::string& sText) override;
void InitializeEnemyData(); void InitializeEnemyData();
void InitializeBulletColors(); void InitializeBulletColors();
void InitializePowerupColors();
void LoadLevel(int level); void LoadLevel(int level);
void RenderBulletMesh(mat4x4& matView, std::vector<Triangle>& vecTrianglesToRaster, Bullet& b,bool translucent=true); void RenderBulletMesh(mat4x4& matView, std::vector<Triangle>& vecTrianglesToRaster, Bullet& b,bool translucent=true);
void RenderMesh(mat4x4&matView, std::vector<Triangle>&vecTrianglesToRaster,Object&o,bool translucent=false); void RenderMesh(mat4x4&matView, std::vector<Triangle>&vecTrianglesToRaster,Object&o,bool translucent=false);
@ -343,6 +373,7 @@ class FaceBall : public PixelGameEngine
void RunEnemyAI(Enemy& e,float fElapsedTime,int myIndex); void RunEnemyAI(Enemy& e,float fElapsedTime,int myIndex);
void RenderHud(float fElapsedTime); void RenderHud(float fElapsedTime);
void ConvertBulletColor(Mesh& bullet, Pixel col); void ConvertBulletColor(Mesh& bullet, Pixel col);
void Display3DKillerModel();
public: public:
float restingTriangleYDepth = 0.f; float restingTriangleYDepth = 0.f;
std::vector<Bullet>bullets; std::vector<Bullet>bullets;
@ -355,4 +386,5 @@ class FaceBall : public PixelGameEngine
static bool CheckPlayerCollision(vec3d movementVector, vf2d pos, float radius); static bool CheckPlayerCollision(vec3d movementVector, vf2d pos, float radius);
void SubtractTag(); void SubtractTag();
void HurtPlayer(EnemyID id, int damage=1,bool blinking = false); void HurtPlayer(EnemyID id, int damage=1,bool blinking = false);
void SpawnPowerup(PowerupType type, vec3d pos);
}; };
Loading…
Cancel
Save