Skip to content
Permalink
Browse files

resolve weakref slots

  • Loading branch information
flipcoder committed Mar 26, 2020
1 parent 7cad87a commit 3c3cd6e1e164500434c88482f3c9d21efcc2aa66
Showing with 11 additions and 5 deletions.
  1. +8 −2 game/base/inputs.py
  2. +3 −3 game/entities/player.py
@@ -53,7 +53,10 @@ def update(self, dt):

if self.pressed:
self._repeat.blocked += 1
for c in self._repeat.slots:
for wref in self._repeat.slots:
c = wref()
if not c:
continue
if c.delay * c.repetitions <= self.press_time:
# It isn;t possible to set it directly, I don't know why
c.repetitions += 1
@@ -85,7 +88,10 @@ def event(self, events):
# All keys were just released
self.last_press = 0
self.just_released = True
for c in self._repeat.slots:
for wref in self._repeat.slots:
c = wref()
if not c:
continue
c.repetitions = 0

@property
@@ -54,7 +54,7 @@ def __init__(self, app, scene, speed=PLAYER_SPEED):
self.actionkeys = [pygame.K_RETURN, pygame.K_SPACE, pygame.K_LSHIFT]
self.dir = [False] * len(self.dirkeys)
self.actions = [False] * len(self.actionkeys)
# self.app.inputs["fire"].on_press_repeated(self.fire, 0.15)
self.slots.append(self.app.inputs["fire"].on_press_repeated(self.fire, 0.15))
self.slots.append(self.app.inputs["hmove"].always_call(self.set_vel_x))
self.slots.append(self.app.inputs["vmove"].always_call(self.set_vel_y))

@@ -232,8 +232,8 @@ def update(self, dt):
self.velocity.y = min(0, self.velocity.y)
self.position.y = 300

if self.actions[0] or self.actions[1]:
self.fire()
# if self.actions[0] or self.actions[1]:
# self.fire()

super().update(dt)

0 comments on commit 3c3cd6e

Please sign in to comment.
You can’t perform that action at this time.