Exemple #1
0
    def __init__(self):
        super().__init__()

        self.scale = 0.8
        self.position = -50, -50

        explosion_animation = image.Animation.from_image_sequence(
            image.ImageGrid(image.load('explosion.png'), 1, 8),
            0.1,
        )

        self.explosion = sprite.Sprite(
            explosion_animation,
            position=(320, 240),
            scale=1.5,
        )
        self.explosion2 = sprite.Sprite(
            explosion_animation,
            position=(160, 120),
            scale=1.7,
        )
        self.explosion3 = sprite.Sprite(
            explosion_animation,
            position=(32, 32),
        )
        self.add(self.explosion)
        self.explosion.add(self.explosion2)
        self.explosion2.add(self.explosion3)
Exemple #2
0
    def __init__(self):
        super().__init__(255, 255, 255, 255)

        # method 1
        anim1 = resource.animation('dinosaur.gif', flip_x=True)
        self.sprite1 = Sprite(anim1, (150, 250))
        self.add(self.sprite1)
        anim2 = image.load_animation("dinosaur.gif")
        self.sprite2 = Sprite(anim2, (350, 250))
        self.add(self.sprite2)

        # method 2
        sprite_set = image.load("spriteset.png")
        image_grid = image.ImageGrid(sprite_set, 2, 5)
        frame_seq1 = image_grid[5:8]
        anim3 = image.Animation.from_image_sequence(frame_seq1, 0.1)
        anim3_flip = anim3.get_transform(flip_x=True)
        self.sprite3 = Sprite(anim3_flip, (150, 100))
        self.add(self.sprite3)

        # method 3
        self.sprite4 = Sprite(frame_seq1[0], (350, 100))
        self.add(self.sprite4)
        self.schedule(self.update, frame_seq1)
        self.elapsed = 0
        self.frame_idx = 0
Exemple #3
0
    def __init__(self, filename, tiledim):
        img = resource.texture(filename)

        self.tiledim = tiledim
        self._tw = img.width // tiledim
        self._th = img.height // tiledim
        self._grid = image.ImageGrid(img, self._th, self._tw)
Exemple #4
0
def main():
    director.director.init(width=640, height=480)

    layer_ = layer.Layer()

    # Try animation sprite.
    explosion = image.load('explosion.png')
    explosion_seq = image.ImageGrid(explosion, 1, 8)
    explosion_animation = image.Animation.from_image_sequence(
        explosion_seq, 0.1)
    explosion_sprite = sprite.Sprite(
        explosion_animation,
        position=(320, 240),
    )
    layer_.add(explosion_sprite)

    # Try move action.
    # [NOTE]: Can overwrite `on_animation_end` method to implement the same thing.
    def move_sprite(_):
        explosion_sprite.position = (random.randint(0, 640),
                                     random.randint(0, 480))

    explosion_sprite.schedule_interval(move_sprite, 0.1 * 8)

    director.director.run(scene.Scene(layer_))
Exemple #5
0
 def _load_multi(filename, labels, rows, columns, anchor=False):
     cache = ImageCache.cache
     multiimage = image.ImageGrid(resource.image(filename), rows, columns)
     for key, texture in zip(labels, multiimage):
         if anchor:
             texture.anchor_x = texture.width / 2
             texture.anchor_y = texture.height / 2
         cache[key] = texture
Exemple #6
0
 def _create_animations(self):
     self._animations = []
     seq_cols = self.sprite_sheet.width // self.sprite_width
     seq_rows = self.sprite_sheet.height // self.sprite_height
     seq = image.ImageGrid(self.sprite_sheet, seq_rows, seq_cols).get_texture_sequence()
     for i in range(seq_rows):
         self._animations.append(image.Animation.from_image_sequence(
             seq[i * seq_cols:(i + 1) * seq_cols], (1 / TICKS_PER_SEC) * TICKS_PER_FRAME, True))
Exemple #7
0
    def __init__(self):
        super().__init__(255, 255, 255, 255)
        sprite_set = resource.image("spriteset.png")
        image_grid = image.ImageGrid(sprite_set, 6, 10)

        image0 = image_grid[54]
        self.add(Sprite(image0, (200, 150)))

        image1 = image_grid[(5, 4)].get_transform(flip_y=True)
        self.add(Sprite(image1, (300, 150)))
Exemple #8
0
    def parse_tiles(self, name):
        logging.info("::reading tileset")

        img = image.load(name)
        w, h = img.width, img.height

        self.tiles_per_row = w / self.size
        self.tiles_per_column = h / self.size

        logging.info(":: tileset properties")
        logging.info("::  name: %s" % self.name)
        logging.info("::  dimensions: %ix%i" % (w, h))
        logging.info("::  tile size %i" % self.size)
        logging.info("::  tiles: %ix%i" %
                     (self.tiles_per_row, self.tiles_per_column))

        self.img_grid = image.ImageGrid(img, self.tiles_per_row,
                                        self.tiles_per_column)
        self.textures = image.TextureGrid(self.img_grid)
Exemple #9
0
    def __init__(self):
        super(MainLayer, self).__init__()
        skip = Label("Натисніть ПРОБІЛ, щоб пропустити", position = (100,550), color = (255,0,0, 255), font_size = 25, bold = True)
        skip.do(Blink (20,20))
        self.add(skip)
        self.img_h = image.load('res/animation/level1_monsters/hell_hound/hell-hound-run.png')
        self.img_grid_h = image.ImageGrid(self.img_h, 1, 5, item_width=67, item_height=31)
        self.anim_h = image.Animation.from_image_sequence(self.img_grid_h[0:], 0.2, loop=True)
        
        self.hell_hound = cocos.sprite.Sprite(self.anim_h)

        self.hell_hound.position = (-100, 180)
        self.hell_hound.scale = 2
        self.hell_hound.scale_x = -1
        self.add(self.hell_hound)

        self.portal = cocos.sprite.Sprite('res/animation/catscene/portal.png')
        self.portal.position = (500, 500)
        self.portal.scale = 0.3
        self.add(self.portal)

        self.img = pyglet.image.load('res/animation/catscene/Character_03/Idle/idle_sheet.png')
        self.img_grid = pyglet.image.ImageGrid(self.img, 1, 13, item_width=64, item_height=64 )
        self.anim = pyglet.image.Animation.from_image_sequence(self.img_grid[0:], 0.1, loop=True)

        self.hero_1 = cocos.sprite.Sprite(self.anim)
        self.hero_1.scale = 2.2
        self.hero_1.position = (300, 180)
        self.add(self.hero_1)

        self.img_1 = pyglet.image.load('res/animation/catscene/girl/Idle_Png/idle_sheet.png')
        self.img_grid_1 = pyglet.image.ImageGrid(self.img_1, 1, 5, item_width=128, item_height=128 )
        self.anim_1 = pyglet.image.Animation.from_image_sequence(self.img_grid_1[0:], 0.1, loop=True)

        self.hero_2 = cocos.sprite.Sprite(self.anim_1)
        self.hero_2.position = (200, 190)
        self.hero_2.scale = 1.6
        self.add(self.hero_2)


        self.img_2 = pyglet.image.load('res/animation/idle/idlesheet.png')
        self.img_grid_2 = pyglet.image.ImageGrid(self.img_2, 1, 4, item_width=50, item_height=37 )
        self.anim_2 = pyglet.image.Animation.from_image_sequence(self.img_grid_2[0:], 0.2, loop=True)

        self.hero_3 = cocos.sprite.Sprite(self.anim_2)
        self.hero_3.position = (100, 180)
        self.hero_3.scale = 2.2
        self.add(self.hero_3)


        self.img_3 = pyglet.image.load('res/animation/level3_monsters/demon boss/demon-idle.png')
        self.img_grid_3 = pyglet.image.ImageGrid(self.img_3, 1, 6, item_width=160, item_height=144 )
        self.anim_3 = pyglet.image.Animation.from_image_sequence(self.img_grid_3[0:], 0.1, loop=True)
        
        self.demon = cocos.sprite.Sprite(self.anim_3)
        self.demon.position = (400, 500)
        self.demon.scale = 1.4
        self.add(self.demon)

        self.hell_hound.do(MoveTo((1000, 180), 11))
        self.hero_3.do(MoveBy((170, 0), 3) + Delay(9.5) + MoveBy((1000, 0), 7.5))

        self.hero_1.do(MoveBy((100,0), 3) + Delay(8.5) + FadeOut(0.5))
        self.hero_2.do(MoveBy((250,0), 3) + Delay(8.5) + FadeOut(0.5))

        self.portal.do(FadeOut(0) + MoveTo((700, 300), 5) + FadeIn(1) + Delay(7.5) + FadeOut(0.5))
        self.demon.do(FadeOut(0) + MoveTo((700, 350), 5) + FadeIn(4) + Delay(1) + MoveTo((550, 250), 1) + Delay(2) + MoveTo((550, 1000), 1))

        self.schedule(self.update)
Exemple #10
0
                  dy=-50 + 100 * random.random())

car = resource.image('car.png')
car.anchor_x = 16
car.anchor_y = 20
car = spryte.Sprite(car, win.width / 2, win.height / 2)


class EffectSprite(spryte.Sprite):
    def on_animation_end(self):
        self.delete()


explosions = spryte.SpriteBatch()
explosion_images = resource.image('explosion.png')
explosion_images = image.ImageGrid(explosion_images, 2, 8)
explosion_animation = image.Animation.from_image_sequence(explosion_images,
                                                          .001,
                                                          loop=False)

keyboard = key.KeyStateHandler()
win.push_handlers(keyboard)


def animate(dt):
    # update car rotation & speed
    r = car.rotation
    r += (keyboard[key.RIGHT] - keyboard[key.LEFT]) * 200 * dt
    if r < 0:
        r += 360
    elif r > 360:
Exemple #11
0
import pyglet
from pyglet import image

#run right --------------------------------------------------
img_r = image.load('res/animation/run/adventurer-run3-sword-Sheet.png')
img_grid_r = image.ImageGrid(img_r, 1, 6, item_width=50, item_height=37)
anim_r = image.Animation.from_image_sequence(img_grid_r[0:], 0.1, loop=True)
# ----------------------------------------------------------

#attack1
img_a1 = image.load('res/animation/attack1/attack1sheet.png')
img_grid_a1 = image.ImageGrid(img_a1, 6, 1, item_width=50, item_height=37)

anim_a1 = image.Animation.from_image_sequence(img_grid_a1[::-1],
                                              0.05,
                                              loop=False)
#------------------------------------------------------------------

#attack2
img_a2 = image.load('res/animation/attack2/attack2sheet.png')
img_grid_a2 = image.ImageGrid(img_a2, 6, 1, item_width=50, item_height=37)
anim_a2 = image.Animation.from_image_sequence(img_grid_a2[::-1],
                                              0.05,
                                              loop=False)
#------------------------------------------------------------------

#attack3
img_a3 = image.load('res/animation/attack3/attack3sheet.png')
img_grid_a3 = image.ImageGrid(img_a3, 6, 1, item_width=50, item_height=37)
anim_a3 = image.Animation.from_image_sequence(img_grid_a3[::-1],
                                              0.1,
Exemple #12
0
from pyglet import image
from poker.client.resources import image_resource
import poker.card
"""
the image grid is an image composed of 52 subimages (one per playing card
in a deck), arranged in a 4x13 grid.  by convention, the order of the ranks per
row is A,2,3,...,T,J,Q,K and the order of the suits from bottom to top is
diamonds, hearts, clubs, spades.
"""

ROWS, COLS = 4, 13
deck_grid = image.ImageGrid(image_path('deck.png'), ROWS,
                            COLS).texture_sequence


def get_card_image(card):
    """returns a pyglet image for the given card"""

    col = card.rank + 1
    if card.rank == poker.card.ACE: col = 0
    return deck_grid[(card.suit, col)]


def render_hand(win, h):
    """simply renders the given hand in the center of the given window.
       really just for testing."""

    card_images = [get_card_image(c) for c in h.cards]
    padding = 20
    full_width = (card_images[0].width + padding) * len(h.cards)
    x = win.width / 2 - full_width / 2
Exemple #13
0
 def _create_animations(self):
     seq_cols = self.sprite_sheet.width // self.sprite_width
     seq_rows = self.sprite_sheet.height // self.sprite_height
     seq = image.ImageGrid(self.sprite_sheet, seq_rows,
                           seq_cols).get_texture_sequence()
     self._animations += seq[::6]
Exemple #14
0
class PlayLayer(KeyboardInputLayer):
   explosionSmall_image = pyglet.resource.image('images/explosionSmall.png')
   explosionSmall_grid = pyglet.image.ImageGrid(explosionSmall_image, 5, 5)
   explosionSmall_textures = pyglet.image.TextureGrid(explosionSmall_grid)
   explosionSmall_textures_list = explosionSmall_textures[:]
   explosionSmall_frame_period = 0.05
   explosionSmall_animation = pyglet.image.Animation.from_image_sequence(
      explosionSmall_textures_list, explosionSmall_frame_period, loop=True)
   duration = len(explosionSmall_textures_list) * explosionSmall_frame_period
   explosionSmall_opacity = 128

   rubbleWallSpritesheet = pyglet.resource.image('images/TileObjectsRubbleWalls.png')
   rubbleWallGrid = Image.ImageGrid(rubbleWallSpritesheet, 8, 8)
   rubbleWallTextures = Image.TextureGrid(rubbleWallGrid)
   idToWyvernTable = {}
   
   #############################################################################
   def __init__(self):
      """ """
      super(PlayLayer, self).__init__()
      self.groundOffsetX = 0
      self.groundOffsetY = 0
      self.backgroundLayer = cocos.layer.ColorLayer(100, 100, 100, 255,
            width=1024, height=768)
      self.add(self.backgroundLayer, z=0)
      self.groundLayer = GroundLayer()
      self.backgroundLayer.add(self.groundLayer, z=0)

      self.obstacleLayer = cocos.layer.Layer()
      self.backgroundLayer.add(self.obstacleLayer, z=2)

      self.wyvern = Wyvern.Wyvern()
      self.do(PlayLayerAction())

      self.obstacleDict = {}
      
      for obstacleInfo in Map.obstacleInfos:
         obstacle = cocos.sprite.Sprite(PlayLayer.rubbleWallTextures[obstacleInfo['id']])
         mapPosition = (
               obstacleInfo['x'], 
               obstacleInfo['y'], 
               obstacleInfo['z']
         )
         obstacle.position = Map.Map.positionForMapPosition(
               mapPosition[0], mapPosition[1], mapPosition[2])
         self.obstacleLayer.add(obstacle, z=Map.Map.zForMapPosition(
               mapPosition[0], mapPosition[1], mapPosition[2]))
         self.obstacleDict[mapPosition] = True
       
      self.allWyvernsBatch = cocos.batch.BatchNode()
      self.obstacleLayer.add(self.allWyvernsBatch, z=66)
      
      self.allWyvernsShadowsBatch = cocos.batch.BatchNode()
      self.obstacleLayer.add(self.allWyvernsShadowsBatch)
      
      PlayLayer.addWyvern(self.getOwnID(), self.wyvern)   

   #############################################################################
   @staticmethod
   def addWyvern(id, wyvern):
      PlayLayer.idToWyvernTable[id] = wyvern
      print("Added wyvern {}\n".format(id))
   
   #############################################################################
   def getOwnID(self):
      return ""
      
   #############################################################################
   def respawn(self):
     self.wyvern.respawn()
      
   #############################################################################
   def update(self, dt):
      for id in PlayLayer.idToWyvernTable:
         currentWyvern = PlayLayer.idToWyvernTable[id]
         if currentWyvern.parent == None:
            self.obstacleLayer.add(currentWyvern.sprite)
            self.allWyvernsShadowsBatch.add(currentWyvern.sprites)
         currentWyvern.update(dt)
      self.groundOffsetX = -self.wyvern.sprite.position[0] + 200
      self.groundOffsetY = -self.wyvern.sprite.position[1] + 80 + self.wyvern.altitude
      self.groundLayer.position = self.groundOffsetX, self.groundOffsetY
      self.obstacleLayer.position = self.groundOffsetX, self.groundOffsetY
      self.obstacleLayer.remove(self.wyvern.sprite)
      self.obstacleLayer.add(self.wyvern.sprite,
            z=Map.Map.zForMapPosition(4, self.wyvern.altitude / 96, 0))
      x, y, z = self.wyvern.mapPosition
      intMapPosition = (
         int(x + 0.5),
         int(y + 0.5),
         int(z + 0.5)
      )
      #print(intMapPosition)
      if intMapPosition in self.obstacleDict:
         if not self.wyvern.isDead:
            #print('Collision!')
            self.wyvern.isDead = True
            self.wyvern.mapPosition = (self.wyvern.mapPosition[0],
               self.wyvern.mapPosition[1],
               self.wyvern.mapPosition[2] - 1.5)
            self.horizontalVelocity = -0.02
            self.do(cocos.actions.Delay(3) + cocos.actions.CallFunc(self.respawn))
            
   #############################################################################
   def on_key_press(self, key, modifiers):
      """ """
      super(PlayLayer, self).on_key_press(key, modifiers)
      if pyglet.window.key.SPACE in self.keys_being_pressed:
         self.wyvern.flap()
      if pyglet.window.key.LEFT in self.keys_being_pressed:
          self.wyvern.moveLeft()
      if pyglet.window.key.RIGHT in self.keys_being_pressed:
          self.wyvern.moveRight()

   #############################################################################
   def on_key_release(self, key, modifiers):
      super(PlayLayer, self).on_key_release(key, modifiers)
Exemple #15
0
from pyglet import resource
from pyglet import image

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

player_image = resource.image('player.png')
tiles_image = resource.image("tiles.png")
tiles_image_grid = image.ImageGrid(image=tiles_image, rows=19, columns=9)
map_tiles = image.TextureGrid(tiles_image_grid)

monsters_image = resource.image("monster1.png")
monsters_grid = image.ImageGrid(image=monsters_image, rows=16, columns=6)
monsters = image.TextureGrid(monsters_grid)

from pyglet import sprite
blue_overlay = sprite.Sprite(img=resource.image('blue_overlay.png'), x=0, y=0)
Exemple #16
0
map = [
    [0, 1, 1, 1, 2, 3],
    [5, 6, 16, 16, 7, 8],
    [5, 8, 9, 9, 5, 8],
    [5, 8, 9, 9, 5, 8],
    [5, 8, 9, 9, 5, 8],
    [5, 8, 9, 9, 5, 8],
    [5, 8, 9, 9, 5, 8],
    [5, 8, 9, 9, 5, 8],
    [10, 11, 1, 1, 12, 13],
    [15, 16, 16, 16, 17, 18],
]

v = view.View.for_window(win)
tiles = resource.image('road-tiles.png')
tiles = image.ImageGrid(tiles, 4, 5)
v.add_map(tiles, map)
car = resource.image('car.png')
car.anchor_x = 16
car.anchor_y = 20
car = v.add_sprite(car, 64, 64, z=1)

keyboard = key.KeyStateHandler()
win.push_handlers(keyboard)

# mouse picking ... needs to be in a different example


def f(x, y, buttons, modifiers):
    print((x, y))