This directory contains additional Lua modules you might find useful when developing a game. If not stated otherwise those modules are public domain.
Provides additional color palettes.
local palette = require('palette')
palette.Commodore64()The default palette of PiXL. See https://github.com/geoffb/dawnbringer-palettes
Set the PICO-8 palette. PICO8 is a fantasy 8-bit console using Lua for scripting. See https://www.lexaloffle.com/pico-8.php
Set the 16 colors to the palette of the famous Commodore 64.
The old IBM PC EGA 16 color palette. If you want to create old MS-DOS games.
The 16 colors of Britains famous Sinclair ZX Spectrum home computer.
The 4 color palette modes that IBM CGA graphics mode could provide. For really old MS-DOS games 😄.
Sets the first 4 colors to the greenish 4 shades of the original Nintendo GameBoy. Other colors will be set to black.
A very simple commandline argument parser. PiXL sets like lua all arguments to the global variable arg.
local params = require('params')Checks if argument is present in the command line arguments.
if params.has('-debug') then
-- enable debug mode
endReturns the command line argument after argument. Useful if you want to check args like -file additional.lua.
local file = params.arg('-file')
if file then
-- load additional file
loadfile(file)
endA very minimalistic Object for prototype based programming.
local Object = require('object')
-- create new Player object
local Player = Object({
x = 0,
y = 0,
move = function(self, dx, dy)
self.x = self.x + dx
self.y = self.y + dy
end,
})
-- create Player instances
local Player1 = Player()
local Player2 = Player()
Player1:move(-10, 5)
Player2:move(20, -7)
print(Player1.x, Player1.y) --> -10 5
print(Player2.x, Player2.y) --> 20 -7
-- create an object with "constructor" method
local List = Object({
__init = function(self)
-- this init function will called when a new object is created
self.list = {}
end,
})A simple module to program with coroutines and waits. You can use the functions directly from the module or create a separate instance.
local threads = require('threads')
local my_threads = threads()
print(my_threads.active())Starts a new thread. The given function will be called with wait which is function to wait a certain amount of seconds. It returns a function to "stop" the coroutine (it will not be resumed anymore).
local stop_it = threads.start(function(wait)
-- do some stuff
wait(5.0) -- wait for 5s
-- do some other stuff
wait(0.1) -- wait for 0.1s
end)
-- now let's stop the thread
stop_it()This should be called regularely with the dt counting the time in seconds since the last thread.update() call. You typically can call this inside the global update(dt) function which will be called by PiXL.
function update(dt)
-- we update also our timed threads
threads.update(dt)
endReturns true if there are any running threads.
if threads.active() then
-- still some threads running
end