gam
This commit is contained in:
parent
7b8e798662
commit
d1782e1265
4 changed files with 221 additions and 27 deletions
|
|
@ -43,7 +43,6 @@ typedef int socklen_t;
|
|||
#define BTN_USE_MEDKIT (1u << 4)
|
||||
#define BTN_JUMP (1u << 5)
|
||||
|
||||
// ============== DIRECTIONAL LIGHT ==============
|
||||
typedef struct {
|
||||
Vector3 direction; // Normalized light direction
|
||||
Vector3 color; // RGB color (0-1 range)
|
||||
|
|
@ -53,7 +52,6 @@ typedef struct {
|
|||
float shadowIntensity; // How dark shadows are (0-1)
|
||||
} DirectionalLight;
|
||||
|
||||
// ============== TERRAIN SHADER ==============
|
||||
typedef struct {
|
||||
Shader shader;
|
||||
int locViewPos;
|
||||
|
|
@ -86,7 +84,6 @@ static void unload_terrain_shader(TerrainShader *ts) {
|
|||
}
|
||||
}
|
||||
|
||||
// ============== END TERRAIN SHADER ==============
|
||||
static const uint8_t perm[512] = {
|
||||
151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7,
|
||||
225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190,
|
||||
|
|
@ -284,9 +281,7 @@ static Mesh generate_terrain_mesh(void) {
|
|||
UploadMesh(&mesh, false);
|
||||
return mesh;
|
||||
}
|
||||
// ============== END SIMPLEX NOISE ==============
|
||||
|
||||
// ============== LIGHTING HELPERS ==============
|
||||
// apply_directional_lighting: Basic Lambertian diffuse lighting
|
||||
// Applies directional light with diffuse component based on surface normal
|
||||
static Color apply_directional_lighting(Color baseColor, Vector3 normal,
|
||||
|
|
@ -389,7 +384,6 @@ static Vector3 v3_normalize(Vector3 v) {
|
|||
return (Vector3){v.x / len, v.y / len, v.z / len};
|
||||
}
|
||||
|
||||
// ============== VECTOR3 HELPERS ==============
|
||||
static Vector3 v3(float x, float y, float z) {
|
||||
Vector3 v = {x, y, z};
|
||||
return v;
|
||||
|
|
@ -412,9 +406,6 @@ static Vector3 v3_norm(Vector3 a) {
|
|||
return v3(0, 0, 1);
|
||||
return v3(a.x / l, a.y / l, a.z / l);
|
||||
}
|
||||
// ============== END VECTOR3 HELPERS ==============
|
||||
|
||||
// ============== ENHANCED LIGHTING & AMBIENT OCCLUSION ==============
|
||||
|
||||
// calculate_ambient_occlusion: Estimates how occluded a point is based on
|
||||
// terrain curvature Samples heights in cardinal directions and computes horizon
|
||||
|
|
@ -504,8 +495,6 @@ static Color apply_phong_lighting_per_pixel(Color baseColor, Vector3 normal,
|
|||
return (Color){r, g, b, baseColor.a};
|
||||
}
|
||||
|
||||
// ============== END ENHANCED LIGHTING & AMBIENT OCCLUSION ==============
|
||||
|
||||
static void set_nonblocking(int sock) {
|
||||
#ifdef _WIN32
|
||||
u_long mode = 1;
|
||||
|
|
@ -523,7 +512,8 @@ typedef enum MsgType : uint8_t {
|
|||
MSG_INPUT = 3,
|
||||
MSG_SNAPSHOT = 4,
|
||||
MSG_SHOOT = 5,
|
||||
MSG_ITEMS = 6
|
||||
MSG_ITEMS = 6,
|
||||
MSG_ROOM_STATE = 7
|
||||
} MsgType;
|
||||
|
||||
typedef struct MsgHello {
|
||||
|
|
@ -582,6 +572,14 @@ typedef struct MsgItems {
|
|||
uint8_t count;
|
||||
ItemNet items[MAX_ITEMS];
|
||||
} MsgItems;
|
||||
|
||||
typedef struct MsgRoomState {
|
||||
uint8_t type;
|
||||
uint8_t state;
|
||||
float countdownRemaining;
|
||||
uint8_t winnerId;
|
||||
char winnerName[USERNAME_MAX];
|
||||
} MsgRoomState;
|
||||
#pragma pack(pop)
|
||||
|
||||
typedef struct RemotePlayer {
|
||||
|
|
@ -711,12 +709,17 @@ int main(void) {
|
|||
RemotePlayer rp[MAX_PLAYERS] = {0};
|
||||
WorldItem wi[MAX_ITEMS] = {0};
|
||||
|
||||
// Room state
|
||||
int roomState = 0;
|
||||
float countdownRemaining = 0.0f;
|
||||
char winnerName[USERNAME_MAX] = {0};
|
||||
|
||||
Vector3 camPos = v3(0, 5.0f, 6);
|
||||
float yaw = 0.0f, pitch = 0.0f;
|
||||
|
||||
float recoilYaw = 0.0f, recoilPitch = 0.0f, crossSpread = 0.0f;
|
||||
int scoped = 0;
|
||||
float fireCooldown = 0.0f;
|
||||
float recoilYaw = 0.0f, recoilPitch = 0.0f, crossSpread = 0.0f;
|
||||
int scoped = 0;
|
||||
float fireCooldown = 0.0f;
|
||||
int shotsInBurst = 0;
|
||||
float burstResetTimer = 0.0f;
|
||||
|
||||
|
|
@ -829,6 +832,14 @@ int main(void) {
|
|||
wi[i].qty = m->items[i].qty;
|
||||
wi[i].pos = v3(m->items[i].x, m->items[i].y, m->items[i].z);
|
||||
}
|
||||
} else if (type == MSG_ROOM_STATE && n >= (int)sizeof(MsgRoomState)) {
|
||||
const MsgRoomState *rs = (const MsgRoomState *)buf;
|
||||
roomState = rs->state;
|
||||
countdownRemaining = rs->countdownRemaining;
|
||||
memset(winnerName, 0, USERNAME_MAX);
|
||||
if (rs->winnerId < 255) {
|
||||
strncpy(winnerName, rs->winnerName, USERNAME_MAX - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1068,6 +1079,30 @@ int main(void) {
|
|||
|
||||
DrawFPS(sw - 90, 10);
|
||||
|
||||
// Room state overlay
|
||||
if (roomState == 0) { // Waiting
|
||||
DrawRectangle(sw / 2 - 150, sh / 2 - 50, 300, 100, (Color){0, 0, 0, 200});
|
||||
DrawText("WAITING FOR PLAYERS", sw / 2 - 120, sh / 2 - 30, 24, RAYWHITE);
|
||||
DrawText("Need at least 2 players", sw / 2 - 100, sh / 2 - 5, 18,
|
||||
(Color){200, 200, 200, 255});
|
||||
} else if (roomState == 1) { // Counting down
|
||||
DrawRectangle(sw / 2 - 150, sh / 2 - 50, 300, 100, (Color){0, 0, 0, 200});
|
||||
DrawText("GAME STARTING SOON", sw / 2 - 120, sh / 2 - 30, 24,
|
||||
(Color){255, 255, 80, 255});
|
||||
DrawText(TextFormat("%.1f seconds", countdownRemaining), sw / 2 - 60,
|
||||
sh / 2 - 5, 20, RAYWHITE);
|
||||
} else if (roomState == 3) { // Finished
|
||||
DrawRectangle(sw / 2 - 200, sh / 2 - 50, 400, 100, (Color){0, 0, 0, 200});
|
||||
DrawText("GAME FINISHED", sw / 2 - 80, sh / 2 - 30, 28,
|
||||
(Color){255, 80, 80, 255});
|
||||
if (winnerName[0]) {
|
||||
DrawText(TextFormat("Winner: %s", winnerName), sw / 2 - 100, sh / 2 - 5,
|
||||
24, (Color){255, 255, 80, 255});
|
||||
} else {
|
||||
DrawText("No winner", sw / 2 - 50, sh / 2 - 5, 24, RAYWHITE);
|
||||
}
|
||||
}
|
||||
|
||||
// Crosshair
|
||||
{
|
||||
int cx = sw / 2, cy = sh / 2;
|
||||
|
|
@ -1078,7 +1113,8 @@ int main(void) {
|
|||
DrawRectangle(cx + gap, cy - thick / 2, len, thick, col);
|
||||
DrawRectangle(cx - thick / 2, cy - gap - len, thick, len, col);
|
||||
DrawRectangle(cx - thick / 2, cy + gap, thick, len, col);
|
||||
DrawCircleLines(cx, cy, scoped ? 1.5f : 3.0f, (Color){240, 240, 245, 160});
|
||||
DrawCircleLines(cx, cy, scoped ? 1.5f : 3.0f,
|
||||
(Color){240, 240, 245, 160});
|
||||
}
|
||||
|
||||
EndDrawing();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue