Porting from PICO 8 - neilpopham/tic80 GitHub Wiki
PHP Script to convert PICO-8 map and gff data to TIC80 equivalents, and to convert TIC80 .map files to PICO-8 map data
https://github.com/neilpopham/pico8/blob/master/tests/convert.php
From PICO-8 to TIC80
Usage
The following will output myfile.p8.map and myfile.p8.gff files.
> php convert.php myfile.p8
The map data myfile.p8.map can be imported into your TIC80 cart.
> import myfile.p8.map
The sprite flag data is output as a table, which can be used with some bespoke TIC80 functions to mimic PICO-8's functionality.
Please note: These functions can be found in the following file which is discussed below: https://github.com/neilpopham/tic80/blob/master/projects/gunslugs/pico8.lua
-- __gff__ data
local sprf={0,3,1,1,1}
-- http://pico-8.wikia.com/wiki/Fget
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
end
-- http://pico-8.wikia.com/wiki/Fset
function fset(s,i,b)
if b==nil then
sprf[s+1]=i
else
local e
if sprf[s+1]==nil then
sprf[s+1]=0
e=false
else
e=fget(s,i)
end
if (e and not b) or (not e and b) then
sprf[s+1]=sprf[s+1]+(b and 2^i or -2^i)
end
end
end
From TIC80 to PICO-8
Usage
The following will convert a TIC80 map file into a p8 file with map data called myfile.map.p8.
> php convert.php myfile.map
PHP script to merge all required files into one LUA file
https://github.com/neilpopham/tic80/blob/master/merge-requires.php
While developing you can use LUA's require
much like PICO-8's #include
; however you will need to merge all files together before being able to release your game.
Usage
The following will parse myfile.lua for any use of require
and replace the line with the contents of the file required.
> php merge-requires.php myfile.lua
A new file called myfile.merged.lua will be created.
LUA functions to handle PICO-8 API calls
https://github.com/neilpopham/tic80/blob/master/projects/gunslugs/pico8.lua
Please note: Much of that code has been taken from here: https://github.com/musurca/pico2tic
Some function calls just need mapping to an inbuilt LUA function.
abs=math.abs
Some functions need a little conversion.
function cos(x) return math.cos((x or 0)*(math.pi*2)) end
Some functions need to be created from scratch
function mid(a,b,c) t={a,b,c} table.sort(t) return t[2] end
Camera
https://github.com/neilpopham/tic80/blob/master/projects/gunslugs/camera.lua
The required functions can be found below.
camera_x,camera_y=0,0
camera=function(x,y)
camera_x,camera_y=x,y
end
tic80spr=spr
function spr(sprite,x,y)
tic80spr(sprite,x-camera_x,y-camera_y,0)
end
function pset(x,y,col)
pix(x-camera_x,y-camera_y,col)
end
function circfill(x,y,r,col)
circ(x-camera_x,y-camera_y,r,col)
end
function rectfill(x1,y1,x2,y2,col)
rect(x1-camera_x,y1-camera_y,x2-x1+1,y2-y1+1,col)
end
This allows you to use camera()
, spr()
, pset()
, circfill()
and rectfill()
as you would in PICO-8.
Add other drawing functions as required. If the TIC80 function has the same name as the PICO-8 function you may need to take the spr
approach above. If not, you can take the simpler pset
approach.