about summary refs log tree commit diff
path: root/src/game/client/gc_flow.cpp
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2008-01-29 21:39:41 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2008-01-29 21:39:41 +0000
commit7bc733dc10f3d01985021b7b5d6ae140dd5af6f1 (patch)
treec9b0fcd8d128ec9abd40c10dfe4fcf245650a870 /src/game/client/gc_flow.cpp
parent0dab7db963e2706182ea120c98f746f5e265c14c (diff)
downloadzcatch-7bc733dc10f3d01985021b7b5d6ae140dd5af6f1.tar.gz
zcatch-7bc733dc10f3d01985021b7b5d6ae140dd5af6f1.zip
large update. cleaned up some code. added new effects for almost everything
Diffstat (limited to 'src/game/client/gc_flow.cpp')
-rw-r--r--src/game/client/gc_flow.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/game/client/gc_flow.cpp b/src/game/client/gc_flow.cpp
new file mode 100644
index 00000000..aac35058
--- /dev/null
+++ b/src/game/client/gc_flow.cpp
@@ -0,0 +1,87 @@
+#include <engine/e_client_interface.h>
+#include <engine/e_config.h>
+#include "gc_client.h"
+#include "../g_layers.h"
+
+struct FLOWCELL
+{
+	vec2 vel;
+};
+
+static FLOWCELL *cells = 0;
+static int height = 0;
+static int width = 0;
+static int spacing = 16;
+
+void flow_init()
+{
+	if(cells)
+	{
+		mem_free(cells);
+		cells = 0;
+	}
+	
+	MAPITEM_LAYER_TILEMAP *tilemap = layers_game_layer();
+	width = tilemap->width*32/spacing;
+	height = tilemap->height*32/spacing;
+
+	// allocate and clear	
+	cells = (FLOWCELL *)mem_alloc(sizeof(FLOWCELL)*width*height, 1);
+	for(int y = 0; y < height; y++)
+		for(int x = 0; x < width; x++)
+			cells[y*width+x].vel = vec2(0.0f, 0.0f);
+}
+
+void flow_update()
+{
+	if(!config.cl_flow)
+		return;
+		
+	for(int y = 0; y < height; y++)
+		for(int x = 0; x < width; x++)
+			cells[y*width+x].vel *= 0.85f;
+}
+
+void flow_dbg_render()
+{
+	if(!config.cl_flow)
+		return;
+
+	gfx_texture_set(-1);
+	gfx_lines_begin();
+	for(int y = 0; y < height; y++)
+		for(int x = 0; x < width; x++)
+		{
+			vec2 pos(x*spacing, y*spacing);
+			vec2 vel = cells[y*width+x].vel * 0.01f;
+			gfx_lines_draw(pos.x, pos.y, pos.x+vel.x, pos.y+vel.y);
+		}
+		
+	gfx_lines_end();
+}
+
+void flow_add(vec2 pos, vec2 vel, float size)
+{
+	if(!config.cl_flow)
+		return;
+		
+	int x = (int)(pos.x / spacing);
+	int y = (int)(pos.y / spacing);
+	if(x < 0 || y < 0 || x >= width || y >= height)
+		return;
+	
+	cells[y*width+x].vel += vel;
+}
+
+vec2 flow_get(vec2 pos)
+{
+	if(!config.cl_flow)
+		return vec2(0,0);
+	
+	int x = (int)(pos.x / spacing);
+	int y = (int)(pos.y / spacing);
+	if(x < 0 || y < 0 || x >= width || y >= height)
+		return vec2(0,0);
+	
+	return cells[y*width+x].vel;
+}