Forem

Cover image for A MiniTron In 47 Lines
Montegasppα Cacilhας
Montegasppα Cacilhας

Posted on • Edited on

A MiniTron In 47 Lines

Original from Kodumaro.


This is a sample code for learning, written in Moonscript for TIC-80:

-- title:   MiniTron
-- author:  Montegasppa <batalema@cacilhas.info>
-- desc:    A very spartan Tron implementation
-- license: 3-Clause BSD
-- version: 0.1
-- script:  moon
export ^
local  *

local cycle, dir, tic, score

size = 2

move = ->
  with cycle
    next = switch dir
      when 0
        x: .x, y: .y-size
      when 1
        x: .x, y: .y+size
      when 2
        x: .x-size, y: .y
      when 3
        x: .x+size, y: .y
    reset! if pix(next.x, next.y) != 0
    rect .x, .y, size, size, 9
    cycle = next
  score += 1

BOOT = ->
  cycle = x: 120, y: 68
  dir, tic, score = 3, 0, 0
  cls!
  rectb 0, 0, 240, 136, 4
  rectb 1, 1, 238, 134, 4

TIC = ->
  poke 0x3ffb, 0
  rect cycle.x, cycle.y, size, size, 3
  for i = 0, 3 do dir = i if btn i
  tic += 1
  if tic == 10
    move!
    tic = 0

OVR = ->
  print "Score: #{score}", 3, 128, 3, false, 1, true
Enter fullscreen mode Exit fullscreen mode

Download the card!

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay