?? ball.vhd
字號(hào):
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ball is
Port ( clk : in std_logic;
hcnt : in std_logic_vector(9 downto 0);
vcnt : in std_logic_vector(9 downto 0);
reset : in std_logic;
hit_target : in std_logic;
xsign : in std_logic; --mouse motion directoin of x
dataflag : in std_logic; --the flag of whether data output from mouse
board_loc : in std_logic_vector(9 downto 0);
--ball_loc : out std_logic_vector(9 downto 0);
ballx : out std_logic_vector(9 downto 0);
bally : out std_logic_vector(9 downto 0);
ballrgb : out std_logic_vector(7 downto 0));
end ball;
architecture Behavioral of ball is
CONSTANT FRAME_WIDTH : INTEGER :=20;
CONSTANT BOARD_WIDTH : INTEGER :=20;
CONSTANT BOARD_LEN : INTEGER :=40;
CONSTANT BALL_R : INTEGER :=5;
signal movclk : std_logic;
signal hcount : std_logic_vector(9 downto 0);
signal vcount : std_logic_vector(9 downto 0);
signal ball_x,ball_y : std_logic_vector(9 downto 0);
signal move_y : std_logic_vector(9 downto 0);
signal move_x,increase,ball_xx : std_logic_vector(10 downto 0);
signal lose : std_logic;--when '1' the ball is losen
signal bang : std_logic; --when '1' the ball hit the board
begin
movclk <= vcount(6);
hcount <= hcnt;
vcount <= vcnt;
ball_x <= ball_xx(10 downto 1);
ballx <= ball_x;
bally <= ball_y;
drawball: process (clk)
begin
if (clk'event and clk='1') then
if ((hcount>=(ball_x-5)) and (hcount<=(ball_x+5)) and (vcount>=(ball_y-2)) and (vcount<=(ball_y+2))) or
((hcount>=(ball_x-2)) and (hcount<=(ball_x+2)) and (vcount>=(ball_y-5)) and (vcount<=(ball_y+5))) or
((hcount>=(ball_x-3)) and (hcount<=(ball_x+3)) and (vcount>=(ball_y-4)) and (vcount<=(ball_y+4))) or
((hcount>=(ball_x-4)) and (hcount<=(ball_x+4)) and (vcount>=(ball_y-3)) and (vcount<=(ball_y+3))) then
ballrgb <= "00111111";
else
ballrgb <= "00000000";
end if;
end if;
end process;
ballmove: process (movclk,reset)
begin
if reset='0' then
ball_xx <= "01100100000";
ball_y <= "0100101100";
elsif (movclk'event and movclk='1') then
if (lose='1' or hit_target='1') then
ball_xx <= "01100100000";
ball_y <= "0100101100";
else
ball_xx <=ball_xx + move_x;
ball_y <=ball_y + move_y;
end if;
end if;
end process;
--select increasment of x direction
process( reset,movclk)
begin
if reset='0' then
increase <= "00000000010";
elsif (movclk'event and movclk='1') then
increase <= "00000000010";
if bang='1' then
if dataflag='1' then
if xsign='1' then
increase <= "00000000001";
else
increase <= "00000000011";
end if;
end if;
end if;
end if;
end process;
movablex: process (movclk,reset)
begin
if reset='0' then
move_x <= "00000000010";
elsif (movclk'event and movclk='1') then
if (ball_x=(FRAME_WIDTH + BALL_R)) then
move_x <= increase;
elsif (ball_x=(639-FRAME_WIDTH - BALL_R)) then
move_x <= not increase + "1";
end if;
end if;
end process;
movabley: process (movclk,reset)
begin
if reset='0' then
move_y <= "0000000001";
lose <= '0';
bang <= '0';
elsif (movclk'event and movclk='1') then
if (ball_y=(FRAME_WIDTH + BALL_R)) then
move_y <= "0000000001";
elsif (ball_y=(479-FRAME_WIDTH - BOARD_WIDTH - BALL_R)) then
if (ball_x>=(board_loc - BOARD_LEN+1)) and (ball_x<=(board_loc + BOARD_LEN-1)) then
move_y <= "1111111111";
lose <= '0';
bang <= '1';
else
lose <= '1';
bang <= '0';
end if;
else
lose <= '0';
bang <= '0';
end if;
end if;
end process;
end Behavioral;
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -