aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--design.org1
-rw-r--r--src/entity.c2
-rw-r--r--src/game.c68
-rw-r--r--src/game.h6
-rw-r--r--src/settings.c2
-rw-r--r--src/settings.h4
-rw-r--r--src/world.c6
-rw-r--r--src/world.h2
8 files changed, 85 insertions, 6 deletions
diff --git a/design.org b/design.org
index 67bce51..7c8d313 100644
--- a/design.org
+++ b/design.org
@@ -153,6 +153,7 @@ generated first than rest of the world will be based around it.
* TODO Check list [0/5]
+ [ ] World generation completed
++ [ ] Menu and UI
+ [ ] Interaction system
+ [ ] All characters added
+ [ ] All items added
diff --git a/src/entity.c b/src/entity.c
index 018b450..919da95 100644
--- a/src/entity.c
+++ b/src/entity.c
@@ -134,7 +134,7 @@ void updateTrashcan(Entity* entity, Game* game)
void updateEntity(Entity* entity, Game* game)
{
- DrawBoundingBox(entity->box, RED);
+ //DrawBoundingBox(entity->box, RED);
switch (entity->id)
{
diff --git a/src/game.c b/src/game.c
index c4563c9..956c5d2 100644
--- a/src/game.c
+++ b/src/game.c
@@ -1,6 +1,37 @@
#include "game.h"
#include "utils.h"
+void resetScreenScale(Game* game)
+{
+ Texture texture = game->screen.render.texture;
+
+ // Get screen size on window.
+ float renderWidth = GetRenderWidth();
+ float renderHeight = GetRenderHeight();
+ float scale;
+
+ if (renderWidth > renderHeight)
+ {
+ scale = (float)renderHeight / texture.height;
+ }
+ else
+ {
+ scale = (float)renderWidth / texture.width;
+ }
+
+ game->screen.scale = scale;
+
+ float width = texture.width * scale;
+ float height = texture.height * scale;
+
+ game->screen.destination = (Rectangle){
+ renderWidth / 2.0 - width / 2.0,
+ renderHeight / 2.0 - height / 2.0,
+ width,
+ height
+ };
+}
+
void initGame(Game* game)
{
game->sceneId = GAME_SCENE;
@@ -8,11 +39,17 @@ void initGame(Game* game)
// Settings.
game->settings = defaultSettings();
+
// Window.
InitWindow(game->settings.windowWidth, game->settings.windowHeight,
"Find Things");
SetWindowState(FLAG_WINDOW_RESIZABLE);
+ // Screen.
+ game->screen.render = LoadRenderTexture(game->settings.screenWidth,
+ game->settings.screenHeight);
+ resetScreenScale(game);
+
// Assets.
initAssets(&game->assets);
@@ -30,7 +67,7 @@ void initGame(Game* game)
game->player = createPlayer();
game->player.position = Vector3Scale(game->world.size, 0.5);
- DisableCursor();
+ // DisableCursor();
}
void updateMainMenuScene(Game* game)
@@ -38,10 +75,25 @@ void updateMainMenuScene(Game* game)
ClearBackground(BLACK);
}
+void drawGameScreen(Game* game)
+{
+ Texture texture = game->screen.render.texture;
+
+ DrawTexturePro(
+ texture,
+ (Rectangle){0.0, 0.0, texture.width, -texture.height},
+ game->screen.destination,
+ (Vector2){0.0, 0.0},
+ 0.0,
+ WHITE);
+}
+
void updateGameScene(Game* game)
{
ClearBackground(BLACK);
+ BeginTextureMode(game->screen.render);
+ ClearBackground(BLACK);
BeginMode3D(game->player.camera);
// Render skybox.
@@ -56,12 +108,25 @@ void updateGameScene(Game* game)
updateWorld(&game->world, game);
EndMode3D();
+ EndTextureMode();
+
+ drawGameScreen(game);
+}
+
+void handleGameResize(Game* game)
+{
+ resetScreenScale(game);
}
void updateGame(Game* game)
{
BeginDrawing();
+ if (IsWindowResized())
+ {
+ handleGameResize(game);
+ }
+
switch (game->sceneId)
{
case MAIN_MENU_SCENE:
@@ -82,6 +147,7 @@ void updateGame(Game* game)
void closeGame(Game* game)
{
closeAssets(&game->assets);
+ UnloadRenderTexture(game->screen.render);
UnloadTexture(game->skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture);
UnloadModel(game->skybox);
freeWorld(game->world);
diff --git a/src/game.h b/src/game.h
index 0990bd2..d75fd4a 100644
--- a/src/game.h
+++ b/src/game.h
@@ -20,6 +20,12 @@ struct Game {
Player player;
World world;
Model skybox;
+
+ struct {
+ RenderTexture render;
+ float scale;
+ Rectangle destination;
+ } screen;
};
void initGame(Game* game);
diff --git a/src/settings.c b/src/settings.c
index ea54fbe..798fa35 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -5,6 +5,8 @@ Settings defaultSettings()
return (Settings){
.windowWidth = 960,
.windowHeight = 720,
+ .screenWidth = 596,
+ .screenHeight = 447,
.mouseSpeed = 0.1,
.forwardKey = KEY_W,
.backwardKey = KEY_S,
diff --git a/src/settings.h b/src/settings.h
index da67539..9bab9aa 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -8,6 +8,10 @@ typedef struct {
int windowWidth;
int windowHeight;
+ // Screen (render texture for pixellyness).
+ int screenWidth;
+ int screenHeight;
+
// Controls.
float mouseSpeed;
KeyboardKey forwardKey;
diff --git a/src/world.c b/src/world.c
index 6901afe..42e3488 100644
--- a/src/world.c
+++ b/src/world.c
@@ -720,9 +720,9 @@ Seed generateWorldCharacters(World* world, Seed seed, WorldUID start)
{
WorldUID index = start;
- /* Entity ron = createEntity(RON, Vector3Scale(world->size, 0.5)); */
- /* placeEntityOnGround(&ron, world); */
- /* world->entities[index] = ron; */
+ Entity ron = createEntity(RON, Vector3Scale(world->size, 0.5));
+ placeEntityOnGround(&ron, world);
+ world->entities[index] = ron;
return seed;
}
diff --git a/src/world.h b/src/world.h
index 456d68a..93bcb38 100644
--- a/src/world.h
+++ b/src/world.h
@@ -32,7 +32,7 @@
#define PLACE_POND_WALKING_AREA 7
// Characters.
-#define WORLD_CHARACTER_COUNT 0
+#define WORLD_CHARACTER_COUNT 1
#define SAMANTHA_OFFSET (Vector3){0.0, 0.0, 2.0}
#define SAMANTHAS_SPOT_TRASHCAN_COUNT 5