--[[
w9bcc is a built-in library providing all of the functions specific to
WEB1999 bytecode. Loading it binds the provided functions in the global
namespace.
]]
require 'w9bcc'
-- Every window must have its size and title specified. Failing to set either
-- one is an error.
WindowSize{ width = 96, height = 64 }
WindowTitle("WEB1999")
-- If you have a solid background color, filling the entire window
-- is convenient.
FillWindow('white')
--[[
Text foreground and background colors can be set to any color, or transparent.
Background color is optional and the last set background color will be
retained if omitted.
]]
SetTextColor{ fg = 'transparent', bg = 'green'}
DrawText{ "Hello, world!", x = 1, y = 1 }
--[[
Labels for function parameters are optional, but if labels are omitted then
the parameters must be given in the same order as in the examples.
]]
SetTextColor{ 'red', 'transparent' }
DrawText { "", 1, 15 }
local rainbow = "RAINBOW TEXT!!!"
for i = 1, #rainbow do
-- Colors can be specified in any way accepted in CSS, including
-- rgb(r, g, b) or hsl(h, s, l).
local color = string.format("hsl(%d, 75%%, 50%%)", 43 * (i - 1))
SetTextColor{ fg = color }
-- If the location for text is omitted, it is drawn beginning at the
-- end of the most recently drawn text.
local char = rainbow:sub(i, i)
DrawText{ char }
end
SetDrawColor('cyan')
FillRectangle{ x = 2, y = 30, width = 96 - (2 * 2), height = 20 }
--[[
Sprites can be loaded from image files in most common formats. Loaded sprites
have the image width and height available as properties, and can be displayed
at chosen screen coordinates by calling draw_at{x, y}.
The raw sprite data (one byte per pixel, as palette indexes) is available as
the 'data' property on sprites, and the 'is_transparent' property is true if
the sprite has transparency. If it does, the value in its 'transparent_color'
property is the palette index (as appears in the 'data') that represents a
transparent pixel.
]]
local icon = Sprite:load('icon.png')
assert(not icon.is_transparent)
icon:draw_at{x = 96 / 4 - icon.width / 2, y = 32}
--[[
This sprite is drawn on the right side, and has transparency. Notice that
the one on the left has a white background, whereas the one on the right
(this sprite) allows the underlying rectangle to show through.
]]
local icon2 = Sprite:load('icon-transparent.png')
assert(icon2.is_transparent)
icon2:draw_at{x = 3 * 96 / 4 - icon.width / 2, y = 32}