title: Snake game using FPGA in VHDL
body: <p>Im coding a snake game in VHDL using the <strong>DE2-115 FPGA</strong> from <strong>Altera</strong>. I have connected the FPGA with a monitor using VGA protocol to show the game. </p>
  
  <p>I have a problem to show the snake and to move it around the monitor with all push bottom (the FPGA has 4, <strong>up/down/left/right</strong>)</p>
  
  <p>In the code it is used <strong>SQ_X1</strong> and <strong>SQ_Y1</strong> to do the movement every moment a push bottom is in low state. </p>
  
  <p>Is any other way to do the <strong>movement</strong>? without press any bottom (with a <strong>loop</strong> or something like this) and to <strong>change of direction</strong> whe the bottom is pressed to simulate the snake movement? </p>
  
  <pre><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 &lt;= (OTHERS =&gt; '1'); 
                  green   &lt;= (OTHERS =&gt; '0');
                  blue &lt;= (OTHERS =&gt; '0');
              ELSE
                  red &lt;= (OTHERS =&gt; '0');
                  green   &lt;= (OTHERS =&gt; '0');
                  blue &lt;= (OTHERS =&gt; '0');
              END IF;
  
              IF (DRAW = '1') THEN   -- it comes from a package that print a square (head of snake)
                  red &lt;= (OTHERS =&gt; '1');
                  green   &lt;= (OTHERS =&gt; '1');
                  blue &lt;= (OTHERS =&gt; '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 &gt; 20) THEN 
                      SQ_X1&lt;=SQ_X1-40;
                  END IF;        
              END IF;
  
              IF(up='1' AND down='0' AND right='1' AND left='1')THEN
                  IF (SQ_X1+40 &lt; 1180) THEN 
                      SQ_X1&lt;=SQ_X1+40;
                  END IF; 
              END IF;
              IF(tup='1' AND down='1' AND right='0' AND left='1')THEN
                  IF (SQ_Y1+40 &lt; 1900) THEN 
                      SQ_Y1&lt;=SQ_Y1+40;
                  END IF; 
              END IF;
              IF(up='1' AND down='1' AND right='1' AND left='0')THEN
                  IF (SQ_Y1-40 &gt; 20) THEN 
                      SQ_Y1&lt;=SQ_Y1-40;
                  END IF;
              END IF;
          END IF;
  
      END PROCESS;
  END BEHAVIOR;
  </code></pre>