我是vhdl的新手,但我正在尝试建立一个蛇游戏。在下面的循环中,eat ='1'和ate ='0'的约束似乎不起作用。就好像嵌套在if语句中的代码总是运行一样。
有问题的if语句
if(snake_body_ram(i)(14)='1' or (eating='1' and ate='0'))then
这是整个过程
process(move, direction, snake_head_reg, snake_body_ram, clk, head_coord, direction, eating)
variable dir_next, tail_next_dir : std_logic_vector(1 downto 0);
variable coord_next : std_logic_vector(13 downto 0);
variable ate: std_logic := '0';
variable value : unsigned(5 downto 0) := (others=>'0');
begin
if(clk'event and clk='1')then
if(move='1')then
dir_next := snake_head_reg(16 downto 15);
coord_next := snake_head_reg(13 downto 0);
snake_head_reg(16 downto 15) <= direction;
snake_head_reg(13 downto 0) <= head_coord;
ate:='0';
--look here brian
bodyLabel:
for i in 0 to 35 loop
if(snake_body_ram(i)(14)='1' or (eating='1' and ate='0'))then
snake_body_ram(i)(16 downto 15) <= dir_next;
snake_body_ram(i)(13 downto 0) <= coord_next;
snake_body_ram(i)(14) <= '1';
if(eating='1')then
ate:='1';
end if;
dir_next := snake_body_ram(i)(16 downto 15);
coord_next := snake_body_ram(i)(13 downto 0);
if(i > 1)then
tail_next_dir:=snake_body_ram(i-1)(16 downto 15);
end if;
end if;
end loop;
snake_tail_reg(13 downto 0) <= coord_next;
snake_tail_reg(14)<='1';
snake_tail_reg(16 downto 15) <= tail_next_dir;
end if;
end if;
end process;
这是设置“吃”的过程
process(food_reg, snake_head_reg, clk, move, state, btn, snake_tail_reg, snake_body_ram)
--variable ate : std_logic := '0';
begin
--if(clk'event and clk='1' and move='1' and state=play)then
if(clk'event and clk='1')then
eating <= '0';
if(move='1' and state=play)then
you_lose <= '0';
--if()then
if(food_reg = snake_head_reg(13 downto 0))then
--ate food
food_eaten <= food_eaten_next;
eating <= '1';
elsif(snake_head_reg(13 downto 0) = snake_tail_reg(13 downto 0))then
--hit tail
you_lose <= '1';
elsif(unsigned(snake_head_reg(13 downto 7)) < 2 or unsigned(snake_head_reg(13 downto 7)) > 77 or unsigned(snake_head_reg(6 downto 0)) < 2 or unsigned(snake_head_reg(6 downto 0)) > 57)then
--hit a wall
you_lose <= '1';
else
--check for body
bodyLabel:
for i in 0 to 35 loop
if(snake_body_ram(i)(14)='1' and you_lose = '0')then
if(snake_head_reg(13 downto 0) = snake_body_ram(i)(13 downto 0)) then
you_lose <= '1';
exit;
end if;
else
exit;
end if;
end loop;
end if;
--end if;
end if;
else
end if;
end process;
我试图将共享整个文件所需的信息包括在内。如果您需要更多信息,请告诉我。感谢您花时间阅读此内容。