about summary refs log tree commit diff
path: root/src/game/mapres_tilemap.cpp
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2007-05-22 15:03:32 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2007-05-22 15:03:32 +0000
commit73aa9b71c1d8b5c5065d1e474f13601da3ca6b20 (patch)
tree88b6a0a4a2ebdd33a88f4a25682581d329d33f6b /src/game/mapres_tilemap.cpp
downloadzcatch-73aa9b71c1d8b5c5065d1e474f13601da3ca6b20.tar.gz
zcatch-73aa9b71c1d8b5c5065d1e474f13601da3ca6b20.zip
started the major restructure of svn
Diffstat (limited to 'src/game/mapres_tilemap.cpp')
-rw-r--r--src/game/mapres_tilemap.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/game/mapres_tilemap.cpp b/src/game/mapres_tilemap.cpp
new file mode 100644
index 00000000..0868d2e4
--- /dev/null
+++ b/src/game/mapres_tilemap.cpp
@@ -0,0 +1,54 @@
+#include "../interface.h"
+#include "mapres_tilemap.h"
+#include "mapres_image.h"
+#include "mapres.h"
+
+int tilemap_init()
+{
+	return 0;
+}
+
+void tilemap_render(float scale, int fg)
+{
+	if(!map_is_loaded())
+		return;
+	
+	// fetch indecies
+	int start, num;
+	map_get_type(MAPRES_TILEMAP, &start, &num);
+
+	// render tilemaps
+	int passed_main = 0;
+	for(int t = 0; t < num; t++)
+	{
+		mapres_tilemap *tmap = (mapres_tilemap *)map_get_item(start+t,0,0);
+		unsigned char *data = (unsigned char *)map_get_data(tmap->data);
+		
+		if(tmap->main)
+			passed_main = 1;
+
+		if((fg && passed_main) || (!fg && !passed_main))
+		{
+			gfx_texture_set(img_get(tmap->image));
+			gfx_quads_begin();
+			
+			int c = 0;
+			float frac = (1.0f/1024.0f); //2.0f;
+			for(int y = 0; y < tmap->height; y++)
+				for(int x = 0; x < tmap->width; x++, c++)
+				{
+					unsigned char d = data[c*2];
+					if(d)
+					{
+						gfx_quads_setsubset(
+							(d%16)/16.0f+frac,
+							(d/16)/16.0f+frac,
+							(d%16)/16.0f+1.0f/16.0f-frac,
+							(d/16)/16.0f+1.0f/16.0f-frac);
+						gfx_quads_drawTL(x*scale, y*scale, scale, scale);
+					}
+				}
+			gfx_quads_end();
+		}
+	}
+}