Repository navigation
Hello World
The Hello World cartridge is the demo cart created by the new command. With several runtimes in the build, new needs the language name: new lua, new python, new wren, and so on. The NEW submenu of the TIC-80 menu lists the same languages.
-- title: game title
-- author: game developer, email, etc.
-- desc: short description
-- site: website link
-- license: MIT License (change this to your license of choice)
-- version: 0.1
-- script: lua
t=0
x=96
y=24
function TIC()
if btn(0) then y=y-1 end
if btn(1) then y=y+1 end
if btn(2) then x=x-1 end
if btn(3) then x=x+1 end
cls(13)
spr(1+t%60//30*2,x,y,14,3,0,0,2,2)
print("HELLO WORLD!",84,84)
t=t+1
endThe first argument of the spr function corresponds to the sprites indices. The formula 1+t%60//30*2 switches from one sprite to the other to animate the character.
Let's explain it:
The two sprites have indices 1 and 3 so we need something that switches from 1 to 3 regularly.
In lua % is the modulo operator, it returns the remainder of the division.
> eval trace(154 % 60)
34Because 154 is 2×60+34.
So mechanically t%60 increases with t from 0 to 59 and then restart at 0 when t is a multiple of 60.
// is the floor division, it divides the number, then truncates it.
> eval trace(34//30)
1So t%60//30 will be 0 when t%60<30 and 1 else.
Therefore 1+t%60//30*2 switches between 1 and 3.
The default cart template can be modified using the config default command. That can be used to use a custom palette for all your projects. Do not forget to save.
TIC-80 tiny computer https://tic80.com | Twitter | Telegram | Terms
Built-in Editors
Console
save | export | load | import | menu | config | surf | shelf | demo | eval
Platform
RAM | VRAM | Display | Palette | Bits per Pixel (BPP) |
.ticFormat | Supported Languages
Other
Tutorials | Code Snippets | Libraries | External Tools | FFT
API
Callbacks
Input
Drawing
circ | circb | clip | cls | elli | ellib | font | line | map | paint | pix | print | rect | rectb | rrect | rrectb | spr | tri | trib | ttri | fill patterns
- textri (deprecated)
Sound
Memory
memcpy | memset | mget | mset | peek | poke | pmem | sync | vbank
System