Skip to content

Commit 172d7d2

Browse files
committed
more issues fix
1 parent aefdfe9 commit 172d7d2

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/map.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -255,17 +255,17 @@ Map MapCreateFromFile(const char* filename) {
255255
if (ParserElementGetType(tileSurface) == STRING_TYPE) { // Is a file name
256256
char* tileSurfaceName = (char*) ParserElementGetValue(HashMapGet(tilestuff, "surface"));
257257

258-
// Handle transparency
258+
// Handle transparency (TODO: change this to be less ugly)
259259
bool isTransparent = false;
260-
if (HashMapContains(tilestuff, "transparent")) {
261-
ParserElement transparencyelem = HashMapGet(tilestuff, "transparent");
262-
if (ParserElementGetType(transparencyelem) != BOOL_TYPE) {
263-
fprintf(stderr, "Error opening \"%s\": Tile transparency must be represented by a bool value! (in tile \"%s\")\n", filename, n);
264-
exit(EXIT_FAILURE);
265-
}
260+
ParserElement transparencyelem = HashMapGet(tilestuff, "transparent");
261+
if (transparencyelem != NULL && ParserElementGetType(transparencyelem) != BOOL_TYPE) {
262+
fprintf(stderr, "Error opening \"%s\": Tile transparency must be represented by a bool value! (in tile \"%s\")\n", filename, n);
263+
exit(EXIT_FAILURE);
264+
} else if (transparencyelem != NULL) {
266265
isTransparent = *(bool*) ParserElementGetValue(transparencyelem);
267266
}
268-
267+
268+
269269
tileobj = TileCreateTextured(tilename, tileID, tileSurfaceName, isTransparent);
270270

271271
} else { // Might be a color

src/mapray.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ void MapRayCast(MapRay ray) {
242242
int i = 0;
243243
while (!ray->is_colliding) {
244244
MapRayHitSide hitSide;
245-
245+
246246
if (sideDistX < sideDistY) {
247247
sideDistX += deltaDistX;
248248
mapX += sideX;
@@ -256,8 +256,15 @@ void MapRayCast(MapRay ray) {
256256
}
257257

258258
ray->is_colliding = MapGetTile(ray->map, mapX, mapY) != TILE_GROUND;
259+
260+
if (!ray->is_colliding) {
261+
if (i == MAX_RAY_STEPS) {
262+
break;
263+
}
264+
i++;
265+
continue;
266+
}
259267

260-
// If the colliding tile is transparent, then just continue
261268
if (ray->is_colliding) {
262269
// Calculate billboard collisions first because they are before the wall
263270
// Get possible Billboard collisions
@@ -312,7 +319,6 @@ void MapRayCast(MapRay ray) {
312319

313320
ListDestroy(&billboards);
314321

315-
316322
Tile collidingTile = MapGetTileObject(ray->map, MapGetTile(ray->map, mapX, mapY));
317323
rayCollision* col = malloc(sizeof(rayCollision));
318324
*col = (rayCollision) {
@@ -325,8 +331,8 @@ void MapRayCast(MapRay ray) {
325331
.hitSide = hitSide
326332
};
327333
ListAppendFirst(ray->collisions, col);
334+
// If the colliding tile is transparent, then just continue
328335
ray->is_colliding = !TileIsTransparent(collidingTile);
329-
330336
}
331337

332338
if (i == MAX_RAY_STEPS) {

0 commit comments

Comments
 (0)