diff --git a/Faceball2030/main.cpp b/Faceball2030/main.cpp index 9461d10..a4cd8f0 100644 --- a/Faceball2030/main.cpp +++ b/Faceball2030/main.cpp @@ -7,6 +7,13 @@ using namespace olc; const float PI = 3.14159f; +enum Direction { + NORTH=1, + EAST=2, + SOUTH=4, + WEST=8 +}; + struct vec2d { float u = 0; @@ -119,7 +126,7 @@ private: mesh mapMesh; mat4x4 matProj; - vec3d vCamera = { 5,5,5 }; + vec3d vCamera = { 5,0.5,5 }; vec3d vLookDir; float zOffset = 2; @@ -621,7 +628,7 @@ private: {0,0}, {0,0}, {0,0}, - },WHITE); + }, { t.uv[0].w,t.uv[1].w,t.uv[2].w }, { t.p[0].z,t.p[1].z,t.p[2].z }, { BLACK,BLACK,BLACK }); SetDecalStructure(DecalStructure::FAN); triRenderCount++; } @@ -632,7 +639,7 @@ private: } void HandleKeys(float fElapsedTime) { - vec3d vForward = Vector_Mul(vLookDir, 20 * fElapsedTime); + vec3d vForward = Vector_Mul(vLookDir, 2 * fElapsedTime); if (freeRoam) { if (GetKey(olc::DOWN).bHeld) { pitch -= 1 * fElapsedTime; @@ -661,27 +668,133 @@ private: } } - vi2d MAP_SIZE = { 10,2 }; + void AddWall(Direction dir,vi2d gridSquare) { + if (dir & NORTH) { + map[gridSquare.y][gridSquare.x].wallN = dot; + if (gridSquare.y > 0) { + map[gridSquare.y - 1][gridSquare.x].wallS = dot; + } + } + if (dir & WEST) { + map[gridSquare.y][gridSquare.x].wallW = dot; + if (gridSquare.x > 0) { + map[gridSquare.y][gridSquare.x-1].wallE = dot; + } + } + if (dir & SOUTH) { + map[gridSquare.y][gridSquare.x].wallS = dot; + if (gridSquare.y>map; public: bool OnUserCreate() override { + sAppName = "Faceball 2030"; matProj = Matrix_MakeProjection(90.0f, (float)ScreenHeight() / (float)ScreenWidth(), 0.1f, 1000.0f); - Decal* dot = new Decal(new Sprite("dot.png")); + dot = new Decal(new Sprite("dot.png")); mapMesh.texture = dot; - for (int i = 0; i < MAP_SIZE.y; i++) { + for (int y = 0; y < MAP_SIZE.y; y++) { std::vectorrow; - for (int j = 0; j < MAP_SIZE.x; j++) { + for (int x = 0; x < MAP_SIZE.x; x++) { row.push_back({}); - mapMesh.tris.push_back({ {{(float)j * 10,0,(float)i * 10},{(float)j * 10,0,(float)i * 10 + 10},{(float)j * 10 + 10,0,(float)i * 10}},{{0,0},{1,0},{0,1}},Pixel{uint8_t(rand() * 255),uint8_t(rand() * 255),uint8_t(rand() * 255)} }); - mapMesh.tris.push_back({ {{(float)j * 10+10,0,(float)i * 10},{(float)j * 10,0,(float)i * 10 + 10},{(float)j * 10 + 10,0,(float)i * 10+10}},{{0,0},{1,0},{0,1}},Pixel{uint8_t(rand() * 255),uint8_t(rand() * 255),uint8_t(rand() * 255)} }); + mapMesh.tris.push_back({ {{(float)x,0,(float)y},{(float)x,0,(float)y + 1},{(float)x + 1,0,(float)y}},{{0,0},{1,0},{0,1}},BLUE }); + mapMesh.tris.push_back({ {{(float)x+1,0,(float)y},{(float)x,0,(float)y + 1},{(float)x + 1,0,(float)y+1}},{{0,0},{1,0},{0,1}},BLUE }); } map.push_back(row); } + for (int y = 0; y < MAP_SIZE.y; y++) { + for (int x = 0; x < MAP_SIZE.x; x++) { + switch (rand() % 16) { + case 0: {//No Wall. + + }break; + case 1: {//North Wall. + AddWall(NORTH,{x,y}); + }break; + case 2: {//East Wall. + AddWall(EAST, { x,y }); + }break; + case 3: {//South Wall. + AddWall(SOUTH, { x,y }); + }break; + case 4: {//West Wall. + AddWall(WEST, { x,y }); + }break; + case 5: {//NE Wall. + AddWall(Direction(NORTH|EAST), { x,y }); + }break; + case 6: { + AddWall(Direction(NORTH|WEST), { x,y }); + }break; + case 7: { + AddWall(Direction(SOUTH|EAST), { x,y }); + }break; + case 8: { + AddWall(Direction(SOUTH|WEST), { x,y }); + }break; + case 9: { + AddWall(Direction(NORTH|SOUTH), { x,y }); + }break; + case 10: { + AddWall(Direction(EAST|WEST), { x,y }); + }break; + case 11: { + AddWall(Direction(NORTH|WEST|EAST), { x,y }); + }break; + case 12: { + AddWall(Direction(NORTH|WEST|SOUTH), { x,y }); + }break; + case 13: { + AddWall(Direction(WEST|SOUTH|EAST), { x,y }); + }break; + case 14: { + AddWall(Direction(SOUTH|EAST|NORTH), { x,y }); + }break; + case 15: { + AddWall(Direction(SOUTH | EAST | NORTH|WEST), { x,y }); + }break; + } + } + } + AddWall(Direction(SOUTH | EAST | NORTH | WEST), { 0,0 }); + + for (int y = 0; y < MAP_SIZE.y; y++) { + for (int x = 0; x < MAP_SIZE.x; x++) { + 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},{1,0},{0,1}},YELLOW }); + mapMesh.tris.push_back({ {{(float)x,0,(float)y},{(float)x+1,0,(float)y},{(float)x + 1,1,(float)y}},{{0,0},{1,0},{0,1}},YELLOW }); + } + 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,0},{0,1}},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},{1,0},{0,1}},DARK_RED }); + } + 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}},{{0,0},{1,0},{0,1}},MAGENTA }); + mapMesh.tris.push_back({ {{(float)x,0,(float)y},{(float)x,1,(float)y}, {(float)x,0,(float)y + 1}}, {{0,0},{1,0},{0,1}},MAGENTA }); + } + 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}},{{0,0},{1,0},{0,1}},CYAN }); + mapMesh.tris.push_back({ {{(float)x + 1,0,(float)y + 1} ,{(float)x+1,1,(float)y},{(float)x + 1,0,(float)y}},{{0,0},{1,0},{0,1}},CYAN }); + } + } + } + return true; }