updated
This commit is contained in:
@@ -146,9 +146,12 @@ local function buildBoard()
|
||||
local startX = math.floor(PW / 2 - rowW / 2)
|
||||
local py = boardTop + (row - 1) * rowSpacing
|
||||
for col = 1, pegsInRow do
|
||||
-- Jitter each peg slightly so the layout is never identical
|
||||
local jx = math.floor((math.random() - 0.5) * colSpacing * 0.35)
|
||||
local jy = math.floor((math.random() - 0.5) * rowSpacing * 0.35)
|
||||
table.insert(pegs, {
|
||||
x = startX + (col - 1) * colSpacing,
|
||||
y = py,
|
||||
x = startX + (col - 1) * colSpacing + jx,
|
||||
y = py + jy,
|
||||
})
|
||||
end
|
||||
end
|
||||
@@ -272,14 +275,23 @@ local function drawBall(bx, by)
|
||||
end
|
||||
|
||||
local function physicsLoop()
|
||||
-- Random drop X between the leftmost and rightmost peg in the first row.
|
||||
local firstPeg = pegs[1]
|
||||
local lastFirst = pegs[PEG_COLS_TOP]
|
||||
local dropX = firstPeg.x + math.random() * (lastFirst.x - firstPeg.x)
|
||||
-- Re-randomise peg positions each drop
|
||||
buildBoard()
|
||||
drawBoard()
|
||||
gpu.sync()
|
||||
|
||||
-- Random drop X anywhere across the board width
|
||||
local dropX = boardLeft + math.random() * (boardRight - boardLeft)
|
||||
local dropY = boardTop - rowSpacing * 0.6
|
||||
|
||||
local bx, by = dropX, dropY
|
||||
local vx, vy = (math.random() - 0.5) * 40, 60
|
||||
-- Random launch angle: mostly downward but tilted ±35°
|
||||
local launchAngle = (math.pi / 2) + (math.random() - 0.5) * (math.pi / 180 * 70)
|
||||
local launchSpeed = 180 + math.random() * 220 -- px/s
|
||||
|
||||
local bx = dropX
|
||||
local by = dropY
|
||||
local vx = math.cos(launchAngle) * launchSpeed
|
||||
local vy = math.sin(launchAngle) * launchSpeed -- positive = downward (screen coords)
|
||||
|
||||
local lastBx, lastBy = bx, by
|
||||
local elapsed = 0
|
||||
@@ -514,23 +526,14 @@ local function main()
|
||||
while true do
|
||||
waitForRedstonePulse()
|
||||
|
||||
-- Erase subtitle, show "dropping"
|
||||
px_text_centre("Pull lever to drop", 46, COL_BG, COL_BG, 1)
|
||||
px_text_centre(" DROPPING... ", 46, 0xFFD600, COL_BG, 1)
|
||||
gpu.sync()
|
||||
sleep(0.25)
|
||||
px_text_centre(" DROPPING... ", 46, COL_BG, COL_BG, 1)
|
||||
px_text_centre("Pull lever to drop", 46, 0x607080, COL_BG, 1)
|
||||
gpu.sync()
|
||||
|
||||
-- Run physics — outcome determined by simulation
|
||||
-- Run physics — redraws board with fresh peg positions, then drops
|
||||
local winIdx = physicsLoop()
|
||||
|
||||
-- Celebrate
|
||||
flashBucket(winIdx)
|
||||
showResult(buckets[winIdx].mult)
|
||||
|
||||
-- Redraw clean board
|
||||
-- Redraw clean board (fresh pegs already in place from physicsLoop)
|
||||
drawBoard()
|
||||
gpu.sync()
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user