diff --git a/TopModule_tb_behav.wcfg b/TopModule_tb_behav.wcfg index cce84f3d91f445e0744f1e37839213ff544a88a8..3f1f9da6588fa44cb11963106e09e0fdce986103 100644 --- a/TopModule_tb_behav.wcfg +++ b/TopModule_tb_behav.wcfg @@ -12,15 +12,15 @@ </db_ref> </db_ref_list> <zoom_setting> - <ZoomStartTime time="0.000 ns"></ZoomStartTime> - <ZoomEndTime time="3,827.071 ns"></ZoomEndTime> - <Cursor1Time time="1,000.000 ns"></Cursor1Time> + <ZoomStartTime time="0.000000 us"></ZoomStartTime> + <ZoomEndTime time="151.000001 us"></ZoomEndTime> + <Cursor1Time time="7.200000 us"></Cursor1Time> </zoom_setting> <column_width_setting> - <NameColumnWidth column_width="246"></NameColumnWidth> + <NameColumnWidth column_width="238"></NameColumnWidth> <ValueColumnWidth column_width="66"></ValueColumnWidth> </column_width_setting> - <WVObjectSize size="19" /> + <WVObjectSize size="22" /> <wvobject type="logic" fp_name="/TopModule_tb/DUT/clk25"> <obj_property name="ElementShortName">clk25</obj_property> <obj_property name="ObjectShortName">clk25</obj_property> @@ -89,12 +89,24 @@ <obj_property name="ElementShortName">button_pressed</obj_property> <obj_property name="ObjectShortName">button_pressed</obj_property> </wvobject> - <wvobject type="other" fp_name="/TopModule_tb/DUT/scoreDisplay/strobecnt"> - <obj_property name="ElementShortName">strobecnt</obj_property> - <obj_property name="ObjectShortName">strobecnt</obj_property> - </wvobject> <wvobject type="array" fp_name="/TopModule_tb/DUT/scoreDisplay/led_bcd"> <obj_property name="ElementShortName">led_bcd[3:0]</obj_property> <obj_property name="ObjectShortName">led_bcd[3:0]</obj_property> </wvobject> + <wvobject type="array" fp_name="/TopModule_tb/DUT/smallObstacle/lfsr_Q"> + <obj_property name="ElementShortName">lfsr_Q[9:0]</obj_property> + <obj_property name="ObjectShortName">lfsr_Q[9:0]</obj_property> + </wvobject> + <wvobject type="other" fp_name="/TopModule_tb/DUT/smallObstacle/pos_object_y_actual"> + <obj_property name="ElementShortName">pos_object_y_actual</obj_property> + <obj_property name="ObjectShortName">pos_object_y_actual</obj_property> + </wvobject> + <wvobject type="array" fp_name="/TopModule_tb/DUT/smallObstacle/fsm_state"> + <obj_property name="ElementShortName">fsm_state[1:0]</obj_property> + <obj_property name="ObjectShortName">fsm_state[1:0]</obj_property> + </wvobject> + <wvobject type="other" fp_name="/TopModule_tb/DUT/smallObstacle/pos_object_x_target"> + <obj_property name="ElementShortName">pos_object_x_target</obj_property> + <obj_property name="ObjectShortName">pos_object_x_target</obj_property> + </wvobject> </wave_config> diff --git a/game.srcs/sim_1/new/TopModule_tb.vhd b/game.srcs/sim_1/new/TopModule_tb.vhd index cd156fc5c25feaf5bead5d796fd57a03a5884db5..3d3d15ca4a238e4fbe5a6ad89f30158ba5050a38 100644 --- a/game.srcs/sim_1/new/TopModule_tb.vhd +++ b/game.srcs/sim_1/new/TopModule_tb.vhd @@ -84,9 +84,11 @@ Stimulus : process wait for 100* period; btnU_i <= '0'; wait for 500 * period; - btnU_i <= '1'; + --btnU_i <= '1'; + btnCpuReset_i <= '0'; wait for 100* period; - btnU_i <= '0'; + --btnU_i <= '0'; + btnCpuReset_i <= '1'; wait; end process Stimulus; diff --git a/game.srcs/sources_1/new/TopModule.vhd b/game.srcs/sources_1/new/TopModule.vhd index dca855032580cd87c0f70239ce1c441dd3deb142..8bfc2da8b9696d2bede76f6bf04f3060eb8984e8 100644 --- a/game.srcs/sources_1/new/TopModule.vhd +++ b/game.srcs/sources_1/new/TopModule.vhd @@ -70,20 +70,6 @@ component vga ); end component vga; -component priority - Port ( - color_prio : out std_logic_vector(11 downto 0); - en_runner : in boolean; - en_back : in boolean; - en_obstacleS: in boolean; - en_obstacleL: in boolean; - color_runner : in std_logic_vector(11 downto 0); - color_back : in std_logic_vector(11 downto 0); - color_obstacleS: in std_logic_vector(11 downto 0); - color_obstacleL: in std_logic_vector(11 downto 0) - ); -end component priority; - component runner Port (clk_pixel: in std_logic; btnU_r : in std_logic; @@ -118,8 +104,11 @@ component obstacle_S is FStrobe_o : in std_logic; color_obstacle : out std_logic_vector (11 downto 0); exists_obstacle : out boolean; - fsm_state : in std_logic_vector(1 downto 0) - ); + fsm_state : in std_logic_vector(1 downto 0); + my_pos : out integer range 0 to VIRTUAL_SCREEN_LENGTH; + my_new_pos : in integer range 0 to VIRTUAL_SCREEN_LENGTH; + my_start_pos : in integer range 0 to VIRTUAL_SCREEN_LENGTH + ); end component obstacle_S; component obstacle_L is @@ -131,21 +120,13 @@ component obstacle_L is FStrobe_o : in std_logic; color_obstacle : out std_logic_vector (11 downto 0); exists_obstacle : out boolean; - fsm_state : in std_logic_vector(1 downto 0) - ); + fsm_state : in std_logic_vector(1 downto 0); + my_pos : out integer range 0 to VIRTUAL_SCREEN_LENGTH; + my_new_pos : in integer range 0 to VIRTUAL_SCREEN_LENGTH; + my_start_pos : in integer range 0 to VIRTUAL_SCREEN_LENGTH + ); end component obstacle_L; - -component collision is - Port ( - clk_pixel: in std_logic; - btnCpuReset_c : in std_logic; - en_runner : in boolean; - en_obstacleS : in boolean; - en_obstacleL: in boolean; - led : out std_logic_vector(15 downto 0); - collison_detected : out boolean - ); -end component collision; + component scorekeeper is Port ( @@ -170,7 +151,21 @@ component fsm is state : out std_logic_vector(1 downto 0) ); end component fsm; + +component posgenerator is + Port (clk_pixel: in std_logic; + btnCpuReset_g : in std_logic; + fsm_state : in std_logic_vector(1 downto 0); + FStrobe_g : in std_logic; + pos_0 : in integer range 0 to VIRTUAL_SCREEN_LENGTH; + pos_1 : in integer range 0 to VIRTUAL_SCREEN_LENGTH; + pos_2 : in integer range 0 to VIRTUAL_SCREEN_LENGTH; + pos_3 : in integer range 0 to VIRTUAL_SCREEN_LENGTH; + pos_new : out integer range 0 to VIRTUAL_SCREEN_LENGTH -- should be 460 - screen_length + ); +end component posgenerator; + -- Signals signal clk25 : std_logic; @@ -179,7 +174,7 @@ signal color_runner_sig : std_logic_vector (11 downto 0); signal color_background_sig : std_logic_vector (11 downto 0); signal color_obstacleS_sig : std_logic_vector (11 downto 0); signal color_obstacleL_sig : std_logic_vector (11 downto 0); - +signal color_obstacleS2_sig : std_logic_vector (11 downto 0); signal hcounter_sig : integer range 1 to 800; signal vcounter_sig : integer range 1 to 525; @@ -190,13 +185,21 @@ signal exist_runner_sig : boolean; signal exist_background_sig : boolean; signal exists_obstacleS_sig : boolean; signal exists_obstacleL_sig : boolean; +signal exists_obstacleS2_sig : boolean; signal collision_sig : boolean; +signal collision_cnt : std_logic_vector(15 downto 0); signal soft_reset : std_logic; signal fsm_reset : std_logic; signal fsm_state : std_logic_vector(1 downto 0); +signal pos_0_sig : integer range 0 to VIRTUAL_SCREEN_LENGTH; +signal pos_1_sig : integer range 0 to VIRTUAL_SCREEN_LENGTH; +signal pos_2_sig : integer range 0 to VIRTUAL_SCREEN_LENGTH; +signal pos_3_sig : integer range 0 to VIRTUAL_SCREEN_LENGTH; +signal pos_new_sig : integer range 0 to VIRTUAL_SCREEN_LENGTH; + -- mehr hindernisse -- abstände zufall -- abstände aufeinander abstimmen @@ -233,19 +236,6 @@ vgaInterface : vga FCounter => fcounter_sig, FStrobe => fstrobe_sig ); - -priorityLogic : priority - port map ( - color_prio => color_sig, - en_runner => exist_runner_sig, - en_back => exist_background_sig, - color_runner => color_runner_sig, - color_back => color_background_sig, - color_obstacleS => color_obstacleS_sig, - en_obstacleS => exists_obstacleS_sig, - color_obstacleL => color_obstacleL_sig, - en_obstacleL => exists_obstacleL_sig - ); runnerObject : runner port map ( @@ -281,8 +271,26 @@ smallObstacle : obstacle_S FStrobe_o => fstrobe_sig, color_obstacle => color_obstacleS_sig, exists_obstacle => exists_obstacleS_sig, - fsm_state => fsm_state + fsm_state => fsm_state, + my_pos => pos_0_sig, + my_new_pos => pos_new_sig, + my_start_pos => 1453 + ); +smallObstacle2 : obstacle_S + port map (clk_pixel => clk25, + btnCpuReset_o=> soft_reset, + HCounter_o => hcounter_sig, + VCounter_o => vcounter_sig, + FCounter_o => fcounter_sig, + FStrobe_o => fstrobe_sig, + color_obstacle => color_obstacleS2_sig, + exists_obstacle => exists_obstacleS2_sig, + fsm_state => fsm_state, + my_pos => pos_2_sig, + my_new_pos => pos_new_sig, + my_start_pos => 640 ); + largeObstacle : obstacle_L Port map(clk_pixel => clk25, btnCpuReset_o => soft_reset, @@ -292,20 +300,12 @@ largeObstacle : obstacle_L FStrobe_o => fstrobe_sig, color_obstacle => color_obstacleL_sig, exists_obstacle => exists_obstacleL_sig, - fsm_state => fsm_state + fsm_state => fsm_state, + my_pos => pos_1_sig, + my_new_pos => pos_new_sig, + my_start_pos => 1000 ); - - collisionDetection : collision - port map( - clk_pixel => clk25, - btnCpuReset_c => soft_reset, - en_runner => exist_runner_sig, - en_obstacleS => exists_obstacleS_sig, - en_obstacleL => exists_obstacleL_sig, - led => led, - collison_detected => collision_sig - ); scoreDisplay : scorekeeper port map( @@ -328,8 +328,61 @@ statemachine : fsm softReset => fsm_reset, state => fsm_state ); --- Make some modules resettable by state machine +NewPositionGenerator : posgenerator + port map ( + clk_pixel => clk25, + btnCpuReset_g => btnCpuReset, + fsm_state => fsm_state, + FStrobe_g => fstrobe_sig, + pos_0 => pos_0_sig, + pos_1 => pos_1_sig, + pos_2 => pos_2_sig, + pos_3 => 0, + pos_new => pos_new_sig -- should be 460 - screen_length + ); + + + +-- LOGIC: + soft_reset <= fsm_reset and btnCpuReset; - +process(clk25) + begin + if soft_reset = '0' then + collision_cnt <= x"0000"; + elsif rising_edge(clk25) then + if exist_runner_sig = true and (exists_obstacleS_sig = true or exists_obstacleL_sig = true or exists_obstacleS2_sig = true) then + -- collision + collision_sig <= true; + if collision_cnt = x"FFFF" then --overflow + collision_cnt <= x"0000"; + else + collision_cnt <= '1' & collision_cnt(15 downto 1); + end if; + else + collision_sig <= false; + end if; + end if; +end process; + + +process(exist_runner_sig) +begin + if exist_runner_sig = true then + color_sig <= color_runner_sig; + elsif exists_obstacleS2_sig = true then + --color_sig <= color_obstacleS2_sig; + color_sig <= x"126"; + elsif exists_obstacleS_sig = true then + color_sig <= color_obstacleS_sig; + elsif exists_obstacleL_sig = true then + color_sig <= color_obstacleL_sig; + elsif exist_background_sig = true then + color_sig <= color_background_sig; + else + color_sig <= x"000"; + end if; +end process; + end Behavioral; diff --git a/game.srcs/sources_1/new/background.vhd b/game.srcs/sources_1/new/background.vhd index 0e5416cecac23db508a37262d61c8f95d7c911b1..2d66448f5b959936351c34d7dc89dc98483e0c65 100644 --- a/game.srcs/sources_1/new/background.vhd +++ b/game.srcs/sources_1/new/background.vhd @@ -31,7 +31,7 @@ use work.jumpnrun_sizes.all; -- any Xilinx leaf cells in this code. --library UNISIM; --use UNISIM.VComponents.all; - +-- entity background is Port (clk_pixel, btnCpuReset_b : in std_logic; HCounter_b : in integer range 1 to 800; diff --git a/game.srcs/sources_1/new/collision.vhd b/game.srcs/sources_1/new/collision.vhd index 5d5abb1d514b7c09fc5dd96998b587165e6c1766..581d9cda91572defb5386eed0788dee74bcc22cc 100644 --- a/game.srcs/sources_1/new/collision.vhd +++ b/game.srcs/sources_1/new/collision.vhd @@ -1,70 +1,53 @@ ---------------------------------------------------------------------------------- -- Company: --- Engineer: --- --- Create Date: 02/28/2023 03:34:56 PM --- Design Name: --- Module Name: collision - Behavioral --- Project Name: --- Target Devices: --- Tool Versions: --- Description: --- --- Dependencies: --- --- Revision: --- Revision 0.01 - File Created --- Additional Comments: --- ----------------------------------------------------------------------------------- - - -library IEEE; -use IEEE.STD_LOGIC_1164.ALL; - --- Uncomment the following library declaration if using --- arithmetic functions with Signed or Unsigned values ---use IEEE.NUMERIC_STD.ALL; - --- Uncomment the following library declaration if instantiating --- any Xilinx leaf cells in this code. ---library UNISIM; ---use UNISIM.VComponents.all; - -entity collision is - Port ( - clk_pixel: in std_logic; - btnCpuReset_c : in std_logic; - en_runner : in boolean; - en_obstacleS : in boolean; - en_obstacleL: in boolean; - led : out std_logic_vector(15 downto 0); - collison_detected : out boolean - ); -end collision; - -architecture Behavioral of collision is -signal collision_cnt : std_logic_vector(15 downto 0); - -begin -led <= collision_cnt; - -process(clk_pixel) - begin - if btnCpuReset_c = '0' then - collision_cnt <= x"0000"; - elsif rising_edge(clk_pixel) then - if en_runner = true and (en_obstacleS = true or en_obstacleL = true) then - -- collision - collison_detected <= true; - if collision_cnt = x"FFFF" then --overflow - collision_cnt <= x"0000"; - else - collision_cnt <= '1' & collision_cnt(15 downto 1); - end if; - else - collison_detected <= false; - end if; - end if; -end process; -end Behavioral; +---- Engineer: +---- +---- Create Date: 02/28/2023 03:34:56 PM +---- Design Name: +---- Module Name: collision - Behavioral +---- Project Name: +---- Target Devices: +---- Tool Versions: +---- Description: +---- +---- Dependencies: +---- +---- Revision: +---- Revision 0.01 - File Created +---- Additional Comments: +---- +------------------------------------------------------------------------------------ + + +--library IEEE; +--use IEEE.STD_LOGIC_1164.ALL; + +---- Uncomment the following library declaration if using +---- arithmetic functions with Signed or Unsigned values +----use IEEE.NUMERIC_STD.ALL; + +---- Uncomment the following library declaration if instantiating +---- any Xilinx leaf cells in this code. +----library UNISIM; +----use UNISIM.VComponents.all; + +--entity collision is +-- Port ( +-- clk_pixel: in std_logic; +-- btnCpuReset_c : in std_logic; +-- en_runner : in boolean; +-- en_obstacleS : in boolean; +-- en_obstacleL: in boolean; +-- led : out std_logic_vector(15 downto 0); +-- collison_detected : out boolean +-- ); +--end collision; + +--architecture Behavioral of collision is +--signal collision_cnt : std_logic_vector(15 downto 0); + +--begin +--led <= collision_cnt; + + +--end Behavioral; diff --git a/game.srcs/sources_1/new/header.vhd b/game.srcs/sources_1/new/header.vhd index d450b80ced35d34d6e9c135fdfd427f41d29f61d..d13e0eec8f1546136dceba4d718e466381f26ee3 100644 --- a/game.srcs/sources_1/new/header.vhd +++ b/game.srcs/sources_1/new/header.vhd @@ -45,10 +45,12 @@ constant HEIGTH_BIG_OBSTACLE: integer:= 50; --px constant GROUND_LEVEL : integer range 1 to 480 := 350; constant MOVE_INCREMENT : integer := 4; --px per frame -constant VIRTUAL_SCREEN_LENGTH : integer := 1500; --px per frame +constant VIRTUAL_SCREEN_LENGTH : integer := 1800; --px per frame -constant OBST_L_START : integer := 1000; --px per frame -constant OBST_S_START : integer := 800; --px per frame +constant OBST_L_START : integer := 1000; --px per frame --unused +constant OBST_S_START : integer := 800; --px per frame -- unused + +constant SAFETY_DISTANCE : integer := 80; --px -- Runner constant POS_X_RUNNER : integer := 100; diff --git a/game.srcs/sources_1/new/obstacle.vhd b/game.srcs/sources_1/new/obstacle.vhd index 5ffbda6597c4c02a54563e25adc1238e69fe699e..c28592b2c1fedf2fd182760be7ddc4ad4ed1d57c 100644 --- a/game.srcs/sources_1/new/obstacle.vhd +++ b/game.srcs/sources_1/new/obstacle.vhd @@ -21,12 +21,13 @@ library IEEE; use IEEE.STD_LOGIC_1164.ALL; +use IEEE.std_logic_unsigned.all; use work.jumpnrun_sizes.all; -- Uncomment the following library declaration if using -- arithmetic functions with Signed or Unsigned values ---use IEEE.NUMERIC_STD.ALL; +use IEEE.NUMERIC_STD.ALL; -- Uncomment the following library declaration if instantiating -- any Xilinx leaf cells in this code. @@ -42,18 +43,20 @@ entity obstacle_S is FStrobe_o : in std_logic; color_obstacle : out std_logic_vector (11 downto 0); exists_obstacle : out boolean; - fsm_state : in std_logic_vector(1 downto 0) + fsm_state : in std_logic_vector(1 downto 0); + my_pos : out integer range 0 to VIRTUAL_SCREEN_LENGTH; + my_new_pos : in integer range 0 to VIRTUAL_SCREEN_LENGTH; + my_start_pos : in integer range 0 to VIRTUAL_SCREEN_LENGTH );end obstacle_S; architecture Behavioral of obstacle_S is -- Signals -signal pos_object_x_actual : integer range 1 to 640; +signal pos_object_x_actual : integer range 1 to VIRTUAL_SCREEN_LENGTH; signal pos_object_x_target : integer range 1 to VIRTUAL_SCREEN_LENGTH; signal pos_object_y_actual : integer range 1 to 480; signal pos_object_y_target: integer range 1 to 480; - -- Constants @@ -61,8 +64,8 @@ signal pos_object_y_target: integer range 1 to 480; begin -- Logic pos_object_y_target <= GROUND_LEVEL; - - + +my_pos <= pos_object_x_actual; -- detect Frame Strobe process(clk_pixel) @@ -94,16 +97,16 @@ end process; process(clk_pixel) begin if btnCpuReset_o = '0' then - pos_object_x_target <= 640; + pos_object_x_target <= my_start_pos; elsif rising_edge(clk_pixel) then if FStrobe_o = '1' then - if (pos_object_x_target > 1 or pos_object_x_target < VIRTUAL_SCREEN_LENGTH) and fsm_state = "00" then + if pos_object_x_target > 1 and pos_object_x_target < VIRTUAL_SCREEN_LENGTH and fsm_state = "00" then pos_object_x_target <= pos_object_x_target - MOVE_INCREMENT; else - pos_object_x_target <= OBST_S_START; + pos_object_x_target <= my_new_pos; + -- if new_pos - pos_1 < 100 and > 50 then + -- new_pos = pos_1 + 120 end if; - else - pos_object_x_target <= pos_object_x_target; end if; end if; end process; diff --git a/game.srcs/sources_1/new/obstacle2.vhd b/game.srcs/sources_1/new/obstacle2.vhd index a38bd5197958c91211187f5f9090ec12287f39b8..e92c74da694c6f6bb55c722e27b596a802ba45cd 100644 --- a/game.srcs/sources_1/new/obstacle2.vhd +++ b/game.srcs/sources_1/new/obstacle2.vhd @@ -26,7 +26,7 @@ use work.jumpnrun_sizes.all; -- Uncomment the following library declaration if using -- arithmetic functions with Signed or Unsigned values ---use IEEE.NUMERIC_STD.ALL; +use IEEE.NUMERIC_STD.ALL; -- Uncomment the following library declaration if instantiating -- any Xilinx leaf cells in this code. @@ -42,12 +42,14 @@ entity obstacle_L is FStrobe_o : in std_logic; color_obstacle : out std_logic_vector (11 downto 0); exists_obstacle : out boolean; - fsm_state : in std_logic_vector(1 downto 0) - );end obstacle_L; + fsm_state : in std_logic_vector(1 downto 0); + my_pos : out integer range 0 to VIRTUAL_SCREEN_LENGTH; + my_new_pos : in integer range 0 to VIRTUAL_SCREEN_LENGTH; + my_start_pos : in integer range 0 to VIRTUAL_SCREEN_LENGTH );end obstacle_L; architecture Behavioral of obstacle_L is -- Signals -signal pos_object_x_actual : integer range 1 to 640; +signal pos_object_x_actual : integer range 1 to VIRTUAL_SCREEN_LENGTH; signal pos_object_x_target : integer range 1 to VIRTUAL_SCREEN_LENGTH; signal pos_object_y_actual : integer range 1 to 480; @@ -62,6 +64,7 @@ begin -- Logic pos_object_y_target <= GROUND_LEVEL; +my_pos <= pos_object_x_actual; -- detect Frame Strobe @@ -94,13 +97,18 @@ end process; process(clk_pixel) begin if btnCpuReset_o = '0' then - pos_object_x_target <= OBST_L_START; + pos_object_x_target <= my_start_pos; elsif rising_edge(clk_pixel) then if FStrobe_o = '1' then - if (pos_object_x_target > 1 or pos_object_x_target < VIRTUAL_SCREEN_LENGTH) and fsm_state = "00" then + if pos_object_x_target > 1 and pos_object_x_target < VIRTUAL_SCREEN_LENGTH and fsm_state = "00" then pos_object_x_target <= pos_object_x_target - MOVE_INCREMENT; else - pos_object_x_target <= OBST_L_START; + -- pos_object_x_target <= 640 + to_integer(unsigned'('0' & lfsr_Q(0))) * 512 +to_integer(unsigned'('0' & lfsr_Q(1))) * 256 + to_integer(unsigned'('0' & lfsr_Q(2))) * 128 + to_integer(unsigned'('0' & lfsr_Q(3))) * 64 + + --to_integer(unsigned'('0' & lfsr_Q(4))) * 32 + to_integer(unsigned'('0' & lfsr_Q(5))) * 16 + to_integer(unsigned'('0' & lfsr_Q(6))) * 8 + to_integer(unsigned'('0' & lfsr_Q(7))) * 4 + -- + to_integer(unsigned'('0' & lfsr_Q(8))) * 2 + to_integer(unsigned'('0' & lfsr_Q(9))) * 1; + --pos_object_x_target <= 640 + to_integer(signed(lfsr_Q)); + --pos_object_x_target <= to_integer(unsigned'('0' & lfsr_Q(0))); + pos_object_x_target <= my_new_pos; end if; else pos_object_x_target <= pos_object_x_target; diff --git a/game.srcs/sources_1/new/posgenerator.vhd b/game.srcs/sources_1/new/posgenerator.vhd new file mode 100644 index 0000000000000000000000000000000000000000..1ad5e877c5e5cbc8a3653e700807d8846f733444 --- /dev/null +++ b/game.srcs/sources_1/new/posgenerator.vhd @@ -0,0 +1,122 @@ +---------------------------------------------------------------------------------- +-- Company: +-- Engineer: +-- +-- Create Date: 03/02/2023 11:13:43 AM +-- Design Name: +-- Module Name: posgenerator - Behavioral +-- Project Name: +-- Target Devices: +-- Tool Versions: +-- Description: +-- +-- Dependencies: +-- +-- Revision: +-- Revision 0.01 - File Created +-- Additional Comments: +-- +---------------------------------------------------------------------------------- + + +library IEEE; +use IEEE.STD_LOGIC_1164.ALL; +use work.jumpnrun_sizes.all; + +-- Uncomment the following library declaration if using +-- arithmetic functions with Signed or Unsigned values +use IEEE.NUMERIC_STD.ALL; + +-- Uncomment the following library declaration if instantiating +-- any Xilinx leaf cells in this code. +--library UNISIM; +--use UNISIM.VComponents.all; + +entity posgenerator is + Port (clk_pixel: in std_logic; + btnCpuReset_g : in std_logic; + fsm_state : in std_logic_vector(1 downto 0); + FStrobe_g : in std_logic; + pos_0 : in integer range 0 to VIRTUAL_SCREEN_LENGTH; + pos_1 : in integer range 0 to VIRTUAL_SCREEN_LENGTH; + pos_2 : in integer range 0 to VIRTUAL_SCREEN_LENGTH; + pos_3 : in integer range 0 to VIRTUAL_SCREEN_LENGTH; + pos_new : out integer range 0 to VIRTUAL_SCREEN_LENGTH -- should be 460 - screen_length + );end posgenerator; + +architecture Behavioral of posgenerator is +-- Random generator signals +--signal temp: STD_LOGIC; +signal lfsr_Qt: STD_LOGIC_VECTOR(9 downto 0) := "11" & x"01"; +signal lfsr_en : std_logic; +signal lfsr_Q : STD_LOGIC_VECTOR (9 downto 0); + + +type int_array_type is array(0 to 3) of integer; +type integer_vector is array (1 to 8) of integer; + +signal pos : int_array_type; + + + + +begin + +pos <= (pos_0, pos_1, pos_2, pos_3); + +--lfsr_en <= '1'; +-- 10 bit LFSR Pseudo Random generator +process(clk_pixel) + variable tmp : STD_LOGIC := '0'; +begin --process + if rising_edge(clk_pixel) THEN + if (btnCpuReset_g='0') THEN + -- credit to QuantumRipple for pointing out that this should not + -- be reset to all 0's, as you will enter an invalid state + lfsr_Qt <= "11" & x"01"; + --ELSE Qt <= seed; + elsif lfsr_en = '1' THEN + tmp := lfsr_Qt(3) XOR lfsr_Qt(0); --x^10 + x^7 +1 + lfsr_Qt <= tmp & lfsr_Qt(9 downto 1); + end if; + +end if; +end process; +-- check <= temp; +--lfsr_check <= lfsr_Qt(7); +lfsr_Q <= lfsr_Qt; + +-- Too hard distances avoidance process +process(clk_pixel, btnCpuReset_g) + variable max :integer range 0 to VIRTUAL_SCREEN_LENGTH; + variable newpos_tmp :integer range 0 to VIRTUAL_SCREEN_LENGTH * 2; +begin + if btnCpuReset_g = '0' then + elsif rising_edge(clk_pixel) then + if FStrobe_g = '1' then + lfsr_en <= '1'; + max := pos(0); + for i in 1 to 3 loop + if pos(i) > max then + max := pos(i); + end if; + end loop; + if max < 640 then + max := 600; + end if; + newpos_tmp := max + to_integer(unsigned(lfsr_Q)) mod (1600 - max); + if (newpos_tmp >= (max + 90) and newpos_tmp < (max + 150)) or (newpos_tmp <= (max + LENGTH_BIG_OBSTACLE)) then --forbidden zone + newpos_tmp := newpos_tmp + 150; + end if; + if newpos_tmp > 1600 then + pos_new <= 1650; + else + pos_new <= newpos_tmp; + end if; + else + lfsr_en <= '0'; + end if; + end if; +end process; + +end Behavioral; diff --git a/game.srcs/sources_1/new/priority.vhd b/game.srcs/sources_1/new/priority.vhd index 1323426eb7b6bdd70323d716c73df57197f908d5..b05d487b21dac88787015059c9ba724f73a91694 100644 --- a/game.srcs/sources_1/new/priority.vhd +++ b/game.srcs/sources_1/new/priority.vhd @@ -31,37 +31,37 @@ use IEEE.STD_LOGIC_1164.ALL; --library UNISIM; --use UNISIM.VComponents.all; -entity priority is - Port ( - color_prio : out std_logic_vector(11 downto 0); - en_runner : in boolean; - en_back : in boolean; - en_obstacleS: in boolean; - en_obstacleL: in boolean; - color_runner : in std_logic_vector(11 downto 0); - color_back : in std_logic_vector(11 downto 0); - color_obstacleS: in std_logic_vector(11 downto 0); - color_obstacleL: in std_logic_vector(11 downto 0) - ); -end priority; +--entity priority is +-- Port ( +-- color_prio : out std_logic_vector(11 downto 0); +-- en_runner : in boolean; +-- en_back : in boolean; +-- en_obstacleS: in boolean; +-- en_obstacleL: in boolean; +-- color_runner : in std_logic_vector(11 downto 0); +-- color_back : in std_logic_vector(11 downto 0); +-- color_obstacleS: in std_logic_vector(11 downto 0); +-- color_obstacleL: in std_logic_vector(11 downto 0) +-- ); +--end priority; architecture Behavioral of priority is begin -process(en_runner) -begin - if en_runner = true then - color_prio <= color_runner; - elsif en_obstacleS = true then - color_prio <= color_obstacleS; - elsif en_obstacleL = true then - color_prio <= color_obstacleL; - elsif en_back = true then - color_prio <= color_back; - else - color_prio <= x"000"; - end if; -end process; +--process(en_runner) +--begin +-- if en_runner = true then +-- color_prio <= color_runner; +-- elsif en_obstacleS = true then +-- color_prio <= color_obstacleS; +-- elsif en_obstacleL = true then +-- color_prio <= color_obstacleL; +-- elsif en_back = true then +-- color_prio <= color_back; +-- else +-- color_prio <= x"000"; +-- end if; +--end process; end Behavioral; diff --git a/game.srcs/sources_1/new/runner.vhd b/game.srcs/sources_1/new/runner.vhd index 237128e6eba02e9caa5f785abdb314fa3ff30738..a2449b38ea5f04948a6d1a9c1684178db3fa72fc 100644 --- a/game.srcs/sources_1/new/runner.vhd +++ b/game.srcs/sources_1/new/runner.vhd @@ -109,7 +109,7 @@ begin button_pressed <= false; elsif rising_edge(clk_pixel) then --A button_up_shift_reg <= button_up_shift_reg(0) & btnU_r; -- put current button value into shift register - if (btnU_r = '1') and (button_up_shift_reg(0)= '0') and runner_not_landed = '0' then -- if rising edge (btnU) --B + if (btnU_r = '1') and (button_up_shift_reg(0)= '0') and runner_not_landed = '0' and fsm_state = "00" then -- if rising edge (btnU) --B fcount_edge <= FCounter_r; button_pressed <= true; elsif FStrobe_r = '1' then --B @@ -129,14 +129,16 @@ begin else --F pos_object_y_target <= GROUND_LEVEL; end if; -- F - runner_not_landed <= '1'; if pos_object_y_target = GROUND_LEVEL - 3 * JUMP_INCREMENT then --I button_pressed <= false; + runner_not_landed <= '0'; + else + runner_not_landed <= '1'; end if; end if; --D else + runner_not_landed <= '0'; pos_object_y_target <= GROUND_LEVEL; - runner_not_landed <= '0'; end if; --C end if; --B end if; --A diff --git a/game.srcs/utils_1/imports/synth_1/TopModule.dcp b/game.srcs/utils_1/imports/synth_1/TopModule.dcp index 183e82d925c12f06181f32e13f627a4363bfecb1..a28e218a7c135cb2c64ce82db3f24c91932b8522 100755 Binary files a/game.srcs/utils_1/imports/synth_1/TopModule.dcp and b/game.srcs/utils_1/imports/synth_1/TopModule.dcp differ diff --git a/game.xpr b/game.xpr index b63577ef2510b46d0bafe446e56c33487884a7c7..5680bfcd2d62fea4e72eed14f3b572fd2c236e26 100644 --- a/game.xpr +++ b/game.xpr @@ -59,7 +59,7 @@ <Option Name="IPUserFilesDir" Val="$PIPUSERFILESDIR"/> <Option Name="IPStaticSourceDir" Val="$PIPUSERFILESDIR/ipstatic"/> <Option Name="EnableBDX" Val="FALSE"/> - <Option Name="WTXSimLaunchSim" Val="36"/> + <Option Name="WTXSimLaunchSim" Val="39"/> <Option Name="WTModelSimLaunchSim" Val="0"/> <Option Name="WTQuestaLaunchSim" Val="0"/> <Option Name="WTIesLaunchSim" Val="0"/> @@ -102,12 +102,6 @@ <Attr Name="UsedIn" Val="simulation"/> </FileInfo> </File> - <File Path="$PSRCDIR/sources_1/new/collision.vhd"> - <FileInfo> - <Attr Name="UsedIn" Val="synthesis"/> - <Attr Name="UsedIn" Val="simulation"/> - </FileInfo> - </File> <File Path="$PSRCDIR/sources_1/new/obstacle.vhd"> <FileInfo> <Attr Name="UsedIn" Val="synthesis"/> @@ -120,7 +114,7 @@ <Attr Name="UsedIn" Val="simulation"/> </FileInfo> </File> - <File Path="$PSRCDIR/sources_1/new/priority.vhd"> + <File Path="$PSRCDIR/sources_1/new/posgenerator.vhd"> <FileInfo> <Attr Name="UsedIn" Val="synthesis"/> <Attr Name="UsedIn" Val="simulation"/> @@ -156,6 +150,20 @@ <Attr Name="UsedIn" Val="simulation"/> </FileInfo> </File> + <File Path="$PSRCDIR/sources_1/new/priority.vhd"> + <FileInfo> + <Attr Name="AutoDisabled" Val="1"/> + <Attr Name="UsedIn" Val="synthesis"/> + <Attr Name="UsedIn" Val="simulation"/> + </FileInfo> + </File> + <File Path="$PSRCDIR/sources_1/new/collision.vhd"> + <FileInfo> + <Attr Name="AutoDisabled" Val="1"/> + <Attr Name="UsedIn" Val="synthesis"/> + <Attr Name="UsedIn" Val="simulation"/> + </FileInfo> + </File> <File Path="$PSRCDIR/sources_1/ip/clk_wiz_1/clk_wiz_1.xci"> <FileInfo> <Attr Name="AutoDisabled" Val="1"/>