-- VHDL Code for Fish Game -- Edward Mengel -- EE476 Final project library IEEE; use IEEE.STD_LOGIC_1164.all; use IEEE.STD_LOGIC_ARITH.all; use IEEE.STD_LOGIC_UNSIGNED.all; entity fish is Generic(ADDR_WIDTH: integer := 12; DATA_WIDTH: integer := 1); port(signal Reset, Clock,fishdir0x, fishdir0y, fishdir1, fishdir2, fishdir3 : in std_logic; signal Red,Green,Blue : out std_logic; signal Horiz_sync,Vert_sync : out std_logic); end fish; architecture behavior of fish is -- Video Display Signals signal H_count,V_count: std_logic_vector(9 Downto 0); signal Red_Data, Green_Data, Blue_Data: std_logic; constant H_max : std_logic_vector(9 Downto 0) := CONV_STD_LOGIC_VECTOR(799,10); -- 799 is max horiz count constant V_max : std_logic_vector(9 Downto 0) := CONV_STD_LOGIC_VECTOR(524,10); -- 524 is max vert count constant fishsize1 : std_logic_vector(7 Downto 0) := CONV_STD_LOGIC_VECTOR(8,8); constant fishsize2 : std_logic_vector(7 Downto 0) := CONV_STD_LOGIC_VECTOR(32,8); constant fishsize3 : std_logic_vector(7 Downto 0) := CONV_STD_LOGIC_VECTOR(64,8); signal fishsize0 : std_logic_vector(7 Downto 0); signal fishpos0x : std_logic_vector(9 Downto 0); signal fishpos0y : std_logic_vector(9 Downto 0); signal fishpos1x : std_logic_vector(9 Downto 0); signal fishpos1y : std_logic_vector(9 Downto 0); signal fishpos2x : std_logic_vector(9 Downto 0); signal fishpos2y : std_logic_vector(9 Downto 0); signal fishpos3x : std_logic_vector(9 Downto 0); signal fishpos3y : std_logic_vector(9 Downto 0); signal fishend0x : std_logic_vector(9 Downto 0); signal fishend0y : std_logic_vector(9 Downto 0); signal fishend1x : std_logic_vector(9 Downto 0); signal fishend1y : std_logic_vector(9 Downto 0); signal fishend2x : std_logic_vector(9 Downto 0); signal fishend2y : std_logic_vector(9 Downto 0); signal fishend3x : std_logic_vector(9 Downto 0); signal fishend3y : std_logic_vector(9 Downto 0); signal video_on, video_on_H, video_on_V: std_logic; signal h_data : std_logic_vector(9 downto 0); signal v_data : std_logic_vector(9 downto 0); signal address : std_logic_vector(5 downto 0); signal preaddress : std_logic_vector(2 downto 0); signal data : std_logic_vector(2 downto 0); signal curfishsize : std_logic_vector(7 downto 0); signal curfishdir : std_logic; signal gameover : std_logic; signal score : std_logic_vector(9 downto 0); --edit the fish below this line (a0=address of 0 etc) constant a0 : integer := 6; constant a1 : integer := 1; constant a2 : integer := 1; constant a3 : integer := 1; constant a4 : integer := 6; constant a5 : integer := 6; constant a6 : integer := 1; constant a7 : integer := 1; constant a8 : integer := 1; constant a9 : integer := 6; constant a10 : integer := 1; constant a11 : integer := 6; constant a12 : integer := 6; constant a13 : integer := 7; constant a14 : integer := 6; constant a15 : integer := 1; constant a16 : integer := 1; constant a17 : integer := 1; constant a18 : integer := 6; constant a19 : integer := 6; constant a20 : integer := 6; constant a21 : integer := 6; constant a22 : integer := 6; constant a23 : integer := 6; constant a24 : integer := 1; constant a25 : integer := 1; constant a26 : integer := 6; constant a27 : integer := 6; constant a28 : integer := 6; constant a29 : integer := 6; constant a30 : integer := 6; constant a31 : integer := 6; constant a32 : integer := 1; constant a33 : integer := 6; constant a34 : integer := 1; constant a35 : integer := 6; constant a36 : integer := 6; constant a37 : integer := 6; constant a38 : integer := 6; constant a39 : integer := 1; constant a40 : integer := 6; constant a41 : integer := 1; constant a42 : integer := 1; constant a43 : integer := 1; constant a44 : integer := 6; constant a45 : integer := 6; constant a46 : integer := 1; constant a47 : integer := 1; constant a48 : integer := 1; constant a49 : integer := 1; constant a50 : integer := 1; constant a51 : integer := 1; constant a52 : integer := 1; constant a53 : integer := 1; constant a54 : integer := 1; constant a55 : integer := 1; constant a56 : integer := 1; constant a57 : integer := 1; constant a58 : integer := 1; constant a59 : integer := 1; constant a60 : integer := 1; constant a61 : integer := 1; constant a62 : integer := 1; constant a63 : integer := 1; --stop editing here begin -- Colors for pixel data on video signal Red_Data <= data(2); Green_Data <= data(1); Blue_Data <= data(0); Red <= Red_Data and video_on; Green <= Green_Data and video_on; Blue <= Blue_Data and video_on; -- video_on turns off pixel data when not in the view area video_on <= video_on_H and video_on_V; Fish : process Begin fishend0x <= fishpos0x + fishsize0; fishend0y <= fishpos0y + fishsize0; fishend1x <= fishpos1x + fishsize1; fishend1y <= fishpos1y + fishsize1; fishend2x <= fishpos2x + fishsize2; fishend2y <= fishpos2y + fishsize2; fishend3x <= fishpos3x + fishsize3; fishend3y <= fishpos3y + fishsize3; If ((H_count >= fishpos0x) and (V_count >= fishpos0y) and (H_count < fishend0x) and (V_count < fishend0y)) then h_data(9 downto 0) <= H_count - fishpos0x; v_data(9 downto 0) <= V_count - fishpos0y; curfishsize <= fishsize0; curfishdir <= fishdir0x; Else If ((H_count >= fishpos1x) and (V_count >= fishpos1y) and (H_count < fishend1x) and (V_count < fishend1y)) then h_data(9 downto 0) <= H_count - fishpos1x; v_data(9 downto 0) <= V_count - fishpos1y; curfishsize <= fishsize1+To_Stdlogicvector(B"0"); curfishdir <= fishdir1; Else If ((H_count >= fishpos2x) and (V_count >= fishpos2y) and (H_count < fishend2x) and (V_count < fishend2y)) then h_data(9 downto 0) <= H_count - fishpos2x; v_data(9 downto 0) <= V_count - fishpos2y; curfishsize <= fishsize2+To_Stdlogicvector(B"0"); curfishdir <= fishdir2; Else If ((H_count >= fishpos3x) and (V_count >= fishpos3y) and (H_count < fishend3x) and (V_count < fishend3y)) then h_data(9 downto 0) <= H_count - fishpos3x; v_data(9 downto 0) <= V_count - fishpos3y; curfishsize <= fishsize3+To_Stdlogicvector(B"0"); curfishdir <= fishdir3; Else h_data(9 downto 0) <= CONV_STD_LOGIC_VECTOR(7,10); v_data(9 downto 0) <= CONV_STD_LOGIC_VECTOR(7,10); curfishsize <= CONV_STD_LOGIC_VECTOR(8,8); curfishdir <= '0'; End If; End If; End If; End If; case curfishsize is when "00001000" => preaddress(2 downto 0) <= h_data(2 downto 0); address(5 downto 3) <= v_data(2 downto 0); when "00010000" => preaddress(2 downto 0) <= h_data(3 downto 1); address(5 downto 3) <= v_data(3 downto 1); when "00100000" => preaddress(2 downto 0) <= h_data(4 downto 2); address(5 downto 3) <= v_data(4 downto 2); when "01000000" => preaddress(2 downto 0) <= h_data(5 downto 3); address(5 downto 3) <= v_data(5 downto 3); when "10000000" => preaddress(2 downto 0) <= h_data(6 downto 4); address(5 downto 3) <= v_data(6 downto 4); when others => address(5 downto 0) <= CONV_STD_LOGIC_VECTOR(0,6); end case; If (curfishdir = '1') then address(2 downto 0) <= preaddress(2 downto 0); Else address(2 downto 0) <= CONV_STD_LOGIC_VECTOR(7,3) - preaddress(2 downto 0); End If; End process Fish; process(address) begin case address is when "000000" => data <= a0+To_Stdlogicvector(B"0"); when "000001" => data <= a1+To_Stdlogicvector(B"0"); when "000010" => data <= a2+To_Stdlogicvector(B"0"); when "000011" => data <= a3+To_Stdlogicvector(B"0"); when "000100" => data <= a4+To_Stdlogicvector(B"0"); when "000101" => data <= a5+To_Stdlogicvector(B"0"); when "000110" => data <= a6+To_Stdlogicvector(B"0"); when "000111" => data <= a7+To_Stdlogicvector(B"0"); when "001000" => data <= a8+To_Stdlogicvector(B"0"); when "001001" => data <= a9+To_Stdlogicvector(B"0"); when "001010" => data <= a10+To_Stdlogicvector(B"0"); when "001011" => data <= a11+To_Stdlogicvector(B"0"); when "001100" => data <= a12+To_Stdlogicvector(B"0"); when "001101" => data <= a13+To_Stdlogicvector(B"0"); when "001110" => data <= a14+To_Stdlogicvector(B"0"); when "001111" => data <= a15+To_Stdlogicvector(B"0"); when "010000" => data <= a16+To_Stdlogicvector(B"0"); when "010001" => data <= a17+To_Stdlogicvector(B"0"); when "010010" => data <= a18+To_Stdlogicvector(B"0"); when "010011" => data <= a19+To_Stdlogicvector(B"0"); when "010100" => data <= a20+To_Stdlogicvector(B"0"); when "010101" => data <= a21+To_Stdlogicvector(B"0"); when "010110" => data <= a22+To_Stdlogicvector(B"0"); when "010111" => data <= a23+To_Stdlogicvector(B"0"); when "011000" => data <= a24+To_Stdlogicvector(B"0"); when "011001" => data <= a25+To_Stdlogicvector(B"0"); when "011010" => data <= a26+To_Stdlogicvector(B"0"); when "011011" => data <= a27+To_Stdlogicvector(B"0"); when "011100" => data <= a28+To_Stdlogicvector(B"0"); when "011101" => data <= a29+To_Stdlogicvector(B"0"); when "011110" => data <= a30+To_Stdlogicvector(B"0"); when "011111" => data <= a31+To_Stdlogicvector(B"0"); when "100000" => data <= a32+To_Stdlogicvector(B"0"); when "100001" => data <= a33+To_Stdlogicvector(B"0"); when "100010" => data <= a34+To_Stdlogicvector(B"0"); when "100011" => data <= a35+To_Stdlogicvector(B"0"); when "100100" => data <= a36+To_Stdlogicvector(B"0"); when "100101" => data <= a37+To_Stdlogicvector(B"0"); when "100110" => data <= a38+To_Stdlogicvector(B"0"); when "100111" => data <= a39+To_Stdlogicvector(B"0"); when "101000" => data <= a40+To_Stdlogicvector(B"0"); when "101001" => data <= a41+To_Stdlogicvector(B"0"); when "101010" => data <= a42+To_Stdlogicvector(B"0"); when "101011" => data <= a43+To_Stdlogicvector(B"0"); when "101100" => data <= a44+To_Stdlogicvector(B"0"); when "101101" => data <= a45+To_Stdlogicvector(B"0"); when "101110" => data <= a46+To_Stdlogicvector(B"0"); when "101111" => data <= a47+To_Stdlogicvector(B"0"); when "110000" => data <= a48+To_Stdlogicvector(B"0"); when "110001" => data <= a49+To_Stdlogicvector(B"0"); when "110010" => data <= a50+To_Stdlogicvector(B"0"); when "110011" => data <= a51+To_Stdlogicvector(B"0"); when "110100" => data <= a52+To_Stdlogicvector(B"0"); when "110101" => data <= a53+To_Stdlogicvector(B"0"); when "110110" => data <= a54+To_Stdlogicvector(B"0"); when "110111" => data <= a55+To_Stdlogicvector(B"0"); when "111000" => data <= a56+To_Stdlogicvector(B"0"); when "111001" => data <= a57+To_Stdlogicvector(B"0"); when "111010" => data <= a58+To_Stdlogicvector(B"0"); when "111011" => data <= a59+To_Stdlogicvector(B"0"); when "111100" => data <= a60+To_Stdlogicvector(B"0"); when "111101" => data <= a61+To_Stdlogicvector(B"0"); when "111110" => data <= a62+To_Stdlogicvector(B"0"); when "111111" => data <= a63+To_Stdlogicvector(B"0"); when others => data <= (others => '0'); end case; end process; --Generate Horizontal and Vertical Timing Signals for Video Signal VIDEO_DISPLAY: Process Begin Wait until(Clock'Event) and (Clock='1'); If Reset = '1' Then H_count <= CONV_STD_LOGIC_VECTOR(0,10); V_count <= CONV_STD_LOGIC_VECTOR(0,10); Video_on_H <= '0'; Video_on_V <= '0'; fishpos0x <= CONV_STD_LOGIC_VECTOR(320,10); fishpos0y <= CONV_STD_LOGIC_VECTOR(240,10); fishpos1x <= CONV_STD_LOGIC_VECTOR(20,10); fishpos1y <= CONV_STD_LOGIC_VECTOR(20,10); fishpos2x <= CONV_STD_LOGIC_VECTOR(600,10); fishpos2y <= CONV_STD_LOGIC_VECTOR(400,10); fishpos3x <= CONV_STD_LOGIC_VECTOR(20,10); fishpos3y <= CONV_STD_LOGIC_VECTOR(300,10); fishsize0 <= CONV_STD_LOGIC_VECTOR(8,8); gameover <= '0'; score <= CONV_STD_LOGIC_VECTOR(0,10); Else -- H_count counts pixels (640 + extra time for sync signals) -- -- <-Clock out RGB Pixel Row Data -> <-H Sync-> -- ------------------------------------__________-------- -- 0 640 659 755 799 -- If (H_count >= H_max) then H_count <= To_Stdlogicvector(B"0000000000"); Else H_count <= H_count + To_Stdlogicvector(B"0000000001"); End if; --Generate Horizontal Sync Signal If (H_count <= 755) and (H_count >= 659) Then Horiz_Sync <= '0'; ELSE Horiz_Sync <= '1'; End if; --V_count counts rows of pixels (480 + extra time for sync signals) -- -- <---- 480 Horizontal Syncs (pixel rows) --> ->V Sync<- -- -----------------------------------------------_______------------ -- 0 480 493-494 524 -- If (V_count >= V_max) and (H_count >= 699) then V_count <= To_Stdlogicvector(B"0000000000"); Else If (H_count = 699) Then V_count <= V_count + To_Stdlogicvector(B"0000000001"); End if; End if; -- Generate Vertical Sync Signal If (V_count <= 494) and (V_count >= 493) Then Vert_Sync <= '0'; ELSE Vert_Sync <= '1'; End if; -- Generate Video on Screen Signals for Pixel Data If (H_count <= 639) Then video_on_H <= '1'; ELSE video_on_H <= '0'; End if; If (V_count <= 479) Then video_on_V <= '1'; ELSE video_on_V <= '0'; End if; If ((V_Count = 0) and (H_count = 0) and (gameover = '0')) then --fish 0 If (fishdir0x = '1') then fishpos0x <= fishpos0x + CONV_STD_LOGIC_VECTOR(1,10); Else fishpos0x <= fishpos0x - CONV_STD_LOGIC_VECTOR(1,10); End If; If (fishdir0y = '1') then fishpos0y <= fishpos0y + CONV_STD_LOGIC_VECTOR(1,10); Else fishpos0y <= fishpos0y - CONV_STD_LOGIC_VECTOR(1,10); End If; If (fishpos0x <= 0) then fishpos0x <= CONV_STD_LOGIC_VECTOR(639,10); End If; If (fishpos0y <= 0) then fishpos0y <= CONV_STD_LOGIC_VECTOR(479,10); End If; If (fishpos0x >= 640) then fishpos0x <= CONV_STD_LOGIC_VECTOR(1,10); End If; If (fishpos0y >= 480) then fishpos0y <= CONV_STD_LOGIC_VECTOR(1,10); End If; -- fish 1 If (fishdir1 = '1') then fishpos1x <= fishpos1x + CONV_STD_LOGIC_VECTOR(1,10); Else fishpos1x <= fishpos1x - CONV_STD_LOGIC_VECTOR(1,10); End If; If (fishpos1x <= 0) then fishpos1x <= CONV_STD_LOGIC_VECTOR(639,10); End If; If (fishpos1x >= 640) then fishpos1x <= CONV_STD_LOGIC_VECTOR(1,10); End If; If (fishpos1y <= 0) then fishpos1y <= CONV_STD_LOGIC_VECTOR(20,10); End If; -- fish 2 If (fishdir2 = '1') then fishpos2x <= fishpos2x + CONV_STD_LOGIC_VECTOR(1,10); Else fishpos2x <= fishpos2x - CONV_STD_LOGIC_VECTOR(1,10); End If; If (fishpos2x <= 0) then fishpos2x <= CONV_STD_LOGIC_VECTOR(639,10); End If; If (fishpos2x >= 640) then fishpos2x <= CONV_STD_LOGIC_VECTOR(1,10); End If; If (fishpos2y <= 0) then fishpos2y <= CONV_STD_LOGIC_VECTOR(200,10); End If; -- fish 3 If (fishdir3 = '1') then fishpos3x <= fishpos3x + CONV_STD_LOGIC_VECTOR(1,10); Else fishpos3x <= fishpos3x - CONV_STD_LOGIC_VECTOR(1,10); End If; If (fishpos3x <= 0) then fishpos3x <= CONV_STD_LOGIC_VECTOR(639,10); End If; If (fishpos3x >= 640) then fishpos3x <= CONV_STD_LOGIC_VECTOR(1,10); End If; If (fishpos3y <= 0) then fishpos3y <= CONV_STD_LOGIC_VECTOR(400,10); End If; -- collisions --colision with fish 1 If ((((fishpos0xfishpos1x)) or ((fishend0xfishpos1x))) and (((fishpos0yfishpos1y)) or ((fishend0yfishpos1y)))) then If(fishsize0fishpos2x)) or ((fishend0xfishpos2x))) and (((fishpos0yfishpos2y)) or ((fishend0yfishpos2y)))) then If(fishsize0fishpos3x)) or ((fishend0xfishpos3x))) and (((fishpos0yfishpos3y)) or ((fishend0yfishpos3y)))) then If(fishsize0 16) then fishsize0 <= CONV_STD_LOGIC_VECTOR(64,8); Else If (score > 2) then fishsize0 <= CONV_STD_LOGIC_VECTOR(32,8); Else fishsize0 <= CONV_STD_LOGIC_VECTOR(16,8); End If; End If; End if; End if; end process VIDEO_DISPLAY; end behavior;