diff options
Diffstat (limited to 'src/bounce.vhd')
| -rw-r--r-- | src/bounce.vhd | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/bounce.vhd b/src/bounce.vhd index de1e0e1..2a5c187 100644 --- a/src/bounce.vhd +++ b/src/bounce.vhd @@ -5,6 +5,7 @@ use ieee.std_logic_unsigned.all; use ieee.numeric_std.all; entity bounce is + -- bounce motion port ( clk, reset: in std_logic; x, y: out std_logic_vector(9 downto 0)); @@ -16,35 +17,37 @@ architecture Behavioral of bounce is signal direction: std_logic_vector(1 downto 0) := "00"; constant velocity: natural := 1; + -- current square position signal temp_x, temp_y: std_logic_vector(9 downto 0) := (others => '0'); begin - x <= temp_x; - y <= temp_y; + x <= temp_x; + y <= temp_y; process(clk, reset) begin if reset = '1' then - direction <= "00"; + -- async reset + direction <= "00"; -- reset direction to bottom right temp_x <= (others => '0'); temp_y <= (others => '0'); elsif rising_edge(clk) then if direction(0) = '0' then - temp_x <= temp_x + velocity; + temp_x <= temp_x + velocity; -- move left if (temp_x + velocity) > 630 then direction(0) <= '1'; end if; else - temp_x <= temp_x - velocity; + temp_x <= temp_x - velocity; -- move right if (temp_x - velocity) <= 0 then direction(0) <= '0'; end if; end if; if direction(1) = '0' then - temp_y <= temp_y + 1; + temp_y <= temp_y + 1; -- move down if (temp_y + velocity) > 470 then direction(1) <= '1'; end if; else - temp_y <= temp_y - 1; + temp_y <= temp_y - 1; -- move up if (temp_y - velocity) <= 0 then direction(1) <= '0'; end if; |