Log In  

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.

P#131642 2023-07-04 18:49

2

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().

P#131644 2023-07-04 20:16

Is sprite flag 0 actually set on sprite number 2? The sprites start at 0, so you want to make sure you're not counting the first sprite as number 1. The red flag indicator is number 0 so it should be lit when you look at sprite number 2 in the sprite editor.

P#131645 2023-07-04 20:18

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

P#131647 2023-07-04 21:21
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.

P#131648 2023-07-04 21:25 ( Edited 2023-07-04 21:26)
1

Do you convert pixel coordinates to tile coordinates somewhere? You have to divide your players x and y position by 8 to get tile coordinates. This is because while the screen is 128 pixels wide, it is only 16 tiles wide.

P#131661 2023-07-05 05:16

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?

P#131672 2023-07-05 15:15

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!

P#131680 2023-07-06 01:39

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-02-26 22:10:14 | 0.010s | Q:19