
dot = 0
up = 1
rt = 2
dn = 3
lt = 4

def cw( d ):
	return d % 4 + 1

def ccw( d ):
	return ( d + 2 ) % 4 + 1

vec = [ (0, 0), (0, -1), (1, 0), (0, 1), (-1, 0) ]

def delta( d, x, y ):
	dx, dy = vec[d]
	return x + dx, y + dy

class NonPermeable:
	pass

def move_in_world( obj, world, x, y, direction ):
	nx, ny = delta( direction, x, y )
	for o in world.objs_at( nx, ny ):
		o.collide( obj, direction )
		if not o.permeable( obj ): raise NonPermeable
	world.rm_obj( obj, x, y )
	world.add_obj( obj, nx, ny )
	return nx, ny

