-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpico8.txt
executable file
·1644 lines (1148 loc) · 54.4 KB
/
pico8.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
============================================================================================
PICO-8 v0.1.8
http://www.pico-8.com
(c) Copyright 2014-2016 Lexaloffle Games LLP
Author: Joseph White // hey@lexaloffle.com
PICO-8 is built with:
SDL2 http://www.libsdl.org
Lua 5.2 http://www.lua.org // see license.txt
GIFLIB http://giflib.sourceforge.net/
============================================================================================
Welcome to PICO-8!
PICO-8 is a fantasy console for making, sharing and playing tiny games and other computer
programs. When you turn it on, the machine greets you with a shell for typing in Lua programs
straight away and provides simple built-in tools for creating sprites, maps and sound.
The harsh limitations of PICO-8 are carefully chosen to be fun to work with, encourage small
but expressive designs and hopefully to give PICO-8 cartridges their own particular look and
feel.
:: Keys
Toggle Fullscreen: Alt+Enter
Quit: Alt+F4 or command-Q
Reload/Run/Restart cart: Ctrl+R
Quick-Save: Ctrl+S
P: Pause (while running)
Player 1 defaults: Cursors + ZX / NM / CV
Player 2 defaults: SDFE + tab,Q / shift A
// use KEYCONFIG to change the defaults.
:: Specs
Display: 128x128, fixed 16 colour palette
Input: 6 buttons
Cartridge size: 32k
Sound: 4 channel, 64 definable chip blerps
Code: Lua (max 8192 tokens of code)
Sprites: Single bank of 128 8x8 sprites (+128 shared)
Map: 128x32 8-bit cels (+128x32 shared)
:: Hello World
After PICO-8 boots, try typing some of these commands followed by enter:
PRINT("HELLO WORLD")
RECTFILL(80,80,120,100,12)
CIRCFILL(70,90,20,14)
FOR I=1,4 DO PRINT(I) END
(Note: PICO-8 only displays upper-case characters -- just type normally without capslock!)
You can build up an interactive program by using commands like this in the code editing
mode along with two special callback function _update and _draw. For example, the following
program allows you to move a circle around with the cursor keys. Press escape to switch
to the code editor and type or copy & paste the following code:
X = 64 Y = 64
FUNCTION _UPDATE()
IF (BTN(0)) THEN X=X-1 END
IF (BTN(1)) THEN X=X+1 END
IF (BTN(2)) THEN Y=Y-1 END
IF (BTN(3)) THEN Y=Y+1 END
END
FUNCTION _DRAW()
RECTFILL(0,0,127,127,5)
CIRCFILL(X,Y,7,8)
END
Now press escape to return to the main console and type RUN to see it in action.
See the example cartridges for more complex programs.
:: Example Cartridges
These cartridges are included with PICO-8 and can be installed by typing:
INSTALL_DEMOS
CD DEMOS
API Demonstrates most PICO-8 functions
JELPI Platform game demo w/ 2p support
CAST 2.5D Raycaster demo
MANDEL Mandelbrot explorer
COLLIDE Example wall and actor collisions
BUTTERFLY Serpinsky triangles thing
DRIPPY Draw a drippy squiggle
STOMPY Music cart
WOO Music cart
To run a cartridge, open PICO-8 and type:
LOAD JELPI
RUN
Press escape to stop the program, and once more to enter editing mode.
:: Filesystem
These commands can be used to manage files and directories (folders):
DIR list the current directory
CD BLAH change directory
CD .. go up a directory
CD / change back to top directory (on pico-8's virtual drive)
MKDIR make a directory
FOLDER open the current directory in the host operating system's file browser
LOAD BLAH load a cart from the current directory
SAVE BLAH save a cart to the current directory
If you want to move files around, duplicate them or delete them, best use the
FOLDER command and do it in the host operating system.
The default location for PICO-8's drive is:
Windows: C:/Users/Yourname/AppData/Roaming/pico-8/carts
OSX: /Users/Yourname/Library/Application Support/pico-8/carts
Linux: ~/.lexaloffle/pico-8/carts
You can change this and other settings in pico-8/config.txt
Tip: if you are a Dropbox user, it's possible to set the drive directory to be a
shared dropbox folder in order to provide a single disk for PICO-8 machines spread
across different host machines.
:: Backups
If you quit without saving changes, or overwrite an existing file, a backup of the
cartridge is saved to pico-8/backup.
:: Configuration
:: config.txt
You can find some settings in config.txt. Edit the file when PICO-8 is not running.
Windows: C:/Users/Yourname/AppData/Roaming/pico-8/config.txt
OSX: /Users/Yourname/Library/Application Support/pico-8/config.txt
Linux: ~/.lexaloffle/pico-8/config.txt
Use the -home switch (below) to use a different path to store config.txt and other data.
:: Commandline parameters
// note: these override settings found in config.txt
pico-8 [switches] [filename.p8]
-run boot filename.p8 on startup
-width n set the window or screen width and adjust scale to fit if not specified
-height n set the window or screen height and adjust scale to fit if not specified
-scale n set the size of each PICO-8 pixel. "-scale 3" gives pixels rendered at 3x3
-windowed n set windowed mode off (0) or on (1)
-sound n sound volume 0..256
-music n sound volume 0..256
-joystick n joystick controls starts at player n (0..7)
-aspect n set the aspect ratio. 420 means 1:1 (default), 560 for 4:3, 525 for 5:4 etc.
-run filename automatically load and run a cartridge
-splore boot in splore mode
-home path set the path to store config.txt and other user data files
-gif_len n set the maximum gif length in seconds (1..120)
:: Controller Setup
PICO-8 uses the SDL2 controller configuration scheme. It will detect common controllers
on startup and also looks for custom mappings in sdl_controllers.txt in the same directory
as config.txt. sdl_controllers.txt has one mapping per line.
To generate a custom mapping string for your controller, use either the controllermap
program that comes with SDL2, or try http://www.generalarcade.com/gamepadtool/
To set up which keyboard keys trigger joystick buttons presses, use KEYCONFIG.
:: Sharing Cartridges / HTML5 Exporter
There are three ways to share carts:
1. Share the .p8 or .p8.png file directly with other PICO-8 users
2. Post the cart on the Lexaloffe BBS to get a web-playable version
http://www.lexaloffle.com/pico-8.php?page=submit
See save() for notes on how to generate .p8.png versions. (search for .png)
3. Export the cartridge to a stand-alone html5 version:
EXPORT FOO.HTML
This will generate two files: foo.html and foo.js (you need both!)
You are free to distribute and use exported cartridges as you please, provided
that you have permission from the author and contributors.
The .html file is intended as a template that can be modified as needed.
It includes some buttons to control settings and a link to an external website
(PICO-8 BBS cartridges by default), along with javascript to block keypresses
in order to prevent web page scrolling while the cartridge is played.
Note that the width and height of the player can be configured, but should
normally match the size of the canvas it is displayed on (580,540 by default).
:: Screenshots, Videos and Cartridge Labels
While a cartridge is running use:
F6 Save a screenshot to desktop
F7 Capture cartridge label image
F8 Start recording a video
F9 Save GIF video to desktop (max: 8 seconds by default)
// if F6..F9 are not available on your system, use F1..F4
Cartridge label is saved when using save() with p8.png format.
You can save a video at any time (it is always recording) -- use F8 just to reset
the video starting point if you want something less than 8 seconds long.
To change the maximum gif length, edit gif_len in config.txt to specify the number
of seconds to record for. The gif format can not match 30fps exactly, so PICO-8
instead uses the closest match: 33.3fps.
:: Exporters / Importers
1. To import or export the spritesheet as a .png:
import("blah.png") -- expects 128x128 png and colour-fits to the pico-8 palette
export("blah.png") -- use folder() to locate the exported png
2. To export sound effects or music:
export("blah.wav") -- export music from the current pattern (when editor mode is MUSIC)
export("blah.wav") -- export the current SFX (when editor mode is SFX)
export("blah%d.wav") -- exports all of the SFXs as blah0.wav, blah1.wav .. blah63.wav
// From commandline, you can skip the brackets and quotes: EXPORT BLAH.WAV
:: Quirks of PICO-8
Common gotchas to watch out for:
- The bottom half of the spritesheet and bottom half of the map occupy the same memory.
// Best use only one or the other if you're unsure how this works.
- PICO-8 numbers only go up to 32767.99.
// If you add 1 to a counter each frame, it will overflow after around 18 minutes!
- Lua arrays are 1-based by default, not 0-based. FOREACH starts at T[1], not T[0].
- cos() and sin() take 0..1 instead of 0..PI*2, and sin() is inverted.
- sgn(0) returns 1.
- Toggle fullscreen: use alt-enter on OSX (command-F is used for searching text).
- When you want to export a .png cartridge, use SAVE, not EXPORT. EXPORT will save only the spritesheet!
:: Splore
SPLORE is a built-in utility for browsing and organising both local and bbs (online)
cartridges. Type SPLORE [enter] to launch it, or launch PICO-8 with -splore.
It is possible to control SPLORE entirely with a joystick:
LEFT and RIGHT to navigate lists of cartridges
UP AND DOWN to select items in each list
X,O or MENU to launch the cartridge
While inside a cart, press MENU to favourite a cartridge or exit to splore.
If you're using a keyboard, it's also possible to press F to favourite an item
while it is selected in the cartridge list view.
When viewing a list of BBS carts, use the top list item to re-download a list of
cartridges. If you are offline, the last downloaded list is displayed, and it is
still possible to play any cartridges you have downloaded.
If you have installed PICO-8 on a machine with no internet access, you can also
use INSTALL_GAMES to add a small selection of pre-installed BBS carts to your
favourites list.
============================================================================================
Editor Modes
============================================================================================
Press escape to toggle between console and editor
Click editing mode tabs at top right to switch or press ALT+LEFT/RIGHT
** WARNING: The second half of the sprite sheet (banks 2 and 3), and the bottom half
of the map share the same cartridge space. It's up to you how you use the data, but
be aware that drawing on the second half of the sprite sheet could clobber data on
the map and vice versa.
:: Code Editor
Hold shift to select (or click and drag with mouse)
CTRL-X, C, V to cut copy or paste selected
CTRL-Z, Y to undo, redo
CTRL-F to search for text
CTRL-G to repeat the last search again
ALT-UP, DOWN to navigate to the previous, next function
At the bottom right of the code editor you can see how many tokens have been used. One
program can have a maximum of 8192 tokens. Each token is a word (e.g. variable name) or
operator. Pairs of brackets, and strings count as 1 token. commas, periods, LOCALs, semi-
colons, ENDs, and comments are not counted.
To enter special characters that represent buttons, use SHIFT-L,R,U,D,O,X
:: Sprite Editor
The sprite editor is designed to be used both for sprite-wise editing and for freeform
pixel-level editing. The sprite navigator at the bottom of the screen provides an 8x8-wise
view into the sprite-sheet, but it is possible to use freeform tools (pan, select) when
dealing with larger or oddly sized areas.
Draw Tool
Click and drag on the sprite to edit
Applies to visible area
Hold CTRL to search and replace a colour
Use left moust button to select colour
Stamp Tool
Click to stamp whatever is in the
Hold LCONTROL to stamp with transparency
Select Tool // shortcut: LSHIFT or S
Create a selection
Enter or click to select none.
If a pixel-wise selection is not present, many operations are instead applied
to a sprite-wise selection. To select sprites, shift-drag in the sprite navigator.
Pan Tool // shortcut: space
View the spritesheet.
Fill Tool
Fill with the current colour
Applies to the current selection
If no selection, applies to visible area
Extra keys
CTRL-Z to undo // single step only in 0.2.0
CTRL-C to copy selected area or selected sprites
CTRL-V to paste to current sprite location
Q,W to switch to previous/next sprite
1,2 to switch to previous/next colour
Tab to toggle fullscreen view
Mousewheel to zoom (centered in fullscreen)
Operations on selected area or selected sprites:
f to flip
v to flip vertically
r to rotate (must be square selection)
Cursor keys to move (loops if sprite selection)
Sprite flags
The 8 coloured circles are sprite flags for the current sprite.
Each one can be true (on) or false (off), and are accessed by
using the FSET and FGET functions. They are indexed from 0, from
the left (0,1,2..7). See fset() for more information.
:: Map Editor
The pico-8 map is a 128x32 (or 128x64 using shared space) block of 8-bit values.
Each value is shown in the editor as a reference to a sprite (0..255), but you can
of course use the data to represent whatever you like.
The tools are similar to the ones used in sprite editing mode. Select a sprite
and click and drag to paint values into the map.
To draw multiple sprites, select from sprite navigator with shift+drag
To copy a block of values, use the selection tool and then stamp tool to paste
To pan around the map, use the pan tool or hold space
Q,W to switch to previous/next sprite
:: Sfx Editor
There are 64 SFX ("sound effects") in a cartridge, used for both sound and music.
Each SFX has 32 notes, and each note has:
A frequency (C0..C5)
An instrument (0..7)
A volume (0..7)
An effect (0..7)
Each SFX also has these properties:
A play speed (SPD) : the number of 'ticks' to play each note for.
// This means that 1 is fastest, 3 is 3x as slow, etc.
Loop start and end : this is the note index to loop back and to
// Looping is turned off when the start index >= end index
There are 2 modes for editing/viewing a SFX: Pitch mode (more suitable
for sound effects) and tracker mode (more suitable for music). The mode
can be changed using the top-left buttons, or toggled with TAB.
1. Pitch Mode
Click and drag on the pitch area to set the frequency for each note,
using the currently selected instrument (indicated by colour).
Hold shift to apply only the selected instrument
Hold CTRL to snap notes to the C minor pentatonic scale
2. Tracker Mode
Each note shows: frequency octave instrument volume effect
To enter a note, use q2w3er5t6y7ui zsxdcvgbhnjm (piano-like layout)
New notes are given the selected instrument/effect values
To delete a note, press backspace or set the volume to 0
Click and then shift-click to select a range that can be copied
(CTRL-C) and pasted (CTRL-V)
3. Controls for both modes
- + to navigate the current SFX
< > to change the speed.
SPACE to play/stop
A to release a looping sample
Click or left click to increase / decrease the SPD or LOOP values
// Hold shift when clicking to increase / decrease by 4
// Alternatively, click and drag left/right or up/down
Shift-click an instrument, effect, or volume to apply to all notes.
:: Effects
0 none
1 slide // Slide to the next note
2 vibrato // Rapidly vary the pitch within one quarter-tone
3 drop // Rapidly drop the frequency to very low values
4 fade in // Ramp the volume up from 0
5 fade out // Ramp the volume down to 0
6 arpeggio fast // Iterate over groups of 4 notes at speed of 4
7 arpeggio slow // Iterate over groups of 4 notes at speed of 8
If the SFX speed is <= 8, arpeggio speeds are halved to 2, 4
:: Music Editor
Music in PICO-8 is controlled by a sequence of 'patterns'. Each pattern is a list of
4 numbers indicating which SFX will be played on that channel.
:: Flow control
Playback flow can be controlled using the 3 buttons at the top right.
When a pattern has finished playing, the next pattern is played unless:
- there is no data left to play (music stops)
- a STOP command is set on that pattern (the first button)
- a LOOP BACK command is set (the 3rd button), in which case the music player searches
back for a pattern with the LOOP START command set (the 2nd button) or returns to
pattern 0 if none is found.
When a pattern has SFXes with different speeds, the pattern finishes playing when
the left-most non-looping channel has finished playing. This can be used to set up
irregular time signatures, or double-time drum beats etc.
:: Copying music between or within cartridges
To select a range of patterns: click once on the first pattern in the pattern
navigator, then shift-click on the last pattern. Selected patterns can be copied
and pasted with CTRL-C and CTRL-V. When pasting into another cartridge, the SFX
that each pattern points to will also be pasted (possibly with a different index)
if it does not already exist.
============================================================================================
Lua Syntax Primer
============================================================================================
PICO-8 programs are written using Lua syntax, but do not use the standard Lua library.
The following is a brief summary of essential Lua syntax.
For more details, or to find out about proper Lua, see www.lua.org.
:: Comments
-- use two hyphens like this to ignore everything until the end of the line
--[[ multi-line
comments ]]
:: Types and assignment
Types in Lua are numbers, strings, booleans and tables;
NUM = 12/100
S = "THIS IS A STRING"
B = FALSE
T = {1,2,3}
Numbers in PICO-8 are all 16:16 fixed point. They range from -32768.0 to 32767.99
Hexedecimal notation with optional fractional parts can be used:
0x11 -- 17
0x11.4000 -- 17.25
Dividing by zero evaluates as the largest possible number: 0x7fff.ffff
:: Conditionals
IF NOT B THEN
PRINT("B IS FALSE")
ELSE
PRINT("B IS NOT FALSE")
END
-- with ELSEIF
IF X == 0 THEN
PRINT("X IS 0")
ELSEIF X < 0 THEN
PRINT("X IS NEGATIVE")
ELSEIF X > 0 THEN
PRINT("X IS POSITIVE")
ELSE
PRINT("THIS IS LINE IS NEVER REACHED")
END
IF (4 == 4) THEN PRINT("EQUAL") END
IF (4 ~= 3) THEN PRINT("NOT EQUAL") END
IF (4 <= 4) THEN PRINT("LESS THAN OR EQUAL") END
IF (4 > 3) THEN PRINT("MORE THAN") END
:: Loops
FOR X=1,5 DO
PRINT(X)
END
-- prints 1,2,3,4,5
X = 1
WHILE(X <= 5) DO
PRINT(X)
X = X + 1
END
FOR X=1,10,3 DO PRINT(X) END -- 1,4,7,10
FOR X=5,1,-2 DO PRINT(X) END -- 5,3,1
:: Functions and Local Variables
Y=0
FUNCTION PLUSONE(X)
LOCAL Y = X+1
RETURN Y
END
PRINT(PLUSONE(2)) -- 3
PRINT(Y) -- 0
:: Tables
In Lua, tables are a collection of key-value pairs where the key and value types can both
be mixed. They can be used as arrays by indexing them with integers.
A={} -- create an empty table
A[1] = "BLAH"
A[2] = 42
A["FOO"] = {1,2,3}
-- Arrays use 1-based indexing by default
A = {11,12,13,14}
PRINT(A[2]) -- 12
-- The size of a table indexed with sequential 1-based integers:
PRINT(#A) -- 4
-- Indexes that are strings can be written using dot notation
PLAYER = {}
PLAYER.X = 2 -- is equivalent to PLAYER["X"]
PLAYER.Y = 3
-- see also the tables section in the api reference below.
:: PICO-8 Shorthand
PICO-8 also allows several non-standard, shorter ways to write common patterns.
1. IF THEN END statements on a single line can be expressed without the THEN & END
IF (NOT B) I=1 J=2
-- is equivalent to: IF (NOT B) THEN I=1 J=2 END
-- note that the condition must be surrounded by brackets.
2. unary math operators
a += 2 -- equivalent to: a = a + 2
a -= 2 -- equivalent to: a = a - 2
a *= 2 -- equivalent to: a = a * 2
a /= 2 -- equivalent to: a = a / 2
a %= 2 -- equivalent to: a = a % 2
3. != operator
Not shorthand, but pico-8 also accepts != instead of ~= for "not equal to"
============================================================================================
API
============================================================================================
PICO-8 is built on the Lua scripting language, but does not include the Lua standard library.
Instead, a small api is offered in keeping with PICO-8's minimal design and limited screen
space. For an example program that uses most of the api functions, see /DEMOS/API.P8
Functions are written here as:
function_name parameter [optional_parameter]
System functions called from commandline can omit the usual brackets and string quotes:
load blah.p8 --> load("blah.p8")
--------------------------------------------------------------------------------------------------------
System
--------------------------------------------------------------------------------------------------------
load filename
save filename
Load or save a cartridge
Use ".png" format to save a png -- otherwise text format (".p8") is used.
The ".p8" can be omitted in both cases, and it is automatically added
save("blah") --> save("blah.p8")
save("blah.png") --> save("blah.p8.png")
load("blah.png") --> load("blah.p8.png") (if blah.png doesn't exist)
Same goes for loading. If the file is not found, pico-8 will try again with ".p8" inserted.
The ".png" can also be omitted, but only when loading
load ("blah") --> tries "blah.p8.png" and then "blah.png" if "blah.p8" doesn't exist
Once a cartridge has been loaded or saved, it can also be quick-saved with CTRL-S
:: Saving .png carts with a text label and preview image
To generate a preview image saved with the cart, run the program first and press F7 to grab
whatever is on the screen. The first two lines of the program starting with '--' are also drawn
to the cart's label.
e.g.
-- OCEAN DIVER LEGENDS
-- BY LOOPY
:: Code size restrictions for .png format
When saving in .png format, the comrpessed size of the code must be less than 15360 bytes. To find
out the current size of your code, use the INFO command. The compressed size limit is not enforced
for .p8 format. In most cases you don't need to worry about the compressed size, as the token
limit (8192) will be reached first.
folder
Open the carts folder in the host operating system.
ls
List all files in the current folder
run
Run from the start of the program
Can be called from inside a program to reset program.
resume
Run from the existing cart state (flakey)
reboot
Reboot the machine
Useful for starting a new project
stat x
x:0 returns current Lua memory useage (0..1024MB)
x:1 returns cpu useage for last frame (1.0 means 100% at 30fps)
info
Print out some information about the cartridge:
code size, tokens, compressed size
flip
Flip the back buffer to screen and wait for next frame (30fps)
Don't normally need to do this -- _draw() calls it for you.
If your program does not call flip before a frame is up, and a _draw() callback
is not in progress, the current contents of the back buffer are copied to screen.
printh str
Print a string to host operating system's console for debugging.
--------------------------------------------------------------------------------------------
Program Structure
--------------------------------------------------------------------------------------------
There are 3 special functions that, if defined by the user, are called during program
execution:
_update()
Called once per update at 30fps
_draw()
Called once per visible frame
_init()
Called once on program startup
_draw() is normally called at 30fps, but if it can not complete in time, pico-8 will
attempt to run at 15ps and call _update() twice per visible frame to compensate.
:: Running PICO-8 at 60fps
If _update60() is defined instead of _update(), PICO-8 will run in 60fps mode:
- both _update60() and _draw() are called at 60fps
- half the PICO-8 CPU is available per frame before dropping down to 30fps
** please note that not all PICO-8s support 60fps. On machines that do not support it,
_update60() will instead be called twice per frame and _draw() at 30fps. You can check
the behaviour of your program running at 30fps by adding the following snippet to the
bottom of your code:
u60=_update60 _update60=nil function _update() u60() u60() end
--------------------------------------------------------------------------------------------
Graphics
--------------------------------------------------------------------------------------------
PICO-8 has a single bank of 128 8x8 sprites, plus another 128 that overlaps with the
bottom half of the map data ("shared data"). These 256 sprites are collectively called
the sprite sheet, and can be thought of as a 128x128 pixel image.
All of PICO-8's drawing operations are subject to the current draw-state. The draw-state
includes a camera position (for adding an offset to all coordinates), palette mapping
(for recolouring sprites), clipping rectangle, and a draw colour that can optionally be
set by any relevant function but otherwise persists.
The draw state is reset each time a program is run. This is equivalent to calling:
clip() camera() pal() color()
Colours indexes:
0 black 1 dark_blue 2 dark_purple 3 dark_green
4 brown 5 dark_gray 6 light_gray 7 white
8 red 9 orange 10 yellow 11 green
12 blue 13 indigo 14 pink 15 peach
clip [x y w h]
Sets the screen's clipping region in pixels
clip() to reset
pget x y
pset x y [c]
Get or set the colour (c) of a pixel at x, y.
sget x y
sset x y [c]
Get or set the colour (c) of a spritesheet pixel.
fget n [f]
fset n [f] v
Get or set the value (v) of a sprite's flag
f is the flag index 0..7
v is boolean and can be true or false
The initial state of flags 0..7 are settable in the sprite editor,
using the line of little colourful buttons.
The meaning of sprite flags is up to the user, or can be used to
indicate which group ('layer') of sprites should be drawn by map.
If the flag index is omitted, all flags are retrieved/set as a bitfield
fset(2, 1+2+8) -- sets bits 0,1 and 3
fset(2, 4, true) -- sets bit 4
print(fget(2)) -- 27 (1+2+8+16)
print str [x y [col]]
Print a string
If only str is supplied, and the cursor reaches the end of the screen,
a carriage return and vertical scroll is automatically applied.
(terminal-like behaviour)
cursor x y
Set the cursor position and carriage return margin
color col
Set the default color to be used by drawing functions
cls
Clear the screen
camera [x y]
Set a screen offset of -x, -y for all drawing operations
camera() to reset
circ x y r [col]
circfill x y r [col]
Draw a circle or filled circle at x,y with radius r
line x0 y0 x1 y1 [col]
draw line
rect x0 y0 x1 y1 [col]
rectfill x0 y0 x1 y1 [col]
Draw a rectange or filled rectange
pal c0 c1 [p]
Draw all instances of colour c0 as c1 in subsequent draw calls
pal() to reset to system defaults (including transparency values)
Two types of palette (p; defaults to 0)
0 draw palette : colours are remapped on draw // e.g. to re-colour sprites
1 screen palette : colours are remapped on display // e.g. for fades
c0 colour index 0..15
c1 colour index to map to
palt c t
Set transparency for colour index to t (boolean)
Transparency is observed by spr(), sspr() and map()
e.g. palt(8, true) -- red pixels not drawn
palt() resets to default: all colours opaque except colour 0
spr n x y [w h] [flip_x] [flip_y]
draw sprite n (0..255) at position x,y
width and height are 1,1 by default and specify how many sprites wide to blit.
Colour 0 drawn as transparent by default (see palt())
flip_x=true to flip horizontally
flip_y=true to flip vertically
sspr sx sy sw sh dx dy [dw dh] [flip_x] [flip_y]
Stretch rectangle from sprite sheet (sx, sy, sw, sh) // given in pixels
and draw in rectangle (dx, dy, dw, dh)
Colour 0 drawn as transparent by default (see palt())
dw, dh defaults to sw, sh
flip_x=true to flip horizontally
flip_y=true to flip vertically
--------------------------------------------------------------------------------------------
Tables
--------------------------------------------------------------------------------------------
add t v
Add value v to the end of table t.
Equivalent to t[#t+1] = v
FOO={} -- create empty table
ADD(FOO, 11)
ADD(FOO, 22)
PRINT(FOO[2]) -- 22
del t v
Delete the first instance of value v in table t
The remaining entries are shifted left one index to avoid holes.
Note that v is the value of the item to be deleted, not the index into the table!
del() can be called safely on a table's item while iterating over that table.
A={1,10,2,11,3,12}
FOR ITEM IN ALL(A) DO
IF (ITEM < 10) THEN DEL(A, ITEM) END
END
FOREACH(A, PRINT) -- 10,11,12
PRINT(A[3]) -- 12
all t
Used in FOR loops to iterate over all items in a table (that have a 1-based integer index),
in the order they were added.
T = {11,12,13};
ADD(T,14)
ADD(T,"HI")
FOR V IN ALL(T) DO PRINT(V) END -- 11 12 13 14 HI
PRINT(#T) -- 5
foreach t f
For each item in table t, call function f with the item as a single parameter.
FOREACH(T, PRINT)
pairs t
Used in FOR loops to iterate over table t, providing both the key and value for each item.
Unlike all(), pairs() iterates over every item regardless of indexing scheme.
Order is not guaranteed.
T = {["HELLO"]=3, [10]="BLAH"}
T.BLUE = 5;
FOR K,V IN PAIRS(T) DO
PRINT("K: "..K.." V:"..V)
END
Output:
K: 10 v:BLAH
K: HELLO v:3
K: BLUE v:5
--------------------------------------------------------------------------------------------
Input
--------------------------------------------------------------------------------------------
btn [i [p]]
get button i state for player p (default 0)
i: 0..5: left right up down button_o button_x
p: player index 0..7
If no parameters supplied, returns a bitfield of all 12 button states for player 0 & 1
// P0: bits 0..5 P1: bits 8..13
Default keyboard mappings to player buttons:
player 0: cursors, Z,X / C,V / N,M
player 1: ESDF, LSHIFT,A / TAB,Q,E