Skip to content

Instantly share code, notes, and snippets.

local sfxcache = {
channel=1, -- the channel to check (1-4)
beats=8, -- fire on every nth beat (0, 4, 8, or 16)
sfx={},
valid=true,
play=function(self,...)
add(self.sfx,{...})
end,
check=function(self)
if stat(19+self.channel)%self.beats==0 then
@neilpopham
neilpopham / merge-requires.php
Created September 2, 2019 10:33
PHP script to parse a TIC 80 lua file and replace requires() with the contents of the files required. Use before saving as .tic.
<?php
$strRoot = "C:\\Users\\Neil\\AppData\\Roaming\\com.nesbox.tic\\TIC-80\\";
$strMain = file_get_contents($argv[1]);
if (preg_match_all('/^require \"(.+?)\"$/m', $strMain, $arrMatches)) {
foreach ($arrMatches[1] as $i => $strFile) {
$strPath = $strRoot . '\\' . str_replace(["carts/", "\/"], ["", "\\"], $strFile) . ".lua";
$strRequire = file_get_contents($strPath);
$strRequire = trim($strRequire) . "\n";
@neilpopham
neilpopham / convert.php
Last active September 4, 2018 06:43
Converts PICO-8 map and sprite flag data for use with TIC-80, and converts a TIC-80 map file to p8 __map__ format.
<?php
const TIC_MAP_WIDTH = 240;
const TIC_MAP_HEIGHT = 136;
const PICO_MAP_WIDTH = 128;
const PICO_MAP_HEIGHT = 32;
function tic80_map_file_to_p8($strMapFile, $strPicoFile)
{
@neilpopham
neilpopham / fget.lua
Last active August 21, 2018 13:57
LUA implementation of PICO-8's fset()/fget() functions for use with TIC-80 (maybe)
local sprf={}
function fget(s,i)
if sprf[s+1]==nil then sprf[s+1]=0 end
if i==nil then
return math.floor(sprf[s+1])
else
local b=2^i
return sprf[s+1] % (2*b) >= b
end