Beispiel #1
0
def main():
  config = Config(
    FPS,
    WIN_WIDTH,
    WIN_HEIGHT
  )

  game = Game(config)

  game.sprite_manager.register([
    SpriteConfig('bg', os.path.join(local_dir, "assets/bg.png"), [pygame.transform.scale2x]),
    SpriteConfig('bird1', os.path.join(local_dir, "assets/bird1.png"), [pygame.transform.scale2x]),
    SpriteConfig('bird2', os.path.join(local_dir, "assets/bird2.png"), [pygame.transform.scale2x]),
    SpriteConfig('bird3', os.path.join(local_dir, "assets/bird3.png"), [pygame.transform.scale2x]),
    SpriteConfig('base', os.path.join(local_dir, "assets/base.png"), [pygame.transform.scale2x]),
    SpriteConfig('pipe', os.path.join(local_dir, "assets/pipe.png"), [pygame.transform.scale2x]),
  ])

  background = Background(game.sprite_manager.get('bg'))
  birds = [
    Bird(230, 350, game.sprite_manager.get('bird1')),
    Bird(130, 350, game.sprite_manager.get('bird1')),
  ]

  game.state.add([background] + birds)

  game.start()
from engine.game import Game, Scene
from engine.animation import AnimatedSprite


class TestScene(Scene):
    name = "test"

    def on_init(self):
        self.test_sprites = Group()

        spritemap = engine.loader.load("animsprite.png")
        rect = Rect(100, 100, 16, 16)
        test_sprite = AnimatedSprite(spritemap, rect, self.test_sprites)
        test_sprite.animate([0, 1, 2, 1], 5, True)

    def on_cleanup(self):
        pass

    def on_update(self, delta, events):
        self.test_sprites.update(delta)

    def on_render(self, screen):
        self.test_sprites.draw(screen)


if __name__ == "__main__":
    game = Game(640, 480)
    pygame.display.set_caption("Animation Test")
    game.add_scene(TestScene)
    game.start()