first pass on procedural sky
This commit is contained in:
parent
90730990ca
commit
47c829f962
@ -3,7 +3,7 @@ CXXFLAGS = -std=c++20 -Wall -Wextra -O2 -I.
|
||||
LDFLAGS = -lraylib -lboost_system -lpthread -lGL -lm -ldl -lrt -lX11
|
||||
|
||||
TARGET = game
|
||||
SOURCES = main.cpp entity/Entity.cpp entity/player/PlayerController.cpp net/NetworkManager.cpp
|
||||
SOURCES = main.cpp entity/Entity.cpp entity/player/PlayerController.cpp net/NetworkManager.cpp sky/Sky.cpp
|
||||
OBJECTS = $(SOURCES:.cpp=.o)
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
@ -12,8 +12,10 @@
|
||||
#include <cstring>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include "entity/player/PlayerController.hpp"
|
||||
#include "net/NetworkManager.hpp"
|
||||
#include "sky/Sky.hpp"
|
||||
|
||||
constexpr int WORLD_SIZE = 100;
|
||||
constexpr float WORLD_SCALE = 10.0f;
|
||||
@ -112,6 +114,7 @@ class Game {
|
||||
Model playerModel;
|
||||
Heightmap heightmap;
|
||||
NetworkManager network;
|
||||
std::unique_ptr<Sky> sky;
|
||||
Vector3 playerPos{0, 0, 0};
|
||||
Texture2D terrainTexture;
|
||||
std::unordered_map<std::string, Texture2D> playerTextures;
|
||||
@ -133,6 +136,9 @@ public:
|
||||
InitWindow(1280, 720, "Multiplayer Terrain Game");
|
||||
SetTargetFPS(60);
|
||||
|
||||
// Initialize sky after window is created
|
||||
sky = std::make_unique<Sky>();
|
||||
|
||||
// Load heightmap
|
||||
if (!heightmap.load("../assets/heightmap.bin")) {
|
||||
std::cerr << "Failed to load heightmap\n";
|
||||
@ -222,6 +228,17 @@ private:
|
||||
return;
|
||||
}
|
||||
|
||||
// Update sky
|
||||
sky->update(GetFrameTime());
|
||||
|
||||
// Time of day controls (for testing)
|
||||
if (IsKeyPressed(KEY_T)) {
|
||||
float currentTime = sky->getTimeOfDay();
|
||||
currentTime += 0.1f;
|
||||
if (currentTime > 1.0f) currentTime -= 1.0f;
|
||||
sky->setTimeOfDay(currentTime);
|
||||
}
|
||||
|
||||
// Get server position and update player controller
|
||||
playerPos = network.getPosition();
|
||||
playerController.setPlayerPosition(playerPos);
|
||||
@ -317,6 +334,8 @@ private:
|
||||
|
||||
void render() {
|
||||
BeginDrawing();
|
||||
|
||||
// Clear with a default color first
|
||||
ClearBackground(SKYBLUE);
|
||||
|
||||
switch (gameState) {
|
||||
@ -381,6 +400,11 @@ private:
|
||||
|
||||
void renderGame() {
|
||||
BeginMode3D(playerController.getCamera());
|
||||
|
||||
// Render skybox first (it will handle its own depth settings)
|
||||
if (sky) {
|
||||
sky->renderSkybox(playerController.getCamera());
|
||||
}
|
||||
|
||||
// Draw terrain
|
||||
DrawModel(terrainModel, {0, 0, 0}, 1.0f, WHITE);
|
||||
@ -404,11 +428,19 @@ private:
|
||||
DrawText(TextFormat("Logged in as: %s", currentUsername.c_str()), 10, 10, 20, WHITE);
|
||||
DrawText("WASD: Move | Q/E: Strafe | Right-Click: Rotate Camera", 10, 35, 20, WHITE);
|
||||
DrawText("Left/Right Arrow: Change Color | Mouse Wheel: Zoom | ESC: Logout", 10, 60, 20, WHITE);
|
||||
DrawText("T: Change Time of Day", 10, 85, 20, WHITE);
|
||||
if (network.isConnected()) {
|
||||
std::string colorText = "Your color: " + network.getPlayerColor();
|
||||
DrawText(colorText.c_str(), 10, 85, 20, WHITE);
|
||||
DrawText(colorText.c_str(), 10, 110, 20, WHITE);
|
||||
}
|
||||
DrawFPS(10, 110);
|
||||
|
||||
// Show time of day
|
||||
float timeHour = sky->getTimeOfDay() * 24.0f;
|
||||
int hour = (int)timeHour;
|
||||
int minute = (int)((timeHour - hour) * 60);
|
||||
DrawText(TextFormat("Time: %02d:%02d", hour, minute), 10, 135, 20, WHITE);
|
||||
|
||||
DrawFPS(10, 160);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user