from PhysicsBody import PhysicsBody
from Block import Block
+
class Actor:
width, height = 50, 100
colour = (76, 82, 92)
jump_strength = 1
gravity = 0.098
friction = 0.9
-
def __init__(self, pos, collision_layer, collision_mask):
self.position = pg.Vector2(pos)
self.velocity = pg.Vector2(0, 0)
self.on_ground = False
-
+
collision_layer.add(self) # the layer the actor is on for collisions
self.collision_layer = collision_layer
self.collision_mask = collision_mask # the layer the actor detects collisions against
self.movable = False
-
def update(self, delta):
for area in self.areas.values():
- area.update(delta,self.position)
+ area.update(delta, self.position)
if self.is_dead():
return
-
# Apply friction so the enemy isn't walking on ice
if self.on_ground:
- self.velocity.x *= self.friction
+ self.velocity.x *= self.friction
- # Apply gravity
+ # Apply gravity
self.velocity.y += self.gravity
- def is_dead(self,reason=None):
+ def is_dead(self, reason=None):
if self.health <= 0:
self.dead = True
-
- def modify_health(self,amount, reason):
+ def modify_health(self, amount, reason):
self.health += amount
self.is_dead(reason)
target = node.position
# So that actor doesn't come up and hug u lol
- if (self.position - target).length_squared() < pow(stop_dist,2):
+ if (self.position - target).length_squared() < pow(stop_dist, 2):
return
if target.x < self.position.x:
if thing == self:
continue
if collision_rect.colliderect(thing.get_collision_rect()):
- print(self, vel, thing.velocity)
if thing.movable:
if vel.x > 0:
thing.position.x = pos.x + self.width
self.on_ground = False
pos.y += vel.y * delta
collision_rect = self.get_collision_rect(pos)
- for mask in self.collision_mask:
+ for mask in self.collision_mask:
for thing in mask:
if thing == self:
continue
if pressed[pg.K_d] or pressed[pg.K_RIGHT]:
self.move_right()
+ def attack(self, enemy, weapon):
+ self.modify_health(-10,"enemy")
+
def draw(self, surf):
super().draw(surf)
# print(self.position, self.velocity, get_display_rect(self.get_collision_rect()).topleft, Setup.camera_offset)
self.display = self.img
self.display_rect = self.display.get_rect()
self.swing_timer = 0
+ self.attacking = False
def update(self, delta, pos, direction):
self.swing_timer -= delta
self.swing_timer = max(self.swing_timer, 0)
+ if self.swing_timer == 0:
+ self.attacking = False
+ else:
+ self.attacking = True
def get_collision_rect(self):
if self.direction == -1: