def __init__(self): super().__init__() self.sprite = pygame.image.load("assets/loading_screen.png").convert() self.sprite.set_alpha(0) self.should_update = True self.handle_event = True timer = Timer(5, self.animate_part_1, repeat=True, how_many=102) self.add_timer(timer) self.finish = False
def __init__(self, ratio=1, color=(255, 255, 255, 255)): super().__init__() self.ratio = ratio self.color = color self.should_update = True # Constante de notre image... self.bar_rect = pygame.Rect(2, 2, 4 * 48 - 4, 24 - 4) self.add_timer(Timer(500, self.animation, True, infinite=True))
def __init__(self): super().__init__() self.map.add_actor(ActorBackgroundWin()) if StageManager().music_state: pygame.mixer.music.load(MUSIC_WIN) pygame.mixer.music.play() self.map.add_actor(ActorCredits()) self.alpha = 0 self.map.actors[1].sprite.set_alpha(self.alpha) self.add_timer(Timer(56, self.fade_in_image, True, 63))
def __init__(self): super().__init__() self.state = ActorBomb.State.DETONATE self.should_update = True self.damage = 1 #Ca fait quand même beaucoup!!! self.radius = 192 self.velocity = VECTOR_NULL self.fuse_timer = Timer(20, self.fuse, True, infinite=True) self.add_timer(self.fuse_timer) self.collidable = True
def reload(self): super().reload() self.handle_event = True self.should_update = True self.etre_vivant = True self.allowed_attack = False # Permet de ne pas tirer dès le début self.shoot_range = 500 self.shoot_rate = 1000 # Période des tirs : en ms self.detection_range = 1000 # Distance à laquelle il perçoit un ennemi self.jump_range = 700 self.jump_cd = 0 self.jump_cd_max = 400 self.jump_theta = 0 #angle définissant le jump self.jump_in = True self.jump_count = 0 self.jump_count_max = 30 self.jump_initial_pos = None self.jump_velocity = 12 #vitesse du saut self.theta = 0 self.ammo_max = 3 # Le nombre de balles self.ammo = self.ammo_max # Le nombre de balles max self.hp = 50 # vie su slime self.move_cd = 0 self.move_cd_max = 125 self.move_vect = None self.move_count = 0 self.move_count_max = 75 self.move_velocity = 2 self.collidable = True self.should_update = True self.velocity = Vector(0, 0) self.add_timer(Timer(2000, self.allow_attack))
def close(self): if self.is_open and self.timers == []: timer = Timer(200, self.close_animation, True, 2) self.add_timer(timer)
def open(self): if not self.is_open and self.timers == []: timer = Timer(200, self.open_animation, True, 2) self.add_timer(timer)
def reload_ammo(self): self.add_timer(Timer(2500, self.reload_ammo_callback))
def update(self): super().update() if self.state == ActorPlayer.State.ALIVE: # Le player peut jouer self.update_timers() self.walk = False self.direction = DIRECTION.NONE self.direction_walk = [] for value in self.keys_move.values(): if value[0]: self.direction = value[1] self.direction_walk.append(value[1]) self.walk = True self.shoot = False for value in self.keys_shoot.values(): if value[0]: self.direction = value[1] self.shoot = True break if self.walk: speed_x = 0 speed_y = 0 for direction in self.direction_walk: speed_x += direction.value.x speed_y += direction.value.y self.velocity.x = self.velocity_max * speed_x self.velocity.y = self.velocity_max * speed_y else: self.velocity.null() if self.velocity != VECTOR_NULL: self.has_moved = self.move(x=self.velocity.x, y=self.velocity.y) if not self.has_moved: self.velocity.null() if self.shoot and self.can_shoot: # Fait tirer le player if self.ammo > 0: # Si il reste des munitions #self.is_shooting = True #inutile: pas de projet de faire animation de tirs en cours self.can_shoot = False self.add_timer(Timer(self.shoot_rate, self.turn_on_shoot)) # On lance la flèche arrow = ActorArrowPlayer(self.direction, self.velocity) arrow.team = self.team arrow.rect.x = self.rect.x + (self.rect.w - arrow.rect.w) / 2 arrow.rect.y = self.rect.y + (self.rect.h - arrow.rect.w) / 2 self.map.add_actor(arrow) #réduit les munitions self.ammo -= 1 else: self.add_timer(Timer(1200, self.reload_ammo)) self.can_shoot = False # Pour BOMBER ! if self.keys_other[pygame.K_f][0]: if not self.bomb_pressed_and_released and self.bomb_ammo > 0: self.bomb() else: self.bomb_pressed_and_released = False if self.keys_other[pygame.K_SPACE][0]: if not self.charged: self.state = ActorPlayer.State.CHARGE elif self.state == ActorPlayer.State.CHARGED: for value in self.keys_shoot.values(): if value[0]: arrow = ActorArrowChargedPlayer(value[1], VECTOR_NULL) arrow.team = self.team arrow.rect.x = self.rect.x + (self.rect.w - arrow.rect.w) / 2 arrow.rect.y = self.rect.y + (self.rect.h - arrow.rect.w) / 2 self.map.add_actor(arrow) self.state = ActorPlayer.State.ALIVE self.can_shoot = False self.charged = False self.add_timer(Timer(self.shoot_rate, self.turn_on_shoot)) break
def animate_part_2(self, *args, **kwargs): self.add_timer( Timer(5, self.animate_part_3, repeat=True, infinite=True))
def animate_part_1(self, *args, **kwargs): self.sprite.set_alpha(self.sprite.get_alpha() + 5) if self.sprite.get_alpha() >= 255: self.timers.pop(0) self.add_timer(Timer(1500, self.animate_part_2, repeat=False))