1
0
mirror of https://github.com/LDDestroier/CC/ synced 2024-11-14 13:54:52 +00:00
ldd-CC/windont/demo.lua

150 lines
3.3 KiB
Lua
Raw Normal View History

2019-12-11 05:29:51 +00:00
local windont, ONE, TWO, INSTRUCTIONS
term.clear()
local x1, y1 = 2, 5
local x2, y2 = 13, 2
2019-12-11 07:37:30 +00:00
-- demo transformation function
-- mess with these all you like
-- just remember that they apply in reverse (x and y are positions on the screen from 1 to the window's width/height)
2019-12-24 03:34:41 +00:00
local getRandomColor = function(_cols)
local cols = _cols or "0123456789abcdef"
local p = math.random(1, #cols)
return cols:sub(p, p)
end
2019-12-11 07:37:30 +00:00
local TF = {
-- returns new X, new Y, and new character / text color / background color
2019-12-24 03:34:41 +00:00
meta = function(cols)
return function(meta)
for y = 1, meta.height do
for x = 1, meta.width do
if meta.buffer[2][y][x] ~= "-" then
meta.buffer[3][y][x] = getRandomColor(cols)
end
end
end
end
2019-12-11 07:37:30 +00:00
end
}
2019-12-11 05:29:51 +00:00
local keysDown = {}
local tickTimer = os.startTimer(0.05)
local scr_x, scr_y = term.current().getSize()
local pBlit = function(t, y, str)
t.setCursorPos(1, y)
2019-12-24 03:34:41 +00:00
t.blit((" "):rep(#str), str, str)
2019-12-11 05:29:51 +00:00
end
2019-12-25 07:33:31 +00:00
local pWrite = function(t, x, y, str)
t.setCursorPos(x, y)
t.write(str)
end
2019-12-11 05:29:51 +00:00
windont = dofile("windont.lua")
2019-12-24 02:38:05 +00:00
windont.doClearScreen = true
windont.default.alwaysRender = false
2019-12-11 05:29:51 +00:00
INSTRUCTIONS = windont.newWindow(2, scr_y - 5, scr_x - 4, 3, {backColor = "-"})
ONE = windont.newWindow(1, 1, 9, 5, {backColor = "e"})
2019-12-24 03:34:41 +00:00
TWO = windont.newWindow(1, 1, 19, 10, {backColor = "-", textColor = "-"})
2019-12-11 05:29:51 +00:00
2019-12-25 07:33:31 +00:00
pWrite(INSTRUCTIONS, 1, 1, "Arrow keys to move windon't ONE (red)")
pWrite(INSTRUCTIONS, 1, 2, "WASD keys to move windon't TWO (blue)")
pWrite(INSTRUCTIONS, 1, 3, "Press 'Q' to quit")
2019-12-11 05:29:51 +00:00
ONE.setTextColor(0)
ONE.setBackgroundColor(colors.gray)
2019-12-25 07:34:49 +00:00
pWrite(ONE, 2, 2, " I'm ")
pWrite(ONE, 2, 3, "Stencil")
pWrite(ONE, 2, 4, " Man ")
2019-12-11 05:29:51 +00:00
TWO.setTextColor(colors.gray)
TWO.setBackgroundColor(colors.green)
pBlit(TWO, 1, "------5------------")
pBlit(TWO, 2, "5-55-----555---555-")
pBlit(TWO, 3, "55--5-5-5---5-5---5")
pBlit(TWO, 4, "5---5-5-5-----55555")
pBlit(TWO, 5, "5---5-5-5---5-5----")
pBlit(TWO, 6, "5---5-5--555---5555")
pBlit(TWO, 8, "ddddddddddddddddddd")
pBlit(TWO, 9, "ddddddddddddddddddd")
pBlit(TWO, 10, "ddddddddddddddddddd")
2019-12-24 03:34:41 +00:00
ONE.meta.metaTransformation = TF.meta("e-")
TWO.meta.metaTransformation = TF.meta(
string.rep("5", 50) ..
string.rep("d", 40) ..
string.rep("4", 1)
)
2019-12-11 07:37:30 +00:00
2019-12-11 05:29:51 +00:00
while true do
evt = {os.pullEvent()}
scr_x, scr_y = term.current().getSize()
if evt[1] == "timer" and evt[2] == tickTimer then
tickTimer = os.startTimer(0.05)
-- control windont ONE
if keysDown[keys.up] then
y1 = y1 - 1
end
if keysDown[keys.down] then
y1 = y1 + 1
end
if keysDown[keys.left] then
x1 = x1 - 1
end
if keysDown[keys.right] then
x1 = x1 + 1
end
-- control windont TWO
if keysDown[keys.w] then
y2 = y2 - 1
end
if keysDown[keys.s] then
y2 = y2 + 1
end
if keysDown[keys.a] then
x2 = x2 - 1
end
if keysDown[keys.d] then
x2 = x2 + 1
end
ONE.reposition(x1, y1)
TWO.reposition(x2, y2)
windont.render(ONE, TWO, INSTRUCTIONS)
TWO.setCursorPos(2, 9)
TWO.write("blits: " .. windont.info.BLIT_CALLS .. " ")
for k,v in pairs(keysDown) do
keysDown[k] = v + 1
end
elseif evt[1] == "key" and evt[3] == false then
keysDown[evt[2]] = 0
if evt[2] == keys.q then
sleep(0)
break
elseif evt[2] == keys.r then
x1, y1 = 2, 5
x2, y2 = 13, 2
end
elseif evt[1] == "key_up" then
keysDown[evt[2]] = nil
end
end
term.setCursorPos(1, scr_y)