Tile under foot
This commit is contained in:
@@ -46,6 +46,8 @@ void inputInit(void) {
|
|||||||
|
|
||||||
#if INPUT_GAMEPAD == 1
|
#if INPUT_GAMEPAD == 1
|
||||||
#if PSP
|
#if PSP
|
||||||
|
INPUT.deadzone = 0.2890625f;// Taken from the PSP firmware
|
||||||
|
|
||||||
inputBind(inputButtonGetByName("up"), INPUT_ACTION_UP);
|
inputBind(inputButtonGetByName("up"), INPUT_ACTION_UP);
|
||||||
inputBind(inputButtonGetByName("down"), INPUT_ACTION_DOWN);
|
inputBind(inputButtonGetByName("down"), INPUT_ACTION_DOWN);
|
||||||
inputBind(inputButtonGetByName("left"), INPUT_ACTION_LEFT);
|
inputBind(inputButtonGetByName("left"), INPUT_ACTION_LEFT);
|
||||||
|
|||||||
@@ -75,16 +75,16 @@ void entityWalk(entity_t *entity, const entitydir_t direction) {
|
|||||||
newPos.y += relY;
|
newPos.y += relY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Tile in way?
|
// Get tile under foot
|
||||||
chunkpos_t chunkPos;
|
chunkpos_t chunkPos;
|
||||||
worldPosToChunkPos(&newPos, &chunkPos);
|
worldPosToChunkPos(&newPos, &chunkPos);
|
||||||
chunkindex_t chunkIndex = mapGetChunkIndexAt(chunkPos);
|
chunkindex_t chunkIndex = mapGetChunkIndexAt(chunkPos);
|
||||||
|
tile_t tile = TILE_NULL;
|
||||||
if(chunkIndex != -1) {
|
if(chunkIndex != -1) {
|
||||||
chunk_t *chunk = mapGetChunkByIndex((uint8_t)chunkIndex);
|
chunk_t *chunk = mapGetChunk(chunkIndex);
|
||||||
assertNotbNull(chunk, "Chunk pointer cannot be NULL");
|
assertNotNull(chunk, "Chunk pointer cannot be NULL");
|
||||||
chunkGetTile
|
chunktileindex_t tileIndex = woprldPosToChunkTileIndex(&newPos);
|
||||||
} else {
|
tile = chunk->tiles[tileIndex];
|
||||||
return;// Out of bounds
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Entity in way?
|
// Entity in way?
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ chunkindex_t mapGetChunkIndexAt(const chunkpos_t position) {
|
|||||||
return chunkPosToIndex(&relPos);
|
return chunkPosToIndex(&relPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
chunk_t* mapGetChunkByIndex(const uint8_t index) {
|
chunk_t* mapGetChunk(const uint8_t index) {
|
||||||
if(index >= MAP_CHUNK_COUNT) return NULL;
|
if(index >= MAP_CHUNK_COUNT) return NULL;
|
||||||
return &MAP.chunks[index];
|
return &MAP.chunks[index];
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "dusk.h"
|
#include "dusk.h"
|
||||||
|
|
||||||
|
|
||||||
typedef struct tile_s {
|
typedef struct tile_s {
|
||||||
uint8_t id;
|
uint8_t id;
|
||||||
} tile_t;
|
} tile_t;
|
||||||
|
|
||||||
|
#define TILE_NULL ((tile_t){ .id = 0 })
|
||||||
@@ -23,6 +23,18 @@ void worldPosToChunkPos(const worldpos_t* worldPos, chunkpos_t* out) {
|
|||||||
out->z = (chunkunit_t)(worldPos->z / CHUNK_DEPTH);
|
out->z = (chunkunit_t)(worldPos->z / CHUNK_DEPTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chunktileindex_t woprldPosToChunkTileIndex(const worldpos_t* worldPos) {
|
||||||
|
uint8_t localX = (uint8_t)(worldPos->x % CHUNK_WIDTH);
|
||||||
|
uint8_t localY = (uint8_t)(worldPos->y % CHUNK_HEIGHT);
|
||||||
|
uint8_t localZ = (uint8_t)(worldPos->z % CHUNK_DEPTH);
|
||||||
|
|
||||||
|
return (chunktileindex_t)(
|
||||||
|
(localZ * CHUNK_WIDTH * CHUNK_HEIGHT) +
|
||||||
|
(localY * CHUNK_WIDTH) +
|
||||||
|
localX
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
chunkindex_t chunkPosToIndex(const chunkpos_t* pos) {
|
chunkindex_t chunkPosToIndex(const chunkpos_t* pos) {
|
||||||
return (chunkindex_t)(
|
return (chunkindex_t)(
|
||||||
(pos->z * MAP_CHUNK_WIDTH * MAP_CHUNK_HEIGHT) +
|
(pos->z * MAP_CHUNK_WIDTH * MAP_CHUNK_HEIGHT) +
|
||||||
|
|||||||
@@ -20,7 +20,8 @@
|
|||||||
|
|
||||||
typedef int16_t worldunit_t;
|
typedef int16_t worldunit_t;
|
||||||
typedef int16_t chunkunit_t;
|
typedef int16_t chunkunit_t;
|
||||||
typedef int8_t chunkindex_t;
|
typedef int16_t chunkindex_t;
|
||||||
|
typedef uint8_t chunktileindex_t;
|
||||||
|
|
||||||
typedef int32_t worldunits_t;
|
typedef int32_t worldunits_t;
|
||||||
typedef int32_t chunkunits_t;
|
typedef int32_t chunkunits_t;
|
||||||
@@ -58,6 +59,15 @@ void chunkPosToWorldPos(const chunkpos_t* chunkPos, worldpos_t* out);
|
|||||||
*/
|
*/
|
||||||
void worldPosToChunkPos(const worldpos_t* worldPos, chunkpos_t* out);
|
void worldPosToChunkPos(const worldpos_t* worldPos, chunkpos_t* out);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a position in world-space to an index inside a chunk that the tile
|
||||||
|
* resides in.
|
||||||
|
*
|
||||||
|
* @param worldPos The world position.
|
||||||
|
* @return The tile index within the chunk.
|
||||||
|
*/
|
||||||
|
chunktileindex_t woprldPosToChunkTileIndex(const worldpos_t* worldPos);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a chunk position to a world position.
|
* Converts a chunk position to a world position.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user