diff src/map.c @ 21:bb7dfb42b320

Small refactor to object placement. Add spawn point object
author Michael Pavone <pavone@retrodev.com>
date Sun, 12 Jan 2014 23:53:18 -0800
parents 51a0972fcf76
children
line wrap: on
line diff
--- a/src/map.c	Sun Jan 12 22:43:03 2014 -0800
+++ b/src/map.c	Sun Jan 12 23:53:18 2014 -0800
@@ -10,31 +10,33 @@
 	u16 y;
 } mpoint;
 
+#define is_empty(tindex) (tilemap[tindex] == EMPTY_TA || tilemap[tindex] == SPAWN_UL)
+
 s16 explore(mpoint * points, s16 num_points, u16 src, u16 srcx, u16 srcy)
 {
 	u16 dist = distances[src]+1;
-	if (srcx < 19 && distances[src + 1] > dist && !tilemap[(srcx+1)*2+srcy*2*40])
+	if (srcx < 19 && distances[src + 1] > dist && is_empty((srcx+1)*2+srcy*2*40))
 	{
 		distances[src + 1] = dist;
 		points[num_points].index = src + 1;
 		points[num_points].x = srcx+1;
 		points[num_points++].y = srcy;
 	}
-	if (srcx && distances[src - 1] > dist && !tilemap[(srcx-1)*2 + srcy*2*40])
+	if (srcx && distances[src - 1] > dist && is_empty((srcx-1)*2 + srcy*2*40))
 	{
 		distances[src - 1] = dist;
 		points[num_points].index = src - 1;
 		points[num_points].x = srcx-1;
 		points[num_points++].y = srcy;
 	}
-	if (srcy < 13 && distances[src + 20] > dist && !tilemap[srcx*2+(srcy+1)*2*40])
+	if (srcy < 13 && distances[src + 20] > dist && is_empty(srcx*2+(srcy+1)*2*40))
 	{
 		distances[src + 20] = dist;
 		points[num_points].index = src + 20;
 		points[num_points].x = srcx;
 		points[num_points++].y = srcy+1;
 	}
-	if (srcy && distances[src - 20] > dist && !tilemap[srcx*2 + (srcy-1)*2*40])
+	if (srcy && distances[src - 20] > dist && is_empty(srcx*2 + (srcy-1)*2*40))
 	{
 		distances[src - 20] = dist;
 		points[num_points].index = src - 20;
@@ -101,3 +103,20 @@
 		}
 	}
 }
+
+u16 tileinfo[OBJECT_TYPES][4] = {
+	{EMPTY_TA, EMPTY_TA, EMPTY_TA, EMPTY_TA},
+	{WALL_UL, WALL_UL, WALL_UL, WALL_UL},
+	{TOWER_UL, TOWER_UL, TOWER_UL, TOWER_UL},
+	{GOAL_UL, GOAL_UL, GOAL_UL, GOAL_UL},
+	{SPAWN_UL, SPAWN_UL, SPAWN_UL, SPAWN_UL}
+};
+
+void place_object(u16 type, u16 x, u16 y)
+{
+	u16 tindex = x + y*40;
+	tilemap[tindex]      = tileinfo[type][0];
+	tilemap[tindex + 1]  = tileinfo[type][1];
+	tilemap[tindex + 40] = tileinfo[type][2];
+	tilemap[tindex + 41] = tileinfo[type][3];
+}