An overview of using the Pico-8 fantasy console to develop games using the Lua programming language. We look at the steps and code for building a number guessing game and a simple space shooter.
Video presentation - https://youtu.be/glNCIkmy93Q
“carts” • https://www.lexaloffle.com/pico-8.php • Carts can be loaded to website • No lowercase characters, shift for special characters • Playable online or offline • $14.99 - Windows, Mac, Linux – Humble Store • LUA code • https://www.lua.org/manual/5.3/
• Built in sprite / level / sound effect / music editors • Web builds by default • Gamepad works by default • Fast to load/play • Small size (few kilobytes), easy to share • Access to Pico-8 repository built-in (splore) • If you’ve uploaded your game to the website, you can just tell someone the same of your game and they can load it • Lots of examples. All uploaded carts are “open source” • Cons • Limited resolution (128x128) / colors (16) • Not many helper functions • (write your own collision method) • Can’t (easily) load resources from external files (png, wav, etc) • Not for beginners • No console support • Limited lines of code (8192 “tokens” / 65535 characters) • No concept of rooms/scenes
code else code end • for i=1, 10 do code end • while (boolean) do code end • Logic comparison – or, and, not (not pipe or ampersand) • foreach(myarray, do_something) -- the object gets passed as the parameter to the function
green rectangle outline size 50x50 • rectfill(100, 200, 110, 205, 0) – black filled rectangle at 100, 200 with width 10 and height 5 • circ – circle • circfill(x, y, r, color) – filled circle • line – draw line • Sprites • spr(sprite, x, y) • spr(sprite, x, y, w, h, flip_x, flip_y)
btn(0) --left • btn(1) --right • btn(2) --up • btn(3) --down • btn(4) --circle (keyboard default z,c,n) • btn(5) --X (keyboard default x,v,m) • Use btnp(n) to check if a button was pressed that frame (you don’t want the action to constantly happen) • btnp will still be invoked while key is down (like word processor key held down) • Direct keyboard and mouse input is experimental
number between 0 and 100 • flr(3.14) – rounds number down to nearest integer • cls() – clears screen • camera(18, 85) – moves camera right 18 pixels and down 85 pixels • print(“hello”, 8, 16, 9) – prints “hello” at 8,16 in orange
position (x,y), width, height, velocity (x,y) • Draw ship to the screen • Handle input • When arrow button is down add to velocity for each axis • Set maximum and minimum limits for velocity (clamp with mid) • When no arrow button down on axis, subtract from velocity • Update • Add velocity values to position
• x, y, lifetime • Create a bullet drawing function • Create bullet update function • move bullet, add lifetime, delete if lifetime reaches maximum value • Spawn bullet on button down • Add ship shoot delay variable
start of the game or throughout the game • x, y, w, h, lifetime • lifetime counter used for movements • Draw enemy at it’s x, y location • Add simple AI (move left and right) • Change direction every second (30 frames)
• Pythagorean Theorem • distance = sqrt(a2 + b2) • For each bullet, determine if it has collided with an enemy • Will collide if the enemy center is four units away from the center of the bullet • Alternatively, use bounding boxes • Delete enemy and bullet on collision