/** * Copyright (c) 2021 Dominic Masters * * This software is released under the MIT License. * https://opensource.org/licenses/MIT */ #include "common.h" void entityCommonMove(entityid_t id, entity_t *entity, int32_t x, int32_t y, int32_t z) { int32_t newX, newY, newZ, chunkIndex, tileIndex; tileid_t tileId; // Determine the new coordinates. newX = entity->gridX + x; newY = entity->gridY + y; newZ = entity->gridZ + z; // Can we move there, tile check first then entity check. tilegetresult_t result = tileGet(newX, newY, newZ); chunkIndex = chunkGet(result.chunkX, result.chunkY, result.chunkZ); if(chunkIndex == -1) return; tileIndex = chunkGetTile(result.localX, result.localY, result.localZ); tileId = MAP_STATE.chunkList[chunkIndex]->tiles[tileIndex]; if(tileId == TILE_NULL) return; // Update the old and new positions entity->oldGridX = entity->gridX; entity->oldGridY = entity->gridY; entity->oldGridZ = entity->gridZ; entity->gridX = newX; entity->gridY = newY; entity->gridZ = newZ; } void entityCommonRender(entityid_t id, entity_t *entity) { float d = TIME_STATE.delta * ENTITY_COMMON_MOVE_SPEED; entity->positionX += (entity->gridX - entity->positionX) * d; entity->positionY += (entity->gridY - entity->positionY) * d; entity->positionZ += (entity->gridZ - entity->positionZ) * d; // Render sprite spriteBatchQuad(ENTITY_STATE.spriteBatch, -1, entity->positionX, entity->positionY, entity->positionZ, 1, 1, 0, 0, 1, 1 ); }