-
-
Notifications
You must be signed in to change notification settings - Fork 488
Hello World
The Hello World cartridge is the default cart created by the new
command.
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
end
The 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)
34
Because 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)
1
So 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 Hello World cartridge template can be modified using 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
Platform
RAM & VRAM | Display | Palette | Bits per Pixel (BPP) |
.tic
Format | Supported Languages
Other
Tutorials | Code Snippets | Libraries | External Tools | FFT
API
- BDR (0.90)
- BOOT (1.0)
- MENU
- OVR (deprecated)
- SCN (deprecated)
- TIC
- btn & btnp
- circ & circb
- clip
- cls
- elli & ellib (0.90)
- exit
- fget & fset (0.80)
- font
- key & keyp
- line
- map
- memcpy & memset
- mget & mset
- mouse
- music
- peek, peek4
- peek1, peek2 (1.0)
- pix
- pmem
- poke, poke4
- poke1, poke2 (1.0)
- rect & rectb
- reset
- sfx
- spr
- sync
- ttri (1.0)
- time
- trace
- tri & trib (0.90)
- tstamp (0.80)
- vbank (1.0)