aboutsummaryrefslogtreecommitdiff
path: root/game.c
blob: 40d1876c7503e803c604aaf3b5251b844961958b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "all.h"

#include <string.h>

GameState game;

void InitGame(void) {
	memset(&game, 0, sizeof(game));

	game.font_ui = LoadFontVFS(UI_FONT_PATH, UI_FONT_SIZE);
	game.mode = STATE_MENU;
	game.cursor_captured = false;
	EnableCursor();

	game.player.move_mode = MOVE_NORMAL;
	game.player.pos = (Vector3){ 0, 0, 0 };
	game.player.velocity = (Vector3){ 0, 0, 0 };
	game.player.is_grounded = false;

	// Camera setup
	game.camera.up = (Vector3){ 0, 1, 0 };
	game.camera.fovy = PLAYER_FOV;
	game.camera.projection = CAMERA_PERSPECTIVE;
}

void SetMap(const char *path) {
	strncpy(game.map_path, path, sizeof(game.map_path) - 1);
	game.map_path[sizeof(game.map_path) - 1] = '\0';
}

void UpdateGame(void) {
	if (IsMouseButtonPressed(MOUSE_BUTTON_RIGHT)) {
		game.cursor_captured = !game.cursor_captured;
		if (game.cursor_captured) DisableCursor();
		else EnableCursor();
	}

	if (IsKeyPressed(KEY_V)) {
		game.vsync = !game.vsync;
		if (game.vsync) {
			SetWindowState(FLAG_VSYNC_HINT);
			SetTargetFPS(GetMonitorRefreshRate(GetCurrentMonitor()));
		} else {
			ClearWindowState(FLAG_VSYNC_HINT);
			SetTargetFPS(0);
		}
	}

	UpdatePlayer();
}

void DrawGame(void) {
	BeginDrawing();
	ClearBackground(DARKGRAY);

	BeginMode3D(game.camera);

	rlEnableBackfaceCulling();
	for (int i = 0; i < game.map.count; i++) {
		DrawModel(game.map.models[i], (Vector3){ 0, 0, 0 }, 1.0f, WHITE);
	}

	EndMode3D();

	DrawCrosshair();
	DrawDebugInfo();

	EndDrawing();
}