Merge pull request 'merge: dev to master' (#5) from dev into master
Reviewed-on: #5
This commit is contained in:
commit
9e26f58b28
115
FPGA_FINAL.v
115
FPGA_FINAL.v
@ -5,20 +5,21 @@ module FPGA_FINAL(
|
||||
output reg [2:0] life,
|
||||
input left, right,
|
||||
input throw,
|
||||
input show_two_row,
|
||||
output testLED,
|
||||
output reg a,b,c,d,e,f,g,
|
||||
output reg [0:1] COM
|
||||
);
|
||||
|
||||
reg [7:0]blockFirst = 8'b11111111;
|
||||
reg [7:0]blockSecond = 8'b11111111;
|
||||
reg [7:0]blockSecond = 8'b00000000;
|
||||
|
||||
reg [2:0]plat_position; // 板子位置
|
||||
reg [2:0]ball_position; // 球 位置
|
||||
reg [2:0]ball_y_position; // 球 y 座標
|
||||
|
||||
reg [3:0]count_digit; //個位數分數
|
||||
reg count_ten; //十位數分數
|
||||
reg [3:0]count_digit = 4'b000; //個位數分數
|
||||
reg [3:0]count_ten = 4'b0000; //十位數分數
|
||||
|
||||
reg upPosition;
|
||||
integer horizonPosition;
|
||||
@ -26,6 +27,11 @@ module FPGA_FINAL(
|
||||
reg handsOn; // bool,紀錄球現在丟出去了沒
|
||||
reg gameOverFlag;
|
||||
|
||||
reg showBonus; // bool 顯示額外球
|
||||
reg [2:0] Bonus_x; // 額外球的位子x
|
||||
reg [2:0] Bonus_y; // 額外球的位子x
|
||||
|
||||
reg ball_is_on_the_gronud; // 檢查球是否沒被盤子接住
|
||||
|
||||
initial
|
||||
begin
|
||||
@ -41,13 +47,15 @@ module FPGA_FINAL(
|
||||
ball_y_position = 3'b010; // 預設在 y=1 的位置
|
||||
handsOn = 1; // 預設為 為丟出狀態
|
||||
count_digit = 4'b0; // 分數預設0
|
||||
count_ten = 0;
|
||||
count_ten = 4'b0;
|
||||
|
||||
upPosition = 1; // 預設為 向上
|
||||
horizonPosition = 0; // 預設為 正中間方向
|
||||
|
||||
gameOverFlag = 0;
|
||||
|
||||
showBonus = 0;
|
||||
ball_is_on_the_gronud = 0;
|
||||
end
|
||||
|
||||
|
||||
@ -59,19 +67,22 @@ module FPGA_FINAL(
|
||||
|
||||
|
||||
integer ballTime;
|
||||
integer doubleTime;
|
||||
// 判斷 所有操作
|
||||
always @(posedge buttonclk)
|
||||
begin
|
||||
if(start)
|
||||
begin
|
||||
|
||||
|
||||
if(reset)
|
||||
begin
|
||||
if(life==3'b000)
|
||||
begin
|
||||
blockFirst = 8'b11111111;
|
||||
blockSecond = 8'b11111111;
|
||||
if(show_two_row)
|
||||
blockSecond = 8'b11111111;
|
||||
else
|
||||
blockSecond = 8'b00000000;
|
||||
|
||||
life = 3'b111;
|
||||
gameOverFlag = 0;
|
||||
@ -86,6 +97,9 @@ module FPGA_FINAL(
|
||||
upPosition = 1; // 預設為 向上
|
||||
horizonPosition = 0; // 預設為 正中間方向
|
||||
|
||||
showBonus = 0;
|
||||
ball_is_on_the_gronud = 0;
|
||||
|
||||
end
|
||||
|
||||
|
||||
@ -116,7 +130,7 @@ module FPGA_FINAL(
|
||||
|
||||
|
||||
|
||||
// 下方操作球的運行
|
||||
// 下方操作球的運 行
|
||||
// 除頻用
|
||||
if(ballTime<2)
|
||||
ballTime <= ballTime+1;
|
||||
@ -196,6 +210,8 @@ module FPGA_FINAL(
|
||||
begin
|
||||
horizonPosition = 0;
|
||||
ball_y_position <= ball_y_position-1;
|
||||
showBonus = 0;
|
||||
ball_is_on_the_gronud = 1;
|
||||
|
||||
life = life*2; // 扣除生命值
|
||||
if(life==3'b000)
|
||||
@ -214,7 +230,7 @@ module FPGA_FINAL(
|
||||
if(count_digit == 4'b1001)
|
||||
begin
|
||||
count_digit <= 4'b0;
|
||||
count_ten = 1;
|
||||
count_ten = count_ten + 1'b1;
|
||||
end
|
||||
blockSecond[ball_position] = 0;
|
||||
|
||||
@ -238,7 +254,7 @@ module FPGA_FINAL(
|
||||
if(count_digit == 4'b1001)
|
||||
begin
|
||||
count_digit <= 4'b0;
|
||||
count_ten = 1;
|
||||
count_ten = count_ten + 1'b1;
|
||||
end
|
||||
blockFirst[ball_position] = 0;
|
||||
|
||||
@ -252,6 +268,57 @@ module FPGA_FINAL(
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
// Bonus ball 除頻 , 每五秒從左邊射一發
|
||||
if(doubleTime<50 && showBonus == 0 && handsOn == 0 && ball_is_on_the_gronud == 0)
|
||||
begin
|
||||
doubleTime <= doubleTime+1;
|
||||
Bonus_x = plat_position ;
|
||||
Bonus_y = 1;
|
||||
end
|
||||
else
|
||||
begin
|
||||
if(handsOn == 0)
|
||||
begin
|
||||
doubleTime <= 0;
|
||||
showBonus = 1;
|
||||
if(Bonus_y == 7)
|
||||
begin
|
||||
showBonus = 0;
|
||||
end
|
||||
if(Bonus_y < 7)
|
||||
begin
|
||||
Bonus_y = Bonus_y + 1;
|
||||
end
|
||||
|
||||
// Bonus ball 撞到第一排磚塊
|
||||
if((Bonus_y == 6 && blockSecond[Bonus_x] == 1))
|
||||
begin
|
||||
count_digit <= count_digit + 1'b1;
|
||||
if(count_digit == 4'b1001)
|
||||
begin
|
||||
count_digit <= 4'b0;
|
||||
count_ten = count_ten + 1'b1;
|
||||
end
|
||||
blockSecond[Bonus_x] = 0;
|
||||
showBonus = 0;
|
||||
end
|
||||
|
||||
// Bonus ball 撞到第二排磚塊
|
||||
if((Bonus_y == 7 && blockFirst[Bonus_x] == 1))
|
||||
begin
|
||||
count_digit <= count_digit + 1'b1;
|
||||
if(count_digit == 4'b1001)
|
||||
begin
|
||||
count_digit <= 4'b0;
|
||||
count_ten = count_ten + 1'b1;
|
||||
end
|
||||
blockFirst[Bonus_x] = 0;
|
||||
showBonus = 0;
|
||||
end
|
||||
end
|
||||
// Bonus ball
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -319,6 +386,24 @@ module FPGA_FINAL(
|
||||
//開始畫磚塊
|
||||
led[16:23] = {~blockFirst[row], ~blockSecond[row], 6'b111111};
|
||||
|
||||
// 畫 Bonus ball
|
||||
if(showBonus == 1)
|
||||
if(row==Bonus_x)
|
||||
begin
|
||||
reg [7:0] map;
|
||||
case(Bonus_y)
|
||||
3'b000: map = 8'b11111110 ;
|
||||
3'b001: map = 8'b11111101 ;
|
||||
3'b010: map = 8'b11111011 ;
|
||||
3'b011: map = 8'b11110111 ;
|
||||
3'b100: map = 8'b11101111 ;
|
||||
3'b101: map = 8'b11011111 ;
|
||||
3'b110: map = 8'b10111111 ;
|
||||
3'b111: map = 8'b01111111 ;
|
||||
endcase
|
||||
led[8:15] = map;
|
||||
end
|
||||
|
||||
// 顯示分數
|
||||
if(count_digit_enable == 0)
|
||||
begin
|
||||
@ -353,8 +438,16 @@ module FPGA_FINAL(
|
||||
else
|
||||
begin
|
||||
case(count_ten)
|
||||
1'b0:{a,b,c,d,e,f,g}=7'b0000001;
|
||||
1'b1:{a,b,c,d,e,f,g}=7'b1001111;
|
||||
4'b0000:{a,b,c,d,e,f,g}=7'b0000001;
|
||||
4'b0001:{a,b,c,d,e,f,g}=7'b1001111;
|
||||
4'b0010:{a,b,c,d,e,f,g}=7'b0010010;
|
||||
4'b0011:{a,b,c,d,e,f,g}=7'b0000110;
|
||||
4'b0100:{a,b,c,d,e,f,g}=7'b1001100;
|
||||
4'b0101:{a,b,c,d,e,f,g}=7'b0100100;
|
||||
4'b0110:{a,b,c,d,e,f,g}=7'b0100000;
|
||||
4'b0111:{a,b,c,d,e,f,g}=7'b0001111;
|
||||
4'b1000:{a,b,c,d,e,f,g}=7'b0000000;
|
||||
4'b1001:{a,b,c,d,e,f,g}=7'b0000100;
|
||||
endcase
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user