super().update(delta)
if target is not None and self.dizzy_time == 0:
self.follow_target(target,stop_dist=self.weapon.width + self.width + target.width)
+ if self.weapon.get_collision_rect().colliderect(target.get_collision_rect()):
+ self.weapon.swing()
self.dizzy_time -= delta
self.dizzy_time = max(0,self.dizzy_time)
self.offset = pg.Vector2(offset)
self.holder_width = width
+ self.direction = direction
+
+ self.display = self.img
+ self.swing_timer = 0
def update(self, delta, pos, direction):
self.position = pg.Vector2(pos)
self.direction = direction
+ if self.direction == -1:
+ self.display = pg.transform.rotate(self.img, 360 * math.sin(math.radians(self.swing_timer/10)))
+ elif self.direction == 0:
+ self.display = pg.transform.rotate(self.flipped_img, -360 * math.sin(math.radians(self.swing_timer/10)))
+
+ self.swing_timer -= delta
+ self.swing_timer = max(self.swing_timer, 0)
+
def get_collision_rect(self):
if self.direction == -1:
return pg.Rect(self.position - pg.Vector2(self.width,0),(self.width, self.height))
elif self.direction == 1:
return pg.Rect(self.position + pg.Vector2(self.holder_width,0),(self.width, self.height))
+ def swing(self):
+ if self.swing_timer == 0:
+ self.swing_timer = 1800
+
def draw(self, surf):
- if self.direction == -1:
- surf.blit(self.img, self.get_collision_rect().topleft)
- else:
- surf.blit(self.flipped_img, self.get_collision_rect().topleft)
+ surf.blit(self.display, self.get_collision_rect().topleft)