-
-
Notifications
You must be signed in to change notification settings - Fork 559
Using mset() and mget() functions
In it's most basic form, the map is a way of organizing graphics.
You can draw in your sprites in the map editor...but that's only half the story.
There wouldn't be much point if you couldn't read data back from the map.
To do this we use:
mget(cell_x,cell_y)
This takes map coordinates as arguments, and returns the ID number of the sprite drawn in that cell.
In this way we can alter game behaviour based on sprites. Some options include:
collision detection
trip wires
alter player speed based on terrain
damage inflicting tiles
These gameplay mechanics are common in a variety of games.
Another useful thing to do with the map is alter the sprites.
To do that we use:
mset(cell_x,cell_y,sprite_ID)
This takes cell coordinates, and a sprite ID, and places that sprite in that cell.
Some uses for this include:
opening/closing doors
breakable walls
spiked floor traps
Again some very old stand-bys in games.
Often times you'll use both of these together.
one to read the map and the other to modify it.
Let's look at a few examples:
The easiest way to assign properties to sprites is to arrange similar tiles together.
For example:
The non-solid floor sprites are placed in the 1st row...slots 01-15
The non-solid damaging sprites are placed in the 3rd row...slots 33-47
The solid wall tiles are placed in the 5th row slots...slots 66-79
Now we can test for sprite properties by checking it's ID:
--first we'll take the tile the player is standing on and log it into "tile"
tile=mget(player.x, player.y)
--now we'll test it for damage properties...remember they're stored between 33-47
if tile>=33 and tile<=47 then
reduce_player_health()
end
I will only place solid tiles after the solids row (or decorative tiles the player will never encounter such as menu or HUD sprites)
This makes checking collision easier:
FIRST_SOLID_SPRITES=66 --the sprite ID of the first wall
if mget(player.x, player.y) < FIRST_SOLID_SPRITE then
--allow player to move
end
for a full walkthrough on collision detection, check out my tutorial on it here
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)