How to use the ppb.BaseScene function in ppb

To help you get started, we’ve selected a few ppb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pathunstrom / game-tutorial / fundamentals / samples / 1-main.py View on Github external
from ppb import GameEngine, BaseScene

with GameEngine(BaseScene) as engine:
    engine.run()
github pathunstrom / game-tutorial / shooter-tutorial / sample / main.py View on Github external
def simulate(self, time_delta):
        self.rect.centery += -10


class Enemy(BaseGameObject):
    image_path = "enemy.png"

    def __init__(self, scene, x_position):
        super().__init__(scene, (x_position, 0))

    def simulate(self, time_delta):
        self.rect.centery += 3


class Game(BaseScene):

    def __init__(self, engine, background_color=(90, 55, 100), **kwargs):
        super().__init__(engine=engine,
                         background_color=background_color,
                         **kwargs)
        Player(self)
        Bullet(self, (0, 0)).kill()
        self.spawner = Spawner(self, file_spawner("spawn.csv"), Enemy)

    def simulate(self, time_delta):
        super().simulate(time_delta)

        self.spawner.spawn(time_delta)

        player = self.groups[Player.group]
        bullets = self.groups[Bullet.group]
github pathunstrom / game-tutorial / hack-and-slash-tutorial / samples / 4-main.py View on Github external
from math import hypot
from os import path

from ppb import BaseScene
from ppb import GameEngine
from ppb import Vector
from pygame import image
from pygame import mouse
from pygame.sprite import DirtySprite


class Game(BaseScene):
    def __init__(self, engine, background_color=(0, 0, 0), **kwargs):
        super().__init__(engine=engine,
                         background_color=background_color,
                         **kwargs)
        Player(self, Vector(750, 750))


class Player(DirtySprite):

    def __init__(self, scene, target=None):
        super().__init__(scene.groups["player"])
        self.image = image.load(path.join(path.dirname(__file__),
                                          "player.png"))
        self.rect = self.image.get_rect()
        self.position = Vector(*self.rect.center)
        self.scene = scene
github pathunstrom / game-tutorial / fundamentals / samples / 3-main.py View on Github external
from os import path

from ppb import BaseScene, GameEngine
from pygame import image
from pygame.sprite import DirtySprite


class Game(BaseScene):
    def __init__(self, engine, background_color=(0, 0, 0), **kwargs):
        super().__init__(engine=engine,
                         background_color=background_color,
                         **kwargs)
        Player(self)


class Player(DirtySprite):

    def __init__(self, scene):
        super().__init__(scene.groups["player"])
        self.image = image.load(path.join(path.dirname(__file__),
                                          "player.png"))
        self.rect = self.image.get_rect()
        self.scene = scene
github pathunstrom / game-tutorial / shooter-tutorial / sample / 5-main.py View on Github external
class Bullet(DirtySprite):

    def __init__(self, scene, position):
        super().__init__(scene.groups["bullets"])
        b_image = image.load(path.join(path.dirname(__file__), "bullet.png"))
        self.image = b_image
        self.rect = self.image.get_rect()
        self.rect.midbottom = position
        self.scene = scene

    def update(self, time_delta):
        self.rect.centery += -10
        self.dirty = True


class Game(BaseScene):
    def __init__(self, engine, background_color=(0, 0, 0), **kwargs):
        super().__init__(engine=engine,
                         background_color=background_color,
                         **kwargs)
        Player(self)
        Bullet(self, (0, 0)).kill()


class Player(DirtySprite):

    def __init__(self, scene):
        super().__init__(scene.groups["player"])
        self.image = image.load(path.join(path.dirname(__file__),
                                          "player.png"))
        self.rect = self.image.get_rect()
        self.scene = scene
github pathunstrom / game-tutorial / hack-and-slash-tutorial / samples / 7-main.py View on Github external
class TargetABC(ABC):

    @property
    @abstractmethod
    def position(self) -> Vector:
        pass

    @abstractmethod
    def interact(self, player: 'Player'):
        logging.getLogger(type(self).__name__).debug(f"{type(self).__name__} reached!")


# Scenes

class Game(BaseScene):
    def __init__(self, engine, background_color=(0, 0, 0), **kwargs):
        super().__init__(engine=engine,
                         background_color=background_color,
                         **kwargs)

        chest = ClosedChest(self, Vector(750, 750))
        player = Player(self, chest)
        self.groups["terrain"].empty()

        self.controller = Controller(player, self.groups["interact"])

    def simulate(self, time_delta: float):
        self.controller.respond()
        super().simulate(time_delta)
github pathunstrom / game-tutorial / shooter-tutorial / sample / 7-main.py View on Github external
class Enemy(DirtySprite):
    def __init__(self, scene, x_position):
        super().__init__(scene.groups["enemy"])
        p_image = image.load(path.join(path.dirname(__file__), "enemy.png"))
        self.image = p_image
        self.rect = self.image.get_rect()
        self.rect.bottom = 0
        self.rect.centerx = x_position
        self.scene = scene

    def update(self, time_delta):
        self.rect.centery += 3
        self.dirty = True


class Game(BaseScene):
    def __init__(self, engine, background_color=(0, 0, 0), **kwargs):
        super().__init__(engine=engine,
                         background_color=background_color,
                         **kwargs)
        Player(self)
        Bullet(self, (0, 0)).kill()
        Enemy(self, 200)
        self.spawner = Spawner(self, simple_infinite_spawn(1.5, 200), Enemy)

    def simulate(self, time_delta):
        super().simulate(time_delta)
        self.spawner.spawn(time_delta)
        player = self.groups["player"]
        bullets = self.groups["bullets"]
        enemies = self.groups["enemy"]
        groupcollide(player, enemies, True, True)
github pathunstrom / game-tutorial / code_samples / 4.py View on Github external
from os import path

from ppb import BaseScene, GameEngine
from pygame import image
from pygame.sprite import DirtySprite

class Player(DirtySprite):

    def __init__(self, scene):
        super().__init__(scene.groups["player"])
        self.image = image.load(path.join(path.dirname(__file__),
                                          "player.png"))
        self.rect = self.image.get_rect()
        self.scene = scene

class Game(BaseScene):

  def __init__(self, engine, background_color=(90, 55, 100), **kwargs):
      super().__init__(engine=engine,
                       background_color=background_color,
                       **kwargs)
      Player(self)
github pathunstrom / game-tutorial / sample / scenes.py View on Github external
from ppb import BaseScene
from pygame.sprite import groupcollide

import sprites as sprites


def simple_enemies(time_step, x_val):
    time = time_step
    while True:
        yield time, x_val
        time += time_step


class Game(BaseScene):
    def __init__(self, engine, **kwargs):
        super().__init__(engine=engine,
                         background_color=(45, 30, 55),
                         **kwargs)
        self.play_area = engine.display.get_rect()
        self.run_time = 0
        self.spawn = simple_enemies(1.5, 200)
        self.next_spawn, self.next_x = next(self.spawn)
        _ = self.groups[sprites.Bullet.group]  # force setting the key.
        sprites.Player(self)

    def simulate(self, time_delta):
        self.run_time += time_delta
        while self.next_spawn <= self.run_time:
            sprites.Enemy(self, self.next_x)
            self.next_spawn, self.next_x = next(self.spawn)
github pathunstrom / game-tutorial / fundamentals / samples / 2-main.py View on Github external
from ppb import GameEngine, BaseScene


class Game(BaseScene):
    def __init__(self, engine, background_color=(0, 0, 0), **kwargs):
        super().__init__(engine=engine,
                         background_color=background_color,
                         **kwargs)


def main():
    with GameEngine(Game, resolution=(800, 800)) as engine:
        engine.run()

if __name__ == "__main__":
    main()

ppb

An Event Driven Python Game Engine

Artistic-2.0
Latest version published 11 months ago

Package Health Score

70 / 100
Full package analysis