1
fork

Configure Feed

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

feat: camera lag

+44 -11
+43 -10
physics_engine.vhd
··· 105 105 variable grounded : std_logic; 106 106 variable c_left, c_right, c_top, c_bot : std_logic_vector(10 downto 0); 107 107 variable overlap_x, overlap_y : std_logic_vector(10 downto 0); 108 + variable tcx, tcy, dcx, dcy : std_logic_vector(10 downto 0); 108 109 begin 109 110 wait until vert_sync'event and vert_sync = '1'; 110 111 ··· 142 143 if vx(9) = '0' then 143 144 if vx > 0 then 144 145 if vx(9 downto 2) = "00000000" then vx := vx - 1; 145 - else vx := vx - ("000" & vx(9 downto 3)); end if; 146 + else vx := vx - ("00" & vx(9 downto 2)); end if; 146 147 end if; 147 148 else 148 149 if vx /= "0000000000" then ··· 267 268 pos_x <= px; 268 269 pos_y <= py; 269 270 270 - -- == CAMERA: center on character (px/py), clamp to world == 271 - -- cam_x = clamp(px - 320, 0, 860) [1500 - 640 = 860] 271 + -- == CAMERA: lag-follow character (1/8 of gap per frame, min 1px) == 272 + -- Compute clamped target 272 273 if px < CONV_STD_LOGIC_VECTOR(320, 11) then 273 - cam_x_sig <= (others => '0'); 274 + tcx := (others => '0'); 274 275 elsif px > CONV_STD_LOGIC_VECTOR(1180, 11) then 275 - cam_x_sig <= CONV_STD_LOGIC_VECTOR(860, 11); 276 + tcx := CONV_STD_LOGIC_VECTOR(860, 11); 276 277 else 277 - cam_x_sig <= px - CONV_STD_LOGIC_VECTOR(320, 11); 278 + tcx := px - CONV_STD_LOGIC_VECTOR(320, 11); 278 279 end if; 279 280 280 - -- cam_y = clamp(py - 240, 0, 1020) [1500 - 480 = 1020] 281 281 if py < CONV_STD_LOGIC_VECTOR(240, 11) then 282 - cam_y_sig <= (others => '0'); 282 + tcy := (others => '0'); 283 283 elsif py > CONV_STD_LOGIC_VECTOR(1260, 11) then 284 - cam_y_sig <= CONV_STD_LOGIC_VECTOR(1020, 11); 284 + tcy := CONV_STD_LOGIC_VECTOR(1020, 11); 285 285 else 286 - cam_y_sig <= py - CONV_STD_LOGIC_VECTOR(240, 11); 286 + tcy := py - CONV_STD_LOGIC_VECTOR(240, 11); 287 + end if; 288 + 289 + -- Slide camera toward target 290 + if cam_x_sig < tcx then 291 + dcx := tcx - cam_x_sig; 292 + if dcx(10 downto 3) = "00000000" then 293 + cam_x_sig <= cam_x_sig + 1; 294 + else 295 + cam_x_sig <= cam_x_sig + ("000" & dcx(10 downto 3)); 296 + end if; 297 + elsif cam_x_sig > tcx then 298 + dcx := cam_x_sig - tcx; 299 + if dcx(10 downto 3) = "00000000" then 300 + cam_x_sig <= cam_x_sig - 1; 301 + else 302 + cam_x_sig <= cam_x_sig - ("000" & dcx(10 downto 3)); 303 + end if; 304 + end if; 305 + 306 + if cam_y_sig < tcy then 307 + dcy := tcy - cam_y_sig; 308 + if dcy(10 downto 3) = "00000000" then 309 + cam_y_sig <= cam_y_sig + 1; 310 + else 311 + cam_y_sig <= cam_y_sig + ("000" & dcy(10 downto 3)); 312 + end if; 313 + elsif cam_y_sig > tcy then 314 + dcy := cam_y_sig - tcy; 315 + if dcy(10 downto 3) = "00000000" then 316 + cam_y_sig <= cam_y_sig - 1; 317 + else 318 + cam_y_sig <= cam_y_sig - ("000" & dcy(10 downto 3)); 319 + end if; 287 320 end if; 288 321 289 322 -- == SQUISH ==
+1 -1
renderer.vhd
··· 3 3 -- world_col = pixel_column + cam_x 4 4 -- world_row = pixel_row + cam_y 5 5 -- All comparisons in world-space (11-bit). 6 - -- Obstacles imported from level_pkg (use work.level_pkg.all). 6 + -- Obstacles imported from level package (use work.level.all). 7 7 -- ======================================================================== 8 8 9 9 library IEEE;