at main 110 lines 4.3 kB view raw
1-- ======================================================================== 2-- Renderer (scrolling world) 3-- world_col = pixel_column + cam_x 4-- world_row = pixel_row + cam_y 5-- All comparisons in world-space (11-bit). 6-- Obstacles imported from level package (use work.level.all). 7-- 8-- Color priority: 9-- Arrow = White (111) > Char = Red (100) > Obs = Yellow (110) 10-- > Ground/Ceil/Walls = Green (010) > Trail = Magenta (101) > Sky = Black (000) 11-- ======================================================================== 12 13library IEEE; 14use IEEE.STD_LOGIC_1164.all; 15use IEEE.STD_LOGIC_ARITH.all; 16use IEEE.STD_LOGIC_UNSIGNED.all; 17use work.level.all; 18 19entity renderer is 20 port( 21 pixel_row : in std_logic_vector(9 downto 0); 22 pixel_column : in std_logic_vector(9 downto 0); 23 char_x : in std_logic_vector(10 downto 0); 24 char_y : in std_logic_vector(10 downto 0); 25 char_width : in std_logic_vector(9 downto 0); 26 char_height : in std_logic_vector(9 downto 0); 27 cam_x : in std_logic_vector(10 downto 0); 28 cam_y : in std_logic_vector(10 downto 0); 29 trail_on_in : in std_logic; 30 red : out std_logic; 31 green : out std_logic; 32 blue : out std_logic 33 ); 34end renderer; 35 36architecture behavior of renderer is 37 38 -- World boundaries (11-bit) 39 constant GROUND_TOP : std_logic_vector(10 downto 0) := CONV_STD_LOGIC_VECTOR(1488, 11); 40 constant CEIL_BOT : std_logic_vector(10 downto 0) := CONV_STD_LOGIC_VECTOR(8, 11); 41 constant LEFT_WALL : std_logic_vector(10 downto 0) := CONV_STD_LOGIC_VECTOR(8, 11); 42 constant RIGHT_WALL : std_logic_vector(10 downto 0) := CONV_STD_LOGIC_VECTOR(1492, 11); 43 44 -- World-space pixel coordinates (shared between processes) 45 signal wc : std_logic_vector(10 downto 0); 46 signal wr : std_logic_vector(10 downto 0); 47 48 signal char_on, ground_on, wall_on, ceiling_on, obs_on : std_logic; 49 50begin 51 52 -- Convert screen coordinates to world coordinates 53 wc <= ('0' & pixel_column) + cam_x; 54 wr <= ('0' & pixel_row) + cam_y; 55 56 -- ---------------------------------------------------------------- 57 -- Scene geometry: character, world edges, obstacles 58 -- ---------------------------------------------------------------- 59 render : process(wc, wr, char_x, char_y, char_width, char_height) 60 begin 61 char_on <= '0'; 62 ground_on <= '0'; 63 wall_on <= '0'; 64 ceiling_on <= '0'; 65 obs_on <= '0'; 66 67 -- Character 68 if wc >= char_x - ('0' & char_width) and 69 wc <= char_x + ('0' & char_width) and 70 wr >= char_y - ('0' & char_height) and 71 wr <= char_y + ('0' & char_height) then 72 char_on <= '1'; 73 end if; 74 75 -- World edges 76 if wr >= GROUND_TOP then ground_on <= '1'; end if; 77 if wr <= CEIL_BOT then ceiling_on <= '1'; end if; 78 if wc < LEFT_WALL or wc > RIGHT_WALL then wall_on <= '1'; end if; 79 80 -- Obstacles (loop over level_pkg arrays) 81 for obs_i in 0 to OBS_COUNT-1 loop 82 if wc >= OBS_L(obs_i) and wc <= OBS_R(obs_i) and 83 wr >= OBS_T(obs_i) and wr <= OBS_B(obs_i) then 84 obs_on <= '1'; 85 end if; 86 end loop; 87 88 end process render; 89 90 -- ---------------------------------------------------------------- 91 -- Color output with priority 92 -- ---------------------------------------------------------------- 93 color : process(char_on, ground_on, wall_on, ceiling_on, obs_on, trail_on_in) 94 begin 95 if char_on = '1' then 96 red <= '1'; green <= '0'; blue <= '0'; -- Red 97 elsif obs_on = '1' then 98 red <= '1'; green <= '1'; blue <= '0'; -- Yellow 99 elsif ground_on = '1' or ceiling_on = '1' then 100 red <= '0'; green <= '1'; blue <= '0'; -- Green 101 elsif wall_on = '1' then 102 red <= '0'; green <= '1'; blue <= '0'; -- Green 103 elsif trail_on_in = '1' then 104 red <= '1'; green <= '0'; blue <= '1'; -- Magenta 105 else 106 red <= '0'; green <= '0'; blue <= '0'; -- Black (sky) 107 end if; 108 end process color; 109 110end behavior;