Log In  

hello,im making a game like pacman where you are a ghost and can hide in objects. the problem is that i cant get collision detection working. i just need it to detect sprites that cant be passed by the player, im making the game on pocket chip so i cant share the carts code now, thanks!!

P#43321 2017-08-17 09:58 ( Edited 2017-08-17 17:13)

To share the cart, you can either upload it here using a browser (IceWeasel, Surf, etc -- they run a bit slow on the pocketchip but are definitely usable), or you can transfer it to your computer using ftp.

It will be easier to point you in the right direction if you can share that. But the simple way to find is something is overlapping with something else is this:

function check_collide(rect1,rect2)
  //left,top,right,bottom
  local l1=rect1[1]
  local r1=rect1[3]
  local t1=rect1[2]
  local b1=rect1[4]
  local l2=rect2[1]
  local r2=rect2[3]
  local t2=rect2[2]
  local b2=rect2[4]
  //if the right side of rect1 is to the right of rect2's left side,
  //OR the left side of rect1 is to the right of rect2's right side,
  //OR the bottom of rect1 is above the top of rect2,
  //OR the top of rect1 si below the bottom of rect2..
  if (r1<l2 or r2<l1 or b1<t2 or b2<t1) then
    //then they do NOT collide
    return false
  else
    //but if any of the above is false
    //then they DO overlap
    return true
  end

end
P#43323 2017-08-17 10:07 ( Edited 2017-08-17 14:09)

here it is

Cart #43330 | 2017-08-17 | Code ▽ | Embed ▽ | No License

P#43331 2017-08-17 11:57 ( Edited 2017-08-17 15:57)

Since you are using map to create your game board, you can accomplish wall collision detection using sprite flags. Look up fget and mget in the pico-8 documentation/api. It is fairly straightforward. You will likely want to use something like @enargy's collision description for detecting collision with other objects though (items, enemies, etc).

P#43332 2017-08-17 12:20 ( Edited 2017-08-17 16:20)

thanks !!
ive been trying still cant get it working but still thanks!!

P#43335 2017-08-17 13:13 ( Edited 2017-08-17 17:13)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-16 21:22:59 | 0.013s | Q:18