Esempio n. 1
0
    def __init__(self, **kwargs):
        super(Scene, self).__init__(**kwargs)
        self.events = EventAction()
        self.add_action(self.events)

        self.cols, self.rows = self.get_terminal_size()
        self.rows -= 1

        self.wall_left = MoveWall()
        self.wall_right = MoveWall()
        self.wall_right.x = self.cols - self.wall_right.width
        self.add_object(self.wall_left)
        self.add_object(self.wall_right)

        self.score = Score()
        self.add_object(self.score)

        self.music = Audio('songs/music.ogg')
        self.music.play(True)

        self.airplane = Airplane(self)
        self.add_object(self.airplane)
        self.add_action(Keyboard())
        self.add_action(MultipleMoveAction())

        self.add_object(LiveScore())

        self.enemy_generator = EnemyGenerator()
        self.add_action(self.enemy_generator)
Esempio n. 2
0
    def move(self):
        if time.time() - self.started < self.wait:
            return
        self.x = int(self.scene.cols / 2) - int(self.width / 2)
        y = int(self.scene.rows / 2) - int(self.height / 2)

        if y != self.y:
            self.y += 1
        elif self.blink:
            if self.blink == 2:
                music = Audio('songs/pygamii-blink.ogg')
                music.play()

            self.speed = 5
            if self.color == 'blue':
                self.color = 'yellow'
            else:
                self.color = 'blue'
            self.blink -= 1
            if self.blink == 0:
                self.wait = 2
                self.started = time.time()
        elif self.scene.presents.centered:
            Audio('songs/pygamii-out.ogg').play()
            self.print_list[self.cleaned] = ''
            self.to_render = '\n'.join(self.print_list)
            if self.cleaned < len(self.print_list) - 1:
                self.cleaned += 1
            else:
                self.scene.presents.is_kill = True
                self.is_kill = True
                self.scene.add_object(Logo())
Esempio n. 3
0
    def __init__(self, **kwargs):
        super(Scene, self).__init__(**kwargs)
        self.music = Audio('songs/infected_powerball.ogg')
        self.music.play()

        logo = Logo()
        self.add_object(logo)
        self.add_action(MoveAction(logo))
Esempio n. 4
0
def change_move_action(boss):
    if boss.move_method == 'go_down':
        boss.move_method = 'shooting'
        Audio('songs/before-shot.ogg').play()
        boss.color = 'red'
    elif boss.move_method == 'shooting':
        boss.move_method = 'go_up'
        Audio('songs/sonar.ogg').play()
        boss.color = 'red'
    else:
        boss.move_method = 'go_down'
        Audio('songs/sonar.ogg').play()
        boss.color = 'red'
Esempio n. 5
0
class Logo(ToRenderMixin, Object):
    to_render = '\n'.join([
        '·▄▄▄▄▄▌   ▄· ▄▌ ▄▄·       • ▌ ▄ ·. ▄▄▄▄·  ▄▄▄· ▄▄▄▄▄',
        '▐▄▄·██•  ▐█▪██▌▐█ ▌▪▪     ·██ ▐███▪▐█ ▀█▪▐█ ▀█ •██  ',
        '██▪ ██▪  ▐█▌▐█▪██ ▄▄ ▄█▀▄ ▐█ ▌▐▌▐█·▐█▀▀█▄▄█▀▀█  ▐█.▪',
        '██▌.▐█▌▐▌ ▐█▀·.▐███▌▐█▌.▐▌██ ██▌▐█▌██▄▪▐█▐█ ▪▐▌ ▐█▌·',
        '▀▀▀ .▀▀▀   ▀ • ·▀▀▀  ▀█▄▀▪▀▀  █▪▀▀▀·▀▀▀▀  ▀  ▀  ▀▀▀ ',
        '                                                    ',
        '              Press space to start                  '
    ])

    width = 55
    height = 6
    _moving = True
    red = True
    speed = 50
    y = -6
    color = 'green'
    enemy_started = False

    def on_create(self):
        self.music = Audio('songs/intro.ogg')
        self.music.play(True)
        self.scene.bg_color = 'blue'
        self.scene.change_color(self.color, self.bg_color)

    def on_destroy(self):
        self.music.stop()

    def move(self):
        self.scene.objects.remove(self)
        self.scene.objects.append(self)
        self.x = int(self.scene.cols / 2) - int(self.width / 2)
        y = int(self.scene.rows / 2) - int(self.height / 2)

        if self.y != y:
            self.y += 1
        else:
            if not self.enemy_started:
                self.scene.add_action(EnemyGenerator())
                self.enemy_started = True
            self.speed = 4
            if self.color == 'red':
                self.color = 'green'
            elif self.color == 'green':
                self.color = 'white'
            else:
                self.color = 'red'
Esempio n. 6
0
class Scene(BaseScene):
    def __init__(self, **kwargs):
        super(Scene, self).__init__(**kwargs)
        self.music = Audio('songs/infected_powerball.ogg')
        self.music.play()

        logo = Logo()
        self.add_object(logo)
        self.add_action(MoveAction(logo))

        help = HelpText()
        self.add_object(help)

        self.add_action(Keyboard())

    def stop(self):
        super(Scene, self).stop()
        self.music.stop()
Esempio n. 7
0
class Enemy(Object):
    is_kill = False
    kill_animation = False
    kill_steps = 5
    explosion_audio = Audio('songs/explosion.ogg')
    weapon = None
    _moving = True
    random_shot = 15
    points = 5

    def __init__(self, *args, **kwargs):
        super(Enemy, self).__init__(*args, **kwargs)
        self.gift_class = get_gift()
        if self.gift_class:
            self.color = self.gift_class.color

    def on_create(self):
        from weapon import BasicEnemyWeapon
        self.weapon = BasicEnemyWeapon(self.scene, self)

    def kill(self):
        if not self.kill_animation:
            self.scene.score.points += self.points
            self.explosion_audio.set_volume(0.25)
            self.explosion_audio.play()
            self.kill_animation = True
            self.speed = 10

    def is_live(self):
        return not self.is_kill and not self.kill_animation

    def move(self):
        if self.kill_animation:
            if self.kill_steps % 2:
                self.color = 'red'
            else:
                self.color = 'white'
            self.kill_steps -= 1
            if self.kill_steps == 0:
                self.is_kill = True
                if self.gift_class:
                    gift = self.gift_class()
                    gift.x = self.x
                    gift.y = self.y
                    self.scene.add_object(gift)
        else:
            distance = self.scene.airplane.y - self.y
            if random.randint(0, self.random_shot) == 7 and distance > 20:
                if self.weapon:
                    self.weapon.shot()

    def on_collision(self, obj):
        if not self.is_kill and not self.kill_animation:
            if self.scene.airplane is obj and obj.is_live():
                self.kill()
                obj.kill()
Esempio n. 8
0
class Scene(BaseScene):
    music = None

    def __init__(self, **kwargs):
        super(Scene, self).__init__(**kwargs)

        cursor = Cursor()

        self.music = Audio('songs/infected_powerball.ogg')
        self.music.play(True)

        ball = Ball()
        ball.set_cursor(cursor)

        self.add_action(Keyboard(cursor, ball))
        self.add_action(MoveAction(ball))

        self.add_object(cursor)
        self.add_object(ball)

        for i in range(0, int(80 / 5)):
            block = Block()
            block.set_resistence(3)
            block.x = 5 * i
            self.add_object(block)

        for i in range(0, int(80 / 5)):
            block = Block()
            block.set_resistence(2)
            block.x = 5 * i
            block.y = 1
            self.add_object(block)

        for i in range(0, int(80 / 5)):
            block = Block()
            block.set_resistence(1)
            block.x = 5 * i
            block.y = 2
            self.add_object(block)

    def stop(self):
        super(Scene, self).stop()
        self.music.stop()
Esempio n. 9
0
 def on_collision(self, obj):
     if isinstance(obj, AirPlaneBullet):
         if self.can_be_killed:
             self.shot_interval -= 2
             self.lives -= 1
             self.shots = 20 * 3 - self.lives
             self.can_be_killed = False
             self.height = 4
             if self.lives == 0:
                 self.scene.music.stop()
                 self.is_kill = True
                 self.scene.stop()
             else:
                 self.scene.events.trigger('boss_move_complete', self)
                 Audio('songs/explosion.ogg').play()
         obj.is_kill = True
Esempio n. 10
0
class PyGamii(ToRenderMixin, Object):
    print_list = [
        '██████╗ ██╗   ██╗ ██████╗  █████╗ ███╗   ███╗██╗██╗',
        '██╔══██╗╚██╗ ██╔╝██╔════╝ ██╔══██╗████╗ ████║╚═╝╚═╝',
        '██████╔╝ ╚████╔╝ ██║  ███╗███████║██╔████╔██║██╗██╗',
        '██╔═══╝   ╚██╔╝  ██║   ██║██╔══██║██║╚██╔╝██║██║██║',
        '██║        ██║   ╚██████╔╝██║  ██║██║ ╚═╝ ██║█╔╝█╔╝',
        '╚═╝        ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚═╝     ╚═╝╚╝ ╚╝ ',
    ]
    to_render = '\n'.join(print_list)
    width = 51
    height = 6
    color = 'blue'
    _moving = True
    y = -6
    speed = 20
    blink = 2
    cleaned = 0
    wait = 0.25
    started = None
    bg_music = Audio('songs/pygamii-bg.ogg')

    def on_create(self):
        music = Audio('songs/pygamii-open.ogg')
        music.play()
        self.started = time.time()
        self.bg_music.play(True)

    def on_destroy(self):
        self.bg_music.stop()

    def move(self):
        if time.time() - self.started < self.wait:
            return
        self.x = int(self.scene.cols / 2) - int(self.width / 2)
        y = int(self.scene.rows / 2) - int(self.height / 2)

        if y != self.y:
            self.y += 1
        elif self.blink:
            if self.blink == 2:
                music = Audio('songs/pygamii-blink.ogg')
                music.play()

            self.speed = 5
            if self.color == 'blue':
                self.color = 'yellow'
            else:
                self.color = 'blue'
            self.blink -= 1
            if self.blink == 0:
                self.wait = 2
                self.started = time.time()
        elif self.scene.presents.centered:
            Audio('songs/pygamii-out.ogg').play()
            self.print_list[self.cleaned] = ''
            self.to_render = '\n'.join(self.print_list)
            if self.cleaned < len(self.print_list) - 1:
                self.cleaned += 1
            else:
                self.scene.presents.is_kill = True
                self.is_kill = True
                self.scene.add_object(Logo())
Esempio n. 11
0
 def on_create(self):
     self.music = Audio('songs/intro.ogg')
     self.music.play(True)
     self.scene.bg_color = 'blue'
     self.scene.change_color(self.color, self.bg_color)
Esempio n. 12
0
 def on_create(self):
     Audio('songs/final-explosion.ogg').play()
Esempio n. 13
0
 def __init__(self, *args, **kwargs):
     self.song_collision = Audio('songs/pipe9.ogg')
     self.song_lose = Audio('songs/lose.ogg')
Esempio n. 14
0
class Ball(Object):
    color = 'cyan'
    y = 21
    x = 3
    char = 'o'
    started = False
    move_x = 1
    move_y = -1
    speed = 15.0
    lives = 3
    song_collision = None

    def __init__(self, *args, **kwargs):
        self.song_collision = Audio('songs/pipe9.ogg')
        self.song_lose = Audio('songs/lose.ogg')

    def set_cursor(self, cursor):
        self.cursor = cursor

    def in_move(self):
        return self.started

    def move(self):
        self.x += self.move_x
        self.y += self.move_y

        if self.y < 0:
            self.song_collision.play()
            self.y = 1
            self.move_y = 1

        if self.x >= self.scene.cols:
            self.song_collision.play()
            self.x = self.scene.cols - 1
            self.move_x = -1

        if self.x < 0:
            self.song_collision.play()
            self.x = 0
            self.move_x = 1

        if self.y >= 23:
            self.song_lose.play()
            self.lives -= 1
            if self.lives:
                self.x = self.cursor.x + int(self.cursor.width / 2)
                self.started = False
                self.y = 21
                self.move_y = -1
            else:
                self.scene.stop()

    def on_collision(self, obj):
        self.song_collision.play()
        if isinstance(obj, Cursor):
            self.move_y = -1
            self.y -= 2
        elif isinstance(obj, Block):
            self.move_y *= -1
            obj.dec_resistence()
            if obj.resistence == 0:
                self.scene.objects.remove(obj)
Esempio n. 15
0
 def on_create(self):
     music = Audio('songs/pygamii-open.ogg')
     music.play()
     self.started = time.time()
     self.bg_music.play(True)
Esempio n. 16
0
 def on_create(self):
     self.scene.music.stop()
     self.scene.music = Audio('songs/intro.ogg')
     self.scene.music.play(True)
Esempio n. 17
0
 def __init__(self, *args, **kwargs):
     super(Bullet, self).__init__(*args, **kwargs)
     music = Audio(self.music)
     music.set_volume(0.25)
     music.play()
Esempio n. 18
0
class Airplane(Object):
    height = 5
    width = 11
    color = 'green'
    lives = 3
    kill_animation = False
    kill_steps = 5
    kill_music = Audio('songs/lose.ogg')
    to_render = ''
    _moving = True
    speed = 5

    def __init__(self, scene):
        self.weapon = BasicWeapon(scene, self)
        self.y = scene.rows - self.height
        self.x = int((scene.cols - self.width) / 2)
        self.to_render = '\n'.join([
            ' ▄   █   ▄ ',
            '███████████',
            ' ▀   █   ▀ ',
            '     █     ',
            '   ▀▀▀▀▀   ',
        ])

    def __str__(self):
        return self.to_render

    def up(self):
        if self.y > 0:
            self.y -= 1

    def down(self):
        if self.y < self.scene.rows - self.height:
            self.y += 1

    def is_live(self):
        return not self.kill_animation and self.lives > 0

    def left(self):
        if self.x > 6:
            self.x -= 1

    def right(self):
        if self.x < self.scene.cols - self.width - 6:
            self.x += 1

    def kill(self):
        if not self.kill_animation:
            self.kill_steps = 5
            self.kill_animation = True
            self.lives -= 1
            self.kill_music.play()

            if self.lives <= 0:
                self.scene.stop()

    def move(self):
        if self.kill_animation:
            if self.kill_steps % 2:
                self.color = 'red'
            else:
                self.color = 'white'
            self.kill_steps -= 1
            if self.kill_steps == 0:
                self.color = 'green'
                self.kill_animation = False