Skip to content

kevinthompson/object-oriented-pico-8

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

This is the partner repository to my video on "Object Oriented Programming in PICO-8" which you can watch on YouTube. Below you'll find a couple samples from the video with links to additional resources.

Over the course of the video we build up class inheritance logic that ultimately looks something like this (in case you're looking for a quick snippet to get started 😄):

class=setmetatable({
  new=function(_ENV,tbl)
    return setmetatable(tbl or {},{
      __index=_ENV
    })
  end,
},{__index=_ENV})

In this repo I've included two cartridges:

starfield.p8 This is the cartridge that we build up in the video, creating a field of stars using object oriented programming.
heartseeker.p8 This cartridge expands on the initial logic we explore in the video and creates several additional objects. It was originally created for the video but became too complicated to explain concisely.

Metatables

Metatables are a feature of LUA that allow you to change the behavior of a table. In the video above we use the __index metamethod to setup class inheritance and object instantiation.

Additional Resources:

Environments

In LUA, the global environment is a table that can be accessed using _ENV. The current environment can also be reassigned. Using information from the article below, we apply that technique in order to reduce the number of tokens used.

Additional Resources:

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages