feat: 新增生命條 & 失敗畫面
This commit is contained in:
parent
d62591899a
commit
4a9c0ee1be
34
FPGA_FINAL.v
34
FPGA_FINAL.v
@ -2,6 +2,7 @@
|
||||
module FPGA_FINAL(
|
||||
input CLK, reset, start,
|
||||
output reg [0:27] led,
|
||||
output reg [2:0] life,
|
||||
input left, right,
|
||||
input throw,
|
||||
output testLED
|
||||
@ -18,6 +19,7 @@ module FPGA_FINAL(
|
||||
integer horizonPosition;
|
||||
|
||||
reg handsOn; // bool,紀錄球現在丟出去了沒
|
||||
reg gameOverFlag;
|
||||
|
||||
|
||||
initial
|
||||
@ -27,6 +29,8 @@ module FPGA_FINAL(
|
||||
led[27] = 1;
|
||||
led[24:26] = 3'b000;
|
||||
|
||||
life = 3'b111;
|
||||
|
||||
plat_position = 3'b010; // 預設在 x=2 的位置
|
||||
ball_position = 3'b011; // 預設在 x=3 的位置
|
||||
ball_y_position = 3'b010; // 預設在 y=1 的位置
|
||||
@ -34,6 +38,9 @@ module FPGA_FINAL(
|
||||
|
||||
upPosition = 1; // 預設為 向上
|
||||
horizonPosition = 0; // 預設為 正中間方向
|
||||
|
||||
gameOverFlag = 0;
|
||||
|
||||
end
|
||||
|
||||
|
||||
@ -53,10 +60,17 @@ module FPGA_FINAL(
|
||||
|
||||
|
||||
if(reset)
|
||||
begin
|
||||
if(life==3'b000)
|
||||
begin
|
||||
blockFirst = 8'b11111111;
|
||||
blockSecond = 8'b11111111;
|
||||
|
||||
life = 3'b111;
|
||||
gameOverFlag = 0;
|
||||
|
||||
end
|
||||
|
||||
plat_position <= 3'b010; // 預設在 x=2 的位置
|
||||
ball_position <= 3'b011; // 預設在 x=3 的位置
|
||||
ball_y_position <= 3'b010; // 預設在 y=1 的位置
|
||||
@ -64,6 +78,7 @@ module FPGA_FINAL(
|
||||
|
||||
upPosition = 1; // 預設為 向上
|
||||
horizonPosition = 0; // 預設為 正中間方向
|
||||
|
||||
end
|
||||
|
||||
|
||||
@ -174,6 +189,11 @@ module FPGA_FINAL(
|
||||
begin
|
||||
horizonPosition = 0;
|
||||
ball_y_position <= ball_y_position-1;
|
||||
|
||||
life = life*2; // 扣除生命值
|
||||
if(life==3'b000)
|
||||
gameOverFlag = 1;
|
||||
|
||||
end
|
||||
|
||||
|
||||
@ -231,6 +251,19 @@ module FPGA_FINAL(
|
||||
// 設定這次要畫第 n 行
|
||||
led[24:26] = row;
|
||||
|
||||
|
||||
// 如果 gameOverFlag ==1就畫圖
|
||||
if(gameOverFlag)
|
||||
begin
|
||||
led[0:23] = 24'b111111111111111111111111;
|
||||
if(row==0 || row==7) led[0:7] = 8'b01111110;
|
||||
else if(row==1 || row==6) led[0:7] = 8'b10111101;
|
||||
else if(row==2 || row==5) led[0:7] = 8'b11011011;
|
||||
else if(row==3 || row==4) led[0:7] = 8'b11100111;
|
||||
else led[0:7] = 8'b11111111;
|
||||
end
|
||||
else
|
||||
begin
|
||||
// 開始畫板子 ( R )
|
||||
if(row==plat_position || row==plat_position+1 || row==plat_position+2)
|
||||
led[0:7] = 8'b11111110;
|
||||
@ -266,6 +299,7 @@ module FPGA_FINAL(
|
||||
//開始畫磚塊
|
||||
led[16:23] = {~blockFirst[row], ~blockSecond[row], 6'b111111};
|
||||
end
|
||||
end
|
||||
endmodule
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user