Blocks, depth, holding and releasing objects, etc.
This commit is contained in:
@@ -25,17 +25,44 @@ A generic world object.
|
||||
"""
|
||||
|
||||
class WorldObject(object):
|
||||
def __init__(self, x, y, speed=5, tile_x=64, tile_y=48):
|
||||
def __init__(self, level, x, y, z=0, direction=(1, 0), speed=5,
|
||||
tile_x=64, tile_y=48,
|
||||
movable=False):
|
||||
self.__dict__.update(locals())
|
||||
|
||||
self.move_x = self.x = self.x - (self.x % self.tile_x)
|
||||
self.move_y = self.y = self.y - (self.y % self.tile_y)
|
||||
|
||||
self.holding = None
|
||||
self.holder = None
|
||||
|
||||
def check_move(self, move_x, move_y):
|
||||
if self.move_x == self.x and self.move_y == self.y and self.movable:
|
||||
for obj in self.level.objects:
|
||||
if (obj.x == self.x + move_x * self.tile_x
|
||||
and obj.y == self.y + move_y * self.tile_y
|
||||
and obj != self and obj != self.holder
|
||||
and obj != self.holding):
|
||||
return False
|
||||
return True
|
||||
return False
|
||||
|
||||
def move(self, move_x, move_y):
|
||||
if self.move_x == self.x and self.move_y == self.y:
|
||||
if self.check_move(move_x, move_y):
|
||||
|
||||
if self.holding:
|
||||
if not self.holding.check_move(move_x, move_y):
|
||||
return False
|
||||
|
||||
self.move_x += move_x * self.tile_x
|
||||
self.move_y += move_y * self.tile_y
|
||||
|
||||
if self.holding:
|
||||
self.holding.move(move_x, move_y)
|
||||
|
||||
def use(self):
|
||||
pass
|
||||
|
||||
def update(self, e, t, dt):
|
||||
if self.x > self.move_x:
|
||||
self.x -= min(self.speed * dt * self.tile_x,
|
||||
|
||||
Reference in New Issue
Block a user