Exemple #1
0
def create():
    # game.set_cam('game')

    # Player
    game.add(Player(width / 3, height / 2))

    # Manager
    game.add(PipeManager())

    # Next entities will be over player and pipes
    game.add_layer('overlay', z=10)

    # Ground
    ground_height = 256
    game.add(
        Image(width / 2, ground_y - ground_height / 2,
              lg.Region('flappy', lg.Box(0, 1792, width, ground_height))))

    game.add_layer('background', z=-100)
    game.add(
        Image(width / 2, height / 2,
              lg.Region('flappy', lg.Box(1536, 1280, width, height))))
    # TODO : Parallax game.add(Image(width / 2, height / 2, lg.Region('flappy', lg.Box(1536, 1280, 512, 768))))

    game.add_layer('ui', z=100)
    game.add(ScoreManager())
Exemple #2
0
    def hitbox(self):
        '''
            We use a custom hitbox instead of rect to have a smaller region
        '''
        x = self.x - bird_width / 2
        y = self.y - bird_height / 2

        return lg.Box(x, y, bird_width, bird_height)
Exemple #3
0
def create():
    game.add(Play())

    game.add(Player(width / 2, height * 2 / 3, on_menu=True))

    # Background
    game.add_layer('background', z=-100)
    game.add(Image(width / 2, height / 2, lg.Region('flappy', lg.Box(1536, 1280, 512, 768))))
Exemple #4
0
    def __init__(self, x, y, speed):
        # The sprite is a texture region from the top left corner of the 'flappy' texture
        super().__init__(lg.Region('flappy', lg.Box(0, 0, width=256, height=128)))

        # Position of the sprite
        self.x = x
        self.y = y

        # Custom attribute, the speed in pixels per second
        self.speed = speed
Exemple #5
0
    def __init__(self):
        super().__init__(lg.Region('flappy', lg.Box(640, 128, 256, 128)))

        self.x = width / 2
        self.y = height / 3
    
        self.start_width, self.start_height = self.width, self.height

        self.scale = 1
        self.target_scale = self.scale
        self.anim_speed = .2
Exemple #6
0
    def spawn(self):
        '''
            Spawns a pair of pipe
        '''
        game.set_layer('main')
        x = width + pipe_width
        y = (height + ground_y) / 2 + randint(-pipe_range // 2, pipe_range // 2)

        # Top
        pipe_top = Image(x, y + pipe_height / 2 + pipe_gap_y / 2, lg.Region('flappy', lg.Box(512, 128, pipe_width, pipe_height)))
        pipe_top.rot = lg.pi
        game.add(pipe_top)
        self.pipes.append(pipe_top)

        # Bottom
        pipe_bottom = Image(x, y - pipe_height / 2 - pipe_gap_y / 2, lg.Region('flappy', lg.Box(512, 128, pipe_width, pipe_height)))
        game.add(pipe_bottom)
        self.pipes.append(pipe_bottom)

        # Score trigger
        trigger = Trigger(x)
        game.add(trigger)