This commit is contained in:
Aria 2025-03-21 22:23:30 +11:00
commit 9c94d113d3
Signed by untrusted user who does not match committer: aria
GPG key ID: 19AB7AA462B8AB3B
10260 changed files with 1237388 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

View file

@ -0,0 +1,40 @@
{
"gui" : {
"background" : {
"zlevel" : 0,
"type" : "background",
"fileHeader" : "/testconsole2/consoleheader.png",
"fileBody" : "/testconsole2/consolebody.png"
},
"scriptCanvas" : {
"zlevel" : 1,
"type" : "canvas",
"rect" : [40, 45, 434, 254],
"captureMouseEvents" : true,
"captureKeyboardEvents" : true
},
"close" : {
"zlevel" : 2,
"type" : "button",
"base" : "/interface/x.png",
"hover" : "/interface/xhover.png",
"pressed" : "/interface/xpress.png",
"pressedOffset" : [0, 0],
"callback" : "close",
"position" : [419, 263]
}
},
"scripts" : ["/scripts/util.lua", "/testconsole2/testconsolegui.lua"],
"scriptDelta" : 2,
"canvasClickCallbacks" : {
"scriptCanvas" : "canvasClickEvent"
},
"canvasKeyCallbacks" : {
"scriptCanvas" : "canvasKeyEvent"
},
"scriptWidgetCallbacks" : [
]
}

View file

@ -0,0 +1,152 @@
windowCenter = {196, 104}
gameDims = {100, 70}
paddleDims = {2, 8}
ballDims = {3, 3}
ballSpeed = 60
paddleSpeed = 60
gameRect = {
windowCenter[1] - gameDims[1] - ballDims[1],
windowCenter[2] - gameDims[2] - ballDims[2],
windowCenter[1] + gameDims[1] + ballDims[1],
windowCenter[2] + gameDims[2] + ballDims[2]
}
p1, p2, ball = {}, {}, {}
function init()
newGame()
self.canvas = widget.bindCanvas("scriptCanvas")
widget.focus("scriptCanvas")
end
function newGame()
p1.pos = {windowCenter[1] - gameDims[1] + 5, windowCenter[2]}
p2.pos = {windowCenter[1] + gameDims[1] - 5, windowCenter[2]}
p1.score = 0
p2.score = 0
p1.move = 0
p2.move = 0
resetBall()
end
function update(dt)
self.canvas:clear()
ball.pos[1] = ball.pos[1] + ball.vel[1] * dt
ball.pos[2] = ball.pos[2] + ball.vel[2] * dt
p1.pos[2] = p1.pos[2] + p1.move * dt
p2.pos[2] = p2.pos[2] + p2.move * dt
if ball.pos[2] >= windowCenter[2] + gameDims[2] or ball.pos[2] <= windowCenter[2] - gameDims[2] then
ball.vel[2] = -ball.vel[2]
end
if ballHitPaddle(p1) then
ball.vel[1] = ballSpeed
elseif ballHitPaddle(p2) then
ball.vel[1] = -ballSpeed
end
if ball.pos[1] >= windowCenter[1] + gameDims[1] then
p1.score = p1.score + 1
resetBall()
elseif ball.pos[1] <= windowCenter[1] - gameDims[1] then
p2.score = p2.score + 1
resetBall()
end
drawBorders()
drawPaddle(p1)
drawPaddle(p2)
drawBall()
drawScore()
end
function resetBall()
ball.pos = {windowCenter[1], windowCenter[2]}
ball.vel = {ballSpeed * util.randomDirection(), ballSpeed * util.randomDirection()}
end
function ballHitPaddle(paddle)
return math.abs(ball.pos[1] - paddle.pos[1]) < paddleDims[1] + ballDims[1] and math.abs(ball.pos[2] - paddle.pos[2]) < paddleDims[2]
end
function drawBorders()
self.canvas:drawRect(
gameRect,
{0, 40, 0}
)
end
function drawBall()
self.canvas:drawRect(
{ball.pos[1] - ballDims[1], ball.pos[2] - ballDims[2], ball.pos[1] + ballDims[1], ball.pos[2] + ballDims[2]},
{255, 255, 255}
)
end
function drawPaddle(paddle)
self.canvas:drawRect(
{paddle.pos[1] - paddleDims[1], paddle.pos[2] - paddleDims[2], paddle.pos[1] + paddleDims[1], paddle.pos[2] + paddleDims[2]},
{255, 255, 255}
)
end
function drawScore()
self.canvas:drawText(
"Player 1: "..p1.score,
{position={gameRect[1] - 85, gameRect[4]}, horizontalAnchor="left", verticalAnchor="top"},
14,
{255, 255, 255}
)
self.canvas:drawText(
"Player 2: "..p2.score,
{position={gameRect[3] + 5, gameRect[4]}, horizontalAnchor="left", verticalAnchor="top"},
14,
{255, 255, 255}
)
end
function canvasClickEvent(position, button, isButtonDown)
sb.logInfo("Mouse button %s was %s at %s", button, isButtonDown and "pressed" or "released", position)
end
function canvasKeyEvent(key, isKeyDown)
sb.logInfo("Key %s was %s", key, isKeyDown and "pressed" or "released")
if key == 43 then
p1.move = isKeyDown and paddleSpeed or 0
elseif key == 68 then
p1.move = isKeyDown and -paddleSpeed or 0
elseif key == 87 then
p2.move = isKeyDown and paddleSpeed or 0
elseif key == 88 then
p2.move = isKeyDown and -paddleSpeed or 0
end
end
function printTable(t, indent)
if not indent then
indent = ""
sb.logInfo("Printing table...")
end
local tnames = {}
for k,v in pairs(t) do
tnames[#tnames + 1] = k
end
table.sort(tnames, function(a, b) return a < b end)
for _, key in ipairs(tnames) do
if type(t[key]) == "table" then
sb.logInfo(indent.."table "..key)
printTable(t[key], indent.." ")
elseif type(t[key]) == "function" then
sb.logInfo(indent.."function "..key)
else
sb.logInfo(indent..type(t[key]).." "..key.." = %s", t[key])
end
end
end

View file

@ -0,0 +1,14 @@
{
"frameGrid" : {
"size" : [24, 32],
"dimensions" : [3, 1],
"names" : [
[ "default.off", "default.0", "default.1" ]
]
},
"aliases" : {
"default.default" : "default.off"
}
}

View file

@ -0,0 +1,10 @@
function youwin()
self.wintime = 5
end
function update(dt)
if self.wintime and self.wintime > 0 then
self.wintime = self.wintime - dt
world.spawnItem("money", vec2.add(object.position(), {0, 3}), 5)
end
end

View file

@ -0,0 +1,31 @@
{
"objectName" : "testconsole2",
"colonyTags" : [],
"rarity" : "Common",
"category" : "decorative",
"price" : 400,
"lightColor" : [150, 215, 235],
"description" : "Someone's scrawled 'Meta Sux' on the side of this console...",
"shortdescription" : "Blue Test Console",
"race" : "hylotl",
"inventoryIcon" : "testconsoleobjecticon.png",
"orientations" : [
{
"dualImage" : "testconsoleobject.png:<color>.<frame>",
"imagePosition" : [-12, 0],
"frames" : 2,
"animationCycle" : 0.6,
"spaceScan" : 0.1,
"anchors" : [ "bottom" ]
}
],
"scripts" : [ "/scripts/vec2.lua", "testconsoleobject.lua" ],
"scriptDelta" : 5,
"interactAction" : "ScriptPane",
"interactData" : "/testconsole2/testconsolegui.config"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 454 B