I been having trouble figuring out how to draw a map (room)
:(
Can someone do a cartridge that does nothing else but draw a map.
So I don't get lost in code for player controls, etc...
Thank you so much in advance :)
If you've arranged sprites on the map, then you use mapdraw() to draw a section of the map.
For example, if you used the map editor to place sprites on the map starting in the top left (0, 0) and spanning 3 tiles wide and 5 tiles high, you can draw that section to the screen at (41, 37) for example, by doing this:
mapdraw(0, 0, 41, 37, 3, 5) |
Does that help at all?
EDIT: here is a cartridge of that example
Thank you so much, it did help a lot :)
How can I make my character collide with sprites?
plr={} plr.x=5 plr.y=5 plr.spr=16 plr.spd=1 plr.mv=false function move() plr.mv=true plr.spr+=1 if plr.spr>25 then plr.spr=17 end end function _update() plr.mv=false if btn(0) then plr.x-=plr.spd move() end if btn(1) then plr.x+=plr.spd move() end if btn(2) then plr.y-=plr.spd move() end if btn(3) then plr.y+=plr.spd move() end if not plr.mv then plr.spr=16 end end function _draw() cls() mapdraw(0, 0, 0, 30, 16, 9) spr(plr.spr,plr.x,plr.y) end |
Check out the jelpi demo - full source, and platformer-style collisions. I'm sure you can adapt it?
That doesn't work, there is too much code. I can't make sense of it.
Not sure what to look for.
if (btn(2)) then mun=mun-1 end if mun<32 then mun=40 end |
I found a way to make a character move on a map and have an animation. here is the code
ben=0 x=0 y=0 function _update() if (btn(0)) then x=x-1 end if (btn(1)) then x=x+1 end if (btn(2)) then y=y-1 end if (btn(3)) then y=y+1 end if (btn(2)) then ben=ben+1 end if ben>2 then ben=0 end if (btn(1)) then ben=ben+1 end if ben>2 then ben=0 end if (btn(0)) then ben=ben+1 end if ben>2 then ben=0 end if (btn(3)) then ben=ben+1 end if ben>2 then ben=0 end end function _draw() cls() mapdraw(0, 0, 0, 0, 16, 16) spr(ben,x,y) print(ben) end |
You can detect collisions with either sprite flags (good for environment) or hitboxes (good for actors).
for flags the code is something like
function coll(z)
v = mget(flr(z.x)/8,
flr(z.y)/8+1)
return fget (v,0)
end
here's a thread that explains how better than I can
https://www.lexaloffle.com/bbs/?tid=3116
for hitboxes you first assign actors hitboxes like
b.hitbox={
x=0,y=0,w=1,h=1}
add (p_bullet,b)
then check for collisions like
function hitcol(other,obj)
if
other.x+other.hitbox.x+
other.hitbox.w > obj.x+
obj.hitbox.x and
other.y+other.hitbox.y+
other.hitbox.h > obj.y+
obj.hitbox.y and
other.x+other.hitbox.x
< obj.x+obj.hitbox.x+
obj.hitbox.w and
other.y+other.hitbox.y
< obj.y+obj.hitbox.y+
obj.hitbox.h
then
return true
end
end
the picozone 3 zine has an article called "Dom8verse" that goes into setting up hitboxes.
also be sure to check out the pico8 wiki!
I threw a Frankenstein cart together if it helps
[Please log in to post a comment]