📄 top.vhd
字号:
rgb<=clpos; --画出pos2
elsif hcnt>brick1_x+1 and hcnt<brick1_x+14 and vcnt>brick1_y+8 and vcnt<brick1_y+51 then
rgb<=clbrick; --画出brick1
elsif hcnt>brick2_x+1 and hcnt<brick2_x+14 and vcnt>brick2_y+8 and vcnt<brick2_y+51 then
rgb<=clbrick; --画出brick2
elsif hcnt>brick3_x+1 and hcnt<brick3_x+14 and vcnt>brick3_y+8 and vcnt<brick3_y+51 then
rgb<=clbrick; --画出brick3
else
rgb<=clin; --画出区域内背景
end if;
elsif win_sign='0' then
-- 欢迎界面
if count_sec(23)='1' then
if (hcnt>31 and hcnt<37 and vcnt>250 and vcnt<280)
or (hcnt>33 and hcnt<42 and vcnt>295 and vcnt<320)
or (hcnt>42 and hcnt<45 and vcnt>280 and vcnt<320)
or (hcnt>30 and hcnt<33 and vcnt>330 and vcnt<350)
or (hcnt>37 and hcnt<40 and vcnt>330 and vcnt<350)
or (hcnt>27 and hcnt<30 and vcnt>360 and vcnt<380)
or (hcnt>35 and hcnt<38 and vcnt>360 and vcnt<380)then
rgb<="001";
elsif (hcnt>45 and hcnt<55 and vcnt>275 and vcnt<325) then
rgb<="110";
else
rgb<="000";
end if;
else
if (hcnt>29 and hcnt<35 and vcnt>250 and vcnt<280)
or (hcnt>31 and hcnt<40 and vcnt>295 and vcnt<320)
or (hcnt>40 and hcnt<43 and vcnt>280 and vcnt<320)
or (hcnt>30 and hcnt<33 and vcnt>330 and vcnt<350)
or (hcnt>35 and hcnt<38 and vcnt>330 and vcnt<350)
or (hcnt>29 and hcnt<32 and vcnt>360 and vcnt<380)
or (hcnt>37 and hcnt<40 and vcnt>360 and vcnt<380)then
rgb<="001";
elsif (hcnt>43 and hcnt<53 and vcnt>275 and vcnt<325) then
rgb<="110";
else
rgb<="000";
end if;
end if;
else --win_sign=1,life=0
if (vcnt>190 and vcnt<201 )and((hcnt>29 and hcnt<38) or (hcnt>46 and hcnt<53)or hcnt=60 or hcnt=61 or hcnt=68 or hcnt=69 or (hcnt>74 and hcnt<83))
then rgb<=clbox;
elsif (vcnt>200 and vcnt<211 )and(hcnt=30 or hcnt=31 or hcnt=38 or hcnt=39 or hcnt=45 or hcnt=46 or hcnt=53 or hcnt=54 or (hcnt>59 and hcnt<64)or hcnt=68 or hcnt=69 or hcnt=75 or hcnt=76)
then rgb<=clbox;
elsif (vcnt>210 and vcnt<221 )and(hcnt=30 or hcnt=31 or hcnt=38 or hcnt=39 or hcnt=45 or hcnt=46 or hcnt=53 or hcnt=54 or hcnt=60 or hcnt=61 or hcnt=64 or hcnt=65 or hcnt=68 or hcnt=69 or (hcnt>74 and hcnt<83))
then rgb<=clbox;
elsif (vcnt>220 and vcnt<231 )and(hcnt=30 or hcnt=31 or hcnt=38 or hcnt=39 or hcnt=45 or hcnt=46 or hcnt=53 or hcnt=54 or hcnt=60 or hcnt=61 or(hcnt>65 and hcnt<70) or hcnt=75 or hcnt=76)
then rgb<=clbox;
elsif (vcnt>230 and vcnt<241 )and((hcnt>29 and hcnt<38) or (hcnt>46 and hcnt<53)or hcnt=60 or hcnt=61 or hcnt=68 or hcnt=69 or (hcnt>74 and hcnt<83))
then rgb<=clbox;
else
rgb<=clgrid;
end if;
end if; --end win_sign
else
if vcnt>450 and vcnt<490 and hcnt>16 and hcnt<91 then
if life_sign='1' then
if (dout2>0 and hcnt<20 and hcnt>15) or
(dout2>1 and hcnt<25 and hcnt>20 ) or
(dout2>2 and hcnt<30 and hcnt>25 ) or
(dout2>3 and hcnt<35 and hcnt>30 ) or
(dout2>4 and hcnt<40 and hcnt>35 ) then
rgb<="100";
else rgb<=clback;
end if;
end if;
elsif vcnt>400 and vcnt<440 and hcnt>16 and hcnt<91 then
if life_sign='1' then
if ((dout=0 or dout>0)and hcnt<20 and hcnt>15) or
(dout>0 and hcnt<25 and hcnt>20 ) or
(dout>1 and hcnt<30 and hcnt>25 ) or
(dout>2 and hcnt<35 and hcnt>30 ) or
(dout>3 and hcnt<40 and hcnt>35 ) or
(dout>4 and hcnt<45 and hcnt>40 ) or
(dout>5 and hcnt<50 and hcnt>45 ) or
(dout>6 and hcnt<55 and hcnt>50 ) or
(dout>7 and hcnt<60 and hcnt>55 ) or
(dout>8 and hcnt<65 and hcnt>60 ) then
rgb<="100";
else rgb<=clback;
end if;
else
rgb<="010";
end if;
else
rgb<="000"; --区域外背景
end if;
end if;
end if;
end process;
ori_clk<=ori_clkin;
process(clk,push_reset,start) ----用户控制boy位置横纵坐标移动,及必要的box位置横纵坐标移动
begin
if push_reset='0' then --重启设置为默认值'0'
win_sign<='0';
life_sign<='0';
boy_x<= "00111101";
boy_y<="001000001";
box1_x<= "00011111";
box1_y<="011000001";
box2_x<= "00101110";
box2_y<="100000001";
brick1_x<="00111101"; --BRICK1位置
brick1_y<="010000001";
brick2_x<= "00101110"; --BRICK2位置
brick2_y<="011000001";
brick3_x<= "00111101"; --BRICK3位置
brick3_y<="011000001";
pos1_x<= "00010000"; --POS1位置
pos1_y<="101000001";
pos2_x<="00101110"; --POS2位置
pos2_y<="101000001";
elsif clk'event and clk='1' then
if start = '0' then --重启时置位于初始位置
life_sign<='1';
if (win_sign<='0')then
boy_x<= "00111101";
boy_y<="001000001";
box1_x<= "00011111";
box1_y<="011000001";
box2_x<= "00101110";
box2_y<="100000001";
brick1_x<="00111101"; --BRICK1位置
brick1_y<="010000001";
brick2_x<= "00101110"; --BRICK2位置
brick2_y<="011000001";
brick3_x<= "00111101"; --BRICK3位置
brick3_y<="011000001";
pos1_x<= "00010000"; --POS1位置
pos1_y<="101000001";
pos2_x<="00101110"; --POS2位置
pos2_y<="101000001";
else
brick1_x<= "00010000"; --BRICK1位置
brick1_y<="011000001";
brick2_x<= "00111101"; --BRICK2位置
brick2_y<="011000001";
brick3_x<= "00111101";
brick3_y<="101000001";
pos1_x <= "00111101"; --POS1位置
pos1_y <="010000001";
pos2_x <= "01001100"; --POS2位置
pos2_y <="011000001";
box1_x <= "00011111"; --BOX1位置
box1_y <="011000001";
box2_x <= "00011111"; --BOX2位置
box2_y <="100000001";
boy_x <= "00101110";
boy_y <="011000001";
end if;
elsif (box1_x=pos1_x and box1_y=pos1_y and box2_x=pos2_x and box2_y=pos2_y)
or(box2_x=pos1_x and box2_y=pos1_y and box1_x=pos2_x and box1_y=pos2_y) then --完成任务设置为'1'
if win_sign='0' then
win_sign<='1';
else
life_sign<='0';
end if;
elsif life_sign='1' then --用户可以操控移动boy时
if data_ready='1' then
case data_in is
when X"6B" => --left
if (boy_x=box1_x+15 and boy_y=box1_y) then
if (box1_x=box2_x+15 and box1_y=box2_y) or (box1_x=brick1_x+15 and box1_y=brick1_y)
or (box1_x=brick2_x+15 and box1_y=brick2_y) or (box1_x=brick3_x+15 and box1_y=brick3_y) or box1_x=16 then
boy_x<=boy_x+0;
else box1_x<=box1_x-15;
boy_x<=boy_x-15; --move right
end if;
elsif (boy_x=box2_x+15 and boy_y=box2_y) then
if (box2_x=box1_x+15 and box2_y=box1_y) or (box2_x=brick1_x+15 and box2_y=brick1_y)
or (box2_x=brick2_x+15 and box2_y=brick2_y) or (box2_x=brick3_x+15 and box2_y=brick3_y) or box2_x=16 then
boy_x<=boy_x-0;
else box2_x<=box2_x-15;
boy_x<=boy_x-15;
end if;
elsif boy_x=16 or (boy_x=brick1_x+15 and boy_y=brick1_y) or (boy_x=brick2_x+15 and boy_y=brick2_y)
or (boy_x=brick3_x+15 and boy_y=brick3_y) then --移动至下边界/砖上时不动
boy_x<=boy_x-0;
else
boy_x<=boy_x-15;
end if;
when X"74" => --right
if (boy_x=box1_x-15 and boy_y=box1_y) then
if (box1_x=box2_x-15 and box1_y=box2_y) or (box1_x=brick1_x-15 and box1_y=brick1_y)
or (box1_x=brick2_x-15 and box1_y=brick2_y) or (box1_x=brick3_x-15 and box1_y=brick3_y) or box1_x=76 then
boy_x<=boy_x+0;
else box1_x<=box1_x+15;
boy_x<=boy_x+15; --move right
end if;
elsif (boy_x=box2_x-15 and boy_y=box2_y) then
if (box2_x=box1_x-15 and box2_y=box1_y) or (box2_x=brick1_x-15 and box2_y=brick1_y)
or (box2_x=brick2_x-15 and box2_y=brick2_y) or (box2_x=brick3_x-15 and box2_y=brick3_y) or box2_x=76 then
boy_x<=boy_x-0;
else box2_x<=box2_x+15;
boy_x<=boy_x+15;
end if;
elsif boy_x=76 or (boy_x=brick1_x-15 and boy_y=brick1_y) or (boy_x=brick2_x-15 and boy_y=brick2_y)
or (boy_x=brick3_x-15 and boy_y=brick3_y) then --移动至下边界/砖上时不动
boy_x<=boy_x-0;
else
boy_x<=boy_x+15;
end if;
when X"75" => --up
if (boy_y=box1_y+64 and boy_x=box1_x) then
if (box1_y=box2_y+64 and box1_x=box2_x) or (box1_y=brick1_y+64 and box1_x=brick1_x)
or (box1_y=brick2_y+64 and box1_x=brick2_x) or (box1_y=brick3_y+64 and box1_x=brick3_x) or box1_y=65 then
boy_y<=boy_y+0;
else box1_y<=box1_y-64;
boy_y<=boy_y-64; --move up
end if;
elsif (boy_y=box2_y+64 and boy_x=box2_x) then
if (box2_y=box1_y+64 and box2_x=box1_x) or (box2_y=brick1_y+64 and box2_x=brick1_x)
or (box2_y=brick2_y+64 and box2_x=brick2_x) or (box2_y=brick3_y+64 and box2_x=brick3_x) or box2_y=65 then
boy_y<=boy_y-0;
else box2_y<=box2_y-64;
boy_y<=boy_y-64;
end if;
elsif boy_y=65 or (boy_y=brick1_y+64 and boy_x=brick1_x) or (boy_y=brick2_y+64 and boy_x=brick2_x)
or (boy_y=brick3_y+64 and boy_x=brick3_x) then --移动至下边界/砖上时不动
boy_y<=boy_y-0;
else
boy_y<=boy_y-64;
end if;
when X"72" => --down
if (boy_y=box1_y-64 and boy_x=box1_x) then
if (box1_y=box2_y-64 and box1_x=box2_x) or (box1_y=brick1_y-64 and box1_x=brick1_x)
or (box1_y=brick2_y-64 and box1_x=brick2_x) or (box1_y=brick3_y-64 and box1_x=brick3_x) or box1_y=321 then
boy_y<=boy_y+0;
else box1_y<=box1_y+64;
boy_y<=boy_y+64; --向下移动
end if;
elsif (boy_y=box2_y-64 and boy_x=box2_x) then
if (box2_y=box1_y-64 and box2_x=box1_x) or (box2_y=brick1_y-64 and box2_x=brick1_x)
or (box2_y=brick2_y-64 and box2_x=brick2_x) or (box2_y=brick3_y-64 and box2_x=brick3_x) or box2_y=321 then
boy_y<=boy_y-0;
else box2_y<=box2_y+64;
boy_y<=boy_y+64;
end if;
elsif boy_y=321 or (boy_y=brick1_y-64 and boy_x=brick1_x) or (boy_y=brick2_y-64 and boy_x=brick2_x)
or (boy_y=brick3_y-64 and boy_x=brick3_x) then --移动至下边界/砖上时不动
boy_y<=boy_y-0;
else
boy_y<=boy_y+64;
end if;
when others=>
null;
end case;
end if;
end if;
end if;
end process;
end VGA_arch;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -