Day 31 complete.
This commit is contained in:
+23
-21
@@ -149,16 +149,16 @@ static cannonical_position GetCannonicalPosition(world *World,
|
||||
|
||||
X = Pos.X - World->UpperLeftX;
|
||||
Y = Pos.Y - World->UpperLeftY;
|
||||
Result.TileX = FloorF32toS32(X / World->TileWidth);
|
||||
Result.TileY = FloorF32toS32(Y / World->TileHeight);
|
||||
Result.TileX = FloorF32toS32(X / (F32)World->TileSideInPixels);
|
||||
Result.TileY = FloorF32toS32(Y / (F32)World->TileSideInPixels);
|
||||
|
||||
Result.X = X - Result.TileX*World->TileWidth;
|
||||
Result.Y = Y - Result.TileY*World->TileHeight;
|
||||
Result.X = X - (F32)Result.TileX*(F32)World->TileSideInPixels;
|
||||
Result.Y = Y - (F32)Result.TileY*(F32)World->TileSideInPixels;
|
||||
|
||||
ASSERT(Result.X >= 0);
|
||||
ASSERT(Result.Y >= 0);
|
||||
ASSERT(Result.X < World->TileWidth);
|
||||
ASSERT(Result.Y < World->TileHeight);
|
||||
ASSERT(Result.X < (F32)World->TileSideInPixels);
|
||||
ASSERT(Result.Y < (F32)World->TileSideInPixels);
|
||||
|
||||
if(Result.TileX < 0) {
|
||||
Result.TileX = World->CountX + Result.TileX;
|
||||
@@ -271,14 +271,14 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory,
|
||||
World.TileMapCountY = 2;
|
||||
World.CountX = TILEMAP_COUNT_X;
|
||||
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.TileWidth = 57.0f;
|
||||
World.TileHeight = 57.0f;
|
||||
World.TileMaps = (tile_map *)TileMaps;
|
||||
|
||||
PlayerWidth = 0.75f * World.TileWidth;
|
||||
PlayerHeight = World.TileHeight;
|
||||
PlayerWidth = 0.75f * (F32)World.TileSideInPixels;
|
||||
PlayerHeight = (F32)World.TileSideInPixels;
|
||||
|
||||
GameState = (game_state *)Memory->PermanentStorage;
|
||||
if(!Memory->IsInitialized) {
|
||||
@@ -323,10 +323,8 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory,
|
||||
dPlayerX *= 200.0f;
|
||||
dPlayerY *= 200.0f;
|
||||
|
||||
NewPlayerX = RoundF32toS32(GameState->PlayerX +
|
||||
Input->dtForFrame*dPlayerX);
|
||||
NewPlayerY = RoundF32toS32(GameState->PlayerY +
|
||||
Input->dtForFrame*dPlayerY);
|
||||
NewPlayerX = GameState->PlayerX + Input->dtForFrame*dPlayerX;
|
||||
NewPlayerY = GameState->PlayerY + Input->dtForFrame*dPlayerY;
|
||||
|
||||
PlayerPos.TileMapX = GameState->PlayerTileMapX;
|
||||
PlayerPos.TileMapY = GameState->PlayerTileMapY;
|
||||
@@ -349,9 +347,11 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory,
|
||||
GameState->PlayerTileMapX = CanPos.TileMapX;
|
||||
GameState->PlayerTileMapY = CanPos.TileMapY;
|
||||
GameState->PlayerX = World.UpperLeftX +
|
||||
World.TileWidth*CanPos.TileX + CanPos.X;
|
||||
(F32)World.TileSideInPixels * (F32)CanPos.TileX +
|
||||
CanPos.X;
|
||||
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) {
|
||||
Gray = 1.0f;
|
||||
}
|
||||
MinX = World.UpperLeftX + (F32)(Column) * World.TileWidth;
|
||||
MinY = World.UpperLeftY + (F32)(Row) * World.TileHeight;
|
||||
MaxX = MinX + World.TileWidth;
|
||||
MaxY = MinY + World.TileHeight;
|
||||
MinX = World.UpperLeftX +
|
||||
(F32)(Column) * (F32)World.TileSideInPixels;
|
||||
MinY =
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -162,13 +162,14 @@ typedef struct tile_map {
|
||||
} tile_map;
|
||||
|
||||
typedef struct world {
|
||||
F32 TileSideInMeters;
|
||||
S32 TileSideInPixels;
|
||||
|
||||
S32 CountX;
|
||||
S32 CountY;
|
||||
|
||||
F32 UpperLeftX;
|
||||
F32 UpperLeftY;
|
||||
F32 TileWidth;
|
||||
F32 TileHeight;
|
||||
|
||||
S32 TileMapCountX;
|
||||
S32 TileMapCountY;
|
||||
|
||||
+6
-6
@@ -545,12 +545,12 @@ static F32 SDLProcessInputStickValue(F32 Value, S32 DeadZoneThreshold)
|
||||
F32 Result;
|
||||
|
||||
Result = 0.0f;
|
||||
if(Value < -DeadZoneThreshold)
|
||||
Result = (F32)((Value + DeadZoneThreshold) /
|
||||
(32768.0f - DeadZoneThreshold));
|
||||
else if(Value > DeadZoneThreshold)
|
||||
Result = (F32)((Value + DeadZoneThreshold) /
|
||||
(32767.0f - DeadZoneThreshold));
|
||||
if(Value < -(F32)DeadZoneThreshold)
|
||||
Result = ((Value + (F32)DeadZoneThreshold) /
|
||||
(32768.0f - (F32)DeadZoneThreshold));
|
||||
else if(Value > (F32)DeadZoneThreshold)
|
||||
Result = ((Value + (F32)DeadZoneThreshold) /
|
||||
(32767.0f - (F32)DeadZoneThreshold));
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user