aboutsummaryrefslogtreecommitdiff
path: root/src/game.c
blob: 3fd0c78425b4d19f149ba33be8e07a3c48d26e96 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "game.h"

void initGame(Game * game) {
	// Window.
	InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Killa Facsista");

	// Settings.
	initSettings(&game->settings);

	// Assets.
	LoadAssets(&game->assets);

	// Screen id.
	game->screenId = SCREEN_GAME;

	// Main menu.
	initMainMenu(game);

	// Camera.
	initPlayerCamera(&game->playerCamera);

	SetTargetFPS(60);
	DisableCursor();
	
	// World.
	initWorld(&game->world);

	// Debug.
	// Add player.
	addEntityToWorld(
		&game->world,
		createEntity(ENTITY_ANTIFA, game)
	);

	// Test entity.
	Entity soldato = createEntity(ENTITY_SOLDATO, game);
	soldato.position = (Vector3){10.0, 10.0, 10.0};
	addEntityToWorld(&game->world, soldato);

	soldato = createEntity(ENTITY_SOLDATO, game);
	soldato.position = (Vector3){20.0, 20.0, 20.0};
	addEntityToWorld(&game->world, soldato);

	soldato = createEntity(ENTITY_SOLDATO, game);
	soldato.position = (Vector3){30.0, 30.0, 30.0};
	addEntityToWorld(&game->world, soldato);

	printf("%d\n", removeEntityFromWorld(&game->world, 2));
	printf("%d\n", removeEntityFromWorld(&game->world, 3));

	soldato = createEntity(ENTITY_SOLDATO, game);
	soldato.position = (Vector3){-30.0, -30.0, -30.0};
	addEntityToWorld(&game->world, soldato);


	puts("v");

	for (int i = 0; i < game->world.vacantIdsCount; ++i)
		printf("%d\n", game->world.vacantIds[i]);

	puts("l");

	for (int i = 0; i < game->world.lookUpSize; ++i) {
		printf("%d\n", game->world.lookUp[i]);

		Entity * e = getEntityFromWorld(game->world, i);

		if (e == NULL) {
			puts("null");
			continue;
		}

		if (e->id == i)
			printf("good %x\n", e->fingerprint);
		else
			printf("bad %d\n", e->id);
	}
}

void closeGame(Game * game) {
	unloadAssets(&game->assets);
	freeWorld(&game->world);

	// Close window last.
	CloseWindow();
}

void updateGame(Game * game) {
	BeginDrawing();

	switch (game->screenId) {
		case SCREEN_MAIN_MENU:
			updateMainMenu(game);
			break;
		case SCREEN_GAME:
			updateGameScreen(game);
			break;
		default:
			break;
	}

	DrawFPS(5, 5);

	EndDrawing();
}