It's awesome!

This commit is contained in:
Sakse Dalum
2012-08-08 18:13:53 +02:00
parent 0ac3baa8f5
commit ce84def0e0
4 changed files with 80 additions and 26 deletions

View File

@@ -31,11 +31,12 @@ import copy
class WorldObject(object):
def __init__(self, level, x, y, z=0, direction=(1, 0), speed=4,
tile_x=64, tile_y=48,
movable=False, blocking=True):
movable=False, blocking=True, is_moving=False):
self.__dict__.update(locals())
self.init_x = self.move_x = self.x = self.x - (self.x % self.tile_x)
self.init_y = self.move_y = self.y = self.y - (self.y % self.tile_y)
self.init_direction = self.direction
self.holding = None
self.holder = None
@@ -45,9 +46,20 @@ class WorldObject(object):
def set_init_pos(self):
self.init_x, self.init_y = self.x, self.y
self.init_direction = self.direction
def reset_pos(self):
self.x, self.y = self.move_x, self.move_y = self.init_x, self.init_y
self.direction = self.init_direction
def share_tile(self, obj_type):
for obj in self.level.objects:
if (obj.x - (obj.x % self.tile_x) == self.x - (self.x % self.tile_x)
and obj.y - (obj.y % self.tile_y) == self.y - (self.y
% self.tile_y)
and obj is not self and isinstance(obj, obj_type)):
return obj
return None
def check_move(self, move_x, move_y):
if self.move_x == self.x and self.move_y == self.y and self.movable:
@@ -73,6 +85,9 @@ class WorldObject(object):
if self.holding:
self.holding.move(move_x, move_y)
return True
return False
def use(self, obj):
pass
@@ -104,4 +119,6 @@ class WorldObject(object):
self.y += min(self.speed * dt * self.tile_y,
abs(self.y - self.move_y))
self.is_moving = self.x != self.move_x or self.y != self.move_y
self.x, self.y = int(self.x), int(self.y)