当前位置:文档之家› 基于FPGA的游戏代码(VGA现实)

基于FPGA的游戏代码(VGA现实)

//VGA显示

module vga(clkin,btn_click,X,Y,red,green,blue,hsync,vsync,
switch,reset,x_increment,y_increment,q,x_increment_2,y_increment_2,q_2,X_2,Y_2,btn_click_2,showmenu
,inred,ingreen,inblue,inhsync,invsync,man1score,man2score,aiscore,music,nanyi);

input clkin; //50MHz
input [2:0] btn_click; // button click: Left-Middle-Right
input [9:0] X,Y;
input [2:0] btn_click_2; // button click: Left-Middle-Right
input [9:0] X_2,Y_2;
input switch;
input reset;
input [8:0]x_increment;
input [8:0]y_increment;
input [32:0] q; //移位寄存器
input [8:0]x_increment_2;
input [8:0]y_increment_2;
input [32:0] q_2;
input showmenu;
input inred;
input ingreen;
input inblue;
input inhsync,invsync;
input music,nanyi;

output red,green,blue;
output hsync,vsync;

output [8:0]man1score;
output [8:0]man2score;
output [8:0]aiscore;

reg red,green,blue;
reg hsync,vsync;
reg clk1; //25MHz
reg[9:0] hcount,vcount;
reg show;
reg [18:0]e='d0;
reg [18:0]f='d0;
reg [18:0]g='d0;
reg [18:0]h1='d0;
reg [18:0]h2='d0;
reg [18:0]h3='d0;
reg [18:0]h='d0;

reg [12:0]ballx='d475;
reg [12:0]bally='d275;
reg [12:0]ballvx=0;
reg [12:0]ballvy=0;
reg [12:0]aix='d375;
reg [12:0]aiy='d157;
reg [12:0]aivx;
reg [12:0]aivy;
reg [12:0]man1x='d475;
reg [12:0]man1y='d392;
reg [12:0]man1vx;
reg [12:0]man1vy;
reg [12:0]man2x='d475;
reg [12:0]man2y='d157;
reg [12:0]man2vx;
reg [12:0]man2vy;

reg [8:0]aiscore='d0;
reg [8:0]man1score='d0;
reg [8:0]man2score='d0;
reg visible='b1;
reg restart='d0;
reg [12:0]randnum;
reg [12:0]temp;




always@(posedge clkin) //分频
begin
clk1=~clk1;
end
parameter char_line00 = 128'h00000000000000000000000000000000,
char_line01 = 128'h00000000000000000000000000000000,
char_line02 = 128'h00000000000000000006000000000000,
char_line03 = 128'h000E0000000018000003800000000000,
char_line04 = 128'h000E000000001C000000800000001E00,
char_line05 = 128'h000C000000600C0000007F80000FFF00,
char_line06 = 128'h000C000007F00400007FFC0003FE0F80,
char_line07 = 128'h000C00000630000003F0000001C01C00,
char_line08 = 128'h000C0000062000300030780000003800,
char_line09 = 128'h000C7C0006200FFC003F800000007000,
char_line0a = 128'h003FFF000621FE00000000000000C000,
char_line0b = 128'h0FEC0E00042780000001FC0000028000,
char_line0c = 128'h060C0E0004A00200003E1C0000030000,
char_line0d = 128'h060C0C0007A003000020180000018000,
char_line0e = 128'h020FCC0004204320001FE00000018000,
char_line0f = 128'h037F0C00042036300000008000018000,
char_line10 = 128'h030C0C0004221E300001CFC000018000,
char_line11 = 128'h030C180005A31C3007EE688000018000,
char_line12 = 128'h030C180007A30E300648688000018000,
char_line13 = 128'h010DF8000C231F300649488000018000,
char_line14 = 128'h01FFB8200C2333300749488000008000,
char_line15 = 128'h010C10200C23213004494E8000008000,
char_line16 = 128'h000C002008234030044B4A8000018000,

char_line17 = 128'h000C002008230030074A488000018000,
char_line18 = 128'h000400301023FFF0044A088400018000,
char_line19 = 128'h000600701067E0200844D884001F8000,
char_line1a = 128'h000701F031E2002009C850C4000F8000,
char_line1b = 128'h0003FFE020E0002010D0307C00038000,
char_line1c = 128'h00007F004060000020A0203C00030000,
char_line1d = 128'h00000000004000000000400400000000,
char_line1e = 128'h00000000000000000000000000000000,
char_line1f = 128'h00000000000000000000000000000000,
char_line20 = 128'h00000000000000000000000000000000,
char_line21 = 128'h00000000000000000000000000000000,
char_line22 = 128'h00000000000E00000006000000000000,
char_line23 = 128'h00000000000700000003800000000000,
char_line24 = 128'h00000000000100000000800000001E00,
char_line25 = 128'h00000F000000078000007F80000FFF00,
char_line26 = 128'h00F07F000203FFE0007FFC0003FE0F80,
char_line27 = 128'h03E0E00003FE01F003F0000001C01C00,
char_line28 = 128'h1F000000060001800030780000003800,
char_line29 = 128'h0100000006000000003F800000007000,
char_line2a = 128'h010000000E03E000000000000000C000,
char_line2b = 128'h01000FC00C7F00000001FC0000028000,
char_line2c = 128'h0100FF0000060000003E1C0000030000,
char_line2d = 128'h01F7D000000E08000020180000018000,
char_line2e = 128'h03C1980000180C00001FE00000018000,
char_line2f = 128'h1F019800007818000000008000018000,
char_line30 = 128'h010********C30000001CFC000018000,
char_line31 = 128'h010********E600007EE688000018000,
char_line32 = 128'h010********B80000648688000018000,
char_line33 = 128'h01331004006360000649488000018000,
char_line34 = 128'h01C6100400C738000749488000008000,
char_line35 = 128'h03861004010D9E0004494E8000008000,
char_line36 = 128'h0E0C100400198F80044B4A8000018000,
char_line37 = 128'h7C18180E003183F8074A488000018000,
char_line38 = 128'h7030181E00C181F0044A088400018000,
char_line39 = 128'h00600FFC018180000844D884001F8000,
char_line3a = 128'h008007F00601800009C850C4000F8000,
char_line3b = 128'h010000000001800010D0307C00038000,
char_line3c = 128'h00000000001F000020A0203C00030000,
char_line3d = 128'h00000000000700000000400400000000,
char_line3e = 128'h00000000000600000000000000000000,
char_line3f = 128'h00000000000000000000000000000000;


reg[6:0] char_bit; //显示位计算 256 * 32
reg[6:0] char_bit1;
reg[6:0] char_bit2;
reg[6:0] char_bit3;

always@(posedge clk1)
begin
if(hcount==10'b1100011111) //799
begin
if(vco

unt==10'b1000001100)//524
begin
vcount<=10'b0;
hcount<=10'b0;
end
else begin
hcount<=10'b0;
vcount=vcount+1;
end
end
else hcount=hcount+1;
end

always@(posedge clk1)
begin
show=showmenu;
if(show==0)
begin
if((hcount>10'b0000000111)&&(hcount<10'b0001101000)) //行同步宽度96个像素
hsync<=1'b0;
else hsync<=1'b1;
end
else if(show==1) hsync<=inhsync;
end

always@ (posedge clk1)
begin
if(show==0)
begin
if((vcount>10'b0000000001)&&(vcount<10'b0000000100))//场同步宽度2个行
vsync<=1'b0;
else vsync<=1'b1;
end
else if(show==1) vsync<=invsync;
end


///////////////////////////////////////////////main Code////////////////////////////////////////////////////////

always @(posedge clkin) ////////ball's movement
begin
e=e+1;
f=f+1;
if (reset==1'b1)begin /////////reset!
aiscore=0;
man1score=0;
man2score=0;
visible=1;

ballvx=0;
ballvy=0;
ballx=10'd475;
bally=10'd275;

end

if(restart==1) begin /////////restart!
visible=1;
//yanshi3seconds

ballvx=0;
ballvy=0;
ballx=10'd475;
bally=10'd275;

restart=0;
end

//if((ballx-aix)*(ballx-aix)+(bally-aiy)*(bally-aiy)<='d1225)h1=1;
//if((ballx-X_2)*(ballx-X_2)+(bally-Y_2)*(bally-Y_2)<='d1225)h2=1;
//if((ballx-X)*(ballx-X)+(bally-Y)*(bally-Y)<='d1225)h3=1;


if(e==500000)
begin
h=0;
ballx=ballx+ballvx;
bally=bally+ballvy;
e=0;
if(ballx>=770)begin ballx=770;ballvx=-ballvx;end
if(ballx<=180)begin ballx=180;ballvx=-ballvx;end
if(bally>=500)begin bally=500;ballvy=-(ballvy);end
if(bally<=50) begin bally=50;ballvy=-1*(ballvy);end



if(ballx>375&&ballx<=575&&bally>=50&&bally<=58)
begin
visible=0;
ballvx=0;
ballvy=0;
man1score<=man1score+1;
restart=1;
end
if(ballx>=375&&ballx<=575&&bally<=500&&bally>=492)
begin
visible=0;
ballvx=0;
ballvy=0;
if(switch==0) begin
aiscore<=aiscore+1;
restart=1;
end
else man2score<=man2score+1;
restart=1;

end
end
//if(man1score==7)begin youwin=1;man1score=0;man2score=0;aiscore=0;end
//if(aiscore==7||man2score==7)begin youlose=1;man1score=0;man2score=0;aiscore=0;end




if(f==1000&&h==0)
begin
f=0;
if(switch==0) //man VS computer
begin
if((ballx-aix)*(ballx-aix)+(bally-aiy)*(bally-aiy)<='d1225)
b

egin
// ballvx=(ballvx>0?ballvx:(-ballvx))*(ballx>aix?1:(-1));
ballvx=ballvx;
// ballvy=(ballvy>0?ballvy:(-ballvy))*(bally>aiy?1:(-1));
ballvy=-ballvy;
h=1;

end
end
else //man1 vs man2
begin
//if((ballx-man2x)*(ballx-man2x)+(bally-man2y)*(bally-bally)<='d1255)
if((ballx-X_2)*(ballx-X_2)+(bally-Y_2)*(bally-Y_2)<='d1225)
begin
//ballvx=aivx-ballvx;
//ballvy=aivy-ballvy;
ballvx=x_increment_2+(ballvx>0?ballvx:(-ballvx))*(ballx>X?1:(-1));
ballvy=y_increment_2+(ballvy>0?ballvy:(-ballvy))*(bally>Y?1:(-1));
h=1;
end
end


if(show==0)begin/////////////////////////////////////
if((ballx-X)*(ballx-X)+(bally-Y)*(bally-Y)<='d1225)
begin
h=1;
if(x_increment*x_increment+y_increment*y_increment>4)begin end

if((Y-bally)>'d30)//1
begin
if(ballvx==0&&ballvy==0)
begin
if(q[5]==0)
begin
ballvx=x_increment;
ballvy=-y_increment;
end
else
begin
ballvx=-x_increment;
ballvy=-y_increment;
end
end
else
begin
if(x_increment==0)ballvx=ballvx;
else if(q[5]==0) ballvx=ballvx;//mouse right
else ballvx=ballvx;

if(y_increment==0)ballvy=-ballvy;
else if(q[6]==0) ballvy=y_increment>(ballvy>0?ballvy:(-ballvy))?(-y_increment):(-ballvy);//mouse up
else ballvy=y_increment>(ballvy>0?ballvy:(-ballvy))?(-y_increment):(-ballvy);
end
end
else if((bally-Y)>'d30)//2
begin
if(ballvx==0&&ballvy==0)begin ballvx=x_increment;ballvy=y_increment;end
else begin
if(q[5]==0) ballvx=ballvx;//mouse right
else ballvx=ballvx;
if(q[6]==0) ballvy=y_increment>(ballvy>0?ballvy:(-ballvy))?(-y_increment):(-ballvy);//mouse up
else ballvy=y_increment>(ballvy>0?ballvy:(-ballvy))?y_increment:(-ballvy);
end
end


else
begin
if(ballvx==0&&ballvy==0)begin
if(q[5]==0)
begin
ballvx=x_increment;
ballvy=-y_increment;
end
else
begin
ballvx=-x_increment;
ballvy=-y_increment ;
end
end
else
begin
temp=ballvx;
if(ballvx*ballvy<0)begin ballvx=(x_increment>(ballvy>0?ballvy:(-ballvy)))?(q[5]==0?x_increment:(-x_increment)):ballvy;
ballvy=(y_increment>(temp>0?temp:(-temp)))?(q[6]==1?y_increment:(-y_increment)):temp;
end
else begin ballvx=x_increment>((ballvy>0?ballvy:(-ballvy)))?(q[5]==0?x_increment:(-x_increment)):(-ballvy);
ballvy=y_increment>((temp>0?temp:(-temp)))?(q[6]==1?y_increment:(-y_increment)):(-temp);
end
end
end
/* if(bally>=Y&&bally<(Y+'d30)&&ballx>X)//3
begin
temp=ballvx;
if(ballvx*ballvy<0)begin ballvx=ballvy;ballvy=temp;end
else begin ballvx=-ba

llvy;ballvy=-temp;end
end

if(bally=(Y-'d30)&&ballx>X)//4
begin
temp=ballvx;
if(ballvx*ballvy<0)begin ballvx=ballvy;ballvy=temp;end
else begin ballvx=-ballvy;ballvy=-temp;end
end

if(bally<=(Y+'d30)&&bally>Y&&ballxbegin
temp=ballvx;
if(ballvx*ballvy<0)begin ballvx=ballvy;ballvy=temp;end
else begin ballvx=-ballvy;ballvy=-temp;end
end

if(bally>(Y-'d30)&&bally<=Y&&ballxbegin
temp=ballvx;
if(ballvx*ballvy<0)begin ballvx=ballvy;ballvy=temp;end
else begin ballvx=-ballvy;ballvy=-temp;end
end
*/
// if(ballvx*ballvx+ballvy*ballvy>=2)begin ballvx=ballvx;ballvy=ballvy;end

end

end
end
end


always@(posedge clkin) ////////ai's movement
if(switch==0&&show==0)
begin
if(reset==1||restart==1)begin aix='d475;aiy='d157;end

g=g+1;
if(g==500000)
begin
g=0;
aix=aix+aivx;
aiy=aiy+aivy;
if(aix<190)aix=190;
if(aix>760)aix=760;
if(aiy<60) aiy=60;
if(aiy>255) aiy=255;

if(aixbegin
if(ballvx>0)aivx=1*ballvx;
if(ballvx<0)aivx=-1*ballvx;
if(ballvx==0)aivx=1;
end

if(aix>ballx)
begin
if(ballvx>0)aivx=-1*ballvx;
if(ballvx<0)aivx=1*ballvx;
if(ballvx==0)aivx=-1;
end

end

end





////////////////////////////////////////////////Main VGA Code////////////////////////////////////////////////////////////

always@(posedge clk1)
begin
if(show==1)
begin
{red,green,blue}<={inred,ingreen,inblue};
end
///////////////////////////////////////////////////////////////////
if(man1score==7)
begin
if(hcount == 10'd420) char_bit2 <= 7'd128; //先显示最高位数据 128 wei 572是X轴的起始坐标
else if(hcount > 10'd420 && hcount < 10'd548) char_bit2 <= char_bit2-1'b1; //依次显示后面的数据
if(hcount > 10'd420 && hcount < 10'd548) begin //////////kai shi you xi
case(vcount)
10'd321: if(char_line20[char_bit2]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd322: if(char_line21[char_bit2]){red,green,blue}<=3'b110; //红色
else {red,green,blue}<=3'b010; //绿色
10'd323: if(char_line22[char_bit2]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd324: if(char_line23[char_bit2]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd325: if(char_line24[char_bit2]) {red,green,blue}<= 3'b110; //红se
else {red,green,blue}<= 3'b010; //绿色
10'd326: if(char_line25[char_bit2]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd327: if(char_line26[char_bit2]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue} <= 3'b010; //绿色
10'd328: if(char_line27[char_bit2]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色

10'd329: if(char_line28[char_bit2]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd330: if(char_line29[char_bit2]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd331: if(char_line2a[char_bit2]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd332: if(char_line2b[char_bit2]) {red,green,blue}<=3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd333: if(char_line2c[char_bit2]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd334: if(char_line2d[char_bit2]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd335: if(char_line2e[char_bit2]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd336: if(char_line2f[char_bit2]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色

/////-------------------------------------------------------------------

10'd337: if(char_line30[char_bit2]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd338: if(char_line31[char_bit2]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd339: if(char_line32[char_bit2]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd340: if(char_line33[char_bit2]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd341: if(char_line34[char_bit2]) {red,green,blue}<= 3'b110; //红se
else {red,green,blue}<= 3'b010;//绿色
10'd342: if(char_line35[char_bit2]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd343: if(char_line36[char_bit2]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd344: if(char_line37[char_bit2]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd345: if(char_line38[char_bit2]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd346: if(char_line39[char_bit2]) {red,green,blue}<= 3'b110; //红色
else{red,green,blue}<= 3'b010; //绿色
10'd347: if(char_line3a[char_bit2]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd348: if(char_line3b[char_bit2]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd349: if(char_line3c[char_bit2]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd350: if(char_line3d[char_bit2]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd351: if(char_line3e[char_bit2]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd

352: if(char_line3f[char_bit2]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
endcase
end

end
if(man2score==7)
begin

if(hcount == 10'd420) char_bit1 <= 7'd128; //先显示最高位数据 128 wei 572是X轴的起始坐标
else if(hcount > 10'd420 && hcount < 10'd548) char_bit1 <= char_bit1-1'b1; //依次显示后面的数据
if(hcount > 10'd420 && hcount < 10'd548) begin //////////kai shi you xi
case(vcount)
10'd201: if(char_line20[char_bit1]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd202: if(char_line21[char_bit1]){red,green,blue}<=3'b110; //红色
else {red,green,blue}<=3'b010; //绿色
10'd203: if(char_line22[char_bit1]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd204: if(char_line23[char_bit1]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd205: if(char_line24[char_bit1]) {red,green,blue}<= 3'b110; //红se
else {red,green,blue}<= 3'b010; //绿色
10'd206: if(char_line25[char_bit1]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd207: if(char_line26[char_bit1]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue} <= 3'b010; //绿色
10'd208: if(char_line27[char_bit1]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd209: if(char_line28[char_bit1]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd210: if(char_line29[char_bit1]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd211: if(char_line2a[char_bit1]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd212: if(char_line2b[char_bit1]) {red,green,blue}<=3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd213: if(char_line2c[char_bit1]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd214: if(char_line2d[char_bit1]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd215: if(char_line2e[char_bit1]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd216: if(char_line2f[char_bit1]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色

/////-------------------------------------------------------------------

10'd217: if(char_line30[char_bit1]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd218: if(char_line31[char_bit1]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd219: if(char_line32[char_bit1]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd220:

if(char_line33[char_bit1]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd221: if(char_line34[char_bit1]) {red,green,blue}<= 3'b110; //红se
else {red,green,blue}<= 3'b010;//绿色
10'd222: if(char_line35[char_bit1]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd223: if(char_line36[char_bit1]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd224: if(char_line37[char_bit1]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd225: if(char_line38[char_bit1]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd226: if(char_line39[char_bit1]) {red,green,blue}<= 3'b110; //红色
else{red,green,blue}<= 3'b010; //绿色
10'd227: if(char_line3a[char_bit1]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd228: if(char_line3b[char_bit1]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd229: if(char_line3c[char_bit1]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd230: if(char_line3d[char_bit1]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd231: if(char_line3e[char_bit1]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd232: if(char_line3f[char_bit1]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
endcase
end
end

if(aiscore==7)
begin
if(hcount == 10'd420) char_bit <= 7'd128;
else if(hcount > 10'd420 && hcount < 10'd548) char_bit <= char_bit-1'b1;
if(hcount > 10'd420 && hcount < 10'd548) begin
case(vcount)
10'd201: if(char_line00[char_bit]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd202: if(char_line01[char_bit]){red,green,blue}<=3'b110; //红色
else {red,green,blue}<=3'b010; //绿色
10'd203: if(char_line02[char_bit]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd204: if(char_line03[char_bit]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd205: if(char_line04[char_bit]) {red,green,blue}<= 3'b110; //红se
else {red,green,blue}<= 3'b010; //绿色
10'd206: if(char_line05[char_bit]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd207: if(char_line06[char_bit]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue} <= 3'b010; //绿色
10'd208: if(char_line07[char_bit]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd209: if(char_line08[char_bit]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色


10'd210: if(char_line09[char_bit]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd211: if(char_line0a[char_bit]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd212: if(char_line0b[char_bit]) {red,green,blue}<=3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd213: if(char_line0c[char_bit]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd214: if(char_line0d[char_bit]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd215: if(char_line0e[char_bit]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd216: if(char_line0f[char_bit]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色

/////-------------------------------------------------------------------

10'd217: if(char_line10[char_bit]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd218: if(char_line11[char_bit]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd219: if(char_line12[char_bit]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd220: if(char_line13[char_bit]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd221: if(char_line14[char_bit]) {red,green,blue}<= 3'b110; //红se
else {red,green,blue}<= 3'b010;//绿色
10'd222: if(char_line15[char_bit]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd223: if(char_line16[char_bit]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd224: if(char_line17[char_bit]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd225: if(char_line18[char_bit]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd226: if(char_line19[char_bit]) {red,green,blue}<= 3'b110; //红色
else{red,green,blue}<= 3'b010; //绿色
10'd227: if(char_line1a[char_bit]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd228: if(char_line1b[char_bit]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd229: if(char_line1c[char_bit]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd230: if(char_line1d[char_bit]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd231: if(char_line1e[char_bit]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
10'd232: if(char_line1f[char_bit]) {red,green,blue}<= 3'b110; //红色
else {red,green,blue}<= 3'b010; //绿色
endc

ase
end
end
//////////////////////////////////////////////////////////////////
if(show==0&&man1score!=7&&man2score!=7&&aiscore!=7)
begin
if(((hcount-X)*(hcount-X)+(vcount-Y)*(vcount-Y))<='b110111111)
begin
{red,green,blue}<=btn_click + 1'b1;
end ///////////man1
else {red,green,blue}<=3'b000;
if((hcount>=375)&&(hcount<=575)&&(((vcount>=40)&&(vcount<=50))||((vcount>=500)&&(vcount<=510))))
begin
{red,green,blue}<=3'b001; ////////two gates
end

if(hcount>=170&&hcount<=780&&((vcount>=40&&vcount<=42)||(vcount>=508&&vcount<=510)||vcount==275))
begin
{red,green,blue}<=3'b011; ///////heng bian kuang
end

if(vcount>=40&&vcount<=510&&((hcount>=170&&hcount<=172)||(hcount>=778&&hcount<=780)))
begin
{red,green,blue}<=3'b011; ///////shu bian kuang
end

if(((hcount-475)*(hcount-475)+(vcount-275)*(vcount-275))<='b111110111111&&((hcount-475)*(hcount-475)+(vcount-275)*(vcount-275))>='b111110000000)
begin
{red,green,blue}<=3'b011; ///////zhong xin yuan
end

if((((hcount-ballx)*(hcount-ballx)+(vcount-bally)*(vcount-bally))<='b10111111)&&(visible==1))
begin
{red,green,blue}<=3'b100; //////// ball
end

if(switch==0)
begin
if((hcount-aix)*(hcount-aix)+(vcount-aiy)*(vcount-aiy)<='b110111111)
begin
{red,green,blue}<=3'b001; ////////ai
end
end

if(switch==1)
begin
if((hcount-X_2)*(hcount-X_2)+(vcount-Y_2)*(vcount-Y_2)<='b110111111)
begin
{red,green,blue}<=btn_click_2 + 1'b1; //////// man2
end
end


end


end

endmodule

相关主题
文本预览
相关文档 最新文档