self.jumping = False
self.coyote_time = datetime.utcnow()
self.hold_jump = datetime.utcnow()
- self.stun_time = 0
+ self.stun_time = 750
self.attacked = False
self.invincibility_frames = 0
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 and self.on_ground:
self.invincibility_frames = self.invincibility_time
def follow_target(self, node, follow_range=100000, stop_dist=115):
- return
# if stop_dist is None:
# stop_dist = max(self.height, self.width) * 1.5
self.move_left()
elif target.x > self.position.x:
self.move_right()
-
if not (target.y - node.height/2< self.position.y < target.y + node.height/2):
self.jump()
def jump(self):
- if self.stun_time == 0:
- pass
+ # print(self)
+ if self.stun_time > 0:
+ return
if (self.on_ground and not self.jumping) or (datetime.utcnow() - self.hold_jump <= self.variable_jump_time):
self.velocity.y = -self.jump_strength
if not self.jumping:
def dash_right(self):
pass
- def move_left(self, customSpeed=None):
- if customSpeed is None:
- customSpeed = self.speed
+ def move_left(self):
if self.stun_time == 0:
- self.velocity.x = -customSpeed
+ self.velocity.x = -self.speed
- def move_right(self, customSpeed=None):
- if customSpeed is None:
- customSpeed = self.speed
+ def move_right(self):
if self.stun_time == 0:
- self.velocity.x = customSpeed
+ self.velocity.x = self.speed
def push(self, direction, strength=1, y=-1):
self.velocity += pg.Vector2(direction * strength, y)
if thing == self:
continue
if collision_rect.colliderect(thing.get_collision_rect()):
+ # print(self, self.position.x, self.velocity.x)
# if thing.movable:
# if vel.x > 0:
# thing.position.x = pos.x + self.width
# thing.position.x = pos.x - thing.width
if vel.x > 0:
pos.x = thing.position.x - self.width
- # vel.x = min(vel.x, 0)
+ vel.x = min(vel.x, 0)
elif vel.x < 0:
pos.x = thing.position.x + thing.width
- # vel.x = max(vel.x, 0)
+ vel.x = max(vel.x, 0)
+ # print(pos.x, vel.x)
collision_rect = self.get_collision_rect(pos)
if datetime.utcnow() - self.coyote_time >= self.coyote_time_amount or self.jumping:
class Enemy(Actor):
- speed = Actor.speed * 0.5
- # jump_strength = Actor.jump_strength * 0.5
+ speed = Actor.speed * 0.33
+ jump_strength = Actor.jump_strength * 0.5
colour = (235, 64, 52)
friction = 0.9
-
+ run_gif = Image.open("Assets/skeleton/skeleton_run.gif")
+ run_frames = []
+ for i in range(run_gif.n_frames):
+ run_frames.append(pg.transform.scale(pil_to_game(get_gif_frame(run_gif, i)), (125, 125)))
def __init__(self, pos, collision_layer, collision_mask):
super().__init__(pos, collision_layer, collision_mask)
"head": Area(self.position, pg.Vector2(self.width * 1 / 3 * 1 / 2, -2), self.width * 2 / 3, 25, Player,
self.knockout)}
self.movable = False
- self.dizzy_time = 0
self.direction = -1
self.buffer = []
+ self.display_offsets = {"enemy":pg.Vector2(0,0)}
+
+ self.current_frame = 0
+ self.display = self.run_frames[math.floor(self.current_frame)]
+ self.state = "RUN"
+
def update(self, delta, target=None):
super().update(delta)
- if not self.attacked and target is not None and self.dizzy_time == 0:
+ if not self.attacked and target is not None and self.stun_time == 0:
+ # print('a')
self.follow_target(target)
- if random.random() < 2/fps and not self.weapon.attacking and self.weapon.get_collision_rect().colliderect(target.get_collision_rect()):
- target.attack(self, self.weapon, self.direction)
- print('attack')
- self.dizzy_time -= delta
- self.dizzy_time = max(0, self.dizzy_time)
+ # if random.random() < 2/fps and not self.weapon.attacking and self.weapon.get_collision_rect().colliderect(target.get_collision_rect()):
+ # target.attack(self, self.weapon, self.direction)
+ # print('attack')
# Deals with collision and applying velocity
self.position, self.velocity = self.move_and_collide(self.position.copy(), self.velocity.copy(), delta)
else:
self.direction = math.copysign(1, self.velocity.x)
self.weapon.update(delta, self.position, self.direction)
+
+ if self.state == "RUN":
+ frame = math.floor(self.current_frame)
+ if self.velocity.x > 0:
+ self.display = self.run_frames[math.floor(frame)]
+ self.display_offsets["enemy"] = pg.Vector2(-40, -35)
+ elif self.velocity.x <= 0:
+ self.display = pg.transform.flip(self.run_frames[math.floor(frame)], True, False)
+ self.display_offsets["enemy"] = pg.Vector2(-55, -35)
+
+ self.current_frame = (self.current_frame + 0.5) % self.run_gif.n_frames
+
# print(self.velocity)
def knockout(self, node):
- self.dizzy_time = 100
+ self.stun_time = 100
self.modify_health(-25, None)
node.on_ground = False
node.push(math.copysign(1, node.velocity.x), 0.25, -2.25)
def draw(self, surf):
self.weapon.draw(surf)
- super(Enemy, self).draw(surf)
+ # super(Enemy, self).draw(surf)
+ surf.blit(self.display, get_display_rect(self.get_collision_rect()).topleft + self.display_offsets["enemy"])
# for b in self.buffer:
- # pg.draw.rect(surf,(0,0,255),b,3)
- # self.buffer.append(get_display_rect(self.get_collision_rect()))
+ # pg.draw.rect(surf,(0,0,255),get_display_rect(b),3)
+ # self.buffer.append(self.get_collision_rect())
# pg.draw.rect(surf, (0, 255, 0), get_display_rect(self.get_collision_rect()), 2)
# screen.fill((0, 191, 255))
# screen.fill((255,255,255))
- sky = pg.image.load("Assets/world/SKY.png")
+ sky = pg.image.load("Assets/world/VOID.png")
surf.blit(sky,(0,0))
if (self.level == 1):
self.display = self.idle_frames[0]
self.display_offsets = {"weapon": pg.Vector2(0, 0), "player": pg.Vector2(0, 0)}
+ self.buffer = []
+
# def attack(self, enemy, weapon):
# super(Player, self).attack(enemy, weapon)
if len(self.potion_bag) > 0:
self.potion_bag[0].get_input(self)
- print(self.state, self.previous_state)
+ # print(self.state, self.previous_state)
# Deals with collision and applying velocity
self.position, self.velocity = self.move_and_collide(self.position.copy(), self.velocity.copy(), delta)
return self.position - center
def handle_input(self):
+ if self.stun_time > 0:
+ return
+
pressed = pygame.key.get_pressed()
if pressed[pg.K_w] or pressed[pg.K_UP] or pressed[pg.K_SPACE]:
get_display_rect(self.get_collision_rect()).topleft + pg.Vector2(0, 55) +
self.display_offsets["weapon"])
surf.blit(self.display, get_display_rect(self.get_collision_rect()).topleft + self.display_offsets["player"])
+ #
+ # for b in self.buffer:
+ # pg.draw.rect(surf,(0,0,255),get_display_rect(b),3)
+ # self.buffer.append(self.get_collision_rect())
+
# print(self, self.position)
# super().draw(surf)
# print(self.position, self.velocity, get_display_rect(self.get_collision_rect()).topleft, Setup.camera_offset)
# scene = TransitionScene()
scene = DevLevelSelect()
old_level = 0
-level = 0
+level = 5
next_level = 0
while is_running: