-
-
Notifications
You must be signed in to change notification settings - Fork 499
Making Realtime Minimaps
For one of my projects, (a dungeon crawler) I decided I wanted a minimap to help the player navigate the levels.
Here's a screenshot of what I wanted:
The levels are generated using the Drunk Walk algorithm so I wasn't going to be able to draw them beforehand.
I needed a way to read the map and draw a minimap based on the layout.
Immediately I thought of the pix()
function.
this function is very straightforward.
It takes two or three arguments, based on the function you want:
pix( x_coor, y_coor, color_index)
This will take the pixel at the given (x,y) coordinates and make it the color you specified.
If you leave off the color_index, it will return the current color index of that pixel.
The idea of drawing the map is very similar to the section "Building Levels From Blueprints" in my tutorial on Using mset() and mget().
Again we will be using nested for loops to iterate over the entire map area.
From there we will read each cell and decide what color pixel to draw based on the cell sprite's property.
Here's the basic version:
--first some spite
SPACE=0
WALL=17
MAXX=30
MAXY=17
function minimap_simple()
for x=0,MAXX-1 do
for y=0,MAXY-1 do
if mget(x,y)>=WALL then pix(x,y,3) end
if mget(x,y)<WALL then pix(x,y,10) end
if x==p.x and y==p.y then pix(x,y,6) end
end
end
end
-- title: mini-map
-- author: Bear Thorne
-- desc: a dynamically drawn minimap
-- script: lua
--sprite constants
SPACE=0
WALL=17
TILE_GREEN=1
TILE_BROWN=2
TILE_BLUE =3
WALL_GREEN=17
WALL_BROWN=18
WALL_BLUE =19
DUDE=33
MAXX=30
MAXY=17
U={x= 0,y=-1}
D={x= 0,y= 1}
L={x=-1,y= 0}
R={x= 1,y= 0}
DIRS={U,D,L,R}
MOX=1 --minimap offset x
MOY=15*8-3 --minimap offset y
p={x=1,y=1}
function mini_map()
for x=-1,30 do
for y=-1,17 do
if mget(x,y)==TILE_GREEN then
pix(x+MOX,y+MOY,11)
elseif mget(x,y)==TILE_BROWN then
pix(x+MOX,y+MOY,9)
elseif mget(x,y)==TILE_BLUE then
pix(x+MOX,y+MOY,8)
elseif mget(x,y)==WALL_GREEN then
pix(x+MOX,y+MOY,5)
elseif mget(x,y)==WALL_BROWN then
pix(x+MOX,y+MOY,4)
elseif mget(x,y)==WALL_BLUE then
pix(x+MOX,y+MOY,2)
else
pix(x+MOX,y+MOY,7) --space color
end
if x==p.x and y==p.y then
pix(x+MOX,y+MOY,6) --player color
end
end
end
end
function minimap_simple()
for x=0,MAXX-1 do
for y=0,MAXY-1 do
if mget(x,y)>=WALL then pix(x,y,3) end
if mget(x,y)<WALL then pix(x,y,10) end
if x==p.x and y==p.y then pix(x,y,6) end
end
end
end
function clear_ahead(dir)
if mget(p.x+dir.x,p.y+dir.y)<WALL_GREEN then
return true
else
return false
end
end
function draw()
cls()
map(p.x-14,p.y-8,MAXX,MAXY)
minimap_simple()
mini_map()
spr(DUDE,14*8,8*8,0)
end
function TIC()
if btnp(0,6,10)and clear_ahead(U) then p.y=p.y-1 end
if btnp(1,6,10)and clear_ahead(D) then p.y=p.y+1 end
if btnp(2,6,10)and clear_ahead(L) then p.x=p.x-1 end
if btnp(3,6,10)and clear_ahead(R) then p.x=p.x+1 end
draw()
end
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)