コード例 #1
0
    def set_left_color(self, color, on_air=False):
        # self._left_circle.color = color
        if color == 'GREEN':
            self._left_circle_sprite = sprite.Sprite(
                self._green_circle_animation)
        elif color == 'YELLOW':
            self._left_circle_sprite = sprite.Sprite(
                self._yellow_circle_animation)
        elif color == 'BLUE':
            self._left_circle_sprite = sprite.Sprite(
                self._blue_circle_animation)
        elif color == 'RED':
            self._left_circle_sprite = sprite.Sprite(
                self._red_circle_animation)
        else:
            raise RuntimeError("No valid color given: %s" % str(color))
        self._left_circle_sprite.position = TwisterTempoGUI.LEFT_CIRCLE_POS
        self._L_sprite = sprite.Sprite(self._L_animation)
        self._L_sprite.position = TwisterTempoGUI.L_POS

        self._show_circles = True
        self._show_large_circle = False
        if on_air:
            self._draw_on_air = (True, TwisterTempoGUI.LEFT_CIRCLE_POS[0],
                                 TwisterTempoGUI.LEFT_CIRCLE_POS[1])
        else:
            self._draw_on_air = (False, 0, 0)
コード例 #2
0
ファイル: player.py プロジェクト: webguy88/fruitmaster
 def __init__(self):
     self.x = 480
     self.y = 320
     self.vx = 0
     self.vy = 0
     self.direction = "right"
     self.i_right = sprite.Sprite(self.idle_right)
     self.i_left = sprite.Sprite(self.idle_left)
     self.w_right = sprite.Sprite(self.walk_right)
     self.w_left = sprite.Sprite(self.walk_left)
     self.hitbox = Region(self.x, self.y, 54, 112)
     self.spr = self.i_right
     self.moving = False
コード例 #3
0
ファイル: _visual.py プロジェクト: larsoner/genz-1
    def set_image(self, image_buffer):
        """Set image buffer data

        Parameters
        ----------
        image_buffer : array
            N x M x 3 (or 4) array. Can be type ``np.float64`` or ``np.uint8``.
            If ``np.float64``, color values must range between 0 and 1.
            ``np.uint8`` is slightly more efficient.
        """
        from pyglet import image, sprite
        image_buffer = np.ascontiguousarray(image_buffer)
        if image_buffer.dtype not in (np.float64, np.uint8):
            raise TypeError('image_buffer must be np.float64 or np.uint8')
        if image_buffer.dtype == np.float64:
            if image_buffer.max() > 1 or image_buffer.min() < 0:
                raise ValueError('all float values must be between 0 and 1')
            image_buffer = (image_buffer * 255).astype('uint8')
        if image_buffer.ndim == 2:  # grayscale
            image_buffer = np.tile(image_buffer[..., np.newaxis], (1, 1, 3))
        if not image_buffer.ndim == 3 or image_buffer.shape[2] not in [3, 4]:
            raise RuntimeError('image_buffer incorrect size: {}'
                               ''.format(image_buffer.shape))
        # add alpha channel if necessary
        dims = image_buffer.shape
        fmt = 'RGB' if dims[2] == 3 else 'RGBA'
        self._sprite = sprite.Sprite(
            image.ImageData(dims[1], dims[0], fmt, image_buffer.tostring(),
                            -dims[1] * dims[2]))
コード例 #4
0
ファイル: wall.py プロジェクト: severokST/Maze
 def __init__(self, ui, position):
     self.position = position
     self.sprite = sprite.Sprite(images[0],
                                 batch=ui['batch_map'],
                                 group=ui['background'],
                                 x=self.position[0],
                                 y=self.position[1])
コード例 #5
0
    def seed_handler(self, engine, bounds):
        seed_config = self.seed_config
        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.left, bounds.top,
                                                      CHUNK_SIZE, CHUNK_SIZE,
                                                      cfg['freq'],
                                                      cfg['octaves'], 1.0, 32)
            for (oy, pees) in enumerate(perlins):
                for (ox, val) in enumerate(pees):
                    ix = bounds.left + ox * 32
                    iy = bounds.top + oy * 32
                    if val > cfg['threshold'] and (
                            cfg['rand_thresh'] == 0
                            or random() > cfg['rand_thresh']):
                        cells.append(
                            BlueprintCell(cfg['class'],
                                          (engine.textures, (ix, iy))))

        #waters = svgcell.cell_layer(engine.textures.asset_dir + '/water/water',
        #        bounds.left, bounds.top, CHUNK_SIZE, self.make_water)
        #cells.extend(waters)
        image_key = engine.textures.create_background(int(CHUNK_SIZE / 2),
                                                      int(bounds.left / 2),
                                                      int(bounds.top / 2))
        bg_sprite = sprite.Sprite(engine.textures[image_key], bounds.left,
                                  bounds.top)
        bg_sprite.scale = 2
        engine.world.set_bg(bg_sprite, bounds.left, bounds.top)
        return cells
コード例 #6
0
ファイル: draw_card.py プロジェクト: kvackkvack/cards
 def _update_hidden(self):
     self.back = sprite.Sprite(
         self.image, *self.centre,
         batch = self.batch, group = self.group_front
     )
     self.back.opacity = self.opacity
     self.back.scale = ((self.size.y - 2 * CardDrawer.BACK_PADDING)
                       / self.image.height)
コード例 #7
0
def resize(width, height):
    global imageWall
    global imageWallSprites
    imageWall = graphics.Batch()
    imageWallSprites = []
    for y in range(ceil(height / hexImg.height)):
        for x in range(ceil(width / hexImg.width)):
            imageWallSprites.append(sprite.Sprite(hexImg, hexImg.width*x, hexImg.height*y, batch=imageWall))
コード例 #8
0
 def draw(self, x, y):
     self.x = x
     self.y = y
     self.player_sprite = sprite.Sprite(self.image,
                                        self.x,
                                        self.y,
                                        batch=self.background)
     self.player_sprite.scale = self.scale
コード例 #9
0
 def __init__(self, image, xPos, yPos, batch, animation=None):
     self.name = image.split('.')[0]
     self.image = pygletImage.load(image)
     self.width = self.image.width
     self.height = self.image.height
     self.image.anchor_x = self.width / 2
     self.image.anchor_y = self.height / 2
     self.sprite = sprite.Sprite(self.image, x=xPos, y=yPos, batch=batch)
     self.animate = animation
コード例 #10
0
ファイル: base.py プロジェクト: severokST/Maze
 def __init__(self, name, batch, group, position):
     self.name = name
     self.position = position
     self.visible = False
     self.sprite = sprite.Sprite(None,
                                 batch=batch,
                                 group=group,
                                 x=position[0],
                                 y=position[1])
コード例 #11
0
    def __init__(self, game, circle=None, margin=20):
        self.game = game
        self.planets = {}
        self.fleets = {}
        self.margin = margin
        self.circle = circle

        # images
        self.bk_img = resource.image(IMAGES['background'])
        self.bk_sprite = sprite.Sprite(self.bk_img)
コード例 #12
0
ファイル: model.py プロジェクト: NeuronEnix/Battleship
def img(name, xy=[0, 0], wh=[None, None], batch=None, group=0, anchorXY=False):
    obj = pyRes.image('res/img/' + name + '.png')
    if anchorXY: objAnchorXY(obj)
    model = pySpt.Sprite(obj,
                         x=xy[0],
                         y=xy[1],
                         batch=batch,
                         group=genGroup(group))
    scale(model, wh)
    return model
def on_mouse_press(x, y, b, mod):
    global chosen_image, score, player_start
    game.click_record[0] = x
    game.click_record[1] = y
    #options change
    if game.round_no < 4:
        if bounding_box(x, y, o_rock_pos, choice_image_size):
            chosen_image = image_player_rock
            player_start = sprite.Sprite(chosen_image, x = 650, y = 200)
            game.evaluate(image_player_rock, computer_chose())
        elif bounding_box(x, y, o_paper_pos, choice_image_size):
            chosen_image = image_player_paper
            player_start = sprite.Sprite(chosen_image, x = 650, y = 200)
            game.evaluate(image_player_paper, computer_chose())
        elif bounding_box(x, y, o_scissors_pos, choice_image_size):
            chosen_image = image_player_scissors
            player_start = sprite.Sprite(chosen_image, x = 650, y = 200)
            game.evaluate(image_player_scissors, computer_chose())
        else:
            pass # nothing changes if clicked outside the bounding boxes
コード例 #14
0
    def __init__(self, *args, **kwargs):
        """
        Creates the background sprite.
        """

        super(Background, self).__init__(**kwargs)

        self.image_file_name = 'background.jpeg'

        self.image = image.load(config.resources_path + self.image_file_name)
        self.bg_sprite = sprite.Sprite(self.image, self.x, self.y)
コード例 #15
0
    def set_large_color(self, color):
        if color == 'GREEN':
            self._large_circle_sprite = sprite.Sprite(
                self._green_large_circle_animation)
        elif color == 'YELLOW':
            self._large_circle_sprite = sprite.Sprite(
                self._yellow_large_circle_animation)
        elif color == 'BLUE':
            self._large_circle_sprite = sprite.Sprite(
                self._blue_large_circle_animation)
        elif color == 'RED':
            self._large_circle_sprite = sprite.Sprite(
                self._red_large_circle_animation)
        else:
            raise RuntimeError("No valid color given: %s" % str(color))
        self._large_circle_sprite.position = TwisterTempoGUI.LARGE_CIRCLE_POS
        self._plus_sprite = sprite.Sprite(self._plus_animation)
        self._plus_sprite.position = TwisterTempoGUI.PLUS_POS

        self._show_circles = False
        self._show_large_circle = True
コード例 #16
0
ファイル: object_main.py プロジェクト: severokST/Pack
 def __init__(self, position, target, team, batch_set, order_group):
     self.position = position
     self.team = team
     self.speed = 1
     self.range = 5
     self.target_position = self.position
     self.target_grid = target
     self.sprite = sprite.Sprite(images[0],
                                 batch=batch_set,
                                 group=order_group,
                                 x=position[0],
                                 y=position[1])
コード例 #17
0
ファイル: model.py プロジェクト: NeuronEnix/Battleship
def gif(name, xy=[0, 0], wh=[None, None], batch=None, group=0, oneTime=False):
    obj = pyRes.animation('res/gif/' + name + '.gif')
    if oneTime:
        model = OneTimeSprite(xy, obj, batch=batch, group=genGroup(group))
    else:
        model = pySpt.Sprite(obj,
                             x=xy[0],
                             y=xy[1],
                             batch=batch,
                             group=genGroup(group))
    scale(model, wh)
    return model
コード例 #18
0
 def __init__(self, x, y, background):
     self.x = x
     self.y = y
     self.background = background
     self.scale = 0.125
     self.resource_handler = ResourceHandler()
     self.image = self.resource_handler.return_player()
     self.player_sprite = sprite.Sprite(self.image,
                                        self.x,
                                        self.y,
                                        batch=self.background)
     self.player_sprite.scale = self.scale
     self.image_width = self.image.width * self.scale
     self.image_height = self.image.height * self.scale
コード例 #19
0
	def __init__(self):
		self.x = 0
		self.y = 0
		self.sprite = sprite.Sprite(
			img=resources.player_image,
			x=0,
			y=0
		)
		self.direction = None
		self.stats = character.CharacterStats()
		self.HP = self.stats.HP
		self.SP = self.stats.speed
		self.blocker = True
		self.zindex = 100
コード例 #20
0
 def screen_resize(self, width, height):
     # if the screen has been resized, update point conversion factors.
     self.max_y, self.max_x, self.min_y, self.min_x = self.game.extent
     # get game width and height.
     self.dx = abs(self.max_x - self.min_x)
     self.dy = abs(self.max_y - self.min_y)
     # set display box width and height.
     self.display_dx = width - self.margin * 2
     self.display_dy = height - self.margin * 2
     # get the smaller ratio (width height) for radius drawing.
     self.ratio = min(self.display_dx / self.dx, self.display_dy / self.dy)
     # resize the background image also.
     self.bk_img.width = width
     self.bk_img.height = height
     self.bk_sprite = sprite.Sprite(self.bk_img)
コード例 #21
0
ファイル: enemy.py プロジェクト: MrRobot420/pyglet-playground
 def __init__(self, speed, health, x_pos, y_pos, background, level):
     self.speed = speed
     self.health = health
     self.x_pos = x_pos
     self.y_pos = y_pos
     self.background = background
     self.resource_handler = ResourceHandler()
     self.health = level['enemy_health']
     # Png
     self.scale = 0.25
     self.image = self.resource_handler.return_image_for_name(
         level['enemy_type'])
     self.cursor_sprite = sprite.Sprite(self.image, 0, 0)
     self.image_width = self.image.width * self.scale
     self.image_height = self.image.height * self.scale
コード例 #22
0
 def __init__(self, position):
     self.image_reference = 0
     self.position = position
     self.target_position = position
     self.speed = 1
     self.attributes = ()
     self.render_position = tuple(
         map(
             lambda x: UI['Field']['position'][x] + (UI['Field']['size'][
                 x] / UI['grid_size'][x]) * self.position[x], x_y))
     self.target_render_position = self.render_position
     self.sprite = sprite.Sprite(images['Player'],
                                 batch=UI['batch_map'],
                                 group=UI['background'],
                                 x=self.render_position[0],
                                 y=self.render_position[1])
コード例 #23
0
    def __init__(self, *args, **kwargs):
        """
        Creates the PJ's sprite.
        """
        # Starting position
        self.base_x = 240
        self.base_y = 240

        kwargs['x'] = self.base_x
        kwargs['y'] = self.base_y

        super(PJ, self).__init__(**kwargs)

        self.image = image.load(config.resources_path + 'pj.png')
        self.width = self.image.width
        self.height = self.image.height
        self.pj_sprite = sprite.Sprite(self.image, self.x, self.y)
コード例 #24
0
ファイル: ball.py プロジェクト: eBLDR/MasterNotes_Python
    def __init__(self, *args, **kwargs):
        """
        Creates a sprite using a ball image.
        """
        super().__init__(**kwargs)
        self.speed = kwargs.get('speed', 5)

        # Loading image file
        self.ball_image = image.load(config.resources_path + 'ball.png')
        self.width = self.ball_image.width
        self.height = self.ball_image.height
        self.ball_sprite = sprite.Sprite(self.ball_image, self.x, self.y)

        self.ball_image.rotation = randint(0, 360)  # Rotates the sprite
        self.ball_image.scale = uniform(0.5, 2)

        self.x_direction = 1  # 1 for + axis direction
        self.y_direction = 1
コード例 #25
0
    def __init__(self, x, y, target_x, target_y, background, damage):
        self.x = x
        self.y = y
        self.start_x = x
        self.start_y = y
        self.target_x = target_x
        self.target_y = target_y
        self.scale = 0.0625
        self.background = background
        self.start_time = dtime.now().timestamp()
        self.damage = damage

        self.resource_handler = ResourceHandler()
        self.bullet_image = self.resource_handler.return_bullet()

        self.bullet_sprite = sprite.Sprite(self.bullet_image, self.x, self.y, batch=self.background)
        self.bullet_sprite.scale = self.scale
        self.image_width = self.bullet_image.width * self.scale
        self.image_height = self.bullet_image.height * self.scale
コード例 #26
0
 def __init__(self, window):
     """Set up the game state."""
     self.window = window
     window.push_handlers(self)
     self.keys = key.KeyStateHandler()
     window.push_handlers(self.keys)
     self.roomX, self.roomY = 8,8
     pyglet.resource.add_font("8bitlimo.ttf")
     self.font = font.load('8-bit Limit O BRK', 16, bold=False, italic=False)
     self.hfont = font.load('8-bit Limit O BRK', 36, bold=False, italic=False)
     self.ts = TileSet("tiles.png", 32, 32, 32, 32)
     self.room = Room(self.ts, 0, 32, codemap=codemap)
     self.fps_display = pyglet.clock.ClockDisplay()
     self.ouch = pyglet.resource.media("ouch.wav", streaming=False)
     self.hbar = sprite.Sprite(pyglet.resource.image("health.png"),
                               x=10, y=self.window.height-25)
     self.loadTitle()
     pyglet.clock.schedule(self.update)
     pyglet.clock.schedule_interval(self.checkHealth, 0.125)
コード例 #27
0
 def __init__(self):
     self.x = 12
     self.y = 12
     self.vision = 3
     self.tile_index = -1
     self.sprite = sprite.Sprite(img=monsters[11, 0], x=320, y=320)
     self.hunger = 0
     self.target = Vector(self.x, self.y)
     self.stats = MonsterStats()
     self.weapon = Weapon({
         'class': "teeth",
         'name': "Teeth",
         'LVL': 1,
         'AD': 3,
         'MD': 3,
         'special': None,
         'description': "Rats attack using their teeth."
     })
     self.blocker = True
     self.zindex = 100
     self.SP = 32
コード例 #28
0
ファイル: arrow.py プロジェクト: eBLDR/Simple_Games
    def __init__(self, *args, **kwargs):
        """
        Creates the arrow's sprite.
        """
        # Starting position
        init_x = config.window_width + config.arrow_width_margin
        init_y = random.randint(config.height_range_min,
                                config.height_range_max)
        kwargs['x'] = init_x
        kwargs['y'] = init_y

        super(Arrow, self).__init__(**kwargs)

        self.speed = kwargs.get('speed', 1)

        self.image_file_name = 'arrow_{}.png'.format(random.randint(1, 9))

        self.image = image.load(config.resources_path + self.image_file_name)
        self.width = self.image.width
        self.height = self.image.height
        self.arrow_sprite = sprite.Sprite(self.image, self.x, self.y)

        self.out_of_screen = False
コード例 #29
0
    def render(self, batch, x, y, text, align="left", group=None):

        if batch is None:
            batch = pyglet.graphics.Batch()

        px_len = len(text) * self.width
        if align == "center":
            x -= px_len // 2
            y -= self.height // 2
        elif align == "right":
            x -= px_len

        sprites = []
        for i, c in enumerate(text):
            s = sprite.Sprite(
                self.grid[self.font_map.find(c)],
                x=x + i * self.width,
                y=y,
                usage="static",
                batch=batch,
                group=group,
            )
            sprites.append(s)
        return SpriteText(x, y, px_len, self.height, batch, sprites)
コード例 #30
0
def on_key_press(symbol, modifiers):
    global plyr_dx, plyr_dy
    if symbol == key.LEFT:
        plyr_dx = -plyr_speed
        plyr_dy = 0
    elif symbol == key.RIGHT:
        plyr_dx = +plyr_speed
        plyr_dy = 0
    elif symbol == key.UP:
        plyr_dy = +plyr_speed
        plyr_dx = 0
    elif symbol == key.DOWN:
        plyr_dy = -plyr_speed
        plyr_dx = 0


resource.path = ['resources']
resource.reindex()

player_img = resource.image("player.png")

player_sprite = sprite.Sprite(img=player_img, x=500, y=500)

plyr_speed = 100
plyr_dx = 0
plyr_dy = 0

clock.schedule_interval(update, 1 / 120)

app.run()