- Joined
- Apr 29, 2012
- Messages
- 2
- Reaction score
- 0
I am working on a design for a game of "snake". To determine the next position of the snake, I have a section of code that uses arrays to store the position of the snake and variables to store the index values of the head and tail of the snake. Then I have a 'for' loop that goes through every element of the array to determine the next position of the snake based on the value of the "direction" signal
My problem is that the positions aren't updating. Now I'm not very familiar with using loops in VHDL but I have a feeling it may have something to do with the way I compare the index values of the loop to values stored in the variables. Any insight you all can give me would be greatly appreciated. Here is part of the code:
It should be noted that I currently have the direction fixed to "000"
My problem is that the positions aren't updating. Now I'm not very familiar with using loops in VHDL but I have a feeling it may have something to do with the way I compare the index values of the loop to values stored in the variables. Any insight you all can give me would be greatly appreciated. Here is part of the code:
Code:
snake_motion : process(clk, reset, dir, mov_en, snake_pos, snake_dir)
variable r_head_next : integer;
variable c_head_next : integer;
variable r_tail_next : integer;
variable c_tail_next : integer;
variable r_head : integer;
variable c_head : integer;
variable r_tail : integer;
variable c_tail : integer;
begin
if reset = '1' then -- assign default values upon reset
snake_pos <= snake_pos_def;
snake_pos_next <= snake_pos_def;
snake_dir <= snake_dir_def;
snake_dir_next <= snake_dir_def;
r_head := r_head_def;
r_tail := r_tail_def;
c_head := c_head_def;
c_tail := c_tail_def;
elsif (clk'EVENT and clk = '0') then
mov_en <= '1';
elsif (clk'EVENT and clk = '1') then
snake_pos <= snake_pos_next;
snake_dir <= snake_dir_next;
r_head := r_head_next;
r_tail := r_tail_next;
c_head := c_head_next;
c_tail := c_tail_next;
end if;
if mov_en = '1' then
for r in 0 to max_row loop
for c in 0 to max_col loop
if ((r = r_head) and (c = c_head)) then -- head of snake
snake_dir_next(r,c) <= dir;
if dir = "000" then
if r = max_row then
r_head_next := 0;
snake_pos_next(0,c) <= '1';
else
r_head_next := (r+1);
snake_pos_next((r+1),c) <= '1';
end if;
elsif dir = "001" then
......