1
fork

Configure Feed

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

feat: calc x in velcity and increase max velocity and slam

+20 -14
+20 -14
physics_engine.vhd
··· 50 50 -- Physics tuning 51 51 constant GRAVITY : std_logic_vector(9 downto 0) := CONV_STD_LOGIC_VECTOR(1, 10); 52 52 constant IMPULSE : std_logic_vector(9 downto 0) := CONV_STD_LOGIC_VECTOR(3, 10); 53 + constant SLAM_FORCE : std_logic_vector(9 downto 0) := CONV_STD_LOGIC_VECTOR(8, 10); 53 54 constant JUMP_FORCE : std_logic_vector(9 downto 0) := CONV_STD_LOGIC_VECTOR(13, 10); 54 55 constant MAX_VEL_X : std_logic_vector(9 downto 0) := CONV_STD_LOGIC_VECTOR(32, 10); 55 56 ··· 59 60 constant LEFT_WALL : std_logic_vector(10 downto 0) := CONV_STD_LOGIC_VECTOR(8, 11); 60 61 constant RIGHT_WALL : std_logic_vector(10 downto 0) := CONV_STD_LOGIC_VECTOR(1492, 11); 61 62 62 - -- Underflow sentinel: valid positions top out at 1492; underflow wraps to >= 2000. 63 - -- (Min case: CEILING(16) - max_upward(64) = -48 -> 11-bit unsigned = 2000.) 64 - constant UNDERFLOW : std_logic_vector(10 downto 0) := CONV_STD_LOGIC_VECTOR(2000, 11); 63 + -- Underflow sentinel: valid positions top out at 1480 (GROUND). 64 + -- CEILING(16) - max_upward(128) = -112 -> 11-bit unsigned = 1936. 65 + -- So UNDERFLOW must be <= 1936 and > 1480. 1500 gives safe margin. 66 + constant UNDERFLOW : std_logic_vector(10 downto 0) := CONV_STD_LOGIC_VECTOR(1500, 11); 65 67 66 68 -- Tune: vertical speed (0-63) at which all 10 LEDs are fully lit. 67 69 -- Lower = more sensitive (fewer LEDs at low speed fill up faster). ··· 75 77 signal on_ground : std_logic := '0'; 76 78 signal jump_pressed : std_logic := '0'; 77 79 80 + signal abs_vel_x : std_logic_vector(9 downto 0); 78 81 signal abs_vel_y : std_logic_vector(9 downto 0); 79 82 80 83 begin ··· 84 87 cam_x <= cam_x_sig; 85 88 cam_y <= cam_y_sig; 86 89 87 - -- Absolute value of vertical velocity. 90 + -- Absolute values of both velocity axes. 91 + abs_vel_x <= (not vel_x) + 1 when vel_x(9) = '1' else vel_x; 88 92 abs_vel_y <= (not vel_y) + 1 when vel_y(9) = '1' else vel_y; 89 93 90 - -- Thermometer-encode speed to a horizontal bar: each bit = one LED. 94 + -- Thermometer-encode peak speed (max of |vx|,|vy|) → horizontal LED bar. 91 95 -- n LEDs lit from LSB up → 0000011111 for n=5, 1111111111 for n=10. 92 - vel_bar : process(abs_vel_y) 93 - variable v : integer; 96 + vel_bar : process(abs_vel_x, abs_vel_y) 97 + variable vx, vy, vmax : integer; 94 98 variable n : integer range 0 to 10; 95 99 begin 96 - v := CONV_INTEGER(abs_vel_y); 97 - if v >= LED_FULL_VEL then n := 10; 98 - else n := v * 10 / LED_FULL_VEL; 100 + vx := CONV_INTEGER(abs_vel_x); 101 + vy := CONV_INTEGER(abs_vel_y); 102 + if vx > vy then vmax := vx; else vmax := vy; end if; 103 + if vmax >= LED_FULL_VEL then n := 10; 104 + else n := vmax * 10 / LED_FULL_VEL; 99 105 end if; 100 106 case n is 101 107 when 0 => vel_out <= "0000000000"; ··· 148 154 vy := vy - 4; 149 155 end if; 150 156 151 - if key_s = '1' and on_ground = '0' then vy := vy + IMPULSE; end if; 157 + if key_s = '1' and on_ground = '0' then vy := vy + SLAM_FORCE; end if; 152 158 153 159 if key_a = '1' then 154 160 if on_ground = '1' then vx := vx - IMPULSE; else vx := vx - 2; end if; ··· 176 182 -- == CLAMP velocities == 177 183 if vx(9) = '0' and vx > MAX_VEL_X then vx := MAX_VEL_X; end if; 178 184 if vx(9) = '1' and vx < (not MAX_VEL_X) + 1 then vx := (not MAX_VEL_X) + 1; end if; 179 - if vy(9) = '0' and vy > 63 then vy := CONV_STD_LOGIC_VECTOR(63, 10); end if; 180 - if vy(9) = '1' and vy < CONV_STD_LOGIC_VECTOR(960, 10) then 181 - vy := CONV_STD_LOGIC_VECTOR(960, 10); 185 + if vy(9) = '0' and vy > 127 then vy := CONV_STD_LOGIC_VECTOR(127, 10); end if; 186 + if vy(9) = '1' and vy < CONV_STD_LOGIC_VECTOR(896, 10) then 187 + vy := CONV_STD_LOGIC_VECTOR(896, 10); 182 188 end if; 183 189 184 190 -- == MOVE: sign-extend 10-bit velocity to 11-bit before adding ==