I want to make a game in which the user controls a 10 by 10 pixel block (initially spawned on the left side of the screen) with the use of the L,R,U,D buttons on the FPGA in order to avoid/collect (haven't decided yet) other (same size or smaller) blocks that come "flying in" from the right side of the screen.
What I have written so far is the main block controllable with the buttons, unable to go off-screen.
signal cntBlockH: integer range 0 to cstHorAL - 1 := cstHorAL / 8; -- horizontal position
-- cstHorAL - pixels / active lines
signal cntBlockV: integer range 0 to cstVerAF - 1 := cstVerAF / 2; -- vertical position
-- cstVerAF - lines / active frames
signal flgBlock: STD_LOGIC; -- '1' when on block
BlockMove: process (clk100Hz)
begin
if rising_edge (clk100Hz) then
if btnL = '1' then
cntBlockH <= cntBlockH - 1;
if cntBlockH - 9 = 0 then
cntBlockH <= cntBlockH;
end if;
elsif btnR = '1' then
cntBlockH <= cntBlockH + 1;
if cntBlockH + 9 = cstHorAL - 1 then
cntBlockH <= cntBlockH;
end if;
end if;
if btnU = '1' then
cntBlockV <= cntBlockV - 1;
if cntBlockV - 9 = 0 then
cntBlockV <= cntBlockV;
end if;
elsif btnD = '1' then
cntBlockV <= cntBlockV + 1;
if cntBlockV + 9 = cstVerAF - 1 then
cntBlockV <= cntBlockV;
end if;
end if;
end if;
end process;
flgBlock <= '1' when ((adrH >= cntBlockH - 9 and adrH <= cntBlockH + 9) AND
(adrV >= cntBlockV - 9 and adrV <= cntBlockV + 9)) else
'0';
red <= "1111" when flgBlock = '1' else
"0000";
blu <= "1111" when flgBlock = '1' else
"0000";
My question is: how can I randomly generate these other moving blocks so they traverse the screen from right to left but on different positions, each of them appearing after a given time interval (like 2 seconds)?
Any help is appreciated. Thanks!
Aucun commentaire:
Enregistrer un commentaire