diff --git a/Faceball2030/assets/Exit.mtl b/Faceball2030/assets/Exit.mtl new file mode 100644 index 0000000..c108fe1 --- /dev/null +++ b/Faceball2030/assets/Exit.mtl @@ -0,0 +1,11 @@ +# Exported from Wings 3D 2.2.9 +newmtl Cylinder1_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 auvBG.png + diff --git a/Faceball2030/assets/Exit.wings b/Faceball2030/assets/Exit.wings new file mode 100644 index 0000000..eb7c3b1 Binary files /dev/null and b/Faceball2030/assets/Exit.wings differ diff --git a/Faceball2030/assets/auvBG.png b/Faceball2030/assets/auvBG.png new file mode 100644 index 0000000..db95ba4 Binary files /dev/null and b/Faceball2030/assets/auvBG.png differ diff --git a/Faceball2030/assets/exitwall.png b/Faceball2030/assets/exitwall.png new file mode 100644 index 0000000..4ab030e Binary files /dev/null and b/Faceball2030/assets/exitwall.png differ diff --git a/Faceball2030/assets/hud.png b/Faceball2030/assets/hud.png new file mode 100644 index 0000000..3e670a0 Binary files /dev/null and b/Faceball2030/assets/hud.png differ diff --git a/Faceball2030/assets/hud.xcf b/Faceball2030/assets/hud.xcf new file mode 100644 index 0000000..5c2bb2c Binary files /dev/null and b/Faceball2030/assets/hud.xcf differ diff --git a/Faceball2030/assets/map/map1.map b/Faceball2030/assets/map/map1.map index afc4518..dddfc73 100644 --- a/Faceball2030/assets/map/map1.map +++ b/Faceball2030/assets/map/map1.map @@ -8,7 +8,7 @@ 8202 8200 8204 -40969 +40971 32776 0 8194 @@ -16,15 +16,15 @@ 8202 8198 8197 +8351 8193 -8192 8198 8617 8200 8202 8202 8198 -8195 +8203 16662 8207 8195 diff --git a/Faceball2030/main.cpp b/Faceball2030/main.cpp index cc7d992..be17199 100644 --- a/Faceball2030/main.cpp +++ b/Faceball2030/main.cpp @@ -87,16 +87,20 @@ void FaceBall::LoadLevel(int level) objects.clear(); bullets.clear(); enemies.clear(); + vi2d exitCoords = { 0,0 }; for (int y = 0; y < MAP_SIZE.y; y++) { std::vectorrow; for (int x = 0; x < MAP_SIZE.x; x++) { row.push_back({}); - mapFloor.tris.push_back({ {{(float)x,0,(float)y},{(float)x,0,(float)y + 1},{(float)x + 1,0,(float)y}},{{0,0},{0,1},{1,0}},{WHITE,WHITE,WHITE} }); - mapFloor.tris.push_back({ {{(float)x + 1,0,(float)y},{(float)x,0,(float)y + 1},{(float)x + 1,0,(float)y + 1}},{{1,0},{0,1},{1,1}},{WHITE,WHITE,WHITE} }); + mapFloor.tris.push_back({ {{(float)x,0,(float)y},{(float)x,0,(float)y + 1},{(float)x + 1,0,(float)y}},{{0,0},{0,1},{1,0}},{WHITE,WHITE,WHITE}, floor_tex }); + mapFloor.tris.push_back({ {{(float)x + 1,0,(float)y},{(float)x,0,(float)y + 1},{(float)x + 1,0,(float)y + 1}},{{1,0},{0,1},{1,1}},{WHITE,WHITE,WHITE}, floor_tex }); EnemyID id = mapData[y][x].enemyId; if (id>=SHOOTME&& id < COIN) { enemies.push_back({ id,vec3d{x + 0.5f,0,y + 0.5f},((int)mapData[y][x].facingDir-1)*PI/2,0.2f}); } + if (id == EXIT) { + exitCoords = { x,y }; + } } map.push_back(row); } @@ -117,25 +121,42 @@ void FaceBall::LoadLevel(int level) } AddWall(wallData, { x,y }); if (map[y][x].wallN != NULL) { - mapWalls.tris.push_back({ {{(float)x,1,(float)y},{(float)x,0,(float)y},{(float)x + 1,1,(float)y}},{{0,0},{0,1},{1,0}},{WHITE,WHITE,WHITE} }); - mapWalls.tris.push_back({ {{(float)x,0,(float)y},{(float)x + 1,0,(float)y},{(float)x + 1,1,(float)y}},{{0,1},{1,1},{1,0}},{WHITE,WHITE,WHITE} }); + Decal*exitWallTex = wall_tex; + if (vi2d{ x,y } == vi2d{exitCoords.x, exitCoords.y + 1}) { + exitWallTex = exit_wall_tex; + } + mapWalls.tris.push_back({ {{(float)x,1,(float)y},{(float)x,0,(float)y},{(float)x + 1,1,(float)y}},{{0,0},{0,1},{1,0}},{WHITE,WHITE,WHITE}, exitWallTex }); + mapWalls.tris.push_back({ {{(float)x,0,(float)y},{(float)x + 1,0,(float)y},{(float)x + 1,1,(float)y}},{{0,1},{1,1},{1,0}},{WHITE,WHITE,WHITE}, exitWallTex }); } if (map[y][x].wallS != NULL) { - mapWalls.tris.push_back({ {{(float)x + 1,1,(float)y + 1},{(float)x,0,(float)y + 1},{(float)x,1,(float)y + 1}},{{0,0},{1,1},{1,0}},{WHITE,WHITE,WHITE} }); - mapWalls.tris.push_back({ {{(float)x + 1,1,(float)y + 1},{(float)x + 1,0,(float)y + 1},{(float)x,0,(float)y + 1}},{{0,0},{0,1},{1,1}},{WHITE,WHITE,WHITE} }); + Decal* exitWallTex = wall_tex; + if (vi2d{ x,y } == vi2d{ exitCoords.x, exitCoords.y - 1 }) { + exitWallTex = exit_wall_tex; + } + mapWalls.tris.push_back({ {{(float)x + 1,1,(float)y + 1},{(float)x,0,(float)y + 1},{(float)x,1,(float)y + 1}},{{0,0},{1,1},{1,0}},{WHITE,WHITE,WHITE}, exitWallTex }); + mapWalls.tris.push_back({ {{(float)x + 1,1,(float)y + 1},{(float)x + 1,0,(float)y + 1},{(float)x,0,(float)y + 1}},{{0,0},{0,1},{1,1}},{WHITE,WHITE,WHITE}, exitWallTex }); } if (map[y][x].wallW != NULL) { - mapWalls.tris.push_back({ {{(float)x,1,(float)y},{(float)x,1,(float)y + 1}, {(float)x,0,(float)y + 1}},{{1,0},{0,0},{0,1}},{WHITE,WHITE,WHITE} }); - mapWalls.tris.push_back({ {{(float)x,0,(float)y},{(float)x,1,(float)y}, {(float)x,0,(float)y + 1}}, {{1,1},{1,0},{0,1}},{WHITE,WHITE,WHITE} }); + Decal* exitWallTex = wall_tex; + if (vi2d{ x,y } == vi2d{ exitCoords.x+1, exitCoords.y }) { + exitWallTex = exit_wall_tex; + } + mapWalls.tris.push_back({ {{(float)x,1,(float)y},{(float)x,1,(float)y + 1}, {(float)x,0,(float)y + 1}},{{1,0},{0,0},{0,1}},{WHITE,WHITE,WHITE}, exitWallTex }); + mapWalls.tris.push_back({ {{(float)x,0,(float)y},{(float)x,1,(float)y}, {(float)x,0,(float)y + 1}}, {{1,1},{1,0},{0,1}},{WHITE,WHITE,WHITE}, exitWallTex }); } if (map[y][x].wallE != NULL) { - mapWalls.tris.push_back({ {{(float)x + 1,0,(float)y + 1},{(float)x + 1,1,(float)y + 1},{(float)x + 1,1,(float)y}},{{1,1},{1,0},{0,0}},{WHITE,WHITE,WHITE} }); - mapWalls.tris.push_back({ {{(float)x + 1,0,(float)y + 1} ,{(float)x + 1,1,(float)y},{(float)x + 1,0,(float)y}},{{1,1},{0,0},{0,1}},{WHITE,WHITE,WHITE} }); + Decal* exitWallTex = wall_tex; + if (vi2d{ x,y } == vi2d{ exitCoords.x - 1, exitCoords.y }) { + exitWallTex = exit_wall_tex; + } + mapWalls.tris.push_back({ {{(float)x + 1,0,(float)y + 1},{(float)x + 1,1,(float)y + 1},{(float)x + 1,1,(float)y}},{{1,1},{1,0},{0,0}},{WHITE,WHITE,WHITE}, exitWallTex }); + mapWalls.tris.push_back({ {{(float)x + 1,0,(float)y + 1} ,{(float)x + 1,1,(float)y},{(float)x + 1,0,(float)y}},{{1,1},{0,0},{0,1}},{WHITE,WHITE,WHITE}, exitWallTex }); } } } - objects.push_back({ mapWalls,{0,0},0,0 }); - objects.push_back({ mapFloor,{0,0},0,0 }); + objects.push_back({ mapWalls,{0,0,0},0,0 }); + objects.push_back({ mapFloor,{0,0,0},0,0 }); + objects.push_back({ game->mapExit,{(float)exitCoords.x+0.5f,0,(float)exitCoords.y+0.5f},0,0.4f }); } bool FaceBall::CheckCollision(vec3d movementVector,vf2d pos,float radius){ @@ -540,6 +561,7 @@ void FaceBall::RenderMesh(mat4x4&matView,std::vector&vecTrianglesToRas triTransformed.col[0] = tri.col[0]; triTransformed.col[1] = tri.col[1]; triTransformed.col[2] = tri.col[2]; + triTransformed.tex = tri.tex; vec3d normal, line1, line2; line1 = Vector_Sub(triTransformed.p[1], triTransformed.p[0]); @@ -575,6 +597,7 @@ void FaceBall::RenderMesh(mat4x4&matView,std::vector&vecTrianglesToRas triViewed.col[0] = Pixel(triViewed.col[0].r * colorMult, triViewed.col[0].g * colorMult, triViewed.col[0].b * colorMult); triViewed.col[1] = Pixel(triViewed.col[1].r * colorMult2, triViewed.col[1].g * colorMult2, triViewed.col[1].b * colorMult2); triViewed.col[2] = Pixel(triViewed.col[2].r * colorMult3, triViewed.col[2].g * colorMult3, triViewed.col[2].b * colorMult3); + triViewed.tex = triTransformed.tex; for (Bullet& b : bullets) { float dist = std::sqrtf(std::powf(b.pos.x - triTransformed.p[0].x, 2) + std::powf(b.pos.y - triTransformed.p[0].y, 2) + std::powf(b.pos.z - triTransformed.p[0].z, 2)); @@ -602,6 +625,7 @@ void FaceBall::RenderMesh(mat4x4&matView,std::vector&vecTrianglesToRas triProjected.col[0] = clipped[n].col[0]; triProjected.col[1] = clipped[n].col[1]; triProjected.col[2] = clipped[n].col[2]; + triProjected.tex = clipped[n].tex; triProjected.uv[0] = clipped[n].uv[0]; triProjected.uv[1] = clipped[n].uv[1]; triProjected.uv[2] = clipped[n].uv[2]; @@ -640,7 +664,6 @@ void FaceBall::RenderMesh(mat4x4&matView,std::vector&vecTrianglesToRas triProjected.p[1].y *= 0.5f * (float)ScreenHeight(); triProjected.p[2].x *= 0.5f * (float)ScreenWidth(); triProjected.p[2].y *= 0.5f * (float)ScreenHeight(); - triProjected.tex = o.mesh.texture; vecTrianglesToRaster.push_back(triProjected); } @@ -684,8 +707,7 @@ void FaceBall::RenderWorld() { //std::sort(vecTrianglesToRaster.begin(),vecTrianglesToRaster.end(),[](triangle&t1,triangle&t2){return (t1.p[0].z+t1.p[1].z+t1.p[2].z)/3.0f>(t2.p[0].z+t2.p[1].z+t2.p[2].z)/3.0f;}); ClearBuffer(BLACK, true); - int triRenderCount = 0; - + triRenderCount = 0; for (auto& triToRaster : vecTrianglesToRaster) { Triangle clipped[2]; @@ -752,9 +774,6 @@ void FaceBall::RenderWorld() { triRenderCount++; } } - - SetDecalMode(DecalMode::NORMAL); - DrawStringDecal({ 0,0 }, "Triangles: " + std::to_string(triRenderCount), WHITE, { 2,2 }); } void FaceBall::HandleKeys(float fElapsedTime) { @@ -846,6 +865,9 @@ void FaceBall::HandleKeys(float fElapsedTime) { } else { fYaw -= 2 * fElapsedTime; + if (hudOffset < 20) { + hudOffset = std::min(20.f, hudOffset + 128 * fElapsedTime); + } } } if (GetKey(olc::D).bHeld) { @@ -854,6 +876,9 @@ void FaceBall::HandleKeys(float fElapsedTime) { } else { fYaw += 2 * fElapsedTime; + if (hudOffset > -20) { + hudOffset = std::max(-20.f,hudOffset-128 * fElapsedTime); + } } } if (GetKey(olc::F1).bPressed) { @@ -902,10 +927,13 @@ bool FaceBall::OnUserCreate() bullet_tex = new Decal(new Sprite("assets/enemies/bullet.png")); floor_tex = new Decal(new Sprite("assets/floor.png")); enemy_Sonar_tex = new Decal(new Sprite("assets/enemies/Sonar.png")); + hud = new Decal(new Sprite("assets/hud.png")); + exit_wall_tex = new Decal(new Sprite("assets/exitwall.png")); enemy_ShootMe = { "assets/enemies/ShootMe.obj", enemy_ShootMe_tex }; enemy_Sonar = { "assets/enemies/Sonar.obj", enemy_Sonar_tex }; bullet = { "assets/enemies/bullet.obj",bullet_tex }; + mapExit = { "assets/Exit.obj",dot }; mapWalls.texture = wall_tex; mapFloor.texture = floor_tex; @@ -937,6 +965,9 @@ bool Bullet::Update(float fElapsedTime) { Enemy& enemy = game->enemies[collided_enemy]; if (!enemy.isDead()) { enemy.Hurt(); + if (enemy.isDead()) { + game->SubtractTag(); + } return false; } } @@ -951,6 +982,10 @@ bool Bullet::Update(float fElapsedTime) { return true; } +void FaceBall::SubtractTag() { + tagsRemaining = std::max(0, tagsRemaining - 1); +} + void FaceBall::RunEnemyAI(Enemy& e,float fElapsedTime) { if (e.isDead()) { if (!e.deathAnimationOver()) { @@ -1023,6 +1058,18 @@ bool FaceBall::OnUserUpdate(float fElapsedTime) case GAME: { HandleKeys(fElapsedTime); RenderWorld(); + if (!GetKey(olc::D).bHeld && !GetKey(olc::A).bHeld) { + hudOffsetAcc += 20 * fElapsedTime; + while (hudOffsetAcc >= 1) { + hudOffset /= 2; + hudOffsetAcc--; + } + } + SetDecalMode(DecalMode::NORMAL); + DrawDecal({ -32+hudOffset,-18 }, hud, {1.05,1.05}); + DrawStringDecal({ 112+hudOffset,4 }, "Triangles: " + std::to_string(triRenderCount), BLACK, { 2,4 }); + std::string hudText = "Tags Left: " + std::to_string(tagsRemaining) + " Lives: " + std::to_string(lives); + DrawStringPropDecal(vf2d{ hudOffset+(float)(ScreenWidth() / 2 - GetTextSizeProp(hudText).x * 3 / 2),(float)(ScreenHeight() - 64 - GetTextSizeProp(hudText).y*6) }, hudText, WHITE, {3,6}); }break; case EDITOR: { editor.Update(fElapsedTime); @@ -1047,7 +1094,6 @@ void FaceBall::OnTextEntryComplete(const std::string& sText) { } } - int main() { FaceBall demo; diff --git a/Faceball2030/main.h b/Faceball2030/main.h index abb6bcd..31ff0f9 100644 --- a/Faceball2030/main.h +++ b/Faceball2030/main.h @@ -78,7 +78,7 @@ struct Mesh Mesh(std::string filename, Decal* tex) :texture(tex) { - LoadFromObjectFile(filename); + LoadFromObjectFile(filename,tex); } private: @@ -92,7 +92,7 @@ private: //std::cout<<" "<enemies; private: Mesh mapWalls,mapFloor,enemy_ShootMe,bullet,green_bullet,undefined, - enemy_Sonar; + enemy_Sonar, mapExit; Decal* dot, * enemy_ShootMe_tex,*bullet_tex,*wall_tex,*floor_tex, - *enemy_Sonar_tex; + *enemy_Sonar_tex,*hud,*exit_wall_tex; vi2d MAP_SIZE; std::vector>map; std::vectorobjects; @@ -215,6 +215,8 @@ class FaceBall : public PixelGameEngine GAMEMODE mode=GAMEMODE::GAME; Editor editor; int level=1; + int tagsRemaining = 10; + int lives = 3; mat4x4 matProj; @@ -231,8 +233,12 @@ class FaceBall : public PixelGameEngine float freeRoamCamera_pitch = pitch; float freeRoamCamera_yaw = fYaw; - float shotSpd = 3.0f; + float shotSpd = 4.0f; float moveSpd = 2.0f; + float hudOffset = 0; + float hudOffsetAcc = 0; + + int triRenderCount = 0; vec3d Matrix_MultiplyVector(mat4x4& m, vec3d& i); mat4x4 Matrix_MakeIdentity(); @@ -268,4 +274,5 @@ class FaceBall : public PixelGameEngine public: static bool CheckCollision(vec3d movementVector,vf2d pos,float radius); static int CheckEnemyCollision(vec3d movementVector, vf2d pos, float radius); + void SubtractTag(); }; \ No newline at end of file