Michael Wolf
Projects and thoughts from Cincinnati San Jose Oakland an undisclosed location in Grass Valley
Home Projects Photos Github Mastodon Nullbrook RSS
We Made A Pico-8 Game
Last edited - 2020-07-25

PLAY HERE or HERE

Pico-8 is a fantasy console, essentially a virtual machine emulating a retro 8-bit gaming system that never existed. It functions as a way for game developers to create simple pixel-graphic games with some of the convenience of modern development. Even better, it compiles into javascript that can be played in any browser!

The project initially caught my eye with the incredible title De-facto, a Factorio clone in 8-bit! It ran seamlessly on mobile. So cool!

I've been interested in game design for some time, being an avid consumer (particularly of Roller Coaster Tycoon, Foxhole, and Townscaper recently) of video games and a former employee of a gaming company. I'd taken a foray into game development with Unity between jobs once, but I felt overwhelmed at once by the learning curve. I am not a great developer, let alone a game dev. Graphics programming is absolute black magic to me. I barely passed pre-calc.

Pico-8 (and assurdly TIC-80 a similar, open source project) limits the features and options available to the programmer, making it easier to get the fundamental understanding of the core game loop without getting lost in menus and drop-downs. In essence, it provides to newer programmers the experience that many seasoned veterans got with legitimate old-school hardware and magazine code snippets.

So earlier this month I decided I'd give it a whirl and went in with low expectations on the quality of the output. This was to be a little anniversary gift for my wife including some of our favorite characters. Like nearly all of our gifts, this would be collaborative. She's an incredibly talented artist, so I decided I would call on her occasionally for help on sprites.

I started by taking apart one of the demo carts about sorting giraffes and seeing if I could get sprites to display. The code is in lua so it's pretty easy to pick up on go with, but incredibly there's no modulo!

It's a start. Eventually I figured out how to get some movement going. Of course I also let myself get distracted with making the environment prettier.

Finally to the part I dreaded: math. What is math? How does one make a good wiggly algorithm for our frog quarry? I certainly didn't have a good solution.

But I finally did figure out a good solution that didn't require anything more than a simple linear equation. It's not like I'm being graded on this, right? It better not be, my code is disgusting. Look at this horror show of a function. Yeah, I'm sure there's a better way.

            
 function move_water()

	if (w - flr(w/9)*9==0) then --move fish1
		if (fs==41) then
			fp=fp-1
		else
			fp=fp+1
		end
	end

	if (w - flr(w/7)*7==0) then --move fish2
		if (fs2==41) then
			fp2=fp2-1
		else
			fp2=fp2+1
		end
	end

	if (w - flr(w/5)*5==0) then --move fish3
		if (fs3==57) then
			fp3=fp3-1
		else
			fp3=fp3+1
		end
	end

	if (w>75) then
		w=0
		if (y==0) then
			y=1
		else
			y=0
		end
	else
		w=w+1
	end
	-- lord forgive me for this water
	if (y==1) then
		mset(6,3,36)
		mset(7,3,37)
		mset(8,3,36)
		mset(9,3,37)
		mset(10,3,38)
		mset(11,3,36)
		mset(12,3,38)
		mset(13,3,36)
		mset(14,3,37)
		mset(15,3,38)
		mset(7,4,37)
		mset(8,4,51)
		mset(9,4,36)
		mset(10,4,36)
		mset(11,4,51)
		mset(12,4,37)
		mset(13,4,38)
		mset(14,4,36)
		mset(15,4,36)
		mset(8,5,51)
		mset(9,5,37)
		mset(10,5,36)
		mset(11,5,37)
		mset(12,5,38)
		mset(13,5,51)
		mset(14,5,36)
		mset(14,5,37)
	else
		mset(6,3,38)
		mset(7,3,36)
		mset(8,3,37)
		mset(9,3,38)
		mset(10,3,36)
		mset(11,3,37)
		mset(12,3,36)
		mset(13,3,37)
		mset(14,3,38)
		mset(15,3,38)
		mset(7,4,38)
		mset(8,4,36)
		mset(9,4,51)
		mset(10,4,38)
		mset(11,4,36)
		mset(12,4,36)
		mset(13,4,37)
		mset(14,4,36)
		mset(15,4,37)
		mset(8,5,36)
		mset(9,5,51)
		mset(10,5,37)
		mset(11,5,38)
		mset(12,5,36)
		mset(13,5,51)
		mset(14,5,37)
		mset(14,5,38)
	end
	palt(0, false)
	palt(1, true)

	--determine fish1 dir
	if (fp<62) then
		fs=42
	elseif (fp>130) then
		fs=41
	end
	spr(fs,fp,100)

	--determine fish2 dir
	if (fp2<67) then
		fs2=42
	elseif (fp2>130) then
		fs2=41
	end
	spr(fs2,fp2,115)

	--determine fish2 dir
	if (fp3<67) then
		fs3=58
	elseif (fp3>140) then
		fs3=57
	end
	spr(fs3,fp3,107)

	palt(1, false)
	palt(0, true)

	if (c>0) then
		if (c<15) then
			c = c+1
		end
	end
	draw_frog()
end
            
            

The final product is pretty basic, but I'm happy with how quickly we could put this together-- dividing the work up, experimenting, refactoring, and learning. There's of course a lot more that could be done here, but I think we've achieved our goal with this program. I'd make this open-source but I don't want Sanrio to sue me. On to the next game?

You can play the final version of the game here