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!!



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 |






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



thanks !!
ive been trying still cant get it working but still thanks!!
[Please log in to post a comment]