Quantcast
Channel: Altera Forums
Viewing all articles
Browse latest Browse all 19390

Snake game using FPGA in VHDL

$
0
0
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 automatically? (as snake game) 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?

This is my code:


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;

Viewing all articles
Browse latest Browse all 19390

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>