diff --git a/TankGame.srcs/sources_1/new/SEG_DRV.v b/TankGame.srcs/sources_1/new/SEG_DRV.v new file mode 100644 index 0000000..44970bc --- /dev/null +++ b/TankGame.srcs/sources_1/new/SEG_DRV.v @@ -0,0 +1,53 @@ +`timescale 1ns / 1ps +////////////////////////////////////////////////////////////////////////////////// +// Company: +// Engineer: +// +// Create Date: 01/03/2021 09:18:36 PM +// Design Name: +// Module Name: SEG_DRV +// Project Name: +// Target Devices: +// Tool Versions: +// Description: +// +// Dependencies: +// +// Revision: +// Revision 0.01 - File Created +// Additional Comments: +// +////////////////////////////////////////////////////////////////////////////////// + + + + +module SEG_DRV( + input clk, + input [ 31: 0 ] num, + input ena, + input [ 7: 0 ] point, + output S_DT, + output S_CLK, + output S_CLR, + output S_EN + ); + +wire [ 63: 0 ] dto; + +MYMC14495 m1( .D0( num[ 0 ] ), .D1( num[ 1 ] ), .D2( num[ 2 ] ), .D3( num[ 3 ] ), .LE( ~ena ), .point( point[ 0 ] ), .a( dto[ 0 ] ), .b( dto[ 1 ] ), .c( dto[ 2 ] ), .d( dto[ 3 ] ), .e( dto[ 4 ] ), .f( dto[ 5 ] ), .g( dto[ 6 ] ), .p( dto[ 7 ] ) ); +MYMC14495 m2( .D0( num[ 4 ] ), .D1( num[ 5 ] ), .D2( num[ 6 ] ), .D3( num[ 7 ] ), .LE( ~ena ), .point( point[ 1 ] ), .a( dto[ 8 ] ), .b( dto[ 9 ] ), .c( dto[ 10 ] ), .d( dto[ 11 ] ), .e( dto[ 12 ] ), .f( dto[ 13 ] ), .g( dto[ 14 ] ), .p( dto[ 15 ] ) ); +MYMC14495 m3( .D0( num[ 8 ] ), .D1( num[ 9 ] ), .D2( num[ 10 ] ), .D3( num[ 11 ] ), .LE( ~ena ), .point( point[ 2 ] ), .a( dto[ 16 ] ), .b( dto[ 17 ] ), .c( dto[ 18 ] ), .d( dto[ 19 ] ), .e( dto[ 20 ] ), .f( dto[ 21 ] ), .g( dto[ 22 ] ), .p( dto[ 23 ] ) ); +MYMC14495 m4( .D0( num[ 12 ] ), .D1( num[ 13 ] ), .D2( num[ 14 ] ), .D3( num[ 15 ] ), .LE( ~ena ), .point( point[ 3 ] ), .a( dto[ 24 ] ), .b( dto[ 25 ] ), .c( dto[ 26 ] ), .d( dto[ 27 ] ), .e( dto[ 28 ] ), .f( dto[ 29 ] ), .g( dto[ 30 ] ), .p( dto[ 31 ] ) ); +MYMC14495 m5( .D0( num[ 16 ] ), .D1( num[ 17 ] ), .D2( num[ 18 ] ), .D3( num[ 19 ] ), .LE( ~ena ), .point( point[ 4 ] ), .a( dto[ 32 ] ), .b( dto[ 33 ] ), .c( dto[ 34 ] ), .d( dto[ 35 ] ), .e( dto[ 36 ] ), .f( dto[ 37 ] ), .g( dto[ 38 ] ), .p( dto[ 39 ] ) ); +MYMC14495 m6( .D0( num[ 20 ] ), .D1( num[ 21 ] ), .D2( num[ 22 ] ), .D3( num[ 23 ] ), .LE( ~ena ), .point( point[ 5 ] ), .a( dto[ 40 ] ), .b( dto[ 41 ] ), .c( dto[ 42 ] ), .d( dto[ 43 ] ), .e( dto[ 44 ] ), .f( dto[ 45 ] ), .g( dto[ 46 ] ), .p( dto[ 47 ] ) ); +MYMC14495 m7( .D0( num[ 24 ] ), .D1( num[ 25 ] ), .D2( num[ 26 ] ), .D3( num[ 27 ] ), .LE( ~ena ), .point( point[ 6 ] ), .a( dto[ 48 ] ), .b( dto[ 49 ] ), .c( dto[ 50 ] ), .d( dto[ 51 ] ), .e( dto[ 52 ] ), .f( dto[ 53 ] ), .g( dto[ 54 ] ), .p( dto[ 55 ] ) ); +MYMC14495 m8( .D0( num[ 28 ] ), .D1( num[ 29 ] ), .D2( num[ 30 ] ), .D3( num[ 31 ] ), .LE( ~ena ), .point( point[ 7 ] ), .a( dto[ 56 ] ), .b( dto[ 57 ] ), .c( dto[ 58 ] ), .d( dto[ 59 ] ), .e( dto[ 60 ] ), .f( dto[ 61 ] ), .g( dto[ 62 ] ), .p( dto[ 63 ] ) ); + + + +SEG_P2S m9( .clk( clk ), .data_in( dto ), .ena( ena ), .S_DT( S_DT ), .S_CLK( S_CLK ), .S_CLR( S_CLR ), .S_EN( S_EN ) ); + + + +endmodule diff --git a/TankGame.srcs/sources_1/new/SEG_P2S.v b/TankGame.srcs/sources_1/new/SEG_P2S.v new file mode 100644 index 0000000..a1b5959 --- /dev/null +++ b/TankGame.srcs/sources_1/new/SEG_P2S.v @@ -0,0 +1,79 @@ +`timescale 1ns / 1ps +////////////////////////////////////////////////////////////////////////////////// +// Company: +// Engineer: +// +// Create Date: 01/03/2021 09:20:53 PM +// Design Name: +// Module Name: SEG_P2S +// Project Name: +// Target Devices: +// Tool Versions: +// Description: +// +// Dependencies: +// +// Revision: +// Revision 0.01 - File Created +// Additional Comments: +// +////////////////////////////////////////////////////////////////////////////////// + + +module SEG_P2S( clk, + data_in, + ena, + S_DT, + S_CLK, + S_CLR, + S_EN ); +parameter WIDTH = 64; +parameter DELAY = 12; + +input clk; +input ena; +input [ WIDTH - 1: 0 ] data_in; +output S_DT; +output S_CLK; +output S_CLR; +output S_EN; + +wire s_clk, s_data; +reg out_ena; + +assign S_CLK = s_clk; +assign S_DT = s_data; +assign S_EN = out_ena; +assign S_CLR = 1'b1; + +reg [ WIDTH: 0 ] shift; +reg [ DELAY - 1: 0 ] counter = -1; +wire s_clk_Ena; + +assign s_clk_Ena = | shift[ WIDTH - 1: 0 ]; +assign s_clk = ~clk && s_clk_Ena; +assign s_data = shift[ WIDTH ]; + +always @ ( posedge clk or negedge ena ) begin + if ( ena == 0 ) begin + shift <= 0; + counter <= 0; + out_ena <= 1'b1; + end + else if ( s_clk_Ena ) begin + shift <= { shift[ WIDTH - 1: 0 ], 1'b0 }; + end + else begin + if ( & counter ) begin + shift <= { data_in, 1'b1 }; + out_ena <= 1'b0; + end + else begin + out_ena <= 1'b1; + end + + counter <= counter + 1'b1; + end +end + +endmodule diff --git a/TankGame.srcs/sources_1/new/SegAndLed_K7.v b/TankGame.srcs/sources_1/new/SegAndLed_K7.v index 7a56105..f4364c0 100644 --- a/TankGame.srcs/sources_1/new/SegAndLed_K7.v +++ b/TankGame.srcs/sources_1/new/SegAndLed_K7.v @@ -8,7 +8,7 @@ module SegAndLed_K7( input wire [ 15: 0 ] led_infinity, input wire [ 7: 0 ] score_classic, input wire [ 7: 0 ] score_infinity, - input wire [ 31: 0 ] default_num, //when mode is 0 + input wire [ 31: 0 ] default_num, //when mode is 0 input wire [ 4: 0 ] timer, input wire enable_game_classic, input wire enable_game_infinity, @@ -60,7 +60,17 @@ always @( posedge clk ) begin 2'b11: num <= { 4'b1000, 4'b1000, 4'b1000, 4'b1000, 4'b1000, 4'b1000, 4'b1000, 4'b1000 }; default num <= 0; - endcase end +SEG_DRV m_SEG_DRV( + .clk( clk ), + .num( num ), + .ena( 1'b1 ), + .point( 8'b0000_0000 ), + .S_DT( seg_sout ), + .S_CLK( seg_clk ), + .S_CLR( seg_clrn ), + .S_EN( SEG_PEN ) + + ); endmodule diff --git a/TankGame.srcs/sources_1/new/Top.v b/TankGame.srcs/sources_1/new/Top.v index 0b06e6f..31e8275 100644 --- a/TankGame.srcs/sources_1/new/Top.v +++ b/TankGame.srcs/sources_1/new/Top.v @@ -81,7 +81,7 @@ wire [ 3: 0 ] scorea2, scoreb2; wire [ 3: 0 ] scorec1, scorec2; wire [ 3: 0 ] scored1, scored2; wire [ 3: 0 ] player1_HP, player2_HP; - +wire [ 3: 0 ] player1_HP_infinity, player2_HP_infinity; wire [ 15: 0 ] LED_classic, LED_infinity; wire [ 7: 0 ] score_classic, score_infinity; wire [ 4: 0 ] timer; @@ -125,7 +125,7 @@ game_mode u_game_mode( .clk( clk ), .btn_confirm( BTNC ), .btn_mode_sel( SW[ 0 ] ), - .btn_return( BTNU ), //the under button is used for return to the game + .btn_return( BTNU ), //the under button is used for return to the game .gameover_classic( gameover_classic ), .gameover_infinity( gameover_infinity ), .enable_shell1( enable_enermy1_bullet ), @@ -200,7 +200,9 @@ game_logic_infinity u_game_logic_infinity( .gameover_infinity( gameover_infinity ), .led_infinity( LED_infinity ), .score_infinity( score_infinity ), - .timeup( timeup ) + .timeup( timeup ), + .HP1_value( player1_HP_infinity ), + .HP2_value( player2_HP_infinity ) ); @@ -667,6 +669,8 @@ vga_data_heart_gametips u_vga_data_heart_gametips( .gameover_infinity( gameover_infinity ), .HP1_value( player1_HP ), .HP2_value( player2_HP ), + .HP1_value_infinity( player1_HP_infinity ), + .HP2_value_infinity( player2_HP_infinity ), .score_classic( score_classic ), .vgaData( heart_gametips_data ) ); @@ -703,7 +707,7 @@ SegAndLed u_SegAndLed( .score_classic( score_classic ), .score_infinity( score_infinity ), .timer( timer ), - .default_num( num ), //when mode ==00(before begin mode) then output num ,you can also use it as debug + .default_num( num ), //when mode ==00(before begin mode) then output num ,you can also use it as debug .enable_game_classic( enable_game_classic ), .enable_game_infinity( enable_game_infinity ), .player1_tank_en( player1_tank_en ), diff --git a/TankGame.srcs/sources_1/new/game_logic_infinity.v b/TankGame.srcs/sources_1/new/game_logic_infinity.v index 033bbb9..3fc2184 100644 --- a/TankGame.srcs/sources_1/new/game_logic_infinity.v +++ b/TankGame.srcs/sources_1/new/game_logic_infinity.v @@ -39,13 +39,14 @@ module game_logic_infinity( input item_test, input item_invincible, - + output reg [ 3: 0 ] HP1_value, + output reg [ 3: 0 ] HP2_value, output reg [ 4: 0 ] timer, output reg gameover_infinity, output wire [ 15: 0 ] led_infinity, - output reg [ 7: 0 ] score_infinity, //[7:4] is player2 ,[3:0] is player1 + output reg [ 7: 0 ] score_infinity, //[7:4] is player2 ,[3:0] is player1 output reg timeup ); @@ -67,8 +68,8 @@ initial begin score2 <= 0; add_flag <= 0; item_flag <= 0; - HP1_value <= 2; - HP2_value <= 2; + HP1_value <= 3; + HP2_value <= 3; timeup <= 0; end @@ -86,8 +87,8 @@ always @( posedge clk ) begin HP2_value <= HP2_value; end if ( enable_game_infinity == 1'b0 ) begin - HP1_value <= 2; - HP2_value <= 2; + HP1_value <= 3; + HP2_value <= 3; end mytank1_state_last <= mytank1_state; mytank2_state_last <= mytank2_state; @@ -144,7 +145,7 @@ always @( posedge clk ) begin else begin if ( score1 < scorea1 + scoreb1 + scorec1 + scored1 ) begin if ( add_flag == 0 && timer > 0 && timer < 16 ) begin - timer <= timer + 4; + timer <= timer + 3; cnt <= 0; add_flag = 1; end @@ -154,7 +155,7 @@ always @( posedge clk ) begin end if ( score2 < scorea2 + scoreb2 + scorec2 + scored2 ) begin if ( add_flag == 0 && timer > 0 && timer < 16 ) begin - timer <= timer + 4; + timer <= timer + 3; cnt <= 0; add_flag = 1; end @@ -163,7 +164,7 @@ always @( posedge clk ) begin add_flag = 0; end - score1 <= scorea1 + scoreb1 + scorec1 + scored1 ; + score1 <= scorea1 + scoreb1 + scorec1 + scored1; score2 <= scorea2 + scoreb2 + scorec2 + scored2; if ( item_addtime == 1 || item_test ) begin diff --git a/TankGame.srcs/sources_1/new/vga_data_heart_gametips.v b/TankGame.srcs/sources_1/new/vga_data_heart_gametips.v index d099fc2..bdc426e 100644 --- a/TankGame.srcs/sources_1/new/vga_data_heart_gametips.v +++ b/TankGame.srcs/sources_1/new/vga_data_heart_gametips.v @@ -31,6 +31,8 @@ module vga_data_heart_gametips( input gameover_infinity, input [ 3: 0 ] HP1_value, input [ 3: 0 ] HP2_value, + input [ 3: 0 ] HP1_value_infinity, + input [ 3: 0 ] HP2_value_infinity, input [ 7: 0 ] score_classic, output [ 11: 0 ] vgaData ); @@ -46,11 +48,11 @@ always @( posedge clk ) begin heart_reg2 <= 0; end else if ( mode == 1 || mode == 2 ) begin - if ( vgaH >= 5 && vgaH < 25 && vgaV >= 180 && vgaV < 300 && ( vgaV - 180 ) < HP1_value * 20 ) begin + if ( vgaH >= 5 && vgaH < 25 && vgaV >= 180 && vgaV < 300 && ( vgaV - 180 ) < ( mode == 1 ? HP1_value : HP1_value_infinity ) * 20 ) begin addra_heart_pic1 <= ( vgaH - 5 ) + ( ( vgaV - 180 ) % 20 ) * 20; heart_reg1 <= heart_pic1; end - else if ( vgaH >= 615 && vgaH < 635 && vgaV >= 180 && vgaV < 300 && ( vgaV - 180 ) < HP2_value * 20 ) begin + else if ( vgaH >= 615 && vgaH < 635 && vgaV >= 180 && vgaV < 300 && ( vgaV - 180 ) < ( mode == 1 ? HP2_value : HP2_value_infinity ) * 20 ) begin addra_heart_pic2 <= ( vgaH - 615 ) + ( ( vgaV - 180 ) % 20 ) * 20; heart_reg2 <= heart_pic2; end diff --git a/TankGame.xpr b/TankGame.xpr index 2160743..873e5c6 100644 --- a/TankGame.xpr +++ b/TankGame.xpr @@ -453,6 +453,22 @@ + + + + + + + + + + + + + + + +