Modified the time at which levers trigger compared to their animation.

This commit is contained in:
Sakse Dalum 2012-08-10 16:57:22 +02:00
parent 0b730edc6d
commit 29434ab0c5
2 changed files with 28 additions and 4 deletions

View File

@ -37,6 +37,10 @@ class Lever(worldobject.WorldObject):
self.init_setting = setting self.init_setting = setting
self.at_rest = True
self.send_signal = False
self.frame = 0 self.frame = 0
self.anim_speed = 15 self.anim_speed = 15
@ -50,9 +54,8 @@ class Lever(worldobject.WorldObject):
def use(self, obj): def use(self, obj):
self.setting = not self.setting self.setting = not self.setting
self.at_rest = False
for link in self.links: self.send_signal = True
link(self.signal[self.setting])
def update(self, e, t, dt): def update(self, e, t, dt):
# Update the animation # Update the animation
@ -62,9 +65,25 @@ class Lever(worldobject.WorldObject):
else: else:
self.frame = max(self.frame - self.anim_speed * dt, self.frame = max(self.frame - self.anim_speed * dt,
0) 0)
if not self.toggling: if not self.toggling:
if (self.frame - self.anim_speed * dt <= 0): if (self.frame - self.anim_speed * dt <= 0):
self.setting = 0 self.setting = 0
self.at_rest = self.frame == len(self.level.imgs[self.anim]) - 1
else:
self.at_rest = self.frame in [len(self.level.imgs[self.anim]) - 1,
0]
if (((self.frame <= int(len(self.level.imgs[self.anim]) / 3)
and not self.toggling)
or (self.frame <= int(len(self.level.imgs[self.anim]) / 3)
and self.setting and self.toggling)
or (self.frame >= int(2 * len(self.level.imgs[self.anim]) / 3)
and not self.setting and self.toggling))
and self.send_signal):
for link in self.links:
link(self.signal[self.setting])
self.send_signal = False
worldobject.WorldObject.update(self, e, t, dt) worldobject.WorldObject.update(self, e, t, dt)

View File

@ -146,10 +146,13 @@ class Player(worldobject.WorldObject):
if (obj.x == self.x + touch_x * self.tile_x if (obj.x == self.x + touch_x * self.tile_x
and obj.y == self.y + touch_y * self.tile_y and obj.y == self.y + touch_y * self.tile_y
and obj != self): and obj != self):
obj.use(self)
# Concerning levers # Concerning levers
if type(obj) == lever.Lever: if type(obj) == lever.Lever:
if not obj.at_rest:
return
obj.use(self)
self.working = True self.working = True
# List all possible combinations ... # List all possible combinations ...
@ -167,6 +170,8 @@ class Player(worldobject.WorldObject):
self.frame = 0 self.frame = 0
self.anim = ( self.anim = (
self.direction_as_string() + '_' + lever_direction) self.direction_as_string() + '_' + lever_direction)
else:
obj.use(self)
def update(self, e, t, dt): def update(self, e, t, dt):
if not self.working: if not self.working: