Exemple #1
0
    def draw_enemy_tanks_remaining(self, game: Game, reset=False):
        if game.game_director.stage is None:
            return

        tank_icon_count = 0
        target_icon_count = game.game_director.stage.active_tanks
        for row in range(0, self.tank_icons.shape[0]):
            for col in range(0, self.tank_icons.shape[1]):
                tank_icon_count += 1
                if tank_icon_count <= target_icon_count:
                    if self.tank_icons[row, col] is None or reset:
                        tank_icon_sprite = Sprite(img=TextureManager.tank_icon,
                                                  x=game.game_map.map_data["pixel_width"]
                                                    + col * constants.UI_TANK_ICON_SIZE
                                                    + col * constants.UI_TANK_ICONS_GAP
                                                    + constants.UI_SIDE_PANEL_SIZE // 2
                                                    - constants.UI_TANK_ICONS_WIDTH // 2,
                                                  y=game.game_map.map_data["pixel_height"]
                                                    - (row * constants.UI_TANK_ICON_SIZE)
                                                    - constants.UI_TANK_ICON_SIZE
                                                    - constants.UI_TANK_ICONS_TOP_PAD,
                                                  batch=self.batch)
                        tank_icon_sprite.scale = 3
                        self.tank_icons[row, col] = tank_icon_sprite
                else:
                    if self.tank_icons[row, col] is not None:
                        self.tank_icons[row, col].delete()
                        self.tank_icons[row, col] = None
Exemple #2
0
    def seed_handler(self, engine, boundsRect):
        seed_config = self.seed_config
        bounds = (boundsRect.left, boundsRect.top, boundsRect.right,
                  boundsRect.bottom)
        cells = []
        seed_keys = list(seed_config.keys())
        shuffle(seed_keys)
        for key in seed_keys:
            cfg = seed_config[key]
            perlins = self.perlin.perlin_octave_array(bounds[0], bounds[1],
                                                      CHUNK_SIZE, CHUNK_SIZE,
                                                      cfg['freq'],
                                                      cfg['octaves'], 1.0, 16)
            for (oy, pees) in enumerate(perlins):
                for (ox, val) in enumerate(pees):
                    ix = bounds[0] + ox * 16
                    iy = bounds[1] + oy * 16
                    if val > cfg['threshold'] and (
                            cfg['rand_thresh'] == 0
                            or random() > cfg['rand_thresh']):
                        cells.append(
                            BlueprintCell(cfg['class'],
                                          (engine.textures, (ix, iy))))
        image_key = engine.textures.create_background(int(CHUNK_SIZE / 2),
                                                      int(bounds[0] / 2),
                                                      int(bounds[1] / 2))
        bg_sprite = Sprite(engine.textures[image_key], bounds[0], bounds[1])
        bg_sprite.scale = 2
        engine.world.set_bg(bg_sprite, bounds[0], bounds[1])

        return cells
Exemple #3
0
 def resize(self, width, height):
     self._element = list()
     for x in range(width // self._img.width * 2 + 1):
         for y in range(height // self._img.height * 2 + 1):
             sprite = Sprite(self._img, x=x * self._img.width, y = y * self._img.height)
             sprite.scale = 2
             self._element.append(sprite)
Exemple #4
0
 def sprites(self, image, x, y, scale=1.0):
     from pyglet.sprite import Sprite
     for i in range(len(x)):
         sprite = Sprite(image, batch=self._batch)
         sprite.x = x[i]
         sprite.y = y[i]
         sprite.scale = scale
         self._sprites.append(sprite)
Exemple #5
0
def players_lives(num_icons, batch=None):
    lives_left = []
    for idx in range(num_icons):
        new_sprite = Sprite(img=resources.get_image('engine_stop'),
                            x=785-idx*30, y=585, batch=batch)
        new_sprite.scale = 0.3
        lives_left.append(new_sprite)
    return lives_left
 def sprites(self, image, x, y, scale=1.0):
     from pyglet.sprite import Sprite
     for i in range(len(x)):
         sprite = Sprite(image, batch=self._batch, group=background)
         sprite.x = x[i]
         sprite.y = y[i]
         sprite.scale = scale
         self._sprites.append(sprite)
Exemple #7
0
 def __init__(self):
     width, height = get_size()
     HUD.__init__(self, width, height)
     self._status = []
     for i in range(9, -1, -1):
         sprite = Sprite(resource_pack.get_resource('textures/gui/icons').get_region(16, 220, 9, 9),
             x=(width - 364) / 2 + 364 - (i + 1) * 13.5, y=56)
         sprite.scale = 2
         self._status.append(sprite)
Exemple #8
0
 def _set_lives(self):
     for i in range(self._num_lives):
         img = copy(self._control_sys.ShipCls[self._color].img)
         img.anchor_x = 0
         img.anchor_y = 0
         life = Sprite(img)
         life.scale = 0.36
         self._lives.append(life)
         self._set_object(life, sep=3)
Exemple #9
0
    def background_2(self, dt):
	"""Random stars created in back moving faster"""
	fast_star = Sprite(images['star'], batch=self.fast_star_batch)

	fast_star.y = random.uniform(0, self.height)
	fast_star.x = self.width
	
	fast_star.scale = random.uniform(0.2, 2)

	self.fast_stars.append(fast_star)
Exemple #10
0
 def __init__(self):
     width, height = get_size()
     GUI.__init__(self, width, height)
     self._element = list()
     self._img = resource_pack.get_resource('textures/gui/options_background')
     for x in range(width // self._img.width * 2 + 1):
         for y in range(height // self._img.height * 2 + 1):
             sprite = Sprite(self._img, x=x * self._img.width, y = y * self._img.height)
             sprite.scale = 2
             self._element.append(sprite)
Exemple #11
0
 def render_pieces(self):
     # CLear the list of sprites
     self.piece_sprites = []
     # Iterate through all pieces on the board and couple a sprite with each piece
     for piece in self.board.pieces:
         x, y = self.rank_file_to_xy(piece.rank, piece.file)
         image = src.constants.get_image(piece)
         piece_sprite = Sprite(image, x=x, y=y, batch = self.pieces_batch)
         piece_sprite.scale = self.tile_width / image.width
         self.piece_sprites.append(piece_sprite)
Exemple #12
0
 def create_particle(
     self,
     x: float,
     y: float,
     scale: float,
     initial_texture: Texture,
     behaviors: T.List[ParticleBehavior],
 ):
     sprite = Sprite(initial_texture, x, y, batch=self.batch)
     sprite.scale = scale
     self.particles.add(Particle(sprite, behaviors))
Exemple #13
0
 def _add_nuclear_sprite(self, x, y):
     # Add radiation symbols to ---game_batch--- as sprites
     sprite = Sprite(self.nuclear_img,
                     x,
                     y,
                     batch=self.batch,
                     group=self.group)
     if sprite.width > self._field_width:
         sprite.scale = round(self._field_width / sprite.width, 1)
     self._nuclear_sprites.append(sprite)
     return sprite
Exemple #14
0
    def background_1(self, dt):
	"""create random number of stars at random y co ordinates"""
	#for star in self.star:
	star = Sprite(images['star'], batch=self.star_batch)
	
	star.y = random.uniform(0,self.width-2)
	star.x = self.width 

	star.scale = random.uniform(0.2, 2)
	
	self.stars.append(star) 
Exemple #15
0
 def player_icons(self, batch=None):
     self._life_icons = set()
     WIDTH = self.win_size[0]
     HEIGHT = self.win_size[1]
     for idx in range(self._num_lives):
         new_sprite = Sprite(img=resources.get_image('engine_stop'),
                             x=WIDTH - 15 - idx * 30, y=HEIGHT - 15, batch=batch)
         new_sprite.scale = 0.3
         new_sprite.rotation = -90
         self._life_icons.add(new_sprite)
     return self._life_icons
Exemple #16
0
 def draw(self, group):
     batch = Batch()
     ss = []
     for particle in group:
         s = Sprite(self.image, batch=batch)
         s.position = list(particle.position)[:2]
         s.color = [c * 255 for c in list(particle.color)[:3]]
         s.scale = particle.size[0] / 64.0
         s.rotation = particle.age * 720
         s.opacity = particle.color[3] * 255
         ss.append(s)
     batch.draw()
Exemple #17
0
 def __init__(self):
     width, height = get_size()
     HUD.__init__(self, width, height)
     self._status = []
     for i in range(9, -1, -1):
         sprite = Sprite(image.load(join(path['texture.gui'],
                                         'icons.png')).get_region(
                                             16, 220, 9, 9),
                         x=(width - 364) / 2 + 364 - (i + 1) * 13.5,
                         y=56)
         sprite.scale = 2
         self._status.append(sprite)
Exemple #18
0
    def update_stones(self):
        """Update the black and white stones on the game board.

            Attributes updated by this function:
                self.batch_stones
                self.stone_sprites
                self.image_black_stone
                self.image_white_stone
        """
        # Display the stones on the regular batch
        self.batch_stones = self.batch
        self.stone_sprites = []

        # Center black and white stones
        def center_image(image):
            """Sets an image's anchor point to its center"""
            image.anchor_x = image.width/2
            image.anchor_y = image.height/2
            
        center_image(self.image_black_stone)
        center_image(self.image_white_stone)

        # Place all stones on the grid

        # Scale stone images
        scaling = self.grid.field_width / self.image_black_stone.width

        # Limit max size of stones
        if scaling > MAX_STONE_SCALING:
            scaling = MAX_STONE_SCALING

        # Iterate trough all data stones and place the corresponding black or
        # white stone on the grid
        for i in range(0, self.data['size']):
            for j in range(0, self.data['size']):
                if self.data['stones'][j][i] != None:
                    # Get x and y grid coordinates
                    x_coord, y_coord = self.grid.get_coords(i, j)

                    # Get the stone color to place
                    stone_color = self.image_black_stone if self.data['stones'][j][i] == BLACK else None
                    stone_color = self.image_white_stone if self.data['stones'][j][i] == WHITE else stone_color

                    # Place the stone on the grid
                    if stone_color:
                        _s = Sprite(stone_color,
                                    batch=self.batch_stones,
                                    group=self.grp_stones,
                                    x=x_coord,
                                    y=y_coord)
                        _s.scale = scaling
                        self.stone_sprites.append(_s)   
Exemple #19
0
    def _draw_inventory_slot(self, x, y, img, render_batch, sprite_list):
        """Moves the Selection Indicator and draws it above a specific sprite"""
        x += INVENTORY_MARGIN / 2
        y += INVENTORY_MARGIN / 2
        sp = Sprite(img, x=x, y=y, group=self.hud_group, batch=render_batch)

        # todo, shouldn't this line be set on startup?
        gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER,
                           gl.GL_NEAREST)

        # Scaling Image to fit Preview Size
        sp.scale = PREVIEW_SIZE / 16
        sprite_list.append(sp)
Exemple #20
0
 def __init__(self):
     width, height = get_size()
     GUI.__init__(self, width, height)
     self._element = list()
     self._img = image.load(
         join(path['texture.gui'], 'options_background.png'))
     for x in range(width // self._img.width * 2 + 1):
         for y in range(height // self._img.height * 2 + 1):
             sprite = Sprite(self._img,
                             x=x * self._img.width,
                             y=y * self._img.height)
             sprite.scale = 2
             self._element.append(sprite)
Exemple #21
0
 def render_pawn_promotion(self):
     promoted_piece = self.board.get_promoting_piece()
     if promoted_piece is not None:
         self.pawn_promotion = []
         background = pyglet.graphics.OrderedGroup(0)
         foreground = pyglet.graphics.OrderedGroup(1)
         rank, file = promoted_piece.rank, promoted_piece.file
         x, y = self.rank_file_to_xy(rank, file)
         self.promotion_menu_pos = x, y
         # Draw the four possible piece promotions at 1/4 the scale of each piece
         queen_image = src.constants.get_image(Queen(0, 0, promoted_piece.color))
         queen = Sprite(queen_image, x=x, y=y, batch=self.pawn_promotion_batch, group=foreground)
         queen.scale = (0.5 * self.tile_width) / queen_image.width
         self.pawn_promotion.append(queen)
         rook_image = src.constants.get_image(Rook(0, 0, promoted_piece.color))
         rook = Sprite(rook_image, x=x + (0.5 * self.tile_width), y=y,
                       batch=self.pawn_promotion_batch, group=foreground)
         rook.scale = (0.5 * self.tile_width) / rook_image.width
         self.pawn_promotion.append(rook)
         knight_image = src.constants.get_image(Knight(0, 0, promoted_piece.color))
         knight = Sprite(knight_image, x=x, y=y + (0.5 * self.tile_width),
                         batch=self.pawn_promotion_batch, group=foreground)
         knight.scale = (0.5 * self.tile_width) / knight_image.width
         self.pawn_promotion.append(knight)
         bishop_image = src.constants.get_image(Bishop(0, 0, promoted_piece.color))
         bishop = Sprite(bishop_image, x=x + (0.5 * self.tile_width) , y=y + (0.5 * self.tile_width),
                         batch=self.pawn_promotion_batch, group=foreground)
         bishop.scale = (0.5 * self.tile_width) / bishop_image.width
         self.pawn_promotion.append(bishop)
         # Draw a grey box on the square as a background for the promotion menu
         rect = Rectangle(
             x=x, y=y,
             width=self.tile_width, height=self.tile_height,
             color=(127, 127, 127),
             batch=self.pawn_promotion_batch,
             group=background
         )
         self.pawn_promotion.append(rect)
Exemple #22
0
 def register_model(self, model, path, scale=1.0, zindex=1):
     """
     model: the model behind the image
     path: path to the image
     scale: scale of the image
     zindex: lower is drawn in the back higher in the front
     """
     # position of model is the position of the image
     x,y = model.body.position
     img = self._get_img(path)
     group = self._get_group(zindex)
     sprite = Sprite(img, x, y, group=group, batch=self._batch)
     sprite.scale = scale
     self._model2sprite[model] = sprite
Exemple #23
0
    def __init__(self, window, bus):
        super().__init__(window, bus, draw_waves=False, title='tabulr | Done')

        # Check mark
        check_img = image('check.png')
        check_img.anchor_x = check_img.width // 2
        check_img.anchor_y = check_img.height // 2
        check_sprite = Sprite(check_img,
                              x=self.window.width // 2,
                              y=self.window.height // 2 + 120,
                              batch=self.batch)
        check_sprite.scale = 0.5
        self.init_sprite('check', check_sprite, is_button=False)

        # Text
        self.title = Text('Done',
                          batch=self.batch,
                          size=22,
                          bold=True,
                          x=self.window.width // 2,
                          y=self.window.height // 3 + 72)
        self.subtitle = Text('Open the following file to save your wallpaper:',
                             batch=self.batch,
                             size=14,
                             x=self.window.width // 2,
                             y=self.window.height // 3 + 8)
        self.path = Text(abspath('htmlfile.html'),
                         batch=self.batch,
                         size=8,
                         bold=True,
                         x=self.window.width // 2,
                         y=self.window.height // 3 - 16)
        self.title.anchor_x = 'center'
        self.subtitle.anchor_x = 'center'
        self.path.anchor_x = 'center'

        # Restart button
        restart_button = Button('restart',
                                self.window,
                                self.batch,
                                x=self.window.width // 2,
                                y=self.margin)
        restart_button.x -= restart_button.width // 2
        self.init_sprite('restart_button', restart_button)
Exemple #24
0
 def __init__(self, overlay):
     super(HealthHandler, self).__init__()
     self.overlay = overlay
     self.batch = self.overlay.batch
     self.hidden = True
     self.heart = self.overlay.game.textures.sprites['heart']
     self.heart.anchor_x, self.heart.anchor_y, = self.heart.width // 2, self.heart.height // 2,
     self.half_heart = self.overlay.game.textures.sprites['half-heart']
     self.half_heart.anchor_x, self.half_heart.anchor_y, = self.half_heart.width // 2, self.half_heart.height // 2,
     scale = 0.2
     size = scale * 256
     offset = 10
     space = size * 5 + offset * 5
     start = self.overlay.width - space
     y = self.overlay.height - size * 0.8
     for _ in range(5):
         x = start + ((size + offset) * _)
         sprite = Sprite(self.heart, batch=self.batch, x=x, y=y)
         sprite.scale = scale
         sprite.visible = False
         self.append(sprite)
Exemple #25
0
    def draw_player_health(self, game: Game, reset=False):
        if game.game_director.stage is None:
            return

        tank_icon_count = 0
        target_icon_count = game.game_director.stage.active_player_lives
        for row in range(0, self.player_tank_icons.shape[0]):
            for col in range(0, self.player_tank_icons.shape[1]):
                tank_icon_count += 1
                if tank_icon_count <= target_icon_count:
                    if self.player_tank_icons[row, col] is None or reset:
                        tank_icon_sprite = Sprite(img=TextureManager.tank_player_1,
                                                  x=game.game_map.map_data["pixel_width"]
                                                    + constants.UI_SIDE_PANEL_SIZE // 2,
                                                  y=(row * constants.UI_PLAYER_ICON_SIZE)
                                                    + row * constants.UI_TANK_ICONS_GAP*0.5
                                                    + constants.UI_TANK_ICONS_TOP_PAD * 1.5,
                                                  batch=self.batch)
                        tank_icon_sprite.scale = 2
                        self.player_tank_icons[row, col] = tank_icon_sprite
                else:
                    if self.player_tank_icons[row, col] is not None:
                        self.player_tank_icons[row, col].delete()
                        self.player_tank_icons[row, col] = None
Exemple #26
0
enemy_positions = [
    (250, 100), (550, 100), (300, 300),
    (500, 300), (150, 450), (650, 450)
]
for x, y in enemy_positions:
    enemies_sprites.append(
        Sprite(
            img=resources.enemy,
            x=x, y=y,
            batch=enemies_batch
        )
    )

resources.boss.width, resources.boss.height = 100, 100
boss = Sprite(resources.boss, x=400, y=550)
boss.scale = 2

@game_window.event
def on_draw():
    game_window.clear()
    enemies_batch.draw()
    boss.draw()
    player.draw()


@game_window.event
def on_key_press(symbol, modifiers):
    global player_x, player_y
    if symbol == key.LEFT:
        player_x = -player_speed
        player_y = 0
Exemple #27
0
import pyglet
from pyglet_utils.tutorial import resources
from pyglet.window import Window
from pyglet.image import Animation
from pyglet.sprite import Sprite

# Create and open a window
window = Window(width=500, height=500, caption='Bird Atlas')

bird_anim = Animation.from_image_sequence(sequence=resources.bird_seq,
                                          duration=1 / 20,
                                          loop=True)
bird_sprite = Sprite(img=bird_anim, x=50, y=150)
bird_sprite.scale = 2


@window.event
def on_draw():
    window.clear()
    bird_sprite.draw()


if __name__ == '__main__':
    pyglet.app.run()
Exemple #28
0
    def __init__(self, *args, **kwargs):
        super(Lucky, self).__init__(width=WIDTH,
                                    height=HEIGHT,
                                    screen=display,
                                    fullscreen=True)

        self.prepare = 99
        self.lucky = 0  # 1, 2, 3, 5

        self.player1 = pyglet.media.Player()
        music1 = pyglet.resource.media('1.mp3')
        looper = pyglet.media.SourceGroup(music1.audio_format, None)
        looper.loop = True
        looper.queue(music1)
        self.player1.queue(looper)
        self.player1.play()

        self.player2 = pyglet.media.Player()
        self.music2 = pyglet.resource.media('2.mp3')
        self.player2.queue(self.music2)
        self.player2.push_handlers(self.on_eos)

        self.player3 = pyglet.media.Player()
        music3 = pyglet.resource.media('3.mp3')
        looper3 = pyglet.media.SourceGroup(music3.audio_format, None)
        looper3.loop = True
        looper3.queue(music3)
        self.player3.queue(looper3)

        self.ground = pyglet.image.load('bk.jpg')
        self.starBatch = pyglet.graphics.Batch()
        self.stars = []
        starImg = pyglet.resource.image('star.png')
        starImg.anchor_x = starImg.width / 2
        starImg.anchor_y = starImg.height / 2
        for i in range(50):
            star = Sprite(img=starImg,
                          batch=self.starBatch,
                          x=random.randint(1, self.width),
                          y=random.randint(1, self.height))
            star.scale = random.random()
            self.stars.append(star)
        #particials
        self.particials = PartialBatch({'w': self.width, 'h': self.height})

        #load lucky population
        self.total = pickle.load(open('total', 'rb'))
        self.picBatch = pyglet.graphics.Batch()
        self.picDict = {}
        for i in self.total:
            spt = pyglet.text.Label(str(i).zfill(3),
                                    font_size=70,
                                    x=-1000,
                                    y=-1000,
                                    anchor_x='center',
                                    anchor_y='center',
                                    batch=self.picBatch)
            self.picDict[spt] = i

        self.title = pyglet.text.Label('Fiskars Ningbo 2019 Annual Dinner',
                                       font_size=35,
                                       x=self.width / 2,
                                       y=self.height * 6 / 7,
                                       anchor_x='center',
                                       anchor_y='center')

        self.luckyTitle = pyglet.text.Label('',
                                            font_size=80,
                                            x=self.width / 2,
                                            y=self.height * 5 / 7,
                                            anchor_x='center',
                                            anchor_y='center')

        self.samples = []

        pyglet.clock.schedule(self.update)