mirror of
https://github.com/LDDestroier/CC/
synced 2025-05-04 07:54:05 +00:00
Added animated title screen background
This commit is contained in:
parent
56a00b8ed2
commit
df8b88985f
59
tron
59
tron
@ -367,8 +367,8 @@ local doesIntersectBorder = function(x, y)
|
|||||||
return x == grid.x1 or x == grid.x2 or y == grid.y1 or y == grid.y2
|
return x == grid.x1 or x == grid.x2 or y == grid.y1 or y == grid.y2
|
||||||
end
|
end
|
||||||
|
|
||||||
--draws grid and background at scroll 'x' and 'y'
|
--draws grid and background at scroll 'x' and 'y', along with trails and players
|
||||||
local drawGrid = function(x, y)
|
local drawGrid = function(x, y, onlyDrawGrid)
|
||||||
x, y = math.floor(x + 0.5), math.floor(y + 0.5)
|
x, y = math.floor(x + 0.5), math.floor(y + 0.5)
|
||||||
local bg = {{},{},{}}
|
local bg = {{},{},{}}
|
||||||
local foreX, foreY
|
local foreX, foreY
|
||||||
@ -388,28 +388,30 @@ local drawGrid = function(x, y)
|
|||||||
backY = 1 + math.floor(sy + (y / 2)) % #gridBack
|
backY = 1 + math.floor(sy + (y / 2)) % #gridBack
|
||||||
trailChar, trailColor, trailAge = getTrail(adjX, adjY)
|
trailChar, trailColor, trailAge = getTrail(adjX, adjY)
|
||||||
isPlayer = false
|
isPlayer = false
|
||||||
|
if not onlyDrawGrid then
|
||||||
for i = 1, #player do
|
for i = 1, #player do
|
||||||
if player[i].x == adjX and player[i].y == adjY then
|
if player[i].x == adjX and player[i].y == adjY then
|
||||||
isPlayer = i
|
isPlayer = i
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
if isPlayer and not (doesIntersectBorder(adjX, adjY)) then
|
if isPlayer and not (doesIntersectBorder(adjX, adjY)) then
|
||||||
bg[1][sy] = bg[1][sy] .. dirArrow[player[isPlayer].direction]
|
bg[1][sy] = bg[1][sy] .. dirArrow[player[isPlayer].direction]
|
||||||
bg[2][sy] = bg[2][sy] .. toblit[player[isPlayer].color[1]]
|
bg[2][sy] = bg[2][sy] .. toblit[player[isPlayer].color[1]]
|
||||||
bg[3][sy] = bg[3][sy] .. grid.voidcol
|
bg[3][sy] = bg[3][sy] .. grid.voidcol
|
||||||
else
|
else
|
||||||
if trailChar and trailColor then
|
if (not onlyDrawGrid) and trailChar and trailColor then
|
||||||
trailColor = trailColor[1 + ((trailAge - 1) % #trailColor)]
|
trailColor = trailColor[1 + ((trailAge - 1) % #trailColor)]
|
||||||
bg[1][sy] = bg[1][sy] .. trailChar
|
bg[1][sy] = bg[1][sy] .. trailChar
|
||||||
bg[2][sy] = bg[2][sy] .. toblit[trailColor]
|
bg[2][sy] = bg[2][sy] .. toblit[trailColor]
|
||||||
bg[3][sy] = bg[3][sy] .. grid.voidcol
|
bg[3][sy] = bg[3][sy] .. grid.voidcol
|
||||||
else
|
else
|
||||||
if adjX < grid.x1 or adjX > grid.x2 or adjY < grid.y1 or adjY > grid.y2 then
|
if (not onlyDrawGrid) and (adjX < grid.x1 or adjX > grid.x2 or adjY < grid.y1 or adjY > grid.y2) then
|
||||||
bg[1][sy] = bg[1][sy] .. " "
|
bg[1][sy] = bg[1][sy] .. " "
|
||||||
bg[2][sy] = bg[2][sy] .. grid.voidcol
|
bg[2][sy] = bg[2][sy] .. grid.voidcol
|
||||||
bg[3][sy] = bg[3][sy] .. grid.voidcol
|
bg[3][sy] = bg[3][sy] .. grid.voidcol
|
||||||
elseif doesIntersectBorder(adjX, adjY) then
|
elseif (not onlyDrawGrid) and doesIntersectBorder(adjX, adjY) then
|
||||||
bg[1][sy] = bg[1][sy] .. grid.border
|
bg[1][sy] = bg[1][sy] .. grid.border
|
||||||
bg[2][sy] = bg[2][sy] .. grid.voidcol
|
bg[2][sy] = bg[2][sy] .. grid.voidcol
|
||||||
bg[3][sy] = bg[3][sy] .. grid.edgecol
|
bg[3][sy] = bg[3][sy] .. grid.edgecol
|
||||||
@ -498,47 +500,82 @@ local startCountdown = function()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local makeMenu = function(x, y, options)
|
local makeMenu = function(x, y, options, doAnimate)
|
||||||
local cpos = 1
|
local cpos = 1
|
||||||
local cursor = "> "
|
local cursor = "> "
|
||||||
|
local gsX, gsY = 0, 0
|
||||||
|
local step = 0
|
||||||
|
local lastPos = cpos
|
||||||
|
if not doAnimate then
|
||||||
|
drawImage(images.logo, math.ceil(scr_x / 2 - images.logo.x / 2), 2)
|
||||||
|
end
|
||||||
local rend = function()
|
local rend = function()
|
||||||
|
if doAnimate then
|
||||||
|
drawImage(images.logo, math.ceil(scr_x / 2 - images.logo.x / 2), 2)
|
||||||
|
end
|
||||||
for i = 1, #options do
|
for i = 1, #options do
|
||||||
term.setCursorPos(x, y + (i - 1))
|
|
||||||
if i == cpos then
|
if i == cpos then
|
||||||
|
term.setCursorPos(x, y + (i - 1))
|
||||||
term.setTextColor(colors.white)
|
term.setTextColor(colors.white)
|
||||||
term.write(cursor .. options[i])
|
term.write(cursor .. options[i])
|
||||||
else
|
else
|
||||||
|
if i == lastPos then
|
||||||
|
term.setCursorPos(x, y + (i - 1))
|
||||||
|
term.write((" "):rep(#cursor))
|
||||||
|
lastPos = nil
|
||||||
|
else
|
||||||
|
term.setCursorPos(x + #cursor, y + (i - 1))
|
||||||
|
end
|
||||||
term.setTextColor(colors.gray)
|
term.setTextColor(colors.gray)
|
||||||
term.write((" "):rep(#cursor) .. options[i])
|
term.write(options[i])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local evt
|
local gstID, evt = math.random(1,65535)
|
||||||
|
if doAnimate then
|
||||||
|
os.queueEvent("timer", gstID)
|
||||||
|
end
|
||||||
while true do
|
while true do
|
||||||
rend()
|
rend()
|
||||||
evt = {os.pullEvent()}
|
evt = {os.pullEvent()}
|
||||||
if evt[1] == "key" then
|
if evt[1] == "key" then
|
||||||
if evt[2] == keys.up then
|
if evt[2] == keys.up then
|
||||||
|
lastPos = cpos
|
||||||
cpos = (cpos - 2) % #options + 1
|
cpos = (cpos - 2) % #options + 1
|
||||||
elseif evt[2] == keys.down then
|
elseif evt[2] == keys.down then
|
||||||
|
lastPos = cpos
|
||||||
cpos = (cpos % #options) + 1
|
cpos = (cpos % #options) + 1
|
||||||
|
elseif evt[2] == keys.home then
|
||||||
|
lastPos = cpos
|
||||||
|
cpos = 1
|
||||||
|
elseif evt[2] == keys["end"] then
|
||||||
|
lastPos = cpos
|
||||||
|
cpos = #options
|
||||||
elseif evt[2] == keys.enter then
|
elseif evt[2] == keys.enter then
|
||||||
return cpos
|
return cpos
|
||||||
end
|
end
|
||||||
|
elseif evt[1] == "timer" and evt[2] == gstID then
|
||||||
|
gstID = os.startTimer(0.05)
|
||||||
|
drawGrid(gsX, gsY, true)
|
||||||
|
step = step + 1
|
||||||
|
if math.ceil(step / 100) % 2 == 1 then
|
||||||
|
gsX = gsX + 1
|
||||||
|
else
|
||||||
|
gsY = gsY - 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local titleScreen = function()
|
local titleScreen = function()
|
||||||
term.clear()
|
term.clear()
|
||||||
drawImage(images.logo, math.ceil(scr_x / 2 - images.logo.x / 2), 2)
|
|
||||||
|
|
||||||
local choice = makeMenu(2, scr_y - 4, {
|
local choice = makeMenu(2, scr_y - 4, {
|
||||||
"Start Game",
|
"Start Game",
|
||||||
"How to Play",
|
"How to Play",
|
||||||
"Grid Demo",
|
"Grid Demo",
|
||||||
"Exit"
|
"Exit"
|
||||||
})
|
}, true)
|
||||||
if choice == 1 then
|
if choice == 1 then
|
||||||
return "start"
|
return "start"
|
||||||
elseif choice == 2 then
|
elseif choice == 2 then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user