Pico-8: Lines Screensaver

2019-01-22 - Reading time: 2 minutes

Okay, so it's not really a screensaver in this instance, but it's the art from inside one. You recognize it. You've seen it before. But here it is... much lower res than usual. ;)

Source: https://gist.github.com/Fortyseven/a4e2d5d3105ed86e0916d162a1a4d466

pico-8 cartridge // http://www.pico-8.com
version 16
__lua__
-- lines (classic)
-- by fortyseven

SPACING = 4
SPEED = 1

function buildPolyVerts()
    local verts = {
        x=rnd(128),
        y=rnd(128),
        xvel= SPEED,
        yvel= SPEED
    };
    if (rnd(1) > 0.5)  verts.xvel = -verts.xvel
    if (rnd(1) > 0.5)  verts.yvel = -verts.yvel
    return verts;
end;

-------------------------------------------------------------
poly = {}

function poly:init(i, color)
    self.color = color
    self.verts = {}

    -- ensure we use the same seed for each poly object, so it will always
    -- create the same intial x/y/velocity directions

    for i = 1, 4 do
        verts = buildPolyVerts()
        add(self.verts,verts)
    end

    -- run the update a couple times to space them out

    for i = 1, i*SPACING do self:update() end
end

function poly:update()
    foreach(self.verts, function(vert)
        vert.x += vert.xvel
        if ((vert.x >= 128) or (vert.x <= 0)) vert.xvel = -vert.xvel
        vert.y += vert.yvel
        if ((vert.y >= 128) or (vert.y <= 0)) vert.yvel = -vert.yvel
    end)
end

function poly:draw()
    for i = 1, 3 do
        color(self.color);
        line(self.verts[i].x, self.verts[i].y, self.verts[i+1].x, self.verts[i+1].y)
    end
    line(self.verts[4].x, self.verts[4].y, self.verts[1].x, self.verts[1].y)
end

function poly:new(o)
    self.__index = self
    return setmetatable(o or {}, self)
end

-------------------------------------------------------------
polyCluster = {}

function polyCluster:init(col_array)
    self.objects = {}
    seed = flr(rnd(1000))

    -- generate three unique polys
    for i = 1, 3 do
        srand(seed)
        local o = poly:new()
        o:init(i, col_array[i])
        add(self.objects, o )
    end
end

function polyCluster:update()
    foreach(self.objects, function(obj)
        obj:update()
    end)
end

function polyCluster:draw()
    foreach(self.objects, function(obj)
        obj:draw()
    end)
end

function polyCluster:new(o)
    self.__index = self
    return setmetatable(o or {}, self)
end

-------------------------------------------------------------
clusters = {}

function _init()
    local c = polyCluster:new()
    c:init({2,8,14})
    add(clusters, c)

    c = polyCluster:new()
    c:init({1,6,12})
    add(clusters, c)

    c = polyCluster:new()
    c:init({13,6,7})
    add(clusters, c)
end

function _draw()
    foreach(clusters, function(c)
        c:update()
    end)
end

function _update()
    cls()
    foreach(clusters, function(c)
        c:draw()
    end)
end

Fantasy consoles?!

2019-01-05 - Reading time: ~1 minute

Been really enjoying playing with Pico-8 lately. If you're not familiar, it's essentially a so-called 'fantasy console' that you can code against. It has all kinds of restrictions as far as code size, memory, graphics, etc. But that's the point: coding within restraints. Old-school style before entire trucks full of gigabytes and gigahertz were dumped on our doorstep.

The consoles include code, music, and art editors inside the app, so you can do everything in one place. It's possible to edit these things externally, too, if that's your bag. Personally, I've been using VSCode along with an appropriate extension.

My first attempt was recreating the classic demo-scene fire effect, which has popped back into the mainstream consciousness thanks to this post.

As you can see, it runs pretty great in a web browser!

There's other 'fantasy consoles' besides Pico-8, including TIC-80 which has an Android port for coding on-the-go!

Not only is it a good exercise coding down to restrictions, it's very convenient to just pick up and go to sketch out gamedev ideas.

Give it a go!


Elsewhere...

Hit Counter

64