XTRIS - Retrospective and Thank You!


THANK YOU!

To be honest, when I first joined the TweetTweetJam 8, I had about 1 week worth of learning about tweetcarts when I saw a post about this jam hit my timeline. Curious, I read the jam description, and it seemed like the perfect way to try applying what I had learned so far - I did not expect that within 24 hours XTRIS would be featured in the #8 spot in itch.io’s New & Popular category!

I had a lot of help developing this game and refining it to the point that is now, both from my own Discord community (filled with some amazing artists, developers, and other creative folks!) and from the Nerdy Teacher’s Discord. If you haven’t heard of Nerdy Teachers, they produce some high-quality PICO-8 resources and I strongly encourage you to check them out!

Obviously, the code used in the jam game is minified beyond recognition. I have taken the time to “re-hydrate” the code into a more readable PICO-8 format! Thanks to the PICO-8 Education Edition, I can share this code with you! Just note that the re-hydrated version has some aspects changed to avoid “hacky” solutions but it is a rough equivalent of the game.

see the re-hydrated version here

After clicking on that link, you can press ESC twice until you see the code editor - you’ll then be able to read the code, as well as edit it, learn more about XTRIS, or even use it to make your own project!

Thank you all so much for all of the plays, comments, and support. It means a lot to just a little game developer like me who is interesting in creating small experiences during my free time <3

In case you don’t want to read the code in the browser window, here’s the hydrated version pasted into this post:

-- xtris - a game by fletch
-- globals
tiles = {
    {x=18,y=22},
    {x=28,y=22},
    {x=38,y=22},
    {x=28,y=32}
}

points = 0
goal_idx = 4
player_idx = 1
fade_idx = 1
fade_table = {}
elapsed_time = 0
game_over = false

-->8
-- lifecycle functions
function _init()
    -- set to 64x64 mode
    poke(0x5f2c,3)

    -- populate the fade table
    for i=0,64 do
        add(fade_table, 0)
    end
end

function _update()
    -- iterate over each pixel in the fade_idx tile - if we see a green pixel, roll a dice to see if we should set it to black
    for i=0,64 do
        local top_x, top_y = tiles[fade_idx].x, tiles[fade_idx].y
        local pixel_color = fade_table[i+1]
        -- we roll a d100 - if the dice is greater than 70, then we set that pixel to black
        if (pixel_color == 3 and rnd() > 0.7) then
            fade_table[i+1] = 0
        end
    end

    -- determine the game end condition
    elapsed_time = t()
    if (elapsed_time > 63) then
        game_over = true
        return
    end

    -- if we haven't hit game end condition yet, we fall here
    if (btnp(0) and (player_idx == 2 or player_idx == 3)) then -- left was pressed
        player_idx -= 1
    elseif (btnp(1) and (player_idx == 1 or player_idx == 2)) then -- right was pressed
        player_idx += 1
    elseif (btnp(2) and player_idx == 4) then -- up was pressed
        player_idx = 2
    elseif (btnp(3) and player_idx == 2) then -- down was pressed
        player_idx = 4
    end

    -- check to see if we've hit the goal
    if (player_idx == goal_idx) then
        points += 1
        while (goal_idx == player_idx) do 
            goal_idx = rnd({1, 2, 3, 4})
        end

        fade_tile(player_idx)
    end
end

function _draw()
    cls(0)

    -- iterate over each pixel in the fade_idx tile - if we see a green pixel, roll a dice to see if we should set it to black
    for i=0,64 do
        local top_x, top_y = tiles[fade_idx].x, tiles[fade_idx].y
        local pixel_color = fade_table[i+1]
        pset(top_x + i\8, top_y + i%8, pixel_color)
    end

    -- print out the player's points
    print(pad_score(points), 27, 15, 7)

    -- game over text
    if (game_over) then
        print("ctrl+r to retry", 2, 50, 7)
    end

    -- show the timer
    line(0, 63, elapsed_time, 63)

    -- draw the tiles
    for idx,tile in ipairs(tiles) do
        local                           color = 5 -- dark grey
        if (game_over) then             color = 8 -- red
        elseif (idx == goal_idx) then   color = 3 -- dark green
        elseif (idx == player_idx) then color = 7 -- white
        end

        -- print the rectangle
        rect(tile.x, tile.y, tile.x+8, tile.y+8, color)

        -- print the X if we're in a goal slot
        if (idx == goal_idx) then
            print("x", tile.x+3, tile.y+2, color)
        end
    end
end

-->8
-- helper functions
function pad_score(score)
    if (score < 10) then
        return "00"..score
    elseif (score < 100) then
        return "0"..score
    else
        return score
    end
end

function fade_tile(tile_idx)
    fade_idx = tile_idx
    for i=0,64 do
        fade_table[i+1] = 3 -- set the whole fade table to dark green
    end
end

Get XTRIS

Comments

Log in with itch.io to leave a comment.

(+1)

I find the compact version easier to read XD (not the fully compact version, I uncompress the code so it becomes somewhat readable)

(1 edit)

Code that I uncompressed

poke(0x5f2c,3)
a={18,28,38,28}
b={22,22,22,32}
p=0
g=4
i=1
l=0
c=color
q=btnp
::_::
c(0)
--screen black
--use this
for j=0,999 do
 pset(rnd(64),rnd(64))
end
--and not this
--for j=0,4096 do
--if (rnd()>.7) pset(j\64,j%64)
--end
--timer colour
c(7)
--timer size
l=time()
--score
?p,0,0
--timer
line(0,63,l,63)
--loop to draw all rects
for j=1,4 do
 --grey squre colour
 c(5)
 --green squre
 if (j==g) c(3) ?"x",a[j]+3,b[j]+2
 --player
 if (j==i) c(7) 
 --game end
 if (l>63) c(8)
 --draws all rects
 rect(a[j],b[j],a[j]+8,b[j]+8)end if(l<63)then
 --movement
 if (q(0) and i%4>1) i-=1
 if (q(1) and i<3) i+=1
 if (q(2) and i>3) i=2
 if (q(3) and i==2) i=4
 --score + partical effects
 if(g==i) p+=1 g=rnd(4)\1+1 rectfill(a[i],b[i],a[i]+8,b[i]+8,3)
 --idk
 if(g==i) g+=1 g%=4 g+=1
 --end
end
flip()
goto _

It's 737 characters of uncompressed code ;-;