📄 state5.vhd
字号:
library ieee;
use ieee.std_logic_1164.all;
entity state5 is
port(clk:in std_logic;
statein5:in bit_vector(1 downto 0);
dir:in integer range 0 to 5;
m:in std_logic_vector(0 to 8);
rightIn,leftIn:in std_logic;
px:in integer range 0 to 15;
py:in integer range 0 to 15;
change0:out integer range 0 to 8;
change1:out integer range 0 to 8;
dirout:out integer range 0 to 5;
fail:out bit;
move:out bit_vector(1 downto 0));
end state5;
architecture main of state5 is
signal ch0:integer range 0 to 8:=4;
signal ch1:integer range 0 to 8:=4;
signal f:bit:='0';
signal mo:bit_vector(1 downto 0):="00";
signal d:integer range 0 to 5:=dir;
signal right,left:std_logic;
begin
right<=not rightIn;
left<=not leftIn;
change0<=ch0;
change1<=ch1;
fail<=f;
move<=mo;
dirout<=d;
process(clk)
begin
if(falling_edge(clk)) then
if(statein5="00") then
ch0<=4;
ch1<=4;
f<='0';
mo<="00";
d<=dir;
case dir is
when 0 => --direction of up-left
if (m(3)='1') or (px=15) then
if (py=0) then
d<=3;
elsif(m(1)='1') then
d<=3;
ch0<=1;
elsif(m(2)='1') then
d<=3;
ch0<=2;
else
d<=2;
end if;
if (m(3)='1') then ch1<=3; end if;
elsif (m(1)='1') or (py=0) then
if(m(6)='1') then
d<=3;
ch0<=6;
else
d<=5;
end if;
if(m(1)='1') then ch1<=1; end if;
elsif(m(0)='1') then
ch0<=0;
d<=3;
end if;
when 1 => --direction of up
if (m(1)='1') or (py=0) then
d<=4;
if(m(1)='1') then ch0<=1; end if;
end if;
when 2 => --direction of up-right
if(m(5)='1') or (px=0) then
if(py=0) then
d<=5;
elsif(m(1)='1') then
d<=5;
ch0<=1;
elsif(m(0)='1') then
d<=5;
ch0<=0;
else
d<=0;
end if;
if(m(5)='1') then ch1<=5; end if;
elsif(m(1)='1') or (py=0) then
if(m(8)='1') then
d<=5;
ch0<=8;
else
d<=3;
end if;
if(m(1)='1') then ch1<=1; end if;
elsif(m(2)='1') then
d<=5;
ch0<=2;
end if;
when 3 => --fail the game
if(py=15) then
f<='1';
elsif(py=14) then --reflect by the board
if(px=0)then
if(m(7)='1') then
d<=0;
elsif(m(6)='1') then
d<=0;
else
d<=5;
end if;
elsif(m(7)='1') then
if(left='1') then
d<=1;
else
d<=2;
if(right='1') then mo<="01"; end if;
end if;
elsif(m(8)='1') then
d<=0;
end if;
--reflect by the board
--interact with the bricks
else
if (m(5)='1') or (px=0) then
if(m(7)='1') then
d<=0;
ch0<=7;
elsif(m(6)='1')then
d<=0;
ch0<=6;
else
d<=5;
end if;
if(m(5)='1') then ch1<=5; end if;
elsif(m(7)='1') then
ch0<=7;
if(m(2)='1')then
d<=0;
ch1<=2;
else
d<=2;
end if;
elsif(m(2)='1') then
d<=0;
ch0<=2;
end if; --interact with the bricks
end if;
when 4 =>
if(py=15)then
f<='1';
elsif(py=14) then
if(m(7)='1') then
if(left='1')and(m(3)='0')then
d<=0;
elsif(right='1')and(m(5)='0') then
d<=2;
else
d<=1;
end if;
end if;
end if;
when 5 =>
--fail the game
if(py=15) then
f<='1';
--reflect by the board
elsif(py=14) then
if(px=15)then
if( m(7)='1') then
d<=2;
elsif(m(8)='1') then
d<=2;
else
d<=3;
end if;
elsif(m(7)='1') then
if(right='1') then
d<=1;
else
d<=0;
if(left='1') then mo<="10";end if;
end if;
elsif(m(6)='1') then
d<=2;
end if;
--reflect by the board
--interact with the bricks
else
if(m(3)='1') or (px=15) then
if(m(7)='1') then
d<=2;
ch0<=7;
elsif(m(8)='1')then
d<=2;
ch0<=8;
else
d<=3;
end if;
if(m(3)='1') then ch1<=3; end if;
elsif(m(7)='1') then
ch0<=7;
if(m(0)='1') then
d<=2;
ch1<=0;
else
d<=0;
end if;
elsif(m(6)='1') then
d<=2;
ch0<=6;
end if;
--interact with the bricks
end if;
end case;
end if;
end if;
end process; --deal with the event when colliding with the bricks or the wall
end main;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -