library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Game_digit is port( clk : in std_logic; move_left_input : in std_logic; move_right_input : in std_logic; shoot_input : in std_logic; rows : out std_logic_vector(1 to 5) := (others => '0'); cols : out std_logic_vector(1 to 7) := (others => '0') ); end entity Game_digit; architecture Game_digit_arch of Game_digit is component display port( clk : in std_logic; row_1 : in std_logic_vector(1 to 5); row_2 : in std_logic_vector(1 to 5); row_3 : in std_logic_vector(1 to 5); row_4 : in std_logic_vector(1 to 5); row_5 : in std_logic_vector(1 to 5); row_6 : in std_logic_vector(1 to 5); row_7 : in std_logic_vector(1 to 5); rows_out : out std_logic_vector(1 to 5) := (others => '0'); cols_out : out std_logic_vector(1 to 7) := (others => '0') ); end component; component button port( clk : in std_logic; input : in std_logic; output : out std_logic ); end component; component Pseudo_random_generator port ( clk : in std_logic; en : in std_logic; output : out std_logic_vector (4 downto 0) ); end component; --ENEMIES-- constant ENEMY_SPEED : integer := 63; signal enemy_counter : integer range 0 to ENEMY_SPEED := 0; signal random_enemies_row : std_logic_vector (1 to 5); signal en_enemies : std_logic := '0'; --SHOOT-- constant SHOOT_SPEED : integer := 1000; type shoot_position_array is array (1 to 2) of integer range 1 to 7; --(i,j)-- signal shoot_position : shoot_position_array; signal shoot : std_logic; signal shoot_counter : integer range 0 to SHOOT_SPEED := 0; signal en_shoot : boolean := true; --MOVE-- signal move_left : std_logic; signal move_right : std_logic; signal player_position : integer range 1 to 5 := 3; --LED-- type matrix is array (1 to 7) of std_logic_vector(1 to 5); signal led_matrix : matrix := (7 => "00100", others=>(others=>'0')); --OTHERS-- signal reset : std_logic := '0'; begin display_matrix : display port map(clk,led_matrix(1),led_matrix(2),led_matrix(3),led_matrix(4),led_matrix(5),led_matrix(6),led_matrix(7),rows,cols); button_mv_left : button port map(clk,move_left_input,move_left); button_mv_right : button port map(clk,move_right_input,move_right); button_sh : button port map(clk,shoot_input,shoot); ennemies_generator : Pseudo_random_generator port map(clk,en_enemies,random_enemies_row); main : process(clk,move_left,move_right,shoot) begin if rising_edge(clk) then --ENEMIES UPDATE + GENERATION-- enemy_counter <= enemy_counter + 1; if enemy_counter = ENEMY_SPEED then for i in 6 downto 2 loop led_matrix(i) <= led_matrix(i-1); end loop; led_matrix(1) <= random_enemies_row; en_enemies <= '1'; led_matrix(shoot_position(1))(shoot_position(2)) <= '1'; led_matrix(shoot_position(1)-1)(shoot_position(2)) <= '0'; else en_enemies <= '0'; end if; --PLAYER MOVE-- if move_left = '1' and player_position > 1 then led_matrix(7) <= std_logic_vector(shift_left(unsigned(led_matrix(7)),1)); player_position <= player_position - 1; elsif move_right = '1' and player_position < 5 then led_matrix(7) <= std_logic_vector(shift_right(unsigned(led_matrix(7)),1)); end if; --PLAYER SHOOT-- if (shoot = '1') and en_shoot then shoot_position(1) <= 6; shoot_position(2) <= player_position; shoot_counter <= 0; en_shoot <= false; end if; --UPDATE PREVIOUS SHOOT-- if not(en_shoot) then if shoot_counter = SHOOT_SPEED then --first row ?-- if (shoot_position(1) = 1) then led_matrix(1)(shoot_position(2)) <= '0'; en_shoot <= true; --enemy touched?-- elsif led_matrix(shoot_position(1)-1)(shoot_position(2)) = '1' then led_matrix(shoot_position(1)-1)(shoot_position(2)) <= '0'; led_matrix(shoot_position(1))(shoot_position(2)) <= '0'; en_shoot <= true; elsif shoot_position(1) = 6 then led_matrix(6)(shoot_position(2)) <= '1'; else led_matrix(shoot_position(1)-1)(shoot_position(2)) <= '1'; led_matrix(shoot_position(1))(shoot_position(2)) <= '0'; shoot_position(1) <= shoot_position(1) + 1; en_shoot <= false; end if; else shoot_counter <= shoot_counter + 1; end if; end if; --GAME OVER ?-- for i in 1 to 5 loop if((led_matrix(6)(i) = '1') and (not(shoot_position(1) = 6)) and (not(i = shoot_position(2)))) then reset <= '1'; else reset <= '0'; end if; end loop; end if; end process main; end architecture Game_digit_arch;