1
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: tune the slam and jump force

+38 -11
+24 -5
physics_engine.vhd
··· 52 52 -- Physics tuning 53 53 constant GRAVITY : std_logic_vector(9 downto 0) := CONV_STD_LOGIC_VECTOR(1, 10); 54 54 constant IMPULSE : std_logic_vector(9 downto 0) := CONV_STD_LOGIC_VECTOR(3, 10); 55 - constant SLAM_FORCE : std_logic_vector(9 downto 0) := CONV_STD_LOGIC_VECTOR(8, 10); 56 - constant JUMP_FORCE : std_logic_vector(9 downto 0) := CONV_STD_LOGIC_VECTOR(13, 10); 55 + constant SLAM_FORCE : std_logic_vector(9 downto 0) := CONV_STD_LOGIC_VECTOR(4, 10); 56 + -- Jump: base force at zero velocity, tapers off as |vel_y| rises. 57 + -- Piecewise lookup approximates: max(JUMP_MIN, JUMP_BASE*JUMP_SCALE/(JUMP_SCALE+|vy|)) 58 + constant JUMP_BASE : integer := 6; -- force at zero velocity 59 + constant JUMP_VEL_THR1 : integer := 3; -- |vy| <= 3 → force 6 60 + constant JUMP_VEL_THR2 : integer := 8; -- |vy| <= 8 → force 4 61 + constant JUMP_VEL_THR3 : integer := 16; -- |vy| <= 16 → force 3 62 + constant JUMP_MIN_FORCE : integer := 2; -- floor at high velocity 57 63 constant MAX_VEL_X : std_logic_vector(9 downto 0) := CONV_STD_LOGIC_VECTOR(32, 10); 58 64 59 65 -- World bounds (11-bit) ··· 128 134 else SIZE + ("000000" & squish); 129 135 130 136 physics : process 131 - variable vx, vy : std_logic_vector(9 downto 0); 137 + variable vx, vy : std_logic_vector(9 downto 0); 132 138 variable px, py : std_logic_vector(10 downto 0); 133 139 variable bounced : std_logic; 134 140 variable bounce_wall : std_logic; ··· 137 143 variable c_left, c_right, c_top, c_bot : std_logic_vector(10 downto 0); 138 144 variable c_prev_top, c_prev_bot, c_prev_left, c_prev_right : std_logic_vector(10 downto 0); 139 145 variable tcx, tcy, dcx, dcy : std_logic_vector(10 downto 0); 146 + variable abs_vy_int : integer; 147 + variable jforce_int : integer; 148 + variable jforce_slv : std_logic_vector(9 downto 0); 140 149 begin 141 150 wait until vert_sync'event and vert_sync = '1'; 142 151 ··· 148 157 -- == INPUT == 149 158 if key_w = '0' then jump_pressed <= '0'; end if; 150 159 160 + -- Scaled jump: full force at low velocity, tapers as |vy| increases 161 + if vy(9) = '1' then abs_vy_int := CONV_INTEGER((not vy) + 1); 162 + else abs_vy_int := CONV_INTEGER(vy); end if; 163 + if abs_vy_int <= JUMP_VEL_THR1 then jforce_int := JUMP_BASE; 164 + elsif abs_vy_int <= JUMP_VEL_THR2 then jforce_int := 4; 165 + elsif abs_vy_int <= JUMP_VEL_THR3 then jforce_int := 3; 166 + else jforce_int := JUMP_MIN_FORCE; 167 + end if; 168 + jforce_slv := CONV_STD_LOGIC_VECTOR(jforce_int, 10); 169 + 151 170 if key_w = '1' and jump_pressed = '0' and on_ground = '1' then 152 171 vy := (others => '0'); 153 - vy := vy - JUMP_FORCE; 172 + vy := vy - jforce_slv; 154 173 jump_pressed <= '1'; 155 174 end if; 156 175 157 176 if key_w = '1' and jump_pressed = '1' and on_ground = '1' then 158 - vy := vy - JUMP_FORCE; 177 + vy := vy - jforce_slv; 159 178 end if; 160 179 161 180 if key_s = '1' and on_ground = '0' then vy := vy + SLAM_FORCE; end if;
+14 -6
visualizer.py
··· 23 23 # --- Physics constants (match VHDL exactly) --- 24 24 GRAVITY = 1 25 25 IMPULSE = 3 26 - SLAM_FORCE = 8 26 + SLAM_FORCE = 4 27 27 AIR_CONTROL = 2 28 - JUMP_FORCE = 13 28 + JUMP_FORCE = 6 # base jump force at zero velocity 29 + JUMP_VEL_SCALE = 12 # velocity magnitude at which jump force is halved 30 + JUMP_MIN_FORCE = 2 # floor: minimum jump force regardless of velocity 29 31 MAX_VEL_X = 32 30 32 SIZE = 7 31 33 BOUNCE_SHIFT = 3 # energy loss = vel >> 3 (keep 87.5%) ··· 126 128 if not keys_held['w']: 127 129 jump_pressed = False 128 130 131 + # Compute scaled jump force: full force at zero velocity, tapers off as speed rises 132 + def scaled_jump(): 133 + speed = abs(to_signed(vel_y)) 134 + force = JUMP_FORCE * JUMP_VEL_SCALE / (JUMP_VEL_SCALE + speed) 135 + return max(int(force), JUMP_MIN_FORCE) 136 + 129 137 # First press on ground: full jump (elif prevents double-apply on same frame) 130 138 if keys_held['w'] and not jump_pressed and on_ground: 131 139 vy = to_unsigned(0) 132 - vy = (vy - JUMP_FORCE) & MASK 140 + vy = (vy - scaled_jump()) & MASK 133 141 jump_pressed = True 134 142 elif keys_held['w'] and jump_pressed and on_ground: 135 143 # Holding W while bouncing: boost each ground contact 136 - vy = (vy - JUMP_FORCE) & MASK 144 + vy = (vy - scaled_jump()) & MASK 137 145 138 146 # S: slam (air only) 139 147 if keys_held['s'] and not on_ground: ··· 352 360 if show_trail and len(trail) > 1: 353 361 for i, (tx, ty) in enumerate(trail): 354 362 alpha = int(80 * i / len(trail)) 355 - s = pygame.Surface((3, 3)) 363 + s = pygame.Surface((1, 1)) 356 364 s.set_alpha(alpha) 357 365 s.fill((255, 100, 100)) 358 - screen.blit(s, (tx - 1, ty - 1)) 366 + screen.blit(s, (tx, ty)) 359 367 360 368 # Character with squish 361 369 # Vertical squish (floor/ceil): wider + shorter