Compare commits

...

2 Commits

  1. 20
      Faceball2030/assets/worldSkyBox.mtl
  2. 207
      Faceball2030/assets/worldSkyBox.obj
  3. BIN
      Faceball2030/assets/worldSkyBox.png
  4. 119
      Faceball2030/main.cpp
  5. 8
      Faceball2030/main.h

@ -0,0 +1,20 @@
# 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 Cylinder1_auv.png
newmtl default
Ns 19.999999999999996
d 1.0
illum 2
Kd 0.7898538076923077 0.8133333333333334 0.6940444444444445
Ka 0.0 0.0 0.0
Ks 0.1689853807692308 0.17133333333333334 0.15940444444444446
Ke 0.0 0.0 0.0

@ -0,0 +1,207 @@
# Exported from Wings 3D 2.2.9
mtllib worldSkyBox.mtl
o Cylinder1
#64 vertices, 64 faces
v 1.00000000 20.00000000 0.0000000e+0
v 0.98078528 20.00000000 0.19509032
v 0.92387953 20.00000000 0.38268343
v 0.83146961 20.00000000 0.55557023
v 0.70710678 20.00000000 0.70710678
v 0.55557023 20.00000000 0.83146961
v 0.38268343 20.00000000 0.92387953
v 0.19509032 20.00000000 0.98078528
v 6.1232340e-17 20.00000000 1.00000000
v -0.19509032 20.00000000 0.98078528
v -0.38268343 20.00000000 0.92387953
v -0.55557023 20.00000000 0.83146961
v -0.70710678 20.00000000 0.70710678
v -0.83146961 20.00000000 0.55557023
v -0.92387953 20.00000000 0.38268343
v -0.98078528 20.00000000 0.19509032
v -1.00000000 20.00000000 1.2246468e-16
v -0.98078528 20.00000000 -0.19509032
v -0.92387953 20.00000000 -0.38268343
v -0.83146961 20.00000000 -0.55557023
v -0.70710678 20.00000000 -0.70710678
v -0.55557023 20.00000000 -0.83146961
v -0.38268343 20.00000000 -0.92387953
v -0.19509032 20.00000000 -0.98078528
v -1.8369702e-16 20.00000000 -1.00000000
v 0.19509032 20.00000000 -0.98078528
v 0.38268343 20.00000000 -0.92387953
v 0.55557023 20.00000000 -0.83146961
v 0.70710678 20.00000000 -0.70710678
v 0.83146961 20.00000000 -0.55557023
v 0.92387953 20.00000000 -0.38268343
v 0.98078528 20.00000000 -0.19509032
v 1.00000000 0.0000000e+0 0.0000000e+0
v 0.98078528 0.0000000e+0 0.19509032
v 0.92387953 0.0000000e+0 0.38268343
v 0.83146961 0.0000000e+0 0.55557023
v 0.70710678 0.0000000e+0 0.70710678
v 0.55557023 0.0000000e+0 0.83146961
v 0.38268343 0.0000000e+0 0.92387953
v 0.19509032 0.0000000e+0 0.98078528
v 6.1232340e-17 0.0000000e+0 1.00000000
v -0.19509032 0.0000000e+0 0.98078528
v -0.38268343 0.0000000e+0 0.92387953
v -0.55557023 0.0000000e+0 0.83146961
v -0.70710678 0.0000000e+0 0.70710678
v -0.83146961 0.0000000e+0 0.55557023
v -0.92387953 0.0000000e+0 0.38268343
v -0.98078528 0.0000000e+0 0.19509032
v -1.00000000 0.0000000e+0 1.2246468e-16
v -0.98078528 0.0000000e+0 -0.19509032
v -0.92387953 0.0000000e+0 -0.38268343
v -0.83146961 0.0000000e+0 -0.55557023
v -0.70710678 0.0000000e+0 -0.70710678
v -0.55557023 0.0000000e+0 -0.83146961
v -0.38268343 0.0000000e+0 -0.92387953
v -0.19509032 0.0000000e+0 -0.98078528
v -1.8369702e-16 0.0000000e+0 -1.00000000
v 0.19509032 0.0000000e+0 -0.98078528
v 0.38268343 0.0000000e+0 -0.92387953
v 0.55557023 0.0000000e+0 -0.83146961
v 0.70710678 0.0000000e+0 -0.70710678
v 0.83146961 0.0000000e+0 -0.55557023
v 0.92387953 0.0000000e+0 -0.38268343
v 0.98078528 0.0000000e+0 -0.19509032
vt 0.0000000e+0 1.00000000
vt 2.2648550e-14 1.1657342e-15
vt 9.8017140e-3 1.00000000
vt 9.8017140e-3 7.2164497e-16
vt 1.9603428e-2 1.00000000
vt 1.9603428e-2 4.4408921e-16
vt 2.9405142e-2 1.00000000
vt 2.9405142e-2 2.2204460e-16
vt 3.9206856e-2 1.00000000
vt 3.9206856e-2 0.0000000e+0
vt 4.9008570e-2 1.00000000
vt 4.9008570e-2 0.0000000e+0
vt 5.8810284e-2 1.00000000
vt 5.8810284e-2 0.0000000e+0
vt 6.8611998e-2 1.00000000
vt 6.8611998e-2 2.2204460e-16
vt 7.8413712e-2 1.00000000
vt 7.8413712e-2 1.00000000
vt 7.8413712e-2 3.8857806e-16
vt 7.8413712e-2 2.6645353e-15
vt 8.8215426e-2 1.00000000
vt 8.8215426e-2 2.0539126e-15
vt 9.8017140e-2 1.00000000
vt 9.8017140e-2 1.5543122e-15
vt 0.10781885 1.00000000
vt 0.10781885 9.9920072e-16
vt 0.11762057 1.00000000
vt 0.11762057 5.5511151e-16
vt 0.12742228 1.00000000
vt 0.12742228 3.8857806e-16
vt 0.13722400 1.00000000
vt 0.13722400 2.2204460e-16
vt 0.14702571 1.00000000
vt 0.14702571 0.0000000e+0
vt 0.15682742 1.00000000
vt 0.15682742 0.0000000e+0
vt 0.15682742 1.00000000
vt 0.15682742 1.6653345e-16
vt 0.16662914 1.00000000
vt 0.16662914 0.0000000e+0
vt 0.17643085 1.00000000
vt 0.17643085 0.0000000e+0
vt 0.18623257 1.00000000
vt 0.18623257 0.0000000e+0
vt 0.19603428 1.00000000
vt 0.19603428 0.0000000e+0
vt 0.20583599 1.00000000
vt 0.20583599 2.7755576e-16
vt 0.21563771 1.00000000
vt 0.21563771 5.5511151e-16
vt 0.22543942 1.00000000
vt 0.22543942 8.8817842e-16
vt 0.23524114 1.00000000
vt 0.23524114 1.4432899e-15
vt 0.23524114 3.8857806e-16
vt 0.23524114 1.00000000
vt 0.24504285 2.2204460e-16
vt 0.24504285 1.00000000
vt 0.25484456 0.0000000e+0
vt 0.25484456 1.00000000
vt 0.26464628 0.0000000e+0
vt 0.26464628 1.00000000
vt 0.27444799 0.0000000e+0
vt 0.27444799 1.00000000
vt 0.28424971 2.2204460e-16
vt 0.28424971 1.00000000
vt 0.29405142 3.8857806e-16
vt 0.29405142 1.00000000
vt 0.30385314 7.2164497e-16
vt 0.30385314 1.00000000
vt 0.31365485 3.8857806e-16
vt 0.31365485 1.00000000
g Cylinder1_Cylinder1_auv
usemtl Cylinder1_auv
s 1
f 1/64/ 33/63/ 32/66/
f 2/62/ 33/63/ 1/64/
f 2/62/ 35/59/ 34/61/
f 3/60/ 35/59/ 2/62/
f 4/58/ 35/59/ 3/60/
f 4/58/ 37/55/ 36/57/
f 5/56/ 37/55/ 4/58/
f 6/33/ 37/36/ 5/35/
f 6/33/ 39/32/ 38/34/
f 7/31/ 39/32/ 6/33/
f 8/29/ 39/32/ 7/31/
f 8/29/ 41/28/ 40/30/
f 9/27/ 41/28/ 8/29/
f 10/25/ 41/28/ 9/27/
f 10/25/ 43/24/ 42/26/
f 11/23/ 43/24/ 10/25/
f 12/21/ 43/24/ 11/23/
f 12/21/ 45/20/ 44/22/
f 13/18/ 45/20/ 12/21/
f 14/51/ 45/54/ 13/53/
f 14/51/ 47/50/ 46/52/
f 15/49/ 47/50/ 14/51/
f 16/47/ 47/50/ 15/49/
f 16/47/ 49/46/ 48/48/
f 17/45/ 49/46/ 16/47/
f 18/43/ 49/46/ 17/45/
f 18/43/ 51/42/ 50/44/
f 19/41/ 51/42/ 18/43/
f 20/39/ 51/42/ 19/41/
f 20/39/ 53/38/ 52/40/
f 21/37/ 53/38/ 20/39/
f 22/15/ 53/19/ 21/17/
f 22/15/ 55/14/ 54/16/
f 23/13/ 55/14/ 22/15/
f 24/11/ 55/14/ 23/13/
f 24/11/ 57/10/ 56/12/
f 25/9/ 57/10/ 24/11/
f 26/7/ 57/10/ 25/9/
f 26/7/ 59/6/ 58/8/
f 27/5/ 59/6/ 26/7/
f 28/3/ 59/6/ 27/5/
f 28/3/ 61/2/ 60/4/
f 29/1/ 61/2/ 28/3/
f 30/70/ 61/71/ 29/72/
f 30/70/ 63/67/ 62/69/
f 31/68/ 63/67/ 30/70/
f 32/66/ 33/63/ 64/65/
f 32/66/ 63/67/ 31/68/
f 34/61/ 33/63/ 2/62/
f 36/57/ 35/59/ 4/58/
f 38/34/ 37/36/ 6/33/
f 40/30/ 39/32/ 8/29/
f 42/26/ 41/28/ 10/25/
f 44/22/ 43/24/ 12/21/
f 46/52/ 45/54/ 14/51/
f 48/48/ 47/50/ 16/47/
f 50/44/ 49/46/ 18/43/
f 52/40/ 51/42/ 20/39/
f 54/16/ 53/19/ 22/15/
f 56/12/ 55/14/ 24/11/
f 58/8/ 57/10/ 26/7/
f 60/4/ 59/6/ 28/3/
f 62/69/ 61/71/ 30/70/
f 64/65/ 63/67/ 32/66/

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

@ -67,7 +67,7 @@ bool Enemy::CanShoot() {
void Enemy::ShootBullet(int myIndex) { void Enemy::ShootBullet(int myIndex) {
fireDelay = game->enemyData[GetID()].fireDelay; fireDelay = game->enemyData[GetID()].fireDelay;
game->bullets.push_back({ game->bullet, {pos.x,pos.y+0.15f,pos.z},rot,0.2f,{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) { void Enemy::ReloadBullet(float fElapsedTime) {
@ -436,6 +436,7 @@ void FaceBall::LoadLevel(int level)
walls = { mapWalls }; walls = { mapWalls };
MapWallsObjectIndex = objects.size()-1; MapWallsObjectIndex = objects.size()-1;
objects.push_back({ mapFloor,{0,0,0},0,0 }); objects.push_back({ mapFloor,{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 }); //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 }; exit = { game->mapExit,{(float)exitCoords.x + 0.5f,0.02f,(float)exitCoords.y + 0.5f},0,0.4f };
RegenerateMinimap(); RegenerateMinimap();
@ -918,23 +919,32 @@ void FaceBall::RenderBulletMesh(mat4x4& matView, std::vector<Triangle>& vecTrian
void FaceBall::RenderMesh(mat4x4&matView,std::vector<Triangle>&vecTrianglesToRaster, Object&o,bool translucent) { void FaceBall::RenderMesh(mat4x4&matView,std::vector<Triangle>&vecTrianglesToRaster, Object&o,bool translucent) {
for (auto& tri : o.mesh.tris) { for (auto& tri : o.mesh.tris) {
if (translucent&&tri.tex != exit_wall_tex && tri.tex != bullet_tex ||!translucent&&(tri.tex==exit_wall_tex || tri.tex == bullet_tex)) { continue; } if (translucent&&tri.tex != exit_wall_tex && tri.tex != bullet_tex ||!translucent&&(tri.tex==exit_wall_tex || tri.tex == bullet_tex)) { continue; }
Triangle triProjected, triTransformed, triViewed; Triangle triScaled,triProjected, triTransformed, triViewed;
mat4x4 localMat = Matrix_MakeIdentity(); mat4x4 localMat = Matrix_MakeIdentity();
mat4x4 rotMat = Matrix_MakeRotationY(o.rot); mat4x4 rotMat = Matrix_MakeRotationY(o.rot);
localMat = Matrix_MultiplyMatrix(localMat, rotMat); localMat = Matrix_MultiplyMatrix(localMat, rotMat);
mat4x4 matTrans = Matrix_MakeTranslation(o.pos.x, o.pos.y, o.pos.z); mat4x4 matTrans = Matrix_MakeTranslation(o.pos.x, o.pos.y, o.pos.z);
localMat = Matrix_MultiplyMatrix(localMat, matTrans); localMat = Matrix_MultiplyMatrix(localMat, matTrans);
triTransformed.p[0] = Matrix_MultiplyVector(localMat, tri.p[0]); for (int i = 0; i < 3; i++) {
triTransformed.p[1] = Matrix_MultiplyVector(localMat, tri.p[1]); triScaled.p[i].x = tri.p[i].x*o.scale;
triTransformed.p[2] = Matrix_MultiplyVector(localMat, tri.p[2]); triScaled.p[i].y = tri.p[i].y * o.scale;
triTransformed.uv[0] = tri.uv[0]; triScaled.p[i].z = tri.p[i].z * o.scale;
triTransformed.uv[1] = tri.uv[1]; triScaled.uv[i] = tri.uv[i];
triTransformed.uv[2] = tri.uv[2]; triScaled.col[i] = tri.col[i];
triTransformed.col[0] = tri.col[0]; }
triTransformed.col[1] = tri.col[1]; triScaled.tex = tri.tex;
triTransformed.col[2] = tri.col[2];
triTransformed.tex = tri.tex; triTransformed.p[0] = Matrix_MultiplyVector(localMat, triScaled.p[0]);
triTransformed.p[1] = Matrix_MultiplyVector(localMat, triScaled.p[1]);
triTransformed.p[2] = Matrix_MultiplyVector(localMat, triScaled.p[2]);
triTransformed.uv[0] = triScaled.uv[0];
triTransformed.uv[1] = triScaled.uv[1];
triTransformed.uv[2] = triScaled.uv[2];
triTransformed.col[0] = triScaled.col[0];
triTransformed.col[1] = triScaled.col[1];
triTransformed.col[2] = triScaled.col[2];
triTransformed.tex = triScaled.tex;
vec3d normal, line1, line2; vec3d normal, line1, line2;
line1 = Vector_Sub(triTransformed.p[1], triTransformed.p[0]); line1 = Vector_Sub(triTransformed.p[1], triTransformed.p[0]);
@ -945,7 +955,7 @@ void FaceBall::RenderMesh(mat4x4&matView,std::vector<Triangle>&vecTrianglesToRas
vec3d vCameraRay = Vector_Sub(triTransformed.p[0], freeRoam ? freeRoamCamera : player.GetPos()); 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); vec3d light_dir = Vector_Mul(vLookDir, -1);
light_dir = Vector_Normalise(light_dir); light_dir = Vector_Normalise(light_dir);
@ -957,9 +967,11 @@ void FaceBall::RenderMesh(mat4x4&matView,std::vector<Triangle>&vecTrianglesToRas
triViewed.uv[0] = triTransformed.uv[0]; triViewed.uv[0] = triTransformed.uv[0];
triViewed.uv[1] = triTransformed.uv[1]; triViewed.uv[1] = triTransformed.uv[1];
triViewed.uv[2] = triTransformed.uv[2]; 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); if (o.affectedByLighting) {
triViewed.col[1] = Pixel(triTransformed.col[1].r * dp * dp, triTransformed.col[1].g * dp * dp, triTransformed.col[1].b * dp * dp); triViewed.col[0] = Pixel(triTransformed.col[0].r * dp * dp, triTransformed.col[0].g * dp * dp, triTransformed.col[0].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); 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] }; 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 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)); 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));
@ -967,22 +979,31 @@ void FaceBall::RenderMesh(mat4x4&matView,std::vector<Triangle>&vecTrianglesToRas
float colorMult = dist > 5 * PI / 3 ? 0 : std::sinf(0.3 * dist + PI / 2); 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 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); 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); if (o.affectedByLighting) {
triViewed.col[1] = Pixel(triViewed.col[1].r * colorMult2, triViewed.col[1].g * colorMult2, triViewed.col[1].b * colorMult2); triViewed.col[0] = Pixel(triViewed.col[0].r * colorMult, triViewed.col[0].g * colorMult, triViewed.col[0].b * colorMult);
triViewed.col[2] = Pixel(triViewed.col[2].r * colorMult3, triViewed.col[2].g * colorMult3, triViewed.col[2].b * colorMult3); 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; triViewed.tex = triTransformed.tex;
for (Bullet& b : bullets) { if (o.affectedByLighting) {
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)); for (Bullet& b : bullets) {
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 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 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 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 colorMult = (dist < 2 ? std::sinf(0.75 * dist + PI / 2) * 4 :1); 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 colorMult2 = (dist2 < 2 ? std::sinf(0.75 * dist2 + PI / 2) * 4 : 1); float colorMult = (dist < 2 ? std::sinf(0.75 * dist + PI / 2) * 4 : 1);
float colorMult3 = (dist3 < 2 ? std::sinf(0.75 * dist3 + PI / 2) * 4 : 1); float colorMult2 = (dist2 < 2 ? std::sinf(0.75 * dist2 + PI / 2) * 4 : 1);
Pixel lightCol = b.col / 2 + Pixel{ 128, 128, 128 }; float colorMult3 = (dist3 < 2 ? std::sinf(0.75 * dist3 + PI / 2) * 4 : 1);
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)))));} Pixel lightCol = b.col / 2 + Pixel{ 128, 128, 128 };
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 (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 (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 (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; //triViewed.col = triTransformed.col;
@ -1353,16 +1374,30 @@ void FaceBall::RenderWorld() {
RenderMesh(matView, vecTrianglesToRaster, enemy); RenderMesh(matView, vecTrianglesToRaster, enemy);
} }
} }
for (auto& bullet : bullets) { #ifdef OLC_PLATFORM_EMSCRIPTEN
RenderBulletMesh(matView, vecTrianglesToRasterTranslucent, bullet); for (auto& bullet : bullets) {
} RenderBulletMesh(matView, vecTrianglesToRaster, bullet);
for (auto& powerup : powerups) { }
RenderPowerupMesh(matView, vecTrianglesToRasterTranslucent, powerup); for (auto& powerup : powerups) {
} RenderPowerupMesh(matView, vecTrianglesToRaster, powerup);
}
#else
for (auto& bullet : bullets) {
RenderBulletMesh(matView, vecTrianglesToRasterTranslucent, bullet);
}
for (auto& powerup : powerups) {
RenderPowerupMesh(matView, vecTrianglesToRasterTranslucent, powerup);
}
#endif
RenderMesh(matView, vecTrianglesToRaster, walls); RenderMesh(matView, vecTrianglesToRaster, walls);
RenderMesh(matView, vecTrianglesToRasterTranslucent, walls, true); #ifdef OLC_PLATFORM_EMSCRIPTEN
RenderMesh(matView, vecTrianglesToRaster, walls, true);
//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;}); #else
RenderMesh(matView, vecTrianglesToRasterTranslucent, walls, true);
#endif
#ifdef OLC_PLATFORM_EMSCRIPTEN
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;});
#endif
ClearBuffer(BLACK, true); ClearBuffer(BLACK, true);
triRenderCount = 0; triRenderCount = 0;
for (auto& triToRaster : vecTrianglesToRaster) { for (auto& triToRaster : vecTrianglesToRaster) {
@ -1522,7 +1557,7 @@ void FaceBall::HandleKeys(float fElapsedTime) {
pitch = 0; pitch = 0;
if (GetMouse(0).bPressed) { if (GetMouse(0).bPressed) {
if (PlayerActiveShotCount(0) < shotLimit) { if (PlayerActiveShotCount(0) < shotLimit) {
Bullet newBullet={ bullet,{player.GetPos().x,player.GetPos().y - 0.15f, player.GetPos().z},fYaw,0.125f,{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; newBullet.playerIndex=0;
bullets.push_back(newBullet); bullets.push_back(newBullet);
} }
@ -1766,6 +1801,7 @@ bool FaceBall::OnUserCreate()
powerup_tex = new Decal(new Sprite("assets/powerup.png")); powerup_tex = new Decal(new Sprite("assets/powerup.png"));
powerup2_tex = new Decal(new Sprite("assets/powerup2.png")); powerup2_tex = new Decal(new Sprite("assets/powerup2.png"));
powerups_tex = new Decal(new Sprite("assets/powerups.png")); powerups_tex = new Decal(new Sprite("assets/powerups.png"));
worldSkyBox_tex = new Decal(new Sprite("assets/worldSkyBox.png"));
enemy_ShootMe = { "assets/enemies/ShootMe.obj", enemy_ShootMe_tex }; enemy_ShootMe = { "assets/enemies/ShootMe.obj", enemy_ShootMe_tex };
enemy_ShootMe2 = { "assets/enemies/ShootMe2.obj", enemy_ShootMe2_tex }; enemy_ShootMe2 = { "assets/enemies/ShootMe2.obj", enemy_ShootMe2_tex };
@ -1776,6 +1812,7 @@ bool FaceBall::OnUserCreate()
powerup = { "assets/Powerup.obj",powerup_tex}; powerup = { "assets/Powerup.obj",powerup_tex};
powerup2 = { "assets/Powerup2.obj",powerup2_tex }; powerup2 = { "assets/Powerup2.obj",powerup2_tex };
mapExit = { "assets/Exit.obj",dot }; mapExit = { "assets/Exit.obj",dot };
worldSkyBox = { "assets/worldSkyBox.obj",worldSkyBox_tex };
mapWalls.texture = wall_tex; mapWalls.texture = wall_tex;
mapFloor.texture = floor_tex; mapFloor.texture = floor_tex;

@ -144,6 +144,8 @@ struct Object {
vec3d pos = { 0,0 }; vec3d pos = { 0,0 };
float rot = 0; float rot = 0;
float radius = 0.2f; float radius = 0.2f;
float scale = 1.f;
bool affectedByLighting = true;
}; };
struct Bullet : Object{ struct Bullet : Object{
@ -263,7 +265,7 @@ class FaceBall : public PixelGameEngine
private: private:
Mesh mapWalls,mapFloor,enemy_ShootMe,undefined, Mesh mapWalls,mapFloor,enemy_ShootMe,undefined,
enemy_Sonar, mapExit,enemy_ShootMe2,powerup,powerup2, enemy_Sonar, mapExit,enemy_ShootMe2,powerup,powerup2,
enemy_IShoot,enemy_IShoot2; enemy_IShoot,enemy_IShoot2,worldSkyBox;
Sprite*mapSpr; Sprite*mapSpr;
Decal*mapDecal; Decal*mapDecal;
@ -273,7 +275,7 @@ class FaceBall : public PixelGameEngine
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_ShootMe2_tex,*enemy_IShoot_tex, *enemy_Sonar_tex,*hud,*exit_wall_tex,*enemy_ShootMe2_tex,*enemy_IShoot_tex,
*life4,*life3,*life2,*life1,*crosshair,*hudmeter,*powerup_tex,*powerup2_tex, *life4,*life3,*life2,*life1,*crosshair,*hudmeter,*powerup_tex,*powerup2_tex,
*powerups_tex,*enemy_IShoot2_tex; *powerups_tex,*enemy_IShoot2_tex, *worldSkyBox_tex;
vi2d exitCoords = { 0,0 }; vi2d exitCoords = { 0,0 };
std::vector<vf2d>knownGoodPositions; std::vector<vf2d>knownGoodPositions;
std::vector<std::vector<MapSquare>>map; std::vector<std::vector<MapSquare>>map;
@ -282,7 +284,7 @@ class FaceBall : public PixelGameEngine
Editor editor; Editor editor;
int MapWallsObjectIndex = -1; int MapWallsObjectIndex = -1;
bool exitWallsCleared = false; bool exitWallsCleared = false;
int level=3; int level=1;
int tagsRemaining = 10; int tagsRemaining = 10;
int lives = 3; int lives = 3;
double gameTimer = 0; double gameTimer = 0;

Loading…
Cancel
Save