feat: 新增 暫停鈕
This commit is contained in:
parent
f09a089082
commit
d62591899a
279
FPGA_FINAL.v
279
FPGA_FINAL.v
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
module FPGA_FINAL(
|
module FPGA_FINAL(
|
||||||
input CLK, reset,
|
input CLK, reset, start,
|
||||||
output reg [0:27] led,
|
output reg [0:27] led,
|
||||||
input left, right,
|
input left, right,
|
||||||
input throw,
|
input throw,
|
||||||
@ -48,167 +48,170 @@ module FPGA_FINAL(
|
|||||||
// 判斷 所有操作
|
// 判斷 所有操作
|
||||||
always @(posedge buttonclk)
|
always @(posedge buttonclk)
|
||||||
begin
|
begin
|
||||||
|
if(start)
|
||||||
|
|
||||||
if(reset)
|
|
||||||
begin
|
begin
|
||||||
blockFirst = 8'b11111111;
|
|
||||||
blockSecond = 8'b11111111;
|
|
||||||
|
|
||||||
plat_position <= 3'b010; // 預設在 x=2 的位置
|
|
||||||
ball_position <= 3'b011; // 預設在 x=3 的位置
|
|
||||||
ball_y_position <= 3'b010; // 預設在 y=1 的位置
|
|
||||||
handsOn = 1; // 預設為 為丟出狀態
|
|
||||||
|
|
||||||
upPosition = 1; // 預設為 向上
|
|
||||||
horizonPosition = 0; // 預設為 正中間方向
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
// 判斷 向左
|
if(reset)
|
||||||
if(left)
|
|
||||||
if(plat_position>0)
|
|
||||||
begin
|
begin
|
||||||
plat_position <= plat_position-1;
|
blockFirst = 8'b11111111;
|
||||||
if(handsOn==1)ball_position <= ball_position-1;
|
blockSecond = 8'b11111111;
|
||||||
end
|
|
||||||
|
|
||||||
// 判斷 向右
|
plat_position <= 3'b010; // 預設在 x=2 的位置
|
||||||
if(right)
|
ball_position <= 3'b011; // 預設在 x=3 的位置
|
||||||
if(plat_position<5)
|
ball_y_position <= 3'b010; // 預設在 y=1 的位置
|
||||||
begin
|
handsOn = 1; // 預設為 為丟出狀態
|
||||||
plat_position <= plat_position+1;
|
|
||||||
if(handsOn==1)ball_position <= ball_position+1;
|
|
||||||
end
|
|
||||||
|
|
||||||
// 判斷 丟出球
|
upPosition = 1; // 預設為 向上
|
||||||
if(throw)
|
horizonPosition = 0; // 預設為 正中間方向
|
||||||
if(handsOn)
|
|
||||||
begin
|
|
||||||
handsOn = 0;
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
// 判斷 向左
|
||||||
|
if(left)
|
||||||
|
if(plat_position>0)
|
||||||
|
begin
|
||||||
|
plat_position <= plat_position-1;
|
||||||
|
if(handsOn==1)ball_position <= ball_position-1;
|
||||||
|
end
|
||||||
|
|
||||||
|
// 判斷 向右
|
||||||
|
if(right)
|
||||||
|
if(plat_position<5)
|
||||||
|
begin
|
||||||
|
plat_position <= plat_position+1;
|
||||||
|
if(handsOn==1)ball_position <= ball_position+1;
|
||||||
|
end
|
||||||
|
|
||||||
|
// 判斷 丟出球
|
||||||
|
if(throw)
|
||||||
|
if(handsOn)
|
||||||
|
begin
|
||||||
|
handsOn = 0;
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 下方操作球的運行
|
|
||||||
// 除頻用
|
|
||||||
if(ballTime<2)
|
// 下方操作球的運行
|
||||||
ballTime <= ballTime+1;
|
// 除頻用
|
||||||
else
|
if(ballTime<2)
|
||||||
//開始判斷球的行進
|
ballTime <= ballTime+1;
|
||||||
begin
|
else
|
||||||
ballTime <= 0;
|
//開始判斷球的行進
|
||||||
if(handsOn==0) // 如果是丟出去的狀態才移動
|
|
||||||
begin
|
begin
|
||||||
// 先判斷垂直方向
|
ballTime <= 0;
|
||||||
if(upPosition)
|
if(handsOn==0) // 如果是丟出去的狀態才移動
|
||||||
if(ball_y_position<7) // 還沒到頂端
|
begin
|
||||||
ball_y_position <= ball_y_position+1;
|
// 先判斷垂直方向
|
||||||
|
if(upPosition)
|
||||||
|
if(ball_y_position<7) // 還沒到頂端
|
||||||
|
ball_y_position <= ball_y_position+1;
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
ball_y_position <= ball_y_position-1; // 到頂端就開始往下
|
||||||
|
upPosition = 0;
|
||||||
|
end
|
||||||
else
|
else
|
||||||
begin
|
if(ball_y_position>1)
|
||||||
ball_y_position <= ball_y_position-1; // 到頂端就開始往下
|
ball_y_position <= ball_y_position-1;
|
||||||
upPosition = 0;
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if(ball_y_position>1)
|
|
||||||
ball_y_position <= ball_y_position-1;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 判斷水平方向
|
// 判斷水平方向
|
||||||
if(horizonPosition==1)
|
if(horizonPosition==1)
|
||||||
if(ball_position<7)
|
if(ball_position<7)
|
||||||
ball_position <= ball_position+1; // 範圍內右移
|
ball_position <= ball_position+1; // 範圍內右移
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
horizonPosition = -1; // 超過範圍就轉向左邊
|
horizonPosition = -1; // 超過範圍就轉向左邊
|
||||||
ball_position <= ball_position-1;
|
ball_position <= ball_position-1;
|
||||||
end
|
end
|
||||||
else if(horizonPosition==-1)
|
else if(horizonPosition==-1)
|
||||||
if(ball_position>0)
|
if(ball_position>0)
|
||||||
ball_position <= ball_position-1; // 範圍內左移
|
ball_position <= ball_position-1; // 範圍內左移
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
horizonPosition = 1; // 超過範圍就轉向右邊
|
horizonPosition = 1; // 超過範圍就轉向右邊
|
||||||
ball_position <= ball_position+1;
|
ball_position <= ball_position+1;
|
||||||
end
|
end
|
||||||
|
|
||||||
// 判斷特殊狀況(碰到板子)
|
// 判斷特殊狀況(碰到板子)
|
||||||
if(ball_y_position==1)
|
if(ball_y_position==1)
|
||||||
if(ball_position==plat_position)
|
if(ball_position==plat_position)
|
||||||
begin
|
begin
|
||||||
if(horizonPosition==0) horizonPosition = -1;
|
if(horizonPosition==0) horizonPosition = -1;
|
||||||
else ball_y_position <= ball_y_position+1;
|
else ball_y_position <= ball_y_position+1;
|
||||||
upPosition = 1;
|
|
||||||
end
|
|
||||||
else if(ball_position==plat_position+1)
|
|
||||||
begin
|
|
||||||
upPosition = 1;
|
|
||||||
ball_y_position <= ball_y_position+1;
|
|
||||||
end
|
|
||||||
else if(ball_position==plat_position+2)
|
|
||||||
begin
|
|
||||||
if(horizonPosition==0) horizonPosition = 1;
|
|
||||||
else ball_y_position <= ball_y_position+1;
|
|
||||||
upPosition = 1;
|
|
||||||
end
|
|
||||||
else if(ball_position==plat_position-1 && horizonPosition==1)
|
|
||||||
begin
|
|
||||||
horizonPosition = -1;
|
|
||||||
ball_position <= ball_position-1;
|
|
||||||
ball_y_position <= ball_y_position+1;
|
|
||||||
upPosition = 1;
|
|
||||||
end
|
|
||||||
else if(ball_position==plat_position+3 && horizonPosition==-1)
|
|
||||||
begin
|
|
||||||
horizonPosition = 1;
|
|
||||||
ball_position <= ball_position+1;
|
|
||||||
ball_y_position <= ball_y_position+1;
|
|
||||||
upPosition = 1;
|
|
||||||
end
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
horizonPosition = 0;
|
|
||||||
ball_y_position <= ball_y_position-1;
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// // 判斷特殊狀態
|
|
||||||
if(ball_y_position==6)
|
|
||||||
if(blockSecond[ball_position]==1)
|
|
||||||
begin
|
|
||||||
blockSecond[ball_position] = 0;
|
|
||||||
|
|
||||||
if(upPosition) upPosition = 0;
|
|
||||||
else begin
|
|
||||||
horizonPosition = -horizonPosition;
|
|
||||||
upPosition = 1;
|
upPosition = 1;
|
||||||
end
|
end
|
||||||
if(ball_position==0) horizonPosition = 1;
|
else if(ball_position==plat_position+1)
|
||||||
if(ball_position==7) horizonPosition = -1;
|
begin
|
||||||
|
upPosition = 1;
|
||||||
|
ball_y_position <= ball_y_position+1;
|
||||||
|
end
|
||||||
|
else if(ball_position==plat_position+2)
|
||||||
|
begin
|
||||||
|
if(horizonPosition==0) horizonPosition = 1;
|
||||||
|
else ball_y_position <= ball_y_position+1;
|
||||||
|
upPosition = 1;
|
||||||
|
end
|
||||||
|
else if(ball_position==plat_position-1 && horizonPosition==1)
|
||||||
|
begin
|
||||||
|
horizonPosition = -1;
|
||||||
|
ball_position <= ball_position-1;
|
||||||
|
ball_y_position <= ball_y_position+1;
|
||||||
|
upPosition = 1;
|
||||||
|
end
|
||||||
|
else if(ball_position==plat_position+3 && horizonPosition==-1)
|
||||||
|
begin
|
||||||
|
horizonPosition = 1;
|
||||||
|
ball_position <= ball_position+1;
|
||||||
|
ball_y_position <= ball_y_position+1;
|
||||||
|
upPosition = 1;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
horizonPosition = 0;
|
||||||
|
ball_y_position <= ball_y_position-1;
|
||||||
|
end
|
||||||
|
|
||||||
ball_position <= ball_position + horizonPosition;
|
|
||||||
if(upPosition) ball_y_position <= ball_y_position +1;
|
|
||||||
else ball_y_position <= ball_y_position -1;
|
|
||||||
end
|
|
||||||
// // 判斷特殊狀態
|
|
||||||
if(ball_y_position==7)
|
|
||||||
if(blockFirst[ball_position]==1)
|
|
||||||
begin
|
|
||||||
blockFirst[ball_position] = 0;
|
|
||||||
|
|
||||||
upPosition = 0;
|
|
||||||
|
|
||||||
if(ball_position==0) horizonPosition = 1;
|
|
||||||
if(ball_position==7) horizonPosition = -1;
|
|
||||||
|
|
||||||
ball_position <= ball_position + horizonPosition;
|
// // 判斷特殊狀態
|
||||||
ball_y_position <= ball_y_position -1;
|
if(ball_y_position==6)
|
||||||
end
|
if(blockSecond[ball_position]==1)
|
||||||
|
begin
|
||||||
|
blockSecond[ball_position] = 0;
|
||||||
|
|
||||||
|
if(upPosition) upPosition = 0;
|
||||||
|
else begin
|
||||||
|
horizonPosition = -horizonPosition;
|
||||||
|
upPosition = 1;
|
||||||
|
end
|
||||||
|
if(ball_position==0) horizonPosition = 1;
|
||||||
|
if(ball_position==7) horizonPosition = -1;
|
||||||
|
|
||||||
|
ball_position <= ball_position + horizonPosition;
|
||||||
|
if(upPosition) ball_y_position <= ball_y_position +1;
|
||||||
|
else ball_y_position <= ball_y_position -1;
|
||||||
|
end
|
||||||
|
// // 判斷特殊狀態
|
||||||
|
if(ball_y_position==7)
|
||||||
|
if(blockFirst[ball_position]==1)
|
||||||
|
begin
|
||||||
|
blockFirst[ball_position] = 0;
|
||||||
|
|
||||||
|
upPosition = 0;
|
||||||
|
|
||||||
|
if(ball_position==0) horizonPosition = 1;
|
||||||
|
if(ball_position==7) horizonPosition = -1;
|
||||||
|
|
||||||
|
ball_position <= ball_position + horizonPosition;
|
||||||
|
ball_y_position <= ball_y_position -1;
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user