from Setup import *
from Player import Player
from Actors import Actor
+from Weapon import Melee
class Enemy(Actor):
width, height = 25, 50
self.movable = True
self.dizzy_time = 0
+ self.weapon = Melee(self.position, (-35,self.height/2 - 20),self.width,-1)
+
def update(self, delta, target=None):
super().update(delta)
if target is not None and self.dizzy_time == 0:
- self.follow_target(target)
+ self.follow_target(target,stop_dist=self.weapon.width + self.width + target.width)
self.dizzy_time -= delta
self.dizzy_time = max(0,self.dizzy_time)
# Deals with collision and applying velocity
self.position, self.velocity = self.move_and_collide(self.position, self.velocity, delta)
+ self.weapon.update(delta,self.position, math.copysign(1,self.velocity.x))
+
def knockout(self, node):
self.dizzy_time = 5000
self.health -= 10
node.on_ground = True
node.jump()
# self.crouch(1000)
+
+ def draw(self, surf):
+ self.weapon.draw(surf)
+ super(Enemy, self).draw(surf)
class Melee:
- img = pg.image.load("Assets/SWORD.png")
+ img = pg.transform.smoothscale(pg.image.load("Assets/SWORD.png"), (40,40))
+ flipped_img = pg.transform.flip(img,True,False)
+ width,height = img.get_size()
def __init__(self, pos, offset, width,direction):
self.position = pg.Vector2(pos)
self.offset = pg.Vector2(offset)
self.holder_width = width
- def update(self, delta):
- pass
+ def update(self, delta, pos, direction):
+ self.position = pg.Vector2(pos)
+ self.direction = direction
+
+ 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 draw(self, surf):
- pass
+ if self.direction == -1:
+ surf.blit(self.img, self.get_collision_rect().topleft)
+ else:
+ surf.blit(self.flipped_img, self.get_collision_rect().topleft)