Beispiel #1
0
 def take_damage(self, damage: float) -> float:
     actual_damage = damage * self.damage_modifier
     self.health -= actual_damage
     self.update_health_bar()
     if self.health <= 0:
         system.get_window().current_interface.enemy.attack_pattern.stop()
         system.get_window().load_interface(
             interfaces.game_over_interface.GameOverInterface())
     return actual_damage
Beispiel #2
0
    def generate_enemy(self, dt):
        enemy_index = config.get_config('enemy')
        if enemy_index > len(enemies) - 1:
            return system.get_window().load_interface(WinInterface())

        window = system.get_window()
        self.enemy = enemies[enemy_index](self.batch, speed=100)
        self.enemy.move(window.width * 0.8, window.height / 2)
        self.enemy.next_x, self.enemy.next_y = self.enemy.x, self.enemy.y

        def on_die():
            config.set_config('enemy', config.get_config('enemy') + 1)
            clock.schedule_once(self.generate_enemy, 2)

        self.enemy.on_die = on_die
Beispiel #3
0
    def generate(self):
        window: Window = system.get_window()
        player = system.get_player()
        max_range = min(window.width // 2, window.height // 2)
        diameter = randint(300, max_range)
        degrees = randint(0, 359)
        for i in range(self.projectile_per_attack):
            theta = radians(degrees) + (
                (2 * pi) / self.projectile_per_attack) * i
            x = player.x + cos(theta) * diameter
            y = player.y + sin(theta) * diameter
            projectile = Projectile(
                src=join('images', 'staryu.png'),
                x=x,
                y=y,
                damage=self.base_damage,
                speed=self.base_speed,
                acceleration=self.base_acceleration,
                batch=self.batch,
            )
            projectile.point(player.x, player.y)
            self.set_movement(projectile, diameter)

            self.projectiles.append(projectile)
        sword_sharpen.play()
Beispiel #4
0
 def generate(self):
     if not self.running:
         return
     window = system.get_window()
     interface = window.current_interface
     projectiles = randint(0, self.projectile_per_attack)
     for i in range(projectiles):
         # Generate projectiles right above the player
         x = randint(int(interface.border.x),
                     int(interface.border.x + interface.border.width))
         y = window.height - 100
         projectile = Projectile(src=join('images', 'meteor_sequence.png'),
                                 x=x,
                                 y=y,
                                 damage=self.base_damage,
                                 speed=self.base_speed,
                                 acceleration=self.base_acceleration,
                                 batch=self.batch,
                                 animated=True,
                                 animation_rows=1,
                                 animation_columns=4,
                                 animation_item_width=202,
                                 animation_item_height=103,
                                 animation_main_frame=0,
                                 animation_period=.25)
         # Rotate it so it points right below
         projectile.rotate(3 * pi / 2)
         self.projectiles.append(projectile)
Beispiel #5
0
 def resize(self):
     window = system.get_window()
     self.title_label.x = window.width / 2
     self.title_label.y = window.height - self.title_label.content_height / 2
     self.main_container.width = window.width
     self.main_container.height = window.height - self.title_label.height
     self.main_container.x = window.width / 2
     self.main_container.y = window.height - self.title_label.content_height
     self.main_container.render()
Beispiel #6
0
 def __init__(self):
     window = system.get_window()
     self.title_label = Label('Headshot', font_name=press_start_2p, font_size=36)
     self.title_label.anchor_x = 'center'
     self.title_label.anchor_y = 'center'
     self.main_menu = MainMenu()
     self.resize()
     window.on_key_press = self.main_menu.on_key_press
     self.main_menu.focused = True
Beispiel #7
0
 def __init__(self):
     # print('Menu items:', Menu.items)
     self.config_menu = ConfigMenu(x=self.get_window().width / 4,
                                   y=self.get_window().height / 2)
     self.config_menu.focused = True
     window = system.get_window()
     for widget in self.config_menu.config_stack:
         if isinstance(widget, EventWidget):
             window.push_handlers(widget)
     window.on_key_press = self.config_menu.on_key_press
Beispiel #8
0
 def __init__(self):
     self.game_over_label = Label('GAME OVER',
                                  font_name=press_start_2p,
                                  font_size=48)
     self.game_over_label.anchor_x = 'center'
     self.game_over_label.anchor_y = 'center'
     self.game_over_menu = menus.game_over_menu.GameOverMenu()
     self.resize()
     window = system.get_window()
     window.on_key_press = self.game_over_menu.on_key_press
     self.game_over_menu.focused = True
     explosion.play()
Beispiel #9
0
 def change_position(self, dt):
     if not self.running:
         return
     x = randint(-1, 1) * self.calculate_speed()
     y = randint(-1, 1) * self.calculate_speed()
     window = system.get_window()
     # If the enemy would move too far left or right, make it move the other way
     if self.x + x > window.width or self.x + x < window.width / 2:
         x = -x
     if self.y + y > window.height or self.y + y < window.height / 3:
         y = -y
     self.next_x = self.x + x
     self.next_y = self.y + y
Beispiel #10
0
    def generate_powerup(self, dt):
        window = system.get_window()
        # roll = random.randint(1, 10)
        roll = 1
        if roll <= 3:  # 30% chance of getting a powerup
            powerup = random.choice(powerups)(batch=self.batch)
            x = random.randint(int(self.border.x), int(self.border.x + self.border.width))
            powerup.move(x=x, y=window.height)

            @powerup.movement
            def movement():
                powerup.move(powerup.x, powerup.y - powerup.calculate_speed())

            self.powerup = powerup
Beispiel #11
0
    def forward(self):
        if not self.running:
            return
        if self._forward:
            return self._forward()
        else:
            # This allows for boomerang movement, don't remove yet
            # multiplier = (time_delta * self.acceleration - self.speed or self.speed)

            multiplier = self.calculate_speed()
            x = cos(self.radians) * multiplier
            y = sin(self.radians) * multiplier
            self.move(self.x + x, self.y + y)
        self.counter += 1
        window = system.get_window()
        if not (0 < self.x < window.width and 0 < self.y < window.height):
            self.delete()
Beispiel #12
0
 def generate(self):
     window: Window = system.get_window()
     for i in range(self.projectile_per_attack):
         # Generate a projectile anywhere on the right side of the window
         x = randint(window.width // 2, window.width)
         y = randint(window.height // 2, window.height)
         projectile = Projectile(src=join('images', 'bonus-11.png'),
                                 x=x,
                                 y=y,
                                 damage=self.base_damage,
                                 speed=self.base_speed,
                                 acceleration=self.base_acceleration,
                                 batch=self.batch)
         player = system.get_player()
         projectile_generate_one.play()
         if player:
             projectile.point(player.x, player.y)
             self.projectiles.append(projectile)
Beispiel #13
0
    def animate_background(self):
        big_planet_sprite_depth = 3
        far_planet_sprite_depth = 10
        ring_planet_sprite_depth = 5
        stars_sprite_depth = 8

        window = system.get_window()
        self.big_planet_sprite.x = self.big_planet_sprite.x - 1 * (1 / big_planet_sprite_depth)
        if self.big_planet_sprite.x + self.big_planet_sprite.width <= 0:
            self.big_planet_sprite.x = window.width
        self.far_planet_sprite.x = self.far_planet_sprite.x - 1 * (1 / far_planet_sprite_depth)
        if self.far_planet_sprite.x + self.far_planet_sprite.width <= 0:
            self.far_planet_sprite.x = window.width
        self.ring_planet_sprite.x = self.ring_planet_sprite.x - 1 * (1 / ring_planet_sprite_depth)
        if self.ring_planet_sprite.x + self.ring_planet_sprite.width <= 0:
            self.ring_planet_sprite.x = window.width
        self.stars_sprite.x = self.stars_sprite.x - 1 * (1 / stars_sprite_depth)
        if self.stars_sprite.x + self.stars_sprite.width <= 0:
            self.stars_sprite.x = window.width
Beispiel #14
0
    def resize(self):
        window = system.get_window()
        scale = window.width / self.background.width
        self.background_sprite.scale = scale
        self.big_planet_sprite.scale = scale / 2
        self.far_planet_sprite.scale = scale / 2
        self.ring_planet_sprite.scale = scale / 2
        self.stars_sprite.scale = scale

        self.big_planet_sprite.x = window.width / 2
        self.big_planet_sprite.y = window.height / 2
        self.far_planet_sprite.x = window.width - self.far_planet_sprite.width
        self.far_planet_sprite.y = window.height - self.far_planet_sprite.height

        if self.image:
            self.image.x = (window.width - self.image.width) / 2
            self.image.y = (window.height - self.image.height) / 2
        self.border.x = window.width / 2 * 0.3
        self.border.y = (window.height - self.border.height) / 2

        self.generate_powerup(0)
        self.player.move(x=window.width / 2 * 0.3, y=window.height / 2)
Beispiel #15
0
 def __init__(self):
     self.game_over_label = Label('YOU WIN',
                                  font_name=press_start_2p,
                                  font_size=48)
     self.game_over_label.anchor_x = 'center'
     self.game_over_label.anchor_y = 'center'
     self.game_over_menu = menus.game_over_menu.GameOverMenu()
     self.game_over_menu.items.pop(0)
     self.game_over_menu.labels.pop(0)
     self.resize()
     window = system.get_window()
     window.on_key_press = self.game_over_menu.on_key_press
     self.game_over_menu.focused = True
     # media.load(
     #     join(
     #         'sound_FX',
     #         'freesound.org',
     #         'win.wav'
     #     ),
     #     streaming=False
     # ).play()
     audio.win_music.play()
Beispiel #16
0
    def __init__(self):
        super().__init__()
        window = system.get_window()
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
        base_path = os.path.join('images', 'space_background_pack', 'layers')

        self.background = load(os.path.join(base_path, 'parallax-space-background.png'))
        self.background_sprite = Sprite(self.background)
        big_planet = load(os.path.join(base_path, 'parallax-space-big-planet.png'))
        self.big_planet_sprite = Sprite(big_planet)
        far_planet = load(os.path.join(base_path, 'parallax-space-far-planets.png'))
        self.far_planet_sprite = Sprite(far_planet)
        ring_planet = load(os.path.join(base_path, 'parallax-space-ring-planet.png'))
        self.ring_planet_sprite = Sprite(ring_planet)
        self.ring_planet_sprite.x = 100
        self.ring_planet_sprite.y = 100
        stars = load(os.path.join(base_path, 'parallax-space-stars.png'))
        self.stars_sprite = Sprite(stars)
        self.scheduled_functions = (
            (self.randomize_projectiles, 2),
            (self.check_direction, 1 / 120),
            (self.generate_powerup, 20)
        )

        if config.get_config('control') == 1:
            self.face_cascade = cv.CascadeClassifier(
                'venv/Lib/site-packages/cv2/data/haarcascade_frontalface_default.xml')
            self.facecam = Facecam(face_cascade=self.face_cascade).start()
            self.aii = ArrayInterfaceImage(self.facecam.read(), 'BGR')
            self.image = self.aii.texture

            @self.facecam.event('on_face_move')
            def follow_face(x, y, width, height):
                # Need to flip things first to work
                x = self.image.width - x
                y = self.image.height - y
                new_x = self.border.x + x - width // 2
                new_y = self.border.y + y - height // 2
                self.player.move(new_x, new_y)

            self.scheduled_functions = (
                (self.randomize_projectiles, 2),
                (self.generate_powerup, 20),
            )

            window.push_handlers(self.facecam)

        self.player = Player(src='images/ufo.png')
        self.border = Rectangle(
            width=(500 if not self.image else self.image.width) + 10,
            height=(500 if not self.image else self.image.height) + 10,
            color=(0, 0, 0, 127)
        )
        self.player.scale = 1.2
        self.batch = Batch()
        self.projectiles: List[Projectile] = []
        window.push_handlers(self.keys)

        def pause_game(symbol, modifiers):
            if symbol == key.ESCAPE:
                self.enemy.running = not self.enemy.running
                self.enemy.attack_pattern.running = not self.enemy.attack_pattern.running
                self.player.running = not self.player.running

        window.on_key_press = pause_game

        for func, interval in self.scheduled_functions:
            clock.schedule_interval(func, interval)
        self.fps_display = FPSDisplay(window)
        self.generate_enemy(0)
        self.resize()
Beispiel #17
0
 def resize(self):
     window = system.get_window()
     self.main_menu.move(window.width / 2, 100)
     self.title_label.x = window.width / 2
     self.title_label.y = window.height / 2
Beispiel #18
0
 def resize(self):
     window = system.get_window()
     self.game_over_menu.move(window.width / 2, 100)
     self.game_over_label.x = window.width / 2
     self.game_over_label.y = window.height / 2