#define PX_STEP 8 // How many pixels to move each step
atom
var
radius = null
turf
icon='IconSet.dmi'
icon_state="Grass"
mob
icon='IconSet.dmi'
icon_state="Mob"
animate_movement = 0
radius = 16
proc
pxstep(d)
if(d&NORTH)
pixel_y += PX_STEP
if(pixel_y >= 32)
pixel_y = 0
y++
if(d&SOUTH)
pixel_y -= PX_STEP
if(pixel_y <= -32)
pixel_y = 0
y--
if(d&EAST)
pixel_x += PX_STEP
if(pixel_x >= 32)
pixel_x = 0
x++
if(d&WEST)
pixel_x -= PX_STEP
if(pixel_x <= -32)
pixel_x = 0
x--
if(Collision_Check())
world << "Collision!"
Collision_Check()
for(var/atom/a in range(src, 1) - src)
if((round( Get_Distance(src, a) )) < (radius + a.radius) && a.density)
return TRUE
return FALSE
client
North()
mob.pxstep(NORTH)
South()
mob.pxstep(SOUTH)
East()
mob.pxstep(EAST)
West()
mob.pxstep(WEST)
Well my collision detection system works pretty well except from a small minor problem. My Collision_Check() procedure detects collision as expected, but when retreating from the dense object it returns true 3 more times than needed.
So the output being:
Collision!
Collision!
Collision!
Collision!
As there are 4 collision responses I am assuming this is because 32/8(pixel step size) = 4, that's why I need to take the pixel_x and pixel_y variables in account.
One way around could be making my whole collision check dir-specific but that could get pretty annoying when working with non-cardinal directions such as northeast, northwest, southeast, etc.
I understand how the collision system works but I have a strange feeling I'm not implementing it well, if there are any rewrites needed in my system, especially in the "CollisionCheck()" procedure, then please do say.
Here is a working copy of my movement system (including the source code).
Included in the zip file is a video which shows what problem I am running into.
Thank you.
Haywire
Also, "range(1,src)-src" is the same as "orange(1,src)".