def __init__(self, scene, **kwargs): super().__init__() self.__dict__.update(kwargs) self.bg = ppb.Sprite( position=self.position, image=self.BAR_BG, size=1 / 4, layer=50, ) scene.add(self.bg) segments = [] for i in range(16): segment = ppb.Sprite( position=self.position + V(i / 4 - 2, 0), image=self.BAR_SEGMENT, color=self.color, size=1 / 4, layer=51, ) segments.append(segment) scene.add(segment) self.segments = tuple(segments) self.set_value(10)
def setup(scene): scene.background_color = (0, 0, 0) scene.add(ppb.RectangleSprite(width=0.5, height=1, image=tall_rectangle, position=(-2, 2))) scene.add(ppb.RectangleSprite(width=1, height=0.5, image=wide_rectangle, position=(0, 2))) scene.add(ppb.Sprite(size=1, image=square, position=(2, 2))) scene.add(ppb.RectangleSprite(width=0.5, height=1, image=tall_triangle, position=(-2, 0))) scene.add(ppb.RectangleSprite(width=1, height=0.5, image=wide_triangle, position=(0, 0))) scene.add(ppb.Sprite(image=square_triangle, position=(2, 0))) scene.add(ppb.RectangleSprite(width=0.5, height=1, image=tall_ellipse, position=(-2, -2))) scene.add(ppb.RectangleSprite(width=1, height=0.5, image=wide_ellipse, position=(0, -2))) scene.add(ppb.Sprite(image=circle, position=(2, -2)))
def on_scene_started(self, scene_started: ppb.events.SceneStarted, signal): images = [ *self.wall_images, *self.floor_images, self.blob_animation, *self.squares ] for (x, y), image in zip(product(range(-5, 6), range(-3, 4)), images): self.add(ppb.Sprite(image=image, position=ppb.Vector(x, y)))
def create_mushroom(self, cls, position, signal): # TODO: create different kinds mushroom = cls(position=position, layer=LAYER_GAMEPLAY_LOW) self.scene.add(mushroom, tags=['mushroom']) # TODO: Create meters through events CtrlMeter.create(self.scene, FRAMES_HEALTH, target=mushroom, attr='health', track=mushroom, color=COLOR['RED']) CtrlMeter.create(self.scene, FRAMES_HEALTH, target=mushroom, attr='toxins', track=mushroom, color=COLOR['DARKGREEN'], flip=SDL_FLIP_VERTICAL) signal(MeterUpdate(mushroom, 'health', 1.0)) mushroom.root = ppb.Sprite( image=ppb.Image("resources/root_1.png"), position=position - ppb.Vector(0, 0.5), size=6, layer=LAYER_GROUND_HIGHLIGHT, opacity=0, ) self.scene.add(mushroom.root) signal(MushroomPlaced(position, mushroom))
def on_scene_started(self, ev, signal): logo = ppb.Sprite( image=ppb.Image("resources/worldmap.png"), size=10, layer=1, ) ev.scene.add(logo) self.pins = [] for c in PIN_COORDS: pin = ppb.Sprite( image=ppb.Image("resources/worldmap_pin.png"), size=2, position=ppb.Vector(*c), tint=COLOR['RED'], layer=2, ) ev.scene.add(pin) self.pins.append(pin)
def on_scene_started(self, event, signal): for i, font in enumerate( ('B', 'BI', 'C', 'L', 'LI', 'M', 'MI', 'R', 'RI', 'Th')): self.add( ppb.Sprite( image=ppb.Text( "Hello, PPB!", font=ppb.Font( f"resources/ubuntu_font/Ubuntu-{font}.ttf", size=72), color=hsv2rgb(i / 10, 1.0, 75)), position=(0, i - 4.5), ))
def setup(scene): scene.background_color = (0, 0, 0) scene.add( ppb.RectangleSprite(width=0.5, height=1, image=ppb.Rectangle(200, 0, 0, (1, 2)), position=(-2, 2))) scene.add( ppb.RectangleSprite(width=1, height=0.5, image=ppb.Rectangle(100, 200, 0, (2, 1)), position=(0, 2))) scene.add( ppb.Sprite(size=1, image=ppb.Square(200, 200, 100), position=(2, 2))) scene.add( ppb.RectangleSprite(width=0.5, height=1, image=ppb.Triangle(0, 200, 0, (1, 2)), position=(-2, 0))) scene.add( ppb.RectangleSprite(width=1, height=0.5, image=ppb.Triangle(0, 200, 100, (2, 1)), position=(0, 0))) scene.add(ppb.Sprite(image=ppb.Triangle(50, 200, 150), position=(2, 0))) scene.add( ppb.RectangleSprite(width=0.5, height=1, image=ppb.Ellipse(0, 0, 200, (1, 2)), position=(-2, -2))) scene.add( ppb.RectangleSprite(width=1, height=0.5, image=ppb.Ellipse(100, 0, 200, (2, 1)), position=(0, -2))) scene.add(ppb.Sprite(image=ppb.Circle(150, 50, 200), position=(2, -2)))
def __init__(self, image_seq, target, attr, track, color=COLOR['WHITE'], flip=SDL_FLIP_NONE): self.meter_sprite = ppb.Sprite( image=image_seq.copy(), position=track.position, size=self.size, layer=LAYER_METER, tint=color, flip=flip, opacity=0, ) self.target = target self.attr = attr self.track = track self.tweener = Tweener() self.timer = None self.original_color = color
def setup(self, scene, signal): for y in range(-self.height // 2, -self.height // 2 + self.height): for x in range(-self.width // 2, -self.width // 2 + self.width): t = ppb.Sprite( image=random.choice(self.images), position=ppb.Vector(x, y), layer=self.layer, size=1.01, ) self.tiles[x, y] = t scene.add(t) # Load map objects, which can be: # - Decorative items on the map (tree strumps, rocks, etc.) # - Mushroom Spawn, marking the place the first mushroom spawns # - Exit, marking a spot on the map which ends the level when a mushroom is placed level = LevelData(scene.level) for cell in level.map_data.values(): if cell: try: if cell.code[1] == '*': keys = [ k for k in ITEMS.keys() if k[0] == cell.code[0] ] code = random.choice(keys) else: code = cell.code factory = ITEMS[code] except KeyError: print("Missing item key:", code) else: t = factory(cell.x, cell.y) if t: if t.mapitemtype == DECOR: scene.add(t, tags=[t.tag]) self.objects[cell.x, cell.y] = t elif t.mapitemtype == SOLID: scene.add(t, tags=[t.tag]) self.pathfinder.block((cell.x, cell.y)) elif t.mapitemtype == GROUND: self.tiles[cell.x, cell.y].image = t.image self.tiles[cell.x, cell.y].rect = t.rect self.tiles[cell.x, cell.y].size = t.size signal(LevelLoaded(scene.level, level))
def setup(scene): for x in range(-2, 3): for y in range(-2, 3): seed_class = choice(SEEDS) seed = seed_class(position=V(x, y)) scene.add(seed, tags=['seed']) GRID[x, y] = seed player = Player(position=POS_PLAYER) scene.add(player, tags=['player', 'character']) snake = Monster(position=POS_ENEMY) scene.add(snake, tags=['enemy', 'character']) scene.add(Grid(), tags=['grid', 'manager']) scene.add(ppb.Sprite( image=ppb.Image("resources/BACKGROUND.png"), size=12, layer=-1, ), tags=['bg'])
def create(cls, scene): ctrl = cls() ctrl.opt_texts = [] G = 32 ctrl.bg = ppb.Sprite( image=Square(G, G, G), size=0.0, layer=LAYER_HUD, opacity=225, ) scene.add(ctrl.bg) ctrl.txt_title = Text(ctrl.title, V(0, 2), layer=LAYER_HUD + 1, size=0.0) scene.add(ctrl.txt_title) for i, option in enumerate(ctrl.options, 1): txt_option = Text(option, V(0, -i), layer=LAYER_HUD + 1, size=0.0) scene.add(txt_option) ctrl.opt_texts.append(txt_option) scene.add(ctrl) return ctrl
def on_scene_started(self, ev, signal): logo = ppb.Sprite( image=ppb.Image("resources/logo.png"), size=10, ) ev.scene.add(logo)
def __init__(self, **props): super().__init__(**props) self.add(ppb.Sprite( image=ppb.Image('hellopursuedpybear/resources/hellopursuedpybear.png'), ))
def get_progress_sprites(self): for x in range(-2, 3): yield ppb.Sprite(position=ppb.Vector(x, 0))
def setup(scene): scene.add(ppb.Sprite(image=my_first_text)) scene.add(ppb.Sprite(image=my_second_text, position=ppb.Vector(0, -2)))
def __init__(self, **kwargs): super().__init__(**kwargs) self.add( ppb.Sprite(image=ppb.Image("butterfly_effect/resources/title.png"), size=2.5))