aboutsummaryrefslogtreecommitdiffstats
path: root/src/game.c
blob: 35b4c9ac5d5483af1ce4d66fcc9be3af1d8bee56 (plain) (blame)
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
#include "game.h"
#include "utils.h"

void initGame(Game* game)
{
  game->sceneId = GAME_SCENE;
  
  // Settings.
  game->settings = defaultSettings();

  // Window.
  InitWindow(game->settings.windowWidth, game->settings.windowHeight,
             "Find Things");
  SetWindowState(FLAG_WINDOW_RESIZABLE);

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

  // Player.
  game->player = createPlayer();
  game->player.position = (Vector3){50.0, 30.0, 50.0};

  // Heightmap.
  Mesh heightmapMesh = GenMeshHeightmap(game->assets.images[HEIGHT_MAP_IMAGE],
                                        (Vector3){1000.0, 30.0, 1000.0});
  game->heightmap = LoadModelFromMesh(heightmapMesh);
  game->heightmap.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture =
    game->assets.textures[HEIGHT_MAP_TEXTURE];

  game->heightmapColors = LoadImageColors(
    game->assets.images[HEIGHT_MAP_IMAGE]);

  DisableCursor();
}

void updateMainMenuScene(Game* game)
{
  ClearBackground(BLACK);
}

void updateGameScene(Game* game)
{
  ClearBackground(BLACK);

  BeginMode3D(game->player.camera);

  updatePlayer(&game->player, game);

  DrawModel(game->heightmap, Vector3Zero(), 1.0, WHITE);

  EndMode3D();
}

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

  switch (game->sceneId)
  {
  case MAIN_MENU_SCENE:
    updateMainMenuScene(game);
    break;
  case GAME_SCENE:
    updateGameScene(game);
    break;
  default:
    break;
  }

  DrawFPS(0, 0);
  
  EndDrawing();
}

void closeGame(Game* game)
{
  closeAssets(&game->assets);
  UnloadModel(game->heightmap);
  UnloadImageColors(game->heightmapColors);
  CloseWindow();
}