Code Comments

Moon Over Miami

Due: Bring to class on Monday, 28 Sept 2020.

Instructions

  1. Download the file miami_moon.p8.png (see below)
  2. Put the file into your PICO-8 directory (also see below)
  3. Type LOAD MIAMI_MOON at the PICO-8 command prompt.
  4. If you get an error, you likely need to update your version of PICO-8.
  5. Start commenting-up the code. What does each line do for the program as a whole? You want to be able to account for every line of code with specificity.
  6. Errors are not penalized during this round: There is no incentive to cheat. Please do the work yourself.

PICO-8 Directories

Everything is OK!

Looking for that troublesome OS folder where PICO-8 keeps your code and cartridges? Microsoft and Apple actually go out of their way to hide the users' folders. Why would they do that? But it turns out that PICO-8 has a handy shortcut to get you there, anyway.

When you first open up PICO-8, type the command FOLDER from the command line and hit return. The carts folder that your system uses will pop open, just like that. That's where you should store the miami_moon.p8.png cartridge (available below). Remember: It looks like a graphics file (actually, it is a graphics file -- but our program's code is concealed inside)game.

Files for Review

PICO-8 Cart

Remember: This image is the cartridge. The code is actually concealed in the PNG image using steganographic principles.

  1. To open it up in your PICO-8 programming environment, download this PNG to your desktop or downloads folder (usually by right-clicking on the image and choosing "save as...).
  2. Then move the image into the directory PICO-8 opened when you typed FOLDER (see above).
  3. Go back to PICO-8.
  4. Type LS to list your files.
  5. You should see MIAMI_MOON.P8.PNG in the list.
  6. Type LOAD MIAMI_MOON
  7. Once loaded, just type RUN.

Good job!

Additional Version

I've prepared a second version of the file which may be easier to review outside of PICO-8. It will be easier to print out, etc.. But you will need to see how the sprite sheet and map sheet are arranged in order to understand all of the code. Open miami_moon.p8 on Github to view the code.

About this version of the code

NB that this version is provided to make reading the code a bit easier/more portable. You'll definitely need to see the sprite sheet and map sheet though in order to understand all of this code.

function _init()
 astro={1,2,3,4}
 deathstar={40,1}

 shadow=17
 moony=113
 screenwide=128
 anim_speed=21
 move_speed=14
 cel_idx = 1
 framecount = 1
 astro_x = 0
end
function _update()

 framecount = framecount + 1

 astro_y = moony

 local t1 = timer(anim_speed)
 if (t1 == true) then
  cel_idx = cel_idx + 1
  if (cel_idx > #astro) then
   cel_idx = 1
  end
 end

 local t2 = timer(move_speed)
 if (t2 == true) then
  astro_x = astro_x + 1
  if (astro_x > screenwide) then
   astro_x = - 8
  end
 end

end
function _draw()

 cls(0)

 show_moonsurface()
 show_deathstar()
 show_astro()

end
function timer(fs)

 local alarm = false
 local t = framecount % fs

 if (t == 0) then
  alarm = true
 end

 return alarm

end
function show_moonsurface()

 map(0,4,0,0,16,16)

end
function show_deathstar()
 local col=deathstar[1]
 local row=deathstar[2]
 local x=90
 local y=9
 map(col, row, x, y, 2, 2)
end
function show_astro()

 local shadowy=astro_y+7
 spr(shadow, astro_x, shadowy)
 local cel = astro[cel_idx]
 spr(cel, astro_x, astro_y)

end

Graphics removed from this cartridge.

Please load miami_moon into PICO-8 to see the graphic assets.

Addendum

(Removed. See intro of this page for easier way to find the /carts directory).