Day 31 complete.

This commit is contained in:
igor
2026-04-10 02:06:25 -07:00
parent a2985c20ef
commit 1635bebb5d
3 changed files with 33 additions and 30 deletions
+23 -21
View File
@@ -149,16 +149,16 @@ static cannonical_position GetCannonicalPosition(world *World,
X = Pos.X - World->UpperLeftX; X = Pos.X - World->UpperLeftX;
Y = Pos.Y - World->UpperLeftY; Y = Pos.Y - World->UpperLeftY;
Result.TileX = FloorF32toS32(X / World->TileWidth); Result.TileX = FloorF32toS32(X / (F32)World->TileSideInPixels);
Result.TileY = FloorF32toS32(Y / World->TileHeight); Result.TileY = FloorF32toS32(Y / (F32)World->TileSideInPixels);
Result.X = X - Result.TileX*World->TileWidth; Result.X = X - (F32)Result.TileX*(F32)World->TileSideInPixels;
Result.Y = Y - Result.TileY*World->TileHeight; Result.Y = Y - (F32)Result.TileY*(F32)World->TileSideInPixels;
ASSERT(Result.X >= 0); ASSERT(Result.X >= 0);
ASSERT(Result.Y >= 0); ASSERT(Result.Y >= 0);
ASSERT(Result.X < World->TileWidth); ASSERT(Result.X < (F32)World->TileSideInPixels);
ASSERT(Result.Y < World->TileHeight); ASSERT(Result.Y < (F32)World->TileSideInPixels);
if(Result.TileX < 0) { if(Result.TileX < 0) {
Result.TileX = World->CountX + Result.TileX; Result.TileX = World->CountX + Result.TileX;
@@ -271,14 +271,14 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory,
World.TileMapCountY = 2; World.TileMapCountY = 2;
World.CountX = TILEMAP_COUNT_X; World.CountX = TILEMAP_COUNT_X;
World.CountY = TILEMAP_COUNT_Y; World.CountY = TILEMAP_COUNT_Y;
World.UpperLeftX = 0.0f; World.TileSideInMeters = 1.4f;
World.TileSideInPixels = 60;
World.UpperLeftX = -((F32)World.TileSideInPixels / 2.0f);
World.UpperLeftY = 0.0f; World.UpperLeftY = 0.0f;
World.TileWidth = 57.0f;
World.TileHeight = 57.0f;
World.TileMaps = (tile_map *)TileMaps; World.TileMaps = (tile_map *)TileMaps;
PlayerWidth = 0.75f * World.TileWidth; PlayerWidth = 0.75f * (F32)World.TileSideInPixels;
PlayerHeight = World.TileHeight; PlayerHeight = (F32)World.TileSideInPixels;
GameState = (game_state *)Memory->PermanentStorage; GameState = (game_state *)Memory->PermanentStorage;
if(!Memory->IsInitialized) { if(!Memory->IsInitialized) {
@@ -323,10 +323,8 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory,
dPlayerX *= 200.0f; dPlayerX *= 200.0f;
dPlayerY *= 200.0f; dPlayerY *= 200.0f;
NewPlayerX = RoundF32toS32(GameState->PlayerX + NewPlayerX = GameState->PlayerX + Input->dtForFrame*dPlayerX;
Input->dtForFrame*dPlayerX); NewPlayerY = GameState->PlayerY + Input->dtForFrame*dPlayerY;
NewPlayerY = RoundF32toS32(GameState->PlayerY +
Input->dtForFrame*dPlayerY);
PlayerPos.TileMapX = GameState->PlayerTileMapX; PlayerPos.TileMapX = GameState->PlayerTileMapX;
PlayerPos.TileMapY = GameState->PlayerTileMapY; PlayerPos.TileMapY = GameState->PlayerTileMapY;
@@ -349,9 +347,11 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory,
GameState->PlayerTileMapX = CanPos.TileMapX; GameState->PlayerTileMapX = CanPos.TileMapX;
GameState->PlayerTileMapY = CanPos.TileMapY; GameState->PlayerTileMapY = CanPos.TileMapY;
GameState->PlayerX = World.UpperLeftX + GameState->PlayerX = World.UpperLeftX +
World.TileWidth*CanPos.TileX + CanPos.X; (F32)World.TileSideInPixels * (F32)CanPos.TileX +
CanPos.X;
GameState->PlayerY = World.UpperLeftY + GameState->PlayerY = World.UpperLeftY +
World.TileHeight*CanPos.TileY + CanPos.Y; (F32)World.TileSideInPixels * (F32)CanPos.TileY +
CanPos.Y;
} }
} }
} }
@@ -368,10 +368,12 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory,
if(TileID) { if(TileID) {
Gray = 1.0f; Gray = 1.0f;
} }
MinX = World.UpperLeftX + (F32)(Column) * World.TileWidth; MinX = World.UpperLeftX +
MinY = World.UpperLeftY + (F32)(Row) * World.TileHeight; (F32)(Column) * (F32)World.TileSideInPixels;
MaxX = MinX + World.TileWidth; MinY =
MaxY = MinY + World.TileHeight; World.UpperLeftY + (F32)(Row) * (F32)World.TileSideInPixels;
MaxX = MinX + (F32)World.TileSideInPixels;
MaxY = MinY + (F32)World.TileSideInPixels;
DrawRectangle(Buffer, MinX, MinY, MaxX, MaxY, Gray, Gray, Gray); DrawRectangle(Buffer, MinX, MinY, MaxX, MaxY, Gray, Gray, Gray);
} }
} }
+3 -2
View File
@@ -162,13 +162,14 @@ typedef struct tile_map {
} tile_map; } tile_map;
typedef struct world { typedef struct world {
F32 TileSideInMeters;
S32 TileSideInPixels;
S32 CountX; S32 CountX;
S32 CountY; S32 CountY;
F32 UpperLeftX; F32 UpperLeftX;
F32 UpperLeftY; F32 UpperLeftY;
F32 TileWidth;
F32 TileHeight;
S32 TileMapCountX; S32 TileMapCountX;
S32 TileMapCountY; S32 TileMapCountY;
+6 -6
View File
@@ -545,12 +545,12 @@ static F32 SDLProcessInputStickValue(F32 Value, S32 DeadZoneThreshold)
F32 Result; F32 Result;
Result = 0.0f; Result = 0.0f;
if(Value < -DeadZoneThreshold) if(Value < -(F32)DeadZoneThreshold)
Result = (F32)((Value + DeadZoneThreshold) / Result = ((Value + (F32)DeadZoneThreshold) /
(32768.0f - DeadZoneThreshold)); (32768.0f - (F32)DeadZoneThreshold));
else if(Value > DeadZoneThreshold) else if(Value > (F32)DeadZoneThreshold)
Result = (F32)((Value + DeadZoneThreshold) / Result = ((Value + (F32)DeadZoneThreshold) /
(32767.0f - DeadZoneThreshold)); (32767.0f - (F32)DeadZoneThreshold));
return Result; return Result;
} }