ldd-CC/windont/demo.lua

178 lines
4.0 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
2020-02-23 21:14:07 +00:00
if not fs.exists("windont.lua") then
print("'windont.lua' not found! Downloading...")
local net = http.get("https://github.com/LDDestroier/CC/raw/master/windont/windont.lua")
if net then
local file = fs.open("windont.lua", "w")
file.write(net.readAll())
file.close()
net.close()
else
error("Could not download Windon't.", 0)
end
end
local windont = require "windont"
2019-12-11 05:29:51 +00:00
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"})
2020-01-30 04:55:38 +00:00
TWO = windont.newWindow(1, 1, 19, 11, {backColor = "-", textColor = "-"})
2019-12-11 05:29:51 +00:00
2020-01-06 07:53:45 +00:00
INSTRUCTIONS.setCursorPos(1, 1)
INSTRUCTIONS.write("Arrow keys to move windon't ONE (red)")
INSTRUCTIONS.setCursorPos(1, 2)
INSTRUCTIONS.write("WASD keys to move windon't TWO (blue)")
INSTRUCTIONS.setCursorPos(1, 3)
INSTRUCTIONS.write("Press 'Q' to quit")
2019-12-11 05:29:51 +00:00
ONE.setTextColor(0)
ONE.setBackgroundColor(colors.gray)
2020-01-06 07:53:45 +00:00
ONE.setCursorPos(2, 2)
ONE.write(" I'm ")
ONE.setCursorPos(2, 3)
ONE.write("Stencil")
ONE.setCursorPos(2, 4)
ONE.write(" 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")
2020-01-30 04:55:38 +00:00
pBlit(TWO, 11, "ddddddddddddddddddd")
2019-12-11 05:29:51 +00:00
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
2020-02-01 05:56:11 +00:00
local round = function(number)
local v = 100000
return math.floor(number * v) / v
end
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)
2020-01-30 04:55:38 +00:00
windont.render({}, INSTRUCTIONS, ONE, TWO)
2019-12-11 05:29:51 +00:00
TWO.setCursorPos(2, 9)
2020-01-30 04:55:38 +00:00
TWO.setTextColor(colors.gray)
TWO.write(" Blits: ")
TWO.setTextColor(colors.white)
TWO.write(windont.info.BLIT_CALLS .. " ")
TWO.setCursorPos(2, 10)
TWO.setTextColor(colors.gray)
TWO.write("Draw time: ")
TWO.setTextColor(colors.white)
2020-02-01 05:56:11 +00:00
TWO.write(round(windont.info.LAST_RENDER_DURATION) .. " ")
2019-12-11 05:29:51 +00:00
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)