diff --git a/Faceball2030/assets/floor.png b/Faceball2030/assets/floor.png new file mode 100644 index 0000000..5a99779 Binary files /dev/null and b/Faceball2030/assets/floor.png differ diff --git a/Faceball2030/assets/wall.png b/Faceball2030/assets/wall.png new file mode 100644 index 0000000..890ed9d Binary files /dev/null and b/Faceball2030/assets/wall.png differ diff --git a/Faceball2030/main.cpp b/Faceball2030/main.cpp index 07af438..67df1c6 100644 --- a/Faceball2030/main.cpp +++ b/Faceball2030/main.cpp @@ -9,19 +9,28 @@ using namespace olc; FaceBall* game; +Enemy::Enemy(EnemyID id,vec3d pos,float rot,float radius) + :id(id), health(game->enemyData[id].health), fireDelay(0), + Object({game->enemyData[id].mesh,pos,rot,radius}) { + EnemyData data = game->enemyData[id]; + for (int i = 0; i < data.ammo; i++) { + shots.push_back({ data.reloadTime }); + } + } + void FaceBall::InitializeEnemyData() { - enemyData[EnemyID::NONE] = { "VOID",BLACK }; - enemyData[EXIT] = { "EXIT",GREEN }; - enemyData[START] = { "SPAWN POSITION",{128,64,0} }; - enemyData[SHOOTME] = { "SHOOTME",YELLOW,1,1,PI / 8,2,1,3 }; - enemyData[COIN] = { "Coin",BLUE }; - enemyData[POWERUP_ARMOR] = { "Armor",{96,0,96} }; - enemyData[POWERUP_SPEED] = { "Speed",{96,0,96} }; - enemyData[POWERUP_SHOT] = { "Shot",{96,0,96} }; - enemyData[SPECIAL_CAMO] = { "Camouflage",DARK_RED }; - enemyData[SPECIAL_STOP] = { "Stop",DARK_RED }; - enemyData[SPECIAL_SHIELD] = { "Shield",DARK_RED }; - enemyData[AREA_MAP] = { "Map",GREEN }; + enemyData[EnemyID::NONE] = { "VOID",undefined,BLACK }; + enemyData[EXIT] = { "EXIT",undefined,GREEN }; + enemyData[START] = { "SPAWN POSITION",undefined,{128,64,0} }; + enemyData[SHOOTME] = { "SHOOTME",enemy_ShootMe,YELLOW,1,1,PI / 8,2,1,3 }; + enemyData[COIN] = { "Coin",undefined,BLUE }; + enemyData[POWERUP_ARMOR] = { "Armor",undefined,{96,0,96} }; + enemyData[POWERUP_SPEED] = { "Speed",undefined,{96,0,96} }; + enemyData[POWERUP_SHOT] = { "Shot",undefined,{96,0,96} }; + enemyData[SPECIAL_CAMO] = { "Camouflage",undefined,DARK_RED }; + enemyData[SPECIAL_STOP] = { "Stop",undefined,DARK_RED }; + enemyData[SPECIAL_SHIELD] = { "Shield",undefined,DARK_RED }; + enemyData[AREA_MAP] = { "Map",undefined,GREEN }; } void FaceBall::LoadLevel(int level) @@ -30,14 +39,21 @@ void FaceBall::LoadLevel(int level) std::vector>mapData = editor.LoadLevel(level); MAP_SIZE = { (int)mapData[0].size(),(int)mapData.size() }; map.clear(); - mapMesh.tris.clear(); + mapWalls.tris.clear(); + mapFloor.tris.clear(); objects.clear(); + bullets.clear(); + enemies.clear(); for (int y = 0; y < MAP_SIZE.y; y++) { std::vectorrow; for (int x = 0; x < MAP_SIZE.x; x++) { row.push_back({}); - mapMesh.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}},{BLUE,BLUE,BLUE} }); - mapMesh.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}},{BLUE,BLUE,BLUE} }); + 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} }); + 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}); + } } map.push_back(row); } @@ -58,24 +74,25 @@ void FaceBall::LoadLevel(int level) } AddWall(wallData, { x,y }); if (map[y][x].wallN != NULL) { - mapMesh.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}},{YELLOW,YELLOW,YELLOW} }); - mapMesh.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}},{YELLOW,YELLOW,YELLOW} }); + 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} }); } if (map[y][x].wallS != NULL) { - mapMesh.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}},{DARK_RED,DARK_RED,DARK_RED} }); - mapMesh.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}},{DARK_RED,DARK_RED,DARK_RED} }); + 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} }); } if (map[y][x].wallW != NULL) { - mapMesh.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}},{MAGENTA,MAGENTA,MAGENTA} }); - mapMesh.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}},{MAGENTA,MAGENTA,MAGENTA} }); + 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} }); } if (map[y][x].wallE != NULL) { - mapMesh.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}},{CYAN,CYAN,CYAN} }); - mapMesh.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}},{CYAN,CYAN,CYAN} }); + 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} }); } } } - objects.push_back({ mapMesh,{0,0},0,0 }); + objects.push_back({ mapWalls,{0,0},0,0 }); + objects.push_back({ mapFloor,{0,0},0,0 }); } bool FaceBall::CheckCollision(vec3d movementVector,vf2d pos,float radius){ @@ -600,8 +617,8 @@ void FaceBall::RenderWorld() { //matWorld = Matrix_MultiplyMatrix(matWorld, matTrans); vec3d vUp = { 0,1,0 }; - vec3d vTarget = { 0,sinf(pitch),cosf(pitch) }; - mat4x4 matCameraRot = Matrix_MakeRotationY(fYaw-PI/2); + vec3d vTarget = { 0,sinf(freeRoam?freeRoamCamera_pitch:pitch),cosf(freeRoam ? freeRoamCamera_pitch : pitch) }; + mat4x4 matCameraRot = Matrix_MakeRotationY((freeRoam?freeRoamCamera_yaw:fYaw)-PI/2); vLookDir = Matrix_MultiplyVector(matCameraRot, vTarget); vec3d playerCenter = { player.GetPos().x, player.GetPos().y, player.GetPos().z }; vTarget = Vector_Add(freeRoam ? freeRoamCamera : playerCenter, vLookDir); @@ -617,6 +634,9 @@ void FaceBall::RenderWorld() { for (auto& bullet : bullets) { RenderMesh(matView, vecTrianglesToRaster, bullet); } + for (auto& enemy : enemies) { + RenderMesh(matView, vecTrianglesToRaster, enemy); + } //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); @@ -697,10 +717,10 @@ void FaceBall::HandleKeys(float fElapsedTime) { vec3d vForward = Vector_Mul(vLookDir, std::min(player.GetRadius()-0.00001f,moveSpd*fElapsedTime)); if (freeRoam) { if (GetKey(DOWN).bHeld) { - pitch -= 1 * fElapsedTime; + freeRoamCamera_pitch -= 1 * fElapsedTime; } if (GetKey(UP).bHeld) { - pitch += 1 * fElapsedTime; + freeRoamCamera_pitch += 1 * fElapsedTime; } } else { @@ -741,10 +761,20 @@ void FaceBall::HandleKeys(float fElapsedTime) { } } if (GetKey(olc::A).bHeld) { - fYaw -= 2 * fElapsedTime; + if (freeRoam) { + freeRoamCamera_yaw -= 2 * fElapsedTime; + } + else { + fYaw -= 2 * fElapsedTime; + } } if (GetKey(olc::D).bHeld) { - fYaw += 2 * fElapsedTime; + if (freeRoam) { + freeRoamCamera_yaw += 2 * fElapsedTime; + } + else { + fYaw += 2 * fElapsedTime; + } } if (GetKey(olc::F1).bPressed) { freeRoam = !freeRoam; @@ -788,13 +818,16 @@ bool FaceBall::OnUserCreate() arrow = new Decal(new Sprite("assets/arrow.png")); enemy_ShootMe_tex = new Decal(new Sprite("assets/enemies/ShootMe.png")); YAZAWA = new Decal(new Sprite("assets/yazawa.png")); + wall_tex = new Decal(new Sprite("assets/wall.png")); bullet_tex = new Decal(new Sprite("assets/enemies/bullet.png")); + floor_tex = new Decal(new Sprite("assets/floor.png")); - InitializeEnemyData(); - - Mesh testEnemy("assets/enemies/ShootMe.obj", enemy_ShootMe_tex); + enemy_ShootMe = { "assets/enemies/ShootMe.obj", enemy_ShootMe_tex }; bullet = { "assets/enemies/bullet.obj",bullet_tex }; - mapMesh.texture = YAZAWA; + mapWalls.texture = wall_tex; + mapFloor.texture = floor_tex; + + InitializeEnemyData(); LoadLevel(1); diff --git a/Faceball2030/main.h b/Faceball2030/main.h index d8710c2..b45b248 100644 --- a/Faceball2030/main.h +++ b/Faceball2030/main.h @@ -151,6 +151,7 @@ struct Bullet : Object{ struct EnemyData { std::string name; + Mesh mesh; Pixel col=YELLOW; int health = 1; float movSpd = 1; @@ -165,6 +166,16 @@ struct mat4x4 float m[4][4] = { 0 }; }; +struct Enemy : Object { + private: + EnemyID id; + int health=1; + std::vector shots; + float fireDelay=0; + public: + Enemy(EnemyID id, vec3d pos, float rot, float radius); +}; + class FaceBall : public PixelGameEngine { bool freeRoam = false; @@ -176,15 +187,16 @@ class FaceBall : public PixelGameEngine EnemyData GetData(EnemyID id); Decal* circle,*arrow,*YAZAWA; + std::mapenemyData; private: - Mesh mapMesh,enemy_ShootMe,bullet; + Mesh mapWalls,mapFloor,enemy_ShootMe,bullet,undefined; - Decal* dot, * enemy_ShootMe_tex,*bullet_tex; + Decal* dot, * enemy_ShootMe_tex,*bullet_tex,*wall_tex,*floor_tex; vi2d MAP_SIZE; std::vector>map; - std::mapenemyData; std::vectorobjects; std::vectorbullets; + std::vectorenemies; GAMEMODE mode=GAMEMODE::GAME; Editor editor; int level=1; @@ -201,6 +213,8 @@ class FaceBall : public PixelGameEngine Player player = { {3.7,0.3,0.7}, {{0.5,0.5},0.2} }; vec3d freeRoamCamera = { 1,0.5,1 }; + float freeRoamCamera_pitch = pitch; + float freeRoamCamera_yaw = fYaw; float shotSpd = 3.0f; float moveSpd = 2.0f;