From 273b7efe31873a1d4da125c8d59c7cbf5aaa46da Mon Sep 17 00:00:00 2001 From: Kieran Klukas Date: Wed, 1 Apr 2026 15:43:17 -0400 Subject: [PATCH] chore: make the intail jump stronger --- physics_engine.vhd | 26 +++++++++++++++----------- visualizer.py | 11 ++++++----- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/physics_engine.vhd b/physics_engine.vhd index 8b7a914..5cc62ef 100644 --- a/physics_engine.vhd +++ b/physics_engine.vhd @@ -52,14 +52,17 @@ architecture behavior of physics_engine is -- Physics tuning constant GRAVITY : std_logic_vector(9 downto 0) := CONV_STD_LOGIC_VECTOR(1, 10); constant IMPULSE : std_logic_vector(9 downto 0) := CONV_STD_LOGIC_VECTOR(3, 10); - constant SLAM_FORCE : std_logic_vector(9 downto 0) := CONV_STD_LOGIC_VECTOR(4, 10); - -- Jump: base force at zero velocity, tapers off as |vel_y| rises. + constant SLAM_FORCE : std_logic_vector(9 downto 0) := CONV_STD_LOGIC_VECTOR(4, 10); + -- Initial jump: full force at zero velocity, tapers off as |vel_y| rises. -- Piecewise lookup approximates: max(JUMP_MIN, JUMP_BASE*JUMP_SCALE/(JUMP_SCALE+|vy|)) - constant JUMP_BASE : integer := 6; -- force at zero velocity - constant JUMP_VEL_THR1 : integer := 3; -- |vy| <= 3 → force 6 - constant JUMP_VEL_THR2 : integer := 8; -- |vy| <= 8 → force 4 - constant JUMP_VEL_THR3 : integer := 16; -- |vy| <= 16 → force 3 - constant JUMP_MIN_FORCE : integer := 2; -- floor at high velocity + constant JUMP_BASE : integer := 14; -- force at zero velocity + constant JUMP_VEL_THR1 : integer := 3; -- |vy| <= 3 → force 14 + constant JUMP_VEL_THR2 : integer := 10; -- |vy| <= 10 → force 8 + constant JUMP_VEL_THR3 : integer := 20; -- |vy| <= 20 → force 6 + constant JUMP_MIN_FORCE : integer := 4; -- floor at high velocity + -- Trampoline: fixed additive boost on each ground contact while W held. + -- No inverse scaling so energy accumulates each bounce. + constant JUMP_BOUNCE : std_logic_vector(9 downto 0) := CONV_STD_LOGIC_VECTOR(6, 10); constant MAX_VEL_X : std_logic_vector(9 downto 0) := CONV_STD_LOGIC_VECTOR(32, 10); -- World bounds (11-bit) @@ -157,12 +160,12 @@ begin -- == INPUT == if key_w = '0' then jump_pressed <= '0'; end if; - -- Scaled jump: full force at low velocity, tapers as |vy| increases + -- Initial jump: force tapers as |vy| increases (inverse scaling) if vy(9) = '1' then abs_vy_int := CONV_INTEGER((not vy) + 1); else abs_vy_int := CONV_INTEGER(vy); end if; if abs_vy_int <= JUMP_VEL_THR1 then jforce_int := JUMP_BASE; - elsif abs_vy_int <= JUMP_VEL_THR2 then jforce_int := 4; - elsif abs_vy_int <= JUMP_VEL_THR3 then jforce_int := 3; + elsif abs_vy_int <= JUMP_VEL_THR2 then jforce_int := 8; + elsif abs_vy_int <= JUMP_VEL_THR3 then jforce_int := 6; else jforce_int := JUMP_MIN_FORCE; end if; jforce_slv := CONV_STD_LOGIC_VECTOR(jforce_int, 10); @@ -173,8 +176,9 @@ begin jump_pressed <= '1'; end if; + -- Trampoline: fixed boost (no inverse scaling) so energy accumulates each bounce if key_w = '1' and jump_pressed = '1' and on_ground = '1' then - vy := vy - jforce_slv; + vy := vy - JUMP_BOUNCE; end if; if key_s = '1' and on_ground = '0' then vy := vy + SLAM_FORCE; end if; diff --git a/visualizer.py b/visualizer.py index fec9567..5ab6bdd 100644 --- a/visualizer.py +++ b/visualizer.py @@ -25,9 +25,10 @@ GRAVITY = 1 IMPULSE = 3 SLAM_FORCE = 4 AIR_CONTROL = 2 -JUMP_FORCE = 6 # base jump force at zero velocity -JUMP_VEL_SCALE = 12 # velocity magnitude at which jump force is halved -JUMP_MIN_FORCE = 2 # floor: minimum jump force regardless of velocity +JUMP_FORCE = 14 # initial jump force at zero velocity (scales down with |vel_y|) +JUMP_VEL_SCALE = 12 # velocity magnitude at which initial jump force is halved +JUMP_MIN_FORCE = 4 # floor for inverse-scaled initial jump +JUMP_BOUNCE = 6 # fixed additive boost on each ground contact while W held (trampoline) MAX_VEL_X = 32 SIZE = 7 BOUNCE_SHIFT = 3 # energy loss = vel >> 3 (keep 87.5%) @@ -140,8 +141,8 @@ def main(): vy = (vy - scaled_jump()) & MASK jump_pressed = True elif keys_held['w'] and jump_pressed and on_ground: - # Holding W while bouncing: boost each ground contact - vy = (vy - scaled_jump()) & MASK + # Holding W while bouncing: fixed boost so trampoline accumulates each contact + vy = (vy - JUMP_BOUNCE) & MASK # S: slam (air only) if keys_held['s'] and not on_ground: -- 2.51.2