about summary refs log tree commit diff
path: root/src/game
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2007-08-14 23:13:14 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2007-08-14 23:13:14 +0000
commit87ba16401b5576a5f3f9627688903740156a362f (patch)
tree1b8100c3c8bccb89df0d4f9d07098c257edd1112 /src/game
parente11e9a71ca92cb5424f1e0e26fe1261b8a723d6d (diff)
downloadzcatch-87ba16401b5576a5f3f9627688903740156a362f.tar.gz
zcatch-87ba16401b5576a5f3f9627688903740156a362f.zip
added wallslide and walljump
Diffstat (limited to 'src/game')
-rw-r--r--src/game/server/game_server.cpp25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/game/server/game_server.cpp b/src/game/server/game_server.cpp
index 82141d63..7d41f540 100644
--- a/src/game/server/game_server.cpp
+++ b/src/game/server/game_server.cpp
@@ -26,6 +26,9 @@ const float hook_fire_speed = 45.0f;
 const float hook_drag_accel = 3.0f;
 const float hook_drag_speed = 15.0f;
 const float gravity = 0.5f;
+const float wall_friction = 0.80f;
+const float wall_jump_speed_up = ground_jump_speed*0.8f;
+const float wall_jump_speed_out = ground_jump_speed*0.8f;
 
 class player* get_player(int index);
 void create_damageind(vec2 p, float angle_mod, int amount);
@@ -1189,12 +1192,24 @@ void player::tick()
 	
 	// fetch some info
 	bool grounded = is_grounded();
+	int wall_sliding = 0;
 	direction = normalize(vec2(input.target_x, input.target_y));
 	
 	float max_speed = grounded ? ground_control_speed : air_control_speed;
 	float accel = grounded ? ground_control_accel : air_control_accel;
 	float friction = grounded ? ground_friction : air_friction;
 	
+	if(!grounded && vel.y > 0)
+	{
+		if(input.left && col_check_point((int)(pos.x-phys_size/2)-4, (int)(pos.y)))
+			wall_sliding = -1;
+		if(input.right && col_check_point((int)(pos.x+phys_size/2)+4, (int)(pos.y)))
+			wall_sliding = 1;
+	}
+
+	if(wall_sliding)
+		vel.y *= wall_friction;
+	
 	// handle movement
 	if(input.left)
 		vel.x = saturated_add(-max_speed, max_speed, vel.x, -accel);
@@ -1207,10 +1222,16 @@ void player::tick()
 	// handle jumping
 	if(input.jump)
 	{
-		if(!jumped && grounded)
+		if(!jumped && (grounded || wall_sliding))
 		{
 			create_sound(pos, SOUND_PLAYER_JUMP);
-			vel.y = -ground_jump_speed;
+			if(wall_sliding)
+			{
+				vel.y = -wall_jump_speed_up;
+				vel.x = -wall_jump_speed_out*wall_sliding;
+			}
+			else
+				vel.y = -ground_jump_speed;
 			jumped++;
 		}
 	}