|
@@ -1,5 +1,5 @@ |
|
|
#include "handmade.h" |
|
|
#include "handmade.h" |
|
|
#include "handmade_intrinsics.h" |
|
|
|
|
|
|
|
|
#include "handmade_tile.cpp" |
|
|
|
|
|
|
|
|
internal void drawRectangle(GameOffscreenBuffer *buffer, real32 realMinX, real32 realMinY, real32 realMaxX, real32 realMaxY, real32 R, real32 G, real32 B) { |
|
|
internal void drawRectangle(GameOffscreenBuffer *buffer, real32 realMinX, real32 realMinY, real32 realMaxX, real32 realMaxY, real32 R, real32 G, real32 B) { |
|
|
int32 minX = roundReal32ToInt32(realMinX); |
|
|
int32 minX = roundReal32ToInt32(realMinX); |
|
@@ -48,163 +48,115 @@ internal void outputSound(GameSoundOutputBuffer *soundBuffer, GameState *state) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
inline uint32 getTileValueUnchecked(World *world, TileMap *tileMap, int32 testTileX, int32 testTileY) { |
|
|
|
|
|
Assert(tileMap); |
|
|
|
|
|
Assert( |
|
|
|
|
|
(testTileX >= 0) && (testTileX < world->tileCountX) && |
|
|
|
|
|
(testTileY >= 0) && (testTileY < world->tileCountY) |
|
|
|
|
|
); |
|
|
|
|
|
return tileMap->tiles[testTileY * world->tileCountX + testTileX]; |
|
|
|
|
|
|
|
|
internal void initialiseArena(MemoryArena *arena, memory_index size, uint8 *base) { |
|
|
|
|
|
arena->size = size; |
|
|
|
|
|
arena->base = base; |
|
|
|
|
|
arena->used = 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
inline TileMap *getTileMap(World *world, int32 tileMapX, int32 tileMapY) { |
|
|
|
|
|
TileMap *tileMap = NULL; |
|
|
|
|
|
|
|
|
|
|
|
if ((tileMapX >= 0) && (tileMapX < world->tileMapCountX) && |
|
|
|
|
|
(tileMapY >= 0) && (tileMapY < world->tileMapCountY) |
|
|
|
|
|
) { |
|
|
|
|
|
tileMap = &world->tileMaps[tileMapY * world->tileMapCountX + tileMapX]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return tileMap; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
inline void recanonicaliseOrd(World *world, int32 tileCount, int32 *tileMapOrd, int32 *tileOrd, real32* ord) { |
|
|
|
|
|
int32 offset = floorReal32ToInt32(*ord / world->tileSideInPixels); |
|
|
|
|
|
*tileOrd += offset; |
|
|
|
|
|
*ord -= offset*world->tileSideInPixels; |
|
|
|
|
|
|
|
|
|
|
|
Assert(*ord >= 0); |
|
|
|
|
|
Assert(*ord < world->tileSideInPixels); |
|
|
|
|
|
|
|
|
|
|
|
if (*tileOrd < 0) { |
|
|
|
|
|
*tileOrd += tileCount; |
|
|
|
|
|
*tileMapOrd -= 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (*tileOrd >= tileCount) { |
|
|
|
|
|
*tileOrd -= tileCount; |
|
|
|
|
|
*tileMapOrd += 1; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
inline CanonicalPosition recanonicalisePosition(World* world, CanonicalPosition pos) { |
|
|
|
|
|
CanonicalPosition result = pos; |
|
|
|
|
|
|
|
|
|
|
|
recanonicaliseOrd(world, world->tileCountX, &result.tileMapX, &result.tileX, &result.x); |
|
|
|
|
|
recanonicaliseOrd(world, world->tileCountY, &result.tileMapY, &result.tileY, &result.y); |
|
|
|
|
|
// TODO: continue at HH day 32 @ 32:20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal void *_pushSize(MemoryArena *arena, memory_index size) { |
|
|
|
|
|
Assert((arena->used + size) <= arena->size); |
|
|
|
|
|
void *result = (void *)(arena->base + arena->used); |
|
|
|
|
|
arena->used += size; |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
internal bool32 isWorldPointEmpty(World *world, CanonicalPosition testPos) { |
|
|
|
|
|
bool32 isEmpty = false; |
|
|
|
|
|
|
|
|
|
|
|
TileMap *tileMap = getTileMap(world, testPos.tileMapX, testPos.tileMapY); |
|
|
|
|
|
isEmpty = (getTileValueUnchecked(world, tileMap, testPos.tileX, testPos.tileY) == 0); |
|
|
|
|
|
|
|
|
|
|
|
return isEmpty; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
#define pushStruct(arena, type) (type *)_pushSize(arena, sizeof(type)) |
|
|
|
|
|
#define pushArray(arena, count, type) (type *)_pushSize(arena, (count)*sizeof(type)) |
|
|
|
|
|
|
|
|
extern "C" GAME_UPDATE_AND_RENDER(gameUpdateAndRender) { |
|
|
extern "C" GAME_UPDATE_AND_RENDER(gameUpdateAndRender) { |
|
|
Assert(sizeof(GameState) <= memory->permanentStorageSize); |
|
|
Assert(sizeof(GameState) <= memory->permanentStorageSize); |
|
|
|
|
|
|
|
|
GameState *state = (GameState*)memory->permanentStorage; |
|
|
GameState *state = (GameState*)memory->permanentStorage; |
|
|
|
|
|
|
|
|
|
|
|
const int WORLD_WIDTH = 2; |
|
|
|
|
|
const int WORLD_HEIGHT = 2; |
|
|
|
|
|
|
|
|
if (!memory->isInitialised) { |
|
|
if (!memory->isInitialised) { |
|
|
state->playerPos.x = 150.0f; |
|
|
|
|
|
state->playerPos.y = 150.0f; |
|
|
|
|
|
state->playerPos.tileMapX = 0; |
|
|
|
|
|
state->playerPos.tileMapY = 0; |
|
|
|
|
|
|
|
|
state->playerPos.absTileX = 3; |
|
|
|
|
|
state->playerPos.absTileY = 3; |
|
|
|
|
|
state->playerPos.x = 5.0f; |
|
|
|
|
|
state->playerPos.y = 5.0f; |
|
|
|
|
|
|
|
|
|
|
|
initialiseArena( |
|
|
|
|
|
&state->worldArena, |
|
|
|
|
|
memory->permanentStorageSize - sizeof(GameState), |
|
|
|
|
|
(uint8*)memory->permanentStorage + sizeof(GameState) |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
state->world = pushStruct(&state->worldArena, World); |
|
|
|
|
|
World *world = state->world; |
|
|
|
|
|
|
|
|
|
|
|
world->tileMap = pushStruct(&state->worldArena, TileMap); |
|
|
|
|
|
TileMap *tileMap = state->world->tileMap; |
|
|
|
|
|
|
|
|
|
|
|
tileMap->chunkShift = 8; |
|
|
|
|
|
tileMap->chunkMask = 0xFF; |
|
|
|
|
|
tileMap->chunkDim = 256; |
|
|
|
|
|
tileMap->tileChunkCountX = 4; |
|
|
|
|
|
tileMap->tileChunkCountY = 4; |
|
|
|
|
|
tileMap->tileSideInMeters = 1.4f; |
|
|
|
|
|
tileMap->tileSideInPixels = 60; |
|
|
|
|
|
tileMap->metersToPixels = tileMap->tileSideInPixels / tileMap->tileSideInMeters; |
|
|
|
|
|
|
|
|
|
|
|
tileMap->tileChunks = pushArray(&state->worldArena, tileMap->tileChunkCountX*tileMap->tileChunkCountY, TileChunk); |
|
|
|
|
|
|
|
|
|
|
|
for (uint32 y = 0; y < tileMap->tileChunkCountY; y++) { |
|
|
|
|
|
for (uint32 x = 0; x < tileMap->tileChunkCountX; x++) { |
|
|
|
|
|
tileMap->tileChunks[y*tileMap->tileChunkCountX + x].tiles = pushArray(&state->worldArena, tileMap->chunkDim*tileMap->chunkDim, uint32); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
memory->isInitialised = true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const int TILEMAP_WIDTH = 16; |
|
|
|
|
|
const int TILEMAP_HEIGHT = 9; |
|
|
|
|
|
|
|
|
uint32 tilesPerWidth = 17; |
|
|
|
|
|
uint32 tilesPerHeight = 9; |
|
|
|
|
|
|
|
|
const int WORLD_WIDTH = 2; |
|
|
|
|
|
const int WORLD_HEIGHT = 2; |
|
|
|
|
|
|
|
|
for (uint32 screenY = 0; screenY < 32; screenY++) { |
|
|
|
|
|
for (uint32 screenX = 0; screenX < 32; screenX++) { |
|
|
|
|
|
for (uint32 tileY = 0; tileY < tilesPerHeight; tileY++) { |
|
|
|
|
|
for (uint32 tileX = 0; tileX < tilesPerWidth; tileX++) { |
|
|
|
|
|
uint32 absTileX = screenX*tilesPerWidth + tileX; |
|
|
|
|
|
uint32 absTileY = screenY*tilesPerHeight + tileY; |
|
|
|
|
|
setTileMapValue(&state->worldArena, tileMap, absTileX, absTileY, (tileX == tileY && (tileX % 5 == 0))); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
memory->isInitialised = true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
uint32 tiles00[TILEMAP_HEIGHT][TILEMAP_WIDTH] = { |
|
|
|
|
|
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, |
|
|
|
|
|
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, |
|
|
|
|
|
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, |
|
|
|
|
|
{1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, |
|
|
|
|
|
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, |
|
|
|
|
|
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, |
|
|
|
|
|
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, |
|
|
|
|
|
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, |
|
|
|
|
|
{1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1}, |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
uint32 tiles01[TILEMAP_HEIGHT][TILEMAP_WIDTH] = { |
|
|
|
|
|
{1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1}, |
|
|
|
|
|
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1}, |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
uint32 tiles11[TILEMAP_HEIGHT][TILEMAP_WIDTH] = { |
|
|
|
|
|
{1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1}, |
|
|
|
|
|
{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1}, |
|
|
|
|
|
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1}, |
|
|
|
|
|
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, |
|
|
|
|
|
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1}, |
|
|
|
|
|
{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1}, |
|
|
|
|
|
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1}, |
|
|
|
|
|
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1}, |
|
|
|
|
|
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
World world = {}; |
|
|
|
|
|
world.tileCountX = TILEMAP_WIDTH; |
|
|
|
|
|
world.tileCountY = TILEMAP_HEIGHT; |
|
|
|
|
|
world.tileMapCountX = WORLD_WIDTH; |
|
|
|
|
|
world.tileMapCountY = WORLD_HEIGHT; |
|
|
|
|
|
world.upperLeftX = 0; |
|
|
|
|
|
world.upperLeftY = 0; |
|
|
|
|
|
world.tileSideInMeters = 1.4f; |
|
|
|
|
|
world.tileSideInPixels = 60; |
|
|
|
|
|
|
|
|
|
|
|
TileMap maps[WORLD_HEIGHT][WORLD_WIDTH]; |
|
|
|
|
|
maps[0][0].tiles = (uint32*)tiles00; |
|
|
|
|
|
|
|
|
|
|
|
maps[1][0] = maps[0][0]; |
|
|
|
|
|
maps[1][0].tiles = (uint32*)tiles01; |
|
|
|
|
|
|
|
|
|
|
|
maps[0][1] = maps[0][0]; |
|
|
|
|
|
maps[0][1].tiles = (uint32*)tiles10; |
|
|
|
|
|
|
|
|
|
|
|
maps[1][1] = maps[0][0]; |
|
|
|
|
|
maps[1][1].tiles = (uint32*)tiles11; |
|
|
|
|
|
|
|
|
|
|
|
world.tileMaps = (TileMap*)maps; |
|
|
|
|
|
|
|
|
real32 screenCenterX = 0.5f*(real32)videoBuf->width; |
|
|
|
|
|
real32 screenCenterY = 0.5f*(real32)videoBuf->height; |
|
|
|
|
|
|
|
|
|
|
|
// uint32 tiles[TILEMAP_WIDTH][TILEMAP_HEIGHT] = { |
|
|
|
|
|
// {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, |
|
|
|
|
|
// {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1}, |
|
|
|
|
|
// {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1}, |
|
|
|
|
|
// {1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, |
|
|
|
|
|
// {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1}, |
|
|
|
|
|
// {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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0, 0, 0, 1, 0, 1}, |
|
|
|
|
|
// {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1}, |
|
|
|
|
|
// {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1}, |
|
|
|
|
|
// {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, |
|
|
|
|
|
// }; |
|
|
|
|
|
|
|
|
|
|
|
TileMap *tilemap = state->world->tileMap; |
|
|
|
|
|
|
|
|
// player |
|
|
// player |
|
|
real32 playerR = 1.0f; |
|
|
real32 playerR = 1.0f; |
|
|
real32 playerG = 1.0f; |
|
|
real32 playerG = 1.0f; |
|
|
real32 playerB = 0.5f; |
|
|
real32 playerB = 0.5f; |
|
|
real32 playerWidth = 50.0f; |
|
|
|
|
|
real32 playerHeight = 70.0f; |
|
|
|
|
|
|
|
|
real32 playerWidth = 0.7f; |
|
|
|
|
|
real32 playerHeight = 1.4f; |
|
|
|
|
|
|
|
|
for (int controllerIndex = 0; controllerIndex < ArrayCount(input->controllers); controllerIndex++) { |
|
|
for (int controllerIndex = 0; controllerIndex < ArrayCount(input->controllers); controllerIndex++) { |
|
|
GameControllerInput *controller = &input->controllers[controllerIndex]; |
|
|
GameControllerInput *controller = &input->controllers[controllerIndex]; |
|
@@ -213,10 +165,10 @@ extern "C" GAME_UPDATE_AND_RENDER(gameUpdateAndRender) { |
|
|
real32 dPlayerY = 0.0f; |
|
|
real32 dPlayerY = 0.0f; |
|
|
|
|
|
|
|
|
if (controller->stickUp.endedDown) { |
|
|
if (controller->stickUp.endedDown) { |
|
|
dPlayerY = -1.0f; |
|
|
|
|
|
|
|
|
dPlayerY = 1.0f; |
|
|
} |
|
|
} |
|
|
if (controller->stickDown.endedDown) { |
|
|
if (controller->stickDown.endedDown) { |
|
|
dPlayerY = 1.0f; |
|
|
|
|
|
|
|
|
dPlayerY = -1.0f; |
|
|
} |
|
|
} |
|
|
if (controller->stickLeft.endedDown) { |
|
|
if (controller->stickLeft.endedDown) { |
|
|
dPlayerX = -1.0f; |
|
|
dPlayerX = -1.0f; |
|
@@ -225,37 +177,37 @@ extern "C" GAME_UPDATE_AND_RENDER(gameUpdateAndRender) { |
|
|
dPlayerX = 1.0f; |
|
|
dPlayerX = 1.0f; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
dPlayerX *= 96.0f; |
|
|
|
|
|
dPlayerY *= 96.0f; |
|
|
|
|
|
|
|
|
dPlayerX *= 6.0f; |
|
|
|
|
|
dPlayerY *= 6.0f; |
|
|
|
|
|
|
|
|
CanonicalPosition newPlayerPos = state->playerPos; |
|
|
|
|
|
|
|
|
TileMapPosition newPlayerPos = state->playerPos; |
|
|
newPlayerPos.x += dPlayerX * input->dtForFrame; |
|
|
newPlayerPos.x += dPlayerX * input->dtForFrame; |
|
|
newPlayerPos.y += dPlayerY * input->dtForFrame; |
|
|
newPlayerPos.y += dPlayerY * input->dtForFrame; |
|
|
newPlayerPos = recanonicalisePosition(&world, newPlayerPos); |
|
|
|
|
|
|
|
|
newPlayerPos = recanonicalisePosition(tilemap, newPlayerPos); |
|
|
|
|
|
|
|
|
CanonicalPosition playerBottomLeft = newPlayerPos; |
|
|
|
|
|
|
|
|
TileMapPosition playerBottomLeft = newPlayerPos; |
|
|
playerBottomLeft.x -= 0.5f * playerWidth; |
|
|
playerBottomLeft.x -= 0.5f * playerWidth; |
|
|
playerBottomLeft = recanonicalisePosition(&world, playerBottomLeft); |
|
|
|
|
|
|
|
|
playerBottomLeft = recanonicalisePosition(tilemap, playerBottomLeft); |
|
|
|
|
|
|
|
|
CanonicalPosition playerTopLeft = newPlayerPos; |
|
|
|
|
|
|
|
|
TileMapPosition playerTopLeft = newPlayerPos; |
|
|
playerTopLeft.x -= 0.5f * playerWidth; |
|
|
playerTopLeft.x -= 0.5f * playerWidth; |
|
|
playerTopLeft.y -= playerWidth; |
|
|
|
|
|
playerTopLeft = recanonicalisePosition(&world, playerTopLeft); |
|
|
|
|
|
|
|
|
playerTopLeft.y += playerWidth; |
|
|
|
|
|
playerTopLeft = recanonicalisePosition(tilemap, playerTopLeft); |
|
|
|
|
|
|
|
|
CanonicalPosition playerBottomRight = newPlayerPos; |
|
|
|
|
|
|
|
|
TileMapPosition playerBottomRight = newPlayerPos; |
|
|
playerBottomRight.x += 0.5f * playerWidth; |
|
|
playerBottomRight.x += 0.5f * playerWidth; |
|
|
playerBottomRight = recanonicalisePosition(&world, playerBottomRight); |
|
|
|
|
|
|
|
|
playerBottomRight = recanonicalisePosition(tilemap, playerBottomRight); |
|
|
|
|
|
|
|
|
CanonicalPosition playerTopRight = newPlayerPos; |
|
|
|
|
|
|
|
|
TileMapPosition playerTopRight = newPlayerPos; |
|
|
playerTopRight.x += 0.5f * playerWidth; |
|
|
playerTopRight.x += 0.5f * playerWidth; |
|
|
playerTopRight.y -= playerWidth; |
|
|
|
|
|
playerTopRight = recanonicalisePosition(&world, playerTopRight); |
|
|
|
|
|
|
|
|
playerTopRight.y += playerWidth; |
|
|
|
|
|
playerTopRight = recanonicalisePosition(tilemap, playerTopRight); |
|
|
|
|
|
|
|
|
if ( |
|
|
if ( |
|
|
isWorldPointEmpty(&world, playerTopLeft) && |
|
|
|
|
|
isWorldPointEmpty(&world, playerTopRight) && |
|
|
|
|
|
isWorldPointEmpty(&world, playerBottomLeft) && |
|
|
|
|
|
isWorldPointEmpty(&world, playerBottomRight) |
|
|
|
|
|
|
|
|
isTileMapPointEmpty(tilemap, playerTopLeft) && |
|
|
|
|
|
isTileMapPointEmpty(tilemap, playerTopRight) && |
|
|
|
|
|
isTileMapPointEmpty(tilemap, playerBottomLeft) && |
|
|
|
|
|
isTileMapPointEmpty(tilemap, playerBottomRight) |
|
|
) { |
|
|
) { |
|
|
state->playerPos = newPlayerPos; |
|
|
state->playerPos = newPlayerPos; |
|
|
} |
|
|
} |
|
@@ -264,23 +216,29 @@ extern "C" GAME_UPDATE_AND_RENDER(gameUpdateAndRender) { |
|
|
// clearscreen |
|
|
// clearscreen |
|
|
drawRectangle(videoBuf, 0.0f, 0.0f, (real32)videoBuf->width, (real32)videoBuf->height, 1.0f, 0.0f, 1.0f); |
|
|
drawRectangle(videoBuf, 0.0f, 0.0f, (real32)videoBuf->width, (real32)videoBuf->height, 1.0f, 0.0f, 1.0f); |
|
|
|
|
|
|
|
|
TileMap *currMap = getTileMap(&world, state->playerPos.tileMapX, state->playerPos.tileMapY); |
|
|
|
|
|
for (int row = 0; row < world.tileCountY; row++) { |
|
|
|
|
|
for (int col = 0; col < world.tileCountX; col++) { |
|
|
|
|
|
real32 fill = getTileValueUnchecked(&world, currMap, col, row) == 1 ? 1.0f : 0.5f; |
|
|
|
|
|
real32 minX = world.upperLeftX + ((real32)col)*world.tileSideInPixels; |
|
|
|
|
|
real32 minY = world.upperLeftY + ((real32)row)*world.tileSideInPixels; |
|
|
|
|
|
real32 maxX = minX + world.tileSideInPixels; |
|
|
|
|
|
real32 maxY = minY + world.tileSideInPixels; |
|
|
|
|
|
drawRectangle(videoBuf, minX, minY, maxX, maxY, fill, fill, fill); |
|
|
|
|
|
|
|
|
for (int32 relRow = -10; relRow < 10; relRow++) { |
|
|
|
|
|
for (int32 relCol = -20; relCol < 20; relCol++) { |
|
|
|
|
|
uint32 col = state->playerPos.absTileX + relCol; |
|
|
|
|
|
uint32 row = state->playerPos.absTileY + relRow; |
|
|
|
|
|
int32 tileId = getTileValue(tilemap, col, row); |
|
|
|
|
|
real32 fill = 0.5f; |
|
|
|
|
|
if (tileId == 1) { |
|
|
|
|
|
fill = 1.0f; |
|
|
|
|
|
} |
|
|
|
|
|
if ((row == state->playerPos.absTileY) && (col == state->playerPos.absTileX)) { |
|
|
|
|
|
fill = 0.0f; |
|
|
|
|
|
} |
|
|
|
|
|
real32 minX = screenCenterX - tilemap->metersToPixels*state->playerPos.x + ((real32)relCol)*tilemap->tileSideInPixels; |
|
|
|
|
|
real32 minY = screenCenterY + tilemap->metersToPixels*state->playerPos.y - ((real32)relRow)*tilemap->tileSideInPixels; |
|
|
|
|
|
real32 maxX = minX + tilemap->tileSideInPixels; |
|
|
|
|
|
real32 maxY = minY - tilemap->tileSideInPixels; |
|
|
|
|
|
drawRectangle(videoBuf, minX, maxY, maxX, minY, fill, fill, fill); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
real32 playerX = world.upperLeftX + state->playerPos.x + state->playerPos.tileX * world.tileSideInPixels; |
|
|
|
|
|
real32 playerY = world.upperLeftY + state->playerPos.y + state->playerPos.tileY * world.tileSideInPixels; |
|
|
|
|
|
real32 playerLeft = playerX - 0.5f * playerWidth; |
|
|
|
|
|
real32 playerTop = playerY - playerHeight; |
|
|
|
|
|
drawRectangle(videoBuf, playerLeft, playerTop, playerX + playerWidth*0.5f, playerY, playerR, playerG, playerB); |
|
|
|
|
|
|
|
|
real32 playerLeft = screenCenterX - 0.5f*tilemap->metersToPixels*playerWidth; |
|
|
|
|
|
real32 playerTop = screenCenterY - tilemap->metersToPixels*playerHeight; |
|
|
|
|
|
drawRectangle(videoBuf, playerLeft, playerTop, playerLeft + tilemap->metersToPixels*playerWidth, playerTop + tilemap->metersToPixels*playerHeight, playerR, playerG, playerB); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
extern "C" GAME_GET_SOUND_SAMPLES(gameGetSoundSamples) { |
|
|
extern "C" GAME_GET_SOUND_SAMPLES(gameGetSoundSamples) { |
|
|