diff --git a/Faceball2030/assets/worldSkyBox.png b/Faceball2030/assets/worldSkyBox.png index 195e685..7b01807 100644 Binary files a/Faceball2030/assets/worldSkyBox.png and b/Faceball2030/assets/worldSkyBox.png differ diff --git a/Faceball2030/main.cpp b/Faceball2030/main.cpp index bff63ed..6662466 100644 --- a/Faceball2030/main.cpp +++ b/Faceball2030/main.cpp @@ -67,7 +67,7 @@ bool Enemy::CanShoot() { void Enemy::ShootBullet(int myIndex) { fireDelay = game->enemyData[GetID()].fireDelay; - game->bullets.push_back({ game->bullet, {pos.x,pos.y+0.15f,pos.z},rot,0.2f,1,{std::cosf(rot) * game->shotSpd,std::sinf(rot) * game->shotSpd }, YELLOW,false,GetID(),myIndex,blinking}); + game->bullets.push_back({ game->bullet, {pos.x,pos.y+0.15f,pos.z},rot,0.2f,1,true,{std::cosf(rot) * game->shotSpd,std::sinf(rot) * game->shotSpd }, YELLOW,false,GetID(),myIndex,blinking}); } void Enemy::ReloadBullet(float fElapsedTime) { @@ -436,7 +436,7 @@ void FaceBall::LoadLevel(int level) walls = { mapWalls }; MapWallsObjectIndex = objects.size()-1; objects.push_back({ mapFloor,{0,0,0},0,0 }); - objects.push_back({ worldSkyBox,{0,0,0},0,0 }); + objects.push_back({ worldSkyBox,{MAP_SIZE.x/2.f,0,MAP_SIZE.y/2.f},0,0,std::max(float(MAP_SIZE.x),float(MAP_SIZE.y))*2,false }); //objects.push_back({ game->mapExit,{(float)exitCoords.x+0.5f,0,(float)exitCoords.y+0.5f},0,0.4f }); exit = { game->mapExit,{(float)exitCoords.x + 0.5f,0.02f,(float)exitCoords.y + 0.5f},0,0.4f }; RegenerateMinimap(); @@ -955,7 +955,7 @@ void FaceBall::RenderMesh(mat4x4&matView,std::vector&vecTrianglesToRas vec3d vCameraRay = Vector_Sub(triTransformed.p[0], freeRoam ? freeRoamCamera : player.GetPos()); - if (Vector_DotProduct(normal, vCameraRay) < 0) { + if (Vector_DotProduct(normal, vCameraRay) < 0||!o.affectedByLighting) { vec3d light_dir = Vector_Mul(vLookDir, -1); light_dir = Vector_Normalise(light_dir); @@ -967,9 +967,11 @@ void FaceBall::RenderMesh(mat4x4&matView,std::vector&vecTrianglesToRas triViewed.uv[0] = triTransformed.uv[0]; triViewed.uv[1] = triTransformed.uv[1]; triViewed.uv[2] = triTransformed.uv[2]; - triViewed.col[0] = Pixel(triTransformed.col[0].r * dp * dp, triTransformed.col[0].g * dp * dp, triTransformed.col[0].b * dp * dp); - triViewed.col[1] = Pixel(triTransformed.col[1].r * dp * dp, triTransformed.col[1].g * dp * dp, triTransformed.col[1].b * dp * dp); - triViewed.col[2] = Pixel(triTransformed.col[2].r * dp * dp, triTransformed.col[2].g * dp * dp, triTransformed.col[2].b * dp * dp); + if (o.affectedByLighting) { + triViewed.col[0] = Pixel(triTransformed.col[0].r * dp * dp, triTransformed.col[0].g * dp * dp, triTransformed.col[0].b * dp * dp); + triViewed.col[1] = Pixel(triTransformed.col[1].r * dp * dp, triTransformed.col[1].g * dp * dp, triTransformed.col[1].b * dp * dp); + triViewed.col[2] = Pixel(triTransformed.col[2].r * dp * dp, triTransformed.col[2].g * dp * dp, triTransformed.col[2].b * dp * dp); + } Pixel originalCol[3] = { triViewed.col[0],triViewed.col[1],triViewed.col[2] }; float dist = std::sqrtf(std::powf((freeRoam ? freeRoamCamera : player.GetPos()).x - triTransformed.p[0].x, 2) + std::powf((freeRoam ? freeRoamCamera : player.GetPos()).y - triTransformed.p[0].y, 2) + std::powf((freeRoam ? freeRoamCamera : player.GetPos()).z - triTransformed.p[0].z, 2)); float dist2 = std::sqrtf(std::powf((freeRoam ? freeRoamCamera : player.GetPos()).x - triTransformed.p[1].x, 2) + std::powf((freeRoam ? freeRoamCamera : player.GetPos()).y - triTransformed.p[1].y, 2) + std::powf((freeRoam ? freeRoamCamera : player.GetPos()).z - triTransformed.p[1].z, 2)); @@ -977,22 +979,31 @@ void FaceBall::RenderMesh(mat4x4&matView,std::vector&vecTrianglesToRas float colorMult = dist > 5 * PI / 3 ? 0 : std::sinf(0.3 * dist + PI / 2); float colorMult2 = dist2 > 5 * PI / 3 ? 0 : std::sinf(0.3 * dist2 + PI / 2); float colorMult3 = dist3 > 5 * PI / 3 ? 0 : std::sinf(0.3 * dist3 + PI / 2); - 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); + if (o.affectedByLighting) { + 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); + } + if (!o.affectedByLighting) { + triViewed.col[0] = originalCol[0]; + triViewed.col[1] = originalCol[1]; + triViewed.col[2] = originalCol[2]; + } 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)); - float dist2 = std::sqrtf(std::powf(b.pos.x - triTransformed.p[1].x, 2) + std::powf(b.pos.y - triTransformed.p[1].y, 2) + std::powf(b.pos.z - triTransformed.p[1].z, 2)); - float dist3 = std::sqrtf(std::powf(b.pos.x - triTransformed.p[2].x, 2) + std::powf(b.pos.y - triTransformed.p[2].y, 2) + std::powf(b.pos.z - triTransformed.p[2].z, 2)); - float colorMult = (dist < 2 ? std::sinf(0.75 * dist + PI / 2) * 4 :1); - float colorMult2 = (dist2 < 2 ? std::sinf(0.75 * dist2 + PI / 2) * 4 : 1); - float colorMult3 = (dist3 < 2 ? std::sinf(0.75 * dist3 + PI / 2) * 4 : 1); - Pixel lightCol = b.col / 2 + Pixel{ 128, 128, 128 }; - if (dist < 2) {triViewed.col[0] = Pixel(std::min(255, std::max((int)originalCol[0].r, (int)(originalCol[0].r * colorMult / float(255.f/lightCol.r)))), std::min(255, std::max((int)originalCol[0].g, (int)(originalCol[0].g * colorMult / float(255.f / lightCol.g)))), std::min(255, std::max((int)originalCol[0].b, (int)(originalCol[0].b * colorMult / float(255.f / lightCol.b)))));} - if (dist2 < 2) {triViewed.col[1] = Pixel(std::min(255, std::max((int)originalCol[1].r, (int)(originalCol[1].r * colorMult2 / float(255.f / lightCol.r)))), std::min(255, std::max((int)originalCol[1].g, (int)(originalCol[1].g * colorMult2 / float(255.f / lightCol.g)))), std::min(255, std::max((int)originalCol[1].b, (int)(originalCol[1].b * colorMult2 / float(255.f / lightCol.b)))));} - if (dist3 < 2) {triViewed.col[2] = Pixel(std::min(255, std::max((int)originalCol[2].r, (int)(originalCol[2].r * colorMult3 / float(255.f / lightCol.r)))), std::min(255, std::max((int)originalCol[2].g, (int)(originalCol[2].g * colorMult3 / float(255.f / lightCol.g)))), std::min(255, std::max((int)originalCol[2].b, (int)(originalCol[2].b * colorMult3 / float(255.f / lightCol.b)))));} + if (o.affectedByLighting) { + 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)); + float dist2 = std::sqrtf(std::powf(b.pos.x - triTransformed.p[1].x, 2) + std::powf(b.pos.y - triTransformed.p[1].y, 2) + std::powf(b.pos.z - triTransformed.p[1].z, 2)); + float dist3 = std::sqrtf(std::powf(b.pos.x - triTransformed.p[2].x, 2) + std::powf(b.pos.y - triTransformed.p[2].y, 2) + std::powf(b.pos.z - triTransformed.p[2].z, 2)); + float colorMult = (dist < 2 ? std::sinf(0.75 * dist + PI / 2) * 4 : 1); + float colorMult2 = (dist2 < 2 ? std::sinf(0.75 * dist2 + PI / 2) * 4 : 1); + float colorMult3 = (dist3 < 2 ? std::sinf(0.75 * dist3 + PI / 2) * 4 : 1); + Pixel lightCol = b.col / 2 + Pixel{ 128, 128, 128 }; + if (dist < 2) { triViewed.col[0] = Pixel(std::min(255, std::max((int)originalCol[0].r, (int)(originalCol[0].r * colorMult / float(255.f / lightCol.r)))), std::min(255, std::max((int)originalCol[0].g, (int)(originalCol[0].g * colorMult / float(255.f / lightCol.g)))), std::min(255, std::max((int)originalCol[0].b, (int)(originalCol[0].b * colorMult / float(255.f / lightCol.b))))); } + if (dist2 < 2) { triViewed.col[1] = Pixel(std::min(255, std::max((int)originalCol[1].r, (int)(originalCol[1].r * colorMult2 / float(255.f / lightCol.r)))), std::min(255, std::max((int)originalCol[1].g, (int)(originalCol[1].g * colorMult2 / float(255.f / lightCol.g)))), std::min(255, std::max((int)originalCol[1].b, (int)(originalCol[1].b * colorMult2 / float(255.f / lightCol.b))))); } + if (dist3 < 2) { triViewed.col[2] = Pixel(std::min(255, std::max((int)originalCol[2].r, (int)(originalCol[2].r * colorMult3 / float(255.f / lightCol.r)))), std::min(255, std::max((int)originalCol[2].g, (int)(originalCol[2].g * colorMult3 / float(255.f / lightCol.g)))), std::min(255, std::max((int)originalCol[2].b, (int)(originalCol[2].b * colorMult3 / float(255.f / lightCol.b))))); } + } } //triViewed.col = triTransformed.col; @@ -1546,7 +1557,7 @@ void FaceBall::HandleKeys(float fElapsedTime) { pitch = 0; if (GetMouse(0).bPressed) { if (PlayerActiveShotCount(0) < shotLimit) { - Bullet newBullet={ bullet,{player.GetPos().x,player.GetPos().y - 0.15f, player.GetPos().z},fYaw,0.125f,1,{shotSpd * std::cosf(fYaw),shotSpd * std::sinf(fYaw)},GREEN,true }; + Bullet newBullet={ bullet,{player.GetPos().x,player.GetPos().y - 0.15f, player.GetPos().z},fYaw,0.125f,1,true,{shotSpd * std::cosf(fYaw),shotSpd * std::sinf(fYaw)},GREEN,true }; newBullet.playerIndex=0; bullets.push_back(newBullet); } diff --git a/Faceball2030/main.h b/Faceball2030/main.h index 0524c6c..64fbf35 100644 --- a/Faceball2030/main.h +++ b/Faceball2030/main.h @@ -145,6 +145,7 @@ struct Object { float rot = 0; float radius = 0.2f; float scale = 1.f; + bool affectedByLighting = true; }; struct Bullet : Object{ @@ -283,7 +284,7 @@ class FaceBall : public PixelGameEngine Editor editor; int MapWallsObjectIndex = -1; bool exitWallsCleared = false; - int level=3; + int level=1; int tagsRemaining = 10; int lives = 3; double gameTimer = 0;