-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
executable file
·90 lines (68 loc) · 3.56 KB
/
main.c
File metadata and controls
executable file
·90 lines (68 loc) · 3.56 KB
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
#include <string.h>
#include <raylib.h>
#include <voxelspace.h>
#include <math.h>
const static int width = 1080;
const static int height = 720;
int main() {
vsGlobalGameState *gameState = createGlobalGameState("map/color.png", "map/height.png", width, height);
vsScreenData *screenData = gameState->screenData;
SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_WINDOW_HIGHDPI);
InitWindow(width, height, "VoxelSpaceEngine");
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
Image i = (Image) {
.width = screenData->width, .height = screenData->height, .data = screenData->screen, .format = UNCOMPRESSED_R8G8B8A8, .mipmaps = 1
};
Texture2D tex = LoadTextureFromImage(i);
//--------------------------------------------------------------------------------------
gameState->camera->position.z = 250;
gameState->camera->position.y = 90;
gameState->camera->position.x = 490;
gameState->camera->rotation.x = 200;
vsCamera *cam = gameState->camera;
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
gameState->timeLastFrame = gameState->time;
gameState->time = GetFrameTime();
memset(screenData->screen, 0, screenData->width * screenData->height * sizeof(Color));
// Update
//---------------------------------------------------------------------------------
if (IsKeyDown(KEY_LEFT)) cam->rotation.y += 0.7f * gameState->time;
if (IsKeyDown(KEY_RIGHT))cam->rotation.y -= 0.7f * gameState->time;
if (IsKeyDown(KEY_UP)) cam->rotation.x -= 100.f * gameState->time;
if (IsKeyDown(KEY_DOWN)) cam->rotation.x += 100.f * gameState->time;
if (IsKeyDown(KEY_SPACE)) cam->position.y += 20.f * gameState->time;
if (IsKeyDown(KEY_LEFT_SHIFT)) cam->position.y -= 20.f * gameState->time;
if (IsKeyDown(KEY_COMMA)) cam->fov += 10.f * gameState->time;
if (IsKeyDown(KEY_PERIOD)) cam->fov -= 10.f * gameState->time;
float forward = IsKeyDown(KEY_W);
float backward = IsKeyDown(KEY_S);
float left = IsKeyDown(KEY_A);
float right = IsKeyDown(KEY_D);
cam->position.x +=
(sinf(cam->rotation.y) * backward - sinf(cam->rotation.y) * forward - cosf(cam->rotation.y) * left + cosf(cam->rotation.y) * right)
* gameState->time * 20.f;
cam->position.z +=
(cosf(cam->rotation.y) * backward - cosf(cam->rotation.y) * forward + sinf(cam->rotation.y) * left - sinf(cam->rotation.y) * right)
* gameState->time * 20.f;
cam->position.x = fmodf(cam->position.x, (float) gameState->map->width);
cam->position.z = fmodf(cam->position.z, (float) gameState->map->height);
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(GetColor(screenData->backgroundColor));
render(gameState);
UpdateTexture(tex, screenData->screen);
DrawTexture(tex, 0, 0, WHITE);
DrawFPS(0, 0);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}