1
fork

Configure Feed

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

feat: add led out

+20 -4
+19 -3
physics_engine.vhd
··· 7 7 -- Bit-10 was wrong because GROUND(1480) and RIGHT_WALL(1492) both have 8 8 -- bit 10 set (values >= 1024), causing false ceiling/wall triggers. 9 9 -- 10 - -- Obstacles imported from level_pkg (use work.level_pkg.all). 10 + -- Obstacles imported from level package (use work.level.all). 11 11 -- ======================================================================== 12 12 13 13 library IEEE; 14 14 use IEEE.STD_LOGIC_1164.all; 15 15 use IEEE.STD_LOGIC_ARITH.all; 16 16 use IEEE.STD_LOGIC_UNSIGNED.all; 17 - use work.level_pkg.all; 17 + use work.level.all; 18 18 19 19 entity physics_engine is 20 20 port( ··· 28 28 char_width : out std_logic_vector(9 downto 0); 29 29 char_height : out std_logic_vector(9 downto 0); 30 30 cam_x : out std_logic_vector(10 downto 0); 31 - cam_y : out std_logic_vector(10 downto 0) 31 + cam_y : out std_logic_vector(10 downto 0); 32 + vel_out : out std_logic_vector(9 downto 0) 32 33 ); 33 34 end physics_engine; 34 35 ··· 62 63 -- (Min case: CEILING(16) - max_upward(64) = -48 -> 11-bit unsigned = 2000.) 63 64 constant UNDERFLOW : std_logic_vector(10 downto 0) := CONV_STD_LOGIC_VECTOR(2000, 11); 64 65 66 + -- Tune: vertical speed (0-63) at which all 10 LEDs are fully lit. 67 + -- Lower = more sensitive (fewer LEDs at low speed fill up faster). 68 + -- Higher = less sensitive (need a harder bounce to light all LEDs). 69 + constant LED_FULL_VEL : integer := 16; 70 + 65 71 -- Animation 66 72 signal squish : std_logic_vector(3 downto 0) := (others => '0'); 67 73 signal squish_h : std_logic := '0'; 68 74 signal on_ground : std_logic := '0'; 69 75 signal jump_pressed : std_logic := '0'; 76 + 77 + signal abs_vel_y : std_logic_vector(9 downto 0); 70 78 71 79 begin 72 80 ··· 74 82 char_y <= pos_y; 75 83 cam_x <= cam_x_sig; 76 84 cam_y <= cam_y_sig; 85 + 86 + -- Absolute value of vertical velocity. 87 + abs_vel_y <= (not vel_y) + 1 when vel_y(9) = '1' else vel_y; 88 + 89 + -- Scale so LED_FULL_VEL maps to all 10 LEDs on (1023); clamp above that. 90 + vel_out <= CONV_STD_LOGIC_VECTOR(1023, 10) 91 + when CONV_INTEGER(abs_vel_y) >= LED_FULL_VEL else 92 + CONV_STD_LOGIC_VECTOR(CONV_INTEGER(abs_vel_y) * 1023 / LED_FULL_VEL, 10); 77 93 78 94 char_width <= SIZE + ("000000" & squish) when squish_h = '0' 79 95 else SIZE - ("000000" & squish(3 downto 1));
+1 -1
renderer.vhd
··· 10 10 use IEEE.STD_LOGIC_1164.all; 11 11 use IEEE.STD_LOGIC_ARITH.all; 12 12 use IEEE.STD_LOGIC_UNSIGNED.all; 13 - use work.level_pkg.all; 13 + use work.level.all; 14 14 15 15 entity renderer is 16 16 port(