jump_buffer = []
variable_jump_time = timedelta(milliseconds=125) # how long to hold jump so we go higher
terminal_velocity = 15
+ invincibility_time = 150
def __init__(self, pos, collision_layer, collision_mask):
self.position = pg.Vector2(pos)
self.coyote_time = datetime.utcnow()
self.hold_jump = datetime.utcnow()
self.stun_time = 0
+ self.attacked = False
+ self.invincibility_frames = 0
def update(self, delta):
if self.jumping:
self.stun_time -= delta
self.stun_time = max(self.stun_time, 0)
+ self.invincibility_frames -= delta
+ self.invincibility_frames = max(self.invincibility_frames, 0)
+ if self.invincibility_frames == 0:
+ self.attacked = False
for area in self.areas.values():
area.update(delta, self.position)
def attack(self, enemy, weapon):
self.modify_health(weapon.damage, "enemy")
self.push(enemy)
+ self.attacked = True
+ self.invincibility_frames = self.invincibility_time
def follow_target(self, node, follow_range=None, stop_dist=None):
if stop_dist is None:
class Enemy(Actor):
width, height = 50, 100
+ speed = Actor.speed * 0.5
+ jump_strength = Actor.jump_strength * 0.5
colour = (235, 64, 52)
- speed = 0.2
- jump_strength = 0.75
- gravity = 0.098
- friction = 0.9
def __init__(self, pos, collision_layer, collision_mask):
self.movable = True
self.dizzy_time = 0
- self.health = 0 # for debugging without getting killed
+ # self.health = 0 # for debugging without getting killed
self.weapon = Melee(self.position, (-Melee.width/2 + 7, Melee.height/2 + self.height/3 - 8), (-5,Melee.height), self.width,-1, -10)
+
def update(self, delta, target=None):
super().update(delta)
if target is not None and self.dizzy_time == 0:
jump_strength = 1
gravity = 0.098
friction = 0.9
+ invincibility_time = 150
def __init__(self, pos, vel, width, height, colour, collision_layer, collision_mask):
self.position = pg.Vector2(pos)
self.dead = False
self.movable =True
+ self.attacked = False
+ self.invincibility_frames = 0
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
def update(self, delta, test=None):
+ self.invincibility_frames -= delta
+ self.invincibility_frames = max(self.invincibility_frames, 0)
+ if self.invincibility_frames == 0:
+ self.attacked = False
# Apply friction so the enemy isn't walking on ice
if self.on_ground:
self.velocity.x *= self.friction
# print(self.position)
def attack(self, enemy, weapon):
self.push(enemy)
+ self.attacked = True
+ self.invincibility_frames = self.invincibility_time
+
def push(self, enemy):
v = enemy.weapon.direction
# if enemy.velocity.x != pg.Vector2(0,0):
from Actors import Actor
from datetime import datetime, timedelta
from Potion import Potion
-from Weapon import Melee
+from Weapon import Sword
class Player(Actor):
for i in range(self.starting_potions):
self.potion_bag.append(Potion(self)) # use one liner
- self.weapon = Melee(self.position, (-Melee.width / 2 + 7, Melee.height / 2 + self.height / 3 - 8),
- (-5, Melee.height), self.width, -1, -25)
+ self.weapon = Sword(self.position, (0,0), self.width, -1)
self.targets = can_hurt
self.direction = -1
# else:
# self.direction = math.copysign(1, self.velocity.x)
self.direction = math.copysign(1, pg.mouse.get_pos()[0] - get_display_point(self.position).x)
- self.weapon.update(delta, self.position, -self.direction)
+ self.weapon.update(delta, self.position, self.direction)
if self.state == "IDLE":
self.display_offsets["player"] = pg.Vector2(0,0)
mouse_pressed = pg.mouse.get_pressed(3)
if mouse_pressed[0]: # LMB
- if not self.weapon.attacking:
- self.weapon.swing()
+ if self.state != "ATTACK":
self.state = "ATTACK"
self.current_frame = 0
- for mask in self.targets:
- for enemy in mask:
- if self.weapon.get_collision_rect().colliderect(enemy.get_collision_rect()):
- enemy.attack(self, self.weapon)
+ elif self.state == "ATTACK":
+ if math.floor(self.current_frame) > 2:
+ for mask in self.targets:
+ for enemy in mask:
+ if not enemy.attacked and self.weapon.get_collision_rect().colliderect(enemy.get_collision_rect()):
+ enemy.attack(self, self.weapon)
def draw(self, surf):
# super().draw(surf)
# print(self.position, self.velocity, get_display_rect(self.get_collision_rect()).topleft, Setup.camera_offset)
# pg.draw.rect(surf, self.colour, get_display_rect(self.get_collision_rect()), border_radius=8)
-
+ pg.draw.rect(surf, (255,0,0),get_display_rect(self.weapon.get_collision_rect()),width=3)
# pg.draw.rect(surf,self.colour,pg.Rect(center, (self.width, self.height)),border_radius=8)
# pg.draw.circle(surf,(0,255,0),get_display_point(self.position),3)
+
class Sword:
- img = pg.transform.scale(pg.image.load("Assets/SWORD.png"), (40, 40))
+ img = pg.transform.scale(pg.image.load("Assets/SWORD.png"), (50, 50))
+ img,_ = rotate(pg.Vector2(img.get_rect().topright),img, -30,pg.Vector2(img.get_rect().bottomleft))
flipped_img = pg.transform.flip(img,True,False)
- width,height = img.get_size()
+ width,height = (75,200)
+ damage = 25
- def __init__(self, pos, offset, pivot, width,direction, damage):
+ def __init__(self, pos, offset, width,direction):
self.position = pg.Vector2(pos)
self.offset = pg.Vector2(offset)
- self.pivot = self.position + pg.Vector2(pivot)
self.holder_width = width
-
self.direction = direction
-
self.display = self.img
self.display_rect = self.display.get_rect()
- self.swing_timer = 0
- self.attacking = False
-
- self.damage = damage
def update(self, delta, pos, direction):
self.position = pg.Vector2(pos)
- self.pivot = self.position + self.offset + pg.Vector2(self.width/2, self.height/2)
if direction != 0:
self.direction = direction
- if self.direction == -1:
- angle = 25 * (math.sin(math.radians(self.swing_timer)))
- self.display, self.display_rect = rotate(self.position + self.offset, self.img, angle,self.pivot)
- elif self.direction == 1:
- angle = -25 * (math.sin(math.radians(self.swing_timer)))
- self.display, self.display_rect = rotate(self.position+ pg.Vector2(self.holder_width,0) + pg.Vector2(-self.offset.x, self.offset.y), self.flipped_img, angle,self.pivot + pg.Vector2(self.holder_width,0))
-
- 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:
- return pg.Rect(self.display_rect.topleft,(self.width, self.height))
- elif self.direction == 1:
- return pg.Rect(self.display_rect.topleft,(self.width, self.height))
+ if self.direction == 1:
+ return pg.Rect(self.position + self.offset + pg.Vector2(self.holder_width,-self.height/4),(self.width, self.height))
+ elif self.direction == -1:
+ return pg.Rect(self.position - self.offset - pg.Vector2(self.width,self.height/4),(self.width, self.height))
- def swing(self):
- if True:
- if self.swing_timer == 0:
- self.swing_timer = 360
def draw(self, surf, display_offset = pg.Vector2(0,0)):
surf.blit(self.display, get_display_rect(self.get_collision_rect()).topleft + display_offset)
- # pg.draw.circle(surf,(255,0,255),get_display_point(self.pivot),3)
- # pg.draw.circle(surf,(0,255,0),get_display_point(self.position),3)