Hi! So I'm very new to Pico-8 and recently purchased Pico-8 to test my skills in coding and currently I'm having problems trying to find collision. My Current Code is shown below:
function update_game() if fget(2,0) then --wall else if btnp(⬅️) then p_x-=1 end if btnp(➡️) then p_x+=1 end if btnp(⬆️) then p_y-=1 end if btnp(⬇️) then p_y+=1 end end end |
To describe my problem, I currently can go through any wall I want to, and it still moves.
Your code is checking if the sprite at position 2 on the sprite page has flag 0 set, then on false moving the player. If you want to check for a wall at a specific location on the map, you need to use mget()
to find which sprite is at that location, then feed that into the first parameter of fget()
.
Thank you so much for the help, I actually messed up on some bits and forgot to fix a few things, while I'm here, may I ask if there is any way to fix another problem I just encountered? The problem is that when I added another line of code that was supposed to change the map, it doesn't change and when I change it manually in the code, the collision from the original room is still working, I'll submit what my code looks like here in a sec
function moveplayer(dx,dy) local destx=p_x+dx local desty=p_y+dy local tle=mget(destx,desty) if fget(tle,0) then --wall else p_x+=dx p_y+=dy end if fget(tle,1) then change_room(16,7,12) end end |
basically the last fget won't send the change_room function.
function change_room(rm,px,py) cls(6) palt(14,true) palt(0,false) map(rm,0) p_x=px p_y=py end |
Sorry if this is an easy issue to solve btw, I'm very new to Pico-8 and have started a project using Pico-8 to try to challenge myself, and am basically a noob.
I can think of 2 possible reasons the room wouldn't change. First is the sprite not having flag 1 set. That would be the orange flag indicator in the sprite editor. The other possibility is your function working but not doing anything useful. Your change_room()
function has 4 lines that involve drawing to the screen and 2 that change the player position. Are you using a _draw()
function and if so does it use clr()
and map()
but with the starting values?
no. It doesn't use "clr()" but I used map() I honestly kind of am losing passion to work on the project anyways, but thank you both so much for the help!
[Please log in to post a comment]