Modified the time at which levers trigger compared to their animation.
This commit is contained in:
parent
0b730edc6d
commit
29434ab0c5
|
@ -37,6 +37,10 @@ class Lever(worldobject.WorldObject):
|
|||
|
||||
self.init_setting = setting
|
||||
|
||||
self.at_rest = True
|
||||
|
||||
self.send_signal = False
|
||||
|
||||
self.frame = 0
|
||||
self.anim_speed = 15
|
||||
|
||||
|
@ -50,9 +54,8 @@ class Lever(worldobject.WorldObject):
|
|||
|
||||
def use(self, obj):
|
||||
self.setting = not self.setting
|
||||
|
||||
for link in self.links:
|
||||
link(self.signal[self.setting])
|
||||
self.at_rest = False
|
||||
self.send_signal = True
|
||||
|
||||
def update(self, e, t, dt):
|
||||
# Update the animation
|
||||
|
@ -62,9 +65,25 @@ class Lever(worldobject.WorldObject):
|
|||
else:
|
||||
self.frame = max(self.frame - self.anim_speed * dt,
|
||||
0)
|
||||
|
||||
if not self.toggling:
|
||||
if (self.frame - self.anim_speed * dt <= 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)
|
||||
|
||||
|
|
|
@ -146,10 +146,13 @@ class Player(worldobject.WorldObject):
|
|||
if (obj.x == self.x + touch_x * self.tile_x
|
||||
and obj.y == self.y + touch_y * self.tile_y
|
||||
and obj != self):
|
||||
obj.use(self)
|
||||
|
||||
# Concerning levers
|
||||
if type(obj) == lever.Lever:
|
||||
if not obj.at_rest:
|
||||
return
|
||||
|
||||
obj.use(self)
|
||||
self.working = True
|
||||
|
||||
# List all possible combinations ...
|
||||
|
@ -167,6 +170,8 @@ class Player(worldobject.WorldObject):
|
|||
self.frame = 0
|
||||
self.anim = (
|
||||
self.direction_as_string() + '_' + lever_direction)
|
||||
else:
|
||||
obj.use(self)
|
||||
|
||||
def update(self, e, t, dt):
|
||||
if not self.working:
|
||||
|
|
Loading…
Reference in New Issue