Beispiel #1
0
    def on_key_press(self, symbol, modifiers):
        """ Called whenever a key is pressed. """
        # Shoot if the player hit the space bar and we aren't respawning.
        if not self.player_sprite.respawning and symbol == arcade.key.SPACE:
            bullet_sprite = BulletSprite("images/laserBlue01.png", SCALE)

            bullet_speed = 13
            bullet_sprite.change_y = \
                math.cos(math.radians(self.player_sprite.angle)) * bullet_speed
            bullet_sprite.change_x = \
                -math.sin(math.radians(self.player_sprite.angle)) \
                * bullet_speed

            bullet_sprite.center_x = self.player_sprite.center_x
            bullet_sprite.center_y = self.player_sprite.center_y
            bullet_sprite.update()

            self.all_sprites_list.append(bullet_sprite)
            self.bullet_list.append(bullet_sprite)

            arcade.play_sound(self.laser_sound)

        if symbol == arcade.key.LEFT:
            self.player_sprite.change_angle = 3
        elif symbol == arcade.key.RIGHT:
            self.player_sprite.change_angle = -3
        elif symbol == arcade.key.UP:
            self.player_sprite.thrust = 0.15
        elif symbol == arcade.key.DOWN:
            self.player_sprite.thrust = -.2
Beispiel #2
0
 def start_ball(self):
     # direction also affects speed
     self.direction_x = 1
     self.direction_y = 1
     self.speed = 7
     self.player_paddle.center_x = WIDTH - 10
     self.player_paddle.center_y = 50
     self.ball.center_x = 10
     self.ball.center_y = random.randint(10, HEIGHT - 10)
     #self.ball.center_y = 10
     print(f"starting ball at {self.ball.center_x},{self.ball.center_y}")
     arcade.play_sound(self.background_sound)
Beispiel #3
0
    def __init__(self, texture_list, sprite):
        super().__init__(texture_list[0].name, 0.7)

        # Start at the first frame
        self.current_texture = 0
        self.textures = texture_list
        self.timer = 0
        arcade.play_sound(sound_hit)

        # Set up the coordinates of the explosion
        self.center_x = sprite.center_x
        self.center_y = sprite.center_y
Beispiel #4
0
    def on_mouse_press(self, x, y, button, modifiers):
        if button == arcade.MOUSE_BUTTON_LEFT:
            arcade.play_sound(self.sword_sound)
            if len(self.melee_list) == 0:
                sword = melee.Sword()
                self.melee_list.append(
                    sword.attack(self.player, self._mouse_x, self._mouse_y))

        elif button == arcade.MOUSE_BUTTON_RIGHT:
            if self.player.ammo > 0:
                arrow = projectile.Arrow()
                self.charge_list.append(arrow)
Beispiel #5
0
 def mouse_motion(self, mouse_position: tuple):
     if self.hover_texture is not None:
         index = self.textures.index(self.hover_texture)
         if self.collides_with_point(mouse_position):
             if self.cur_texture_index != index:
                 ac.play_sound(self.window.musics["select"])
                 self.cur_texture_index = index
                 self.set_texture(index)
         else:
             if self.cur_texture_index != 0:
                 self.cur_texture_index = 0
                 self.set_texture(0)
Beispiel #6
0
 def on_key_press(self, key, modifiers):
     """Called whenever a key is pressed. """
     if key == arcade.key.UP or key == arcade.key.W or key == arcade.key.SPACE:
         if self.physics_engine.can_jump():
             self.player_sprite.change_y = PLAYER_JUMP_SPEED
             arcade.play_sound(self.jump_sound)
     if key == arcade.key.LEFT or key == arcade.key.A:
         self.left_pressed = True
     if key == arcade.key.RIGHT or key == arcade.key.D:
         self.right_pressed = True
     if key == arcade.key.V:
         self.complete_level()
 def setup_next_window(self, level):
     file = open(pathlib.Path.cwd() / "Stories" / f"{level}.txt")
     first_line = file.readline()
     first_line.rstrip("\n")
     window_visuals = first_line.split()
     scale = float(window_visuals[1])
     self.background = arcade.Sprite(pathlib.Path.cwd() / "Resources" / "Backgrounds" / f"{window_visuals[0]}.png",
                                     scale, center_x=600, center_y=400)
     self.story_box = arcade.Sprite(pathlib.Path.cwd() / "Resources" / "Images" / "Boxes" /
                                    f"{window_visuals[2]}_box.png", 3, center_x=600, center_y=500)
     sound = arcade.load_sound(pathlib.Path.cwd() / "Resources" / "Sounds" / "phone-ringing.wav")
     arcade.play_sound(sound)
Beispiel #8
0
 def drink_potion_on_collision(self):
     """Player drinks potion on collision with the item."""
     potion_list = arcade.check_for_collision_with_list(
         self, self.potion_list)
     for item in potion_list:
         if self.game_manager.curtime > item.force:
             arcade.play_sound(self.sound_mapping['gulp'])
             item.kill()
             if self.health <= 90:
                 self.health += 10
             else:
                 self.health += (100 - self.health)
Beispiel #9
0
 def on_key_press(self, key, modifiers):
     """ Called whenever the user presses a key. """
     if key == arcade.key.LEFT:
         self.emoji.change_x = -MOVEMENT_SPEED
     elif key == arcade.key.RIGHT:
         self.emoji.change_x = MOVEMENT_SPEED
     elif key == arcade.key.UP:
         self.emoji.change_y = MOVEMENT_SPEED
     elif key == arcade.key.DOWN:
         self.emoji.change_y = -MOVEMENT_SPEED
     if key == arcade.key.SPACE:
         arcade.play_sound(self.sonido_Laser)
Beispiel #10
0
 def on_key_press(self, key, modifiers):
     # User Control
     if key == arcade.key.LEFT:
         self.car.velocity[0] = -speed
     elif key == arcade.key.A:
         self.car.velocity[0] = -speed
     elif key == arcade.key.RIGHT:
         self.car.velocity[0] = speed
     elif key == arcade.key.D:
         self.car.velocity[0] = speed
     elif key == arcade.key.SPACE:
         arcade.play_sound(self.sound)
Beispiel #11
0
    def on_update(self, delta_time: float):
        self.physics_engine.update()

        coin_hit_list = arcade.check_for_collision_with_list(
            self.player, self.coin_list)
        for coin in coin_hit_list:
            coin.remove_from_sprite_lists()
            arcade.play_sound(self.collect_coin_sound)

        self.score = COIN_COUNT - len(self.coin_list)
        if self.score == COIN_COUNT:
            self.level_completed = True
Beispiel #12
0
    def __init__(self):
        super().__init__()

        random.seed()

        self.paddle_hit = arcade.Sound('sounds/paddle_hit.wav')
        self.score = arcade.Sound('sounds/score.wav')
        self.wall_hit = arcade.Sound('sounds/wall_hit.wav')
        arcade.play_sound(self.paddle_hit)
        # If you have sprite lists, you should create them here,
        # and set them to None
        self.gd  = None
    def collect(self, direction, radiate):
        for b in game.board_list:
            if (b is not self.board) ^ radiate:
                continue

            target_color = self.board.player.segments[direction].colour
            for segment in b.player.segments:
                if segment.colour == target_color:
                    segment.durability += self.quantity
                    break

        arcade.play_sound(gadgets)
Beispiel #14
0
    def on_update(self, dt):
        self.player_list.update()
        self.trooper_list.update()

        trooper_hit_list = arcade.check_for_collision_with_list(self.BB8, self.trooper_list)
        for trooper in trooper_hit_list:
            trooper.kill()  # order 67
            arcade.play_sound(self.BB8.laser_sound)
            self.score += 1

        if len(self.trooper_list) == 0:
            self.reset()
Beispiel #15
0
 def spawn_explosion(self, delta_time):
     self.bombs_to_spawn -= 1
     if self.bombs_to_spawn > 0:
         explosion = Explosion(self.explosion_texture_list)
         explosion.center_x = random.randrange(0, SCREEN_WIDTH)
         explosion.center_y = random.randrange(0, SCREEN_HEIGHT)
         explosion.update()
         self.explosion_list.append(explosion)
         arcade.play_sound(self.bomb_burst_sounds[random.randrange(8)],
                           volume=.005)
     else:
         arcade.unschedule(self.spawn_explosion)
Beispiel #16
0
def move(delta_time):
    global times
    global first
    global track
    times += 1
    for each in movers:
        thick = 3
        x = each[0]
        y = each[1]
        radius = each[2]
        if radius <= 20:
            thick = 2
        if times > 25 and times < 150:
            if first:
                time.sleep(15)
                first = False
            arcade.draw_circle_filled(x, y, radius, arcade.color.WHEAT)  # big circle body
            arcade.draw_circle_outline(x, y, radius, arcade.color.WHEAT, thick)  # outline
            arcade.draw_circle_filled(x, y, radius * (2 / 3), arcade.color.WHEAT)  # smaller circle in body
            arcade.draw_circle_outline(x, y, radius * (2 / 3), arcade.color.WHEAT, thick)  # outline
            arcade.draw_circle_filled(x, y, (radius * (2 / 3)) / 2, arcade.color.WHEAT)  # smallest circle in body
            arcade.draw_circle_outline(x, y, (radius * (2 / 3)) / 2, arcade.color.WHEAT, thick)  # outline
            arcade.draw_arc_filled(x, y + radius - (radius * .16666667), radius * 1.5, radius * 1.5, arcade.color.WHEAT,
                                   0, 180)
            arcade.draw_arc_outline(x, y + radius - (radius * .16666667), radius * 1.5, radius * 1.5,
                                    arcade.color.WHEAT, 0, 180, thick + 2)
            arcade.draw_line(x - radius * 1.5 / 2, y + radius * (5 / 6), x - radius * 1.5 * -1 / 2,
                             y + radius * (5 / 6), arcade.color.WHEAT, thick)
            arcade.draw_circle_filled(x, y + radius + (radius * .1966667), radius / 4.5, arcade.color.WHEAT)
            arcade.draw_circle_outline(x, y + radius + (radius * .1966667), radius / 4.5, arcade.color.WHEAT, thick)
            each[0] = random.randint(50, 550)
            each[1] = random.randint(50, 550)
            each[2] = radius
            draw_BB8(each[0], each[1], radius)
    print("times:", times)
    if times >= 150 and times <= 200:
        # arcade.play_sound(arcade.load_sound("alarm.mp3"))
        draw_BB8(random.randint(50, 550), random.randint(50, 550), random.randint(10, 60), True)
    elif times > 200 and times <= 320:
        track += 1
        if track == 20:
            print("track")
            arcade.stop_sound(arcade.load_sound("alarm.mp3"))
            arcade.play_sound(arcade.load_sound("alarm.mp3"))
            track = 0
        for i in range(25):
            draw_BB8(random.randint(50, 550), random.randint(50, 550), random.randint(10, 60), True)
    elif times > 320:
        arcade.stop_sound(arcade.load_sound("alarm.mp3"))
        for i in range(60):
            draw_BB8(random.randint(50, 550), random.randint(50, 550), random.randint(times-200, times-100), True)
            print("big")
Beispiel #17
0
    def on_key_press(self, key, modifiers):
        # Only allows bullets and movement if the user has not died or the objective is not completed
        if self.score < 20 and self.lives <= 3 and self.lives != 0:
            # Shoot missiles only if we have missiles
            if key == arcade.key.A and len(self.missile_list) < MISSILE_COUNT + self.new_missiles:
                if self.current_missiles <= 0:
                    return
                self.current_missiles -= 1
                # Play missile sound
                arcade.play_sound(self.missile_sound)
                # Create missile
                # Missile sprite from kenny.nl

                missile = Bullet("spaceMissiles_014.png", SPRITE_SCALING_MISSILE, 2)

                missile.angle = 270

                missile.change_x = MISSILE_SPEED

                missile.center_x = self.player_sprite.center_x + 5
                missile.bottom = self.player_sprite.top - 25

                self.missile_list.append(missile)

            if key == arcade.key.S:
                # Gunshot sound
                arcade.play_sound(self.gun_sound)
                # Create a laser
                # Laser sprite from Kenny.nl
                laser = arcade.Sprite("laserBlue03.png", SPRITE_SCALING_LASER)

                # The image points to the right, and we want it to point up. So
                # rotate it.
                laser.angle = 90

                # Give the bullet a speed
                laser.change_x = LASER_SPEED

                # Position the bullet
                laser.center_x = self.player_sprite.center_x
                laser.bottom = self.player_sprite.top - 25

                # Add the bullet to the appropriate lists
                self.laser_list.append(laser)

            if key == arcade.key.UP:
                if self.physics_engine.can_jump():
                    self.player_sprite.change_y = JUMP_HEIGHT
            elif key == arcade.key.LEFT:
                self.player_sprite.change_x = -MOVEMENT_SPEED
            elif key == arcade.key.RIGHT:
                self.player_sprite.change_x = MOVEMENT_SPEED
Beispiel #18
0
    def on_update(self, dt):
        self.player_list.update()
        self.trooper_list.update()

        trooper_hit_list = arcade.check_for_collision_with_list(
            self.BB8, self.trooper_list)
        for troop in trooper_hit_list:
            troop.kill()
            self.score += 1
            arcade.play_sound(self.BB8.laser)

        if len(self.trooper_list) < 1:
            self.reset()
Beispiel #19
0
    def jump(self, *, big_jump=False):
        """
        Make the player jump and handles his rotation.
        :param big_jump: bool, if true the jump will be 1.6 times more powerful (useful for jump-pads)
        """
        if big_jump:
            self.change_y = PLAYER_JUMP_SPEED * 1.6
        else:
            self.change_y = PLAYER_JUMP_SPEED

        self.angle -= self.ANGLE_CHANGE  # to kick-start update
        self.change_angle = -self.ANGLE_CHANGE
        arcade.play_sound(self.jump_sound)
    def __init__(self, game_view: arcade.View,
                 victory_sound: arcade.Sound) -> None:
        super().__init__()

        # Store a reference to the underlying view
        self.game_view = game_view

        # Play the victory sound
        arcade.play_sound(victory_sound)

        # Store a semi-transparent color to use as an overlay
        self.fill_color = arcade.make_transparent_color(arcade.color.WHITE,
                                                        transparency=150)
Beispiel #21
0
    def hit_target(self, target):
        """ 
        Initialize the "stuck in target" state 
        Copy the target's rotation speed and set the rotation radius and center
        """
        self.stucked_in_target = target

        arcade.play_sound(self.stucked_in_target.TARGET_HITTED_SOUND)
        self.target_hitted = True
        self.change_y = 0
        # self.rotation_speed = rotation_speed
        self.rotation_radius = (self.stucked_in_target.height / 2)
        self.rotation_center = self.stucked_in_target.TARGET_POSITION
Beispiel #22
0
 def on_key_press(self, key, modifiers):
     # Identify which arrow key was pressed
     # CASE 1: UP
     if key == arcade.key.UP or key == arcade.key.W:
         if self.physics_engine.can_jump():
             self.player_sprite.change_y = PLAYER_JUMP_SPEED
             arcade.play_sound(self.jump_sound)
     # CASE 2: LEFT
     elif key == arcade.key.LEFT or key == arcade.key.A:
         self.player_sprite.change_x = -PLAYER_MOVEMENT_SPEED
     # CASE 3: RIGHT
     elif key == arcade.key.RIGHT or key == arcade.key.D:
         self.player_sprite.change_x = PLAYER_MOVEMENT_SPEED
    def break_block(self, block: Block, sprites) -> None:
        arcade.play_sound(self._block_break_sound, 0.005)

        for adjacent_block in self._get_adjacent_blocks_to(block):
            if type(adjacent_block) != BLOCK.AIR and type(adjacent_block) != BLOCK.FLOOR and type(adjacent_block) != BLOCK.DRILLDOWN:
                self._add_block_to_lists(adjacent_block, sprites)

        block.remove_from_sprite_lists()
        x, y = block.x, block.y
        center_x, center_y = block.center_x, block.center_y
        new_air_block = BLOCK.AIR(x, y, center_x, center_y)
        self.blocks[x][y] = new_air_block
        self.air_blocks.append(new_air_block)
def play_sound(file_name: str):
    """Load and play a sound effect

    :param file_name: the name of the sound file saved in the same path as the python file or file path if not
    :return: none
    """

    # Load and play sound effect
    try:
        sound_effect = arcade.load_sound(file_name)
        arcade.play_sound(sound_effect)
    except:
        print("Unable to play sound.")
Beispiel #25
0
 def on_key_press(self, key, modifiers):
     """ Called whenever the user presses a key. """
     if key == arcade.key.LEFT:
         self.player_sprite.change_x = -MOVEMENT_SPEED
     elif key == arcade.key.RIGHT:
         self.player_sprite.change_x = MOVEMENT_SPEED
     elif key == arcade.key.SPACE:
         if self.physics_engine.can_jump():
             self.player_sprite.change_y = PLAYER_JUMP_SPEED
             arcade.play_sound(self.jump_sound)
     elif key == arcade.key.P:
         pause = PauseView(self)
         self.window.show_view(pause)
Beispiel #26
0
    def on_key_press(self, key, modifiers):
        """Called whenever a key is pressed. """

        if key == arcade.key.UP or key == arcade.key.W:
            if self.physics_engine.can_jump():
                self.player_sprite.change_y = PLAYER_JUMP_SPEED
                arcade.play_sound(self.jump_sound)
        elif key == arcade.key.DOWN or key == arcade.key.S:
            self.player_sprite.change_y = -PLAYER_MOVEMENT_SPEED
        elif key == arcade.key.LEFT or key == arcade.key.A:
            self.player_sprite.change_x = -PLAYER_MOVEMENT_SPEED
        elif key == arcade.key.RIGHT or key == arcade.key.D:
            self.player_sprite.change_x = PLAYER_MOVEMENT_SPEED
Beispiel #27
0
    def on_key_press(self, key, modifiers):
        """Called whenever a key is pressed. """

        if key == arcade.key.UP or key == arcade.key.W:
            self._y = constants.PLAYER_JUMP_SPEED
            arcade.play_sound(self.jump_sound)
        elif key == arcade.key.DOWN or key == arcade.key.S:
            self._y = 0
        elif key == arcade.key.LEFT or key == arcade.key.A:
            self._x = -constants.PLAYER_MOVEMENT_SPEED
            # arcade.play_sound(self.walking_sound)
        elif key == arcade.key.RIGHT or key == arcade.key.D:
            self._x = constants.PLAYER_MOVEMENT_SPEED
Beispiel #28
0
 def on_key_press(self, key, modifiers):
     ''' 
     '''
     if key == arcade.key.UP:
         if self.physics_engine.can_jump():
             self.player_sprite.change_y = PLAYER_JUMP_SPEED
             arcade.play_sound(self.jump_sound)
     elif key == arcade.key.DOWN:
         self.player_sprite.change_y = -PLAYER_MOVEMENT_SPEED
     elif key == arcade.key.LEFT:
         self.player_sprite.change_x = -PLAYER_MOVEMENT_SPEED
     elif key == arcade.key.RIGHT:
         self.player_sprite.change_x = PLAYER_MOVEMENT_SPEED
Beispiel #29
0
    def on_key_press(self, key, modifiers):
        """Called whenever a key is pressed. """
        # Only move the user if the game is running.
        if self.current_state == GAME_RUNNING:

            if key == arcade.key.UP or key == arcade.key.W:
                if self.physics_engine.can_jump():
                    self.player_sprite.change_y = PLAYER_JUMP_SPEED
                    arcade.play_sound(self.jump_sound)
            elif key == arcade.key.LEFT or key == arcade.key.A:
                self.player_sprite.change_x = -PLAYER_MOVEMENT_SPEED
            elif key == arcade.key.RIGHT or key == arcade.key.D:
                self.player_sprite.change_x = PLAYER_MOVEMENT_SPEED
Beispiel #30
0
 def on_key_press(self, key, modifiers):
     """Called whenever a key is pressed. """
     if key == arcade.key.UP or key == arcade.key.W:
         for player in self.player_sprite:
             player.change_y = PLAYER_JUMP_SPEED + 20 * random.random() - 5
         arcade.play_sound(self.jump_sound)
     elif key == arcade.key.F:
         self.window.set_fullscreen(not self.window.fullscreen)
         self.window.set_viewport(0, SCREEN_WIDTH, 0, SCREEN_HEIGHT)
     elif key == arcade.key.P:
         pause_view = PauseView(self)
         self.window.show_view(pause_view)
     '''
Beispiel #31
0
    def on_key_press(self, key, modifiers):
        """Called when the user releases a kay"""

        if key == arcade.key.UP or key == arcade.key.W or key == arcade.key.SPACE:
            if self.physics_engine.con_jump():
                self.player_sprite.change_y = PLAYER_MOVEMENT_SPEED
                arcade.play_sound(self.jump_sound)
        elif key == arcade.key.DOWN or key == arcade.key.S:
            self.player_sprite.change_y = PLAYER_MOVEMENT_SPEED
        elif key == arcade.key.LEFT or key == arcade.key.A:
            self.player_sprite.change_x = PLAYER_MOVEMENT_SPEED
        elif key == arcade.key.RIGHT or key == arcade.key.D:
            self.player_sprite.change_x = PLAYER_MOVEMENT_SPEED