Slide 1

Slide 1 text

Pico-8 Knoxville Game Design July 2019 Levi D. Smith

Slide 2

Slide 2 text

Overview • ”Fantasy Console” • Game saves to image file “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/

Slide 3

Slide 3 text

Pros and Cons • Pros • Easy to get started • 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

Slide 4

Slide 4 text

Pico-8 Hello World • Esc • Enter code • Esc • > run Esc to stop a running program Esc switches between editor mode and console mode

Slide 5

Slide 5 text

Data types • Number / String / Boolean • foo = 42 • bar = “hello” • baz = true • Concatenate with .. • Add and assign +=, but no increment ++ • Comparison >,<,== • Tables (array / hash) • mytable = {} mytable.name = “hello” • anothertable = { name=“hello” } • Sequences • obj = { foo = 42, bar = “hello” } • mysequence = {} • mysequence.add(obj) • print mysequence[1].bar --index starts at 1 • #mysequence -- length

Slide 6

Slide 6 text

Control structures • if (boolean_expression) then code elseif (boolean_expression) then 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

Slide 7

Slide 7 text

Number Guessing Game

Slide 8

Slide 8 text

Saving / Loading games • save .p8 • load .p8 • save .p8.png (capture cart image with F7) • export .html (web build) • folder – shows saved game folder • Change default folder • C:\Users\\AppData\Roaming\pico-8\config.txt • root_path E:/ • Other settings • Set window size - window_size 1024 768

Slide 9

Slide 9 text

More Console Commands • reboot (close project) • shutdown (close pico-8) • help • ls (list directory files) • cd (change directory) • keyconfig (configure buttons)

Slide 10

Slide 10 text

Examples • api • Hello • jelpi

Slide 11

Slide 11 text

Special functions • _update() • Game logic • _draw() • Drawing code • _init() • Called at the start of program execution

Slide 12

Slide 12 text

Drawing • Primitives • rect(0, 0, 50, 50, 11) – 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)

Slide 13

Slide 13 text

Inputs • Gamepad (four direction d-pad and two buttons) • 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

Slide 14

Slide 14 text

Helpful Built-In Functions • rnd(100) – returns a random real 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

Slide 15

Slide 15 text

Sprite Editor • Use pencil to place pixels • Select color from palette • Select sprite index at bottom • Can make editor area larger and smaller (8x8, 16x16, etc)

Slide 16

Slide 16 text

Audio • Play sound effect • sfx(0) • Play music • music(1)

Slide 17

Slide 17 text

Functions • function foo(param1, param2) code return value end • Return value is optional

Slide 18

Slide 18 text

Simple Space Shooter - Ship • Define ship variables • 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

Slide 19

Slide 19 text

Simple Space Shooter - Shooting • Create list of bullets • 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

Slide 20

Slide 20 text

Simple Space Shooter - Enemies • Spawn enemies at the 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)

Slide 21

Slide 21 text

Simple Space Shooter – simple collision • Make distance function • 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

Slide 22

Slide 22 text

Simple Shooter - Improvements • Collision with player, game over state • Sound effects • Music • Sprites • Score • Powerups • Faster shooting • Spawn enemies at regular rates • Enemies shoot back • Increased difficulty as game progresses • Background image

Slide 23

Slide 23 text

Docs • Official Docs • https://www.lexaloffle.com/pico-8.php?page=resources • Wiki • https://pico-8.fandom.com/wiki/Pico-8_Wikia • https://pico-8.fandom.com/wiki/Lua - Lua • Cheat Sheet • https://www.lexaloffle.com/bbs/files/16585/PICO- 8_CheatSheet_0111Gm_4k.png

Slide 24

Slide 24 text

Tic-80, Tiny Computer • Web based, https://tic.computer/ • Free (pro $5)