Im coding a snake game in VHDL using the DE2-115 FPGA from Altera. I have connected the FPGA with a monitor using VGA protocol to show the game.
I have a problem to show the snake and to move it around the monitor with all push bottom (the FPGA has 4, up/down/left/right)
In the code it is used SQ_X1 and SQ_Y1 to do the movement every moment a push bottom is in low state.
Is any other way to do the movement? without press any bottom (with a loop or something like this) and to change of direction whe the bottom is pressed to simulate the snake movement?
ARCHITECTURE behavior OF hw_image_generator IS
SIGNAL SQ_X1,SQ_Y1: INTEGER RANGE 0 TO 1688:=400; --initial position X
SIGNAL SQ_X2,SQ_Y2: INTEGER RANGE 0 TO 1688:=600; --initial position Y
SIGNAL DRAW: STD_LOGIC;
BEGIN
SQ(column,row,SQ_X1,SQ_Y1,DRAW); -- function that print a square (head of snake with SQ variables)
PROCESS(disp_ena, row, column, down, up, left, right)
BEGIN
IF(disp_ena = '1') THEN --display time
IF (column=19 or column=1901 or row=19 or row=1181) THEN -- print the border
red <= (OTHERS => '1');
green <= (OTHERS => '0');
blue <= (OTHERS => '0');
ELSE
red <= (OTHERS => '0');
green <= (OTHERS => '0');
blue <= (OTHERS => '0');
END IF;
IF (DRAW = '1') THEN -- it comes from a package that print a square (head of snake)
red <= (OTHERS => '1');
green <= (OTHERS => '1');
blue <= (OTHERS => '1');
END IF;
--up, down right and left are input of FPGA (push bottom)
--SQs are the current postions of X and Y and the add is to make the movement
IF(up='0' AND down='1' AND right='1' AND left='1' )THEN
IF (SQ_X1-40 > 20) THEN
SQ_X1<=SQ_X1-40;
END IF;
END IF;
IF(up='1' AND down='0' AND right='1' AND left='1')THEN
IF (SQ_X1+40 < 1180) THEN
SQ_X1<=SQ_X1+40;
END IF;
END IF;
IF(tup='1' AND down='1' AND right='0' AND left='1')THEN
IF (SQ_Y1+40 < 1900) THEN
SQ_Y1<=SQ_Y1+40;
END IF;
END IF;
IF(up='1' AND down='1' AND right='1' AND left='0')THEN
IF (SQ_Y1-40 > 20) THEN
SQ_Y1<=SQ_Y1-40;
END IF;
END IF;
END IF;
END PROCESS;
END BEHAVIOR;
SQ_X1<=SQ_X1+40;into hardware? Solution 1: Synthesis complains a multiple driver issue. Solution 2: Synthesis infers latches -> this is no good style and in 99.99% of designs an error. - Paebbels