self.areas = dict()
self.movable = False
+ self.stun_time = 0
def update(self, delta):
+ self.stun_time -= delta
+ self.stun_time = max(self.stun_time, 0)
+
for area in self.areas.values():
area.update(delta, self.position)
def modify_health(self, amount, reason):
self.health += amount
+ if amount < 0:
+ self.stun_time = -amount * 50
self.is_dead(reason)
def follow_target(self, node, follow_range=None, stop_dist=None):
self.jump()
def jump(self):
- if self.on_ground:
- self.velocity.y = -self.jump_strength
+ if self.stun_time == 0:
+ if self.on_ground:
+ self.velocity.y = -self.jump_strength
def move_left(self, customSpeed = speed):
- self.velocity.x = -customSpeed
+ if self.stun_time == 0:
+ self.velocity.x = -customSpeed
def move_right(self, customSpeed = speed):
- self.velocity.x = customSpeed
+ if self.stun_time == 0:
+ self.velocity.x = customSpeed
+
+ def push(self, enemy):
+ v = pg.Vector2(0,0)
+ if enemy.velocity.x != v:
+ v = enemy.velocity.normalize().x
+
+ self.velocity += pg.Vector2(v, -1)
def move_and_collide(self, pos, vel, delta):
pos.x += vel.x * delta
[self.collision_layer["enemy"], self.collision_layer["world"]])
# self.pet = Pet(center, self.collision_layer["pet"], [self.collision_layer["world"]])
- self.enemies = [Enemy((SCREEN_WIDTH * 3 / 4, SCREEN_HEIGHT / 2), self.collision_layer["enemy"],
+ self.enemies = [Enemy((SCREEN_WIDTH / 4, SCREEN_HEIGHT / 2), self.collision_layer["enemy"],
[self.collision_layer["player"], self.collision_layer["world"]])]
self.blocks = [Block((0, SCREEN_HEIGHT * 3 / 4), self.collision_layer["world"])]
# Deals with collision and applying velocity
self.position, self.velocity = self.move_and_collide(self.position.copy(), self.velocity.copy(), delta)
- # print(self.velocity)
return self.position - self.initial_position
def attack(self, enemy, weapon):
self.modify_health(-10,"enemy")
+ self.push(enemy)
def draw(self, surf):
super().draw(surf)