• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python sprite.Sprite类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyglet.sprite.Sprite的典型用法代码示例。如果您正苦于以下问题:Python Sprite类的具体用法?Python Sprite怎么用?Python Sprite使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Sprite类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self,
                 x=0, y=0, map=None,
                 blend_src=pyglet.gl.GL_SRC_ALPHA,
                 blend_dest=pyglet.gl.GL_ONE_MINUS_SRC_ALPHA,
                 pos=None,
                 batch=None,
                 group=None,
                 usage='dynamic',
                 ):
        self.dead = False
        self.charName = 'Player'
        self.charClass = 'Fighter'
        self.map = map
        self.mbox = msgBox()
        img = sheet['class'][79]
        self.stats = Stats(self, Con=18, hpRoll=20)
        self.statuswindow = statusWindow(self, batch, group)

        if pos is None:
            self.pos = Position()
        else:
            self.pos = pos
        Sprite.__init__(self, img,
                        x, y, blend_src,
                        blend_dest, batch,
                        group, usage)
开发者ID:codelurker,项目名称:UGUIR,代码行数:26,代码来源:player.py


示例2: __init__

 def __init__(self, img,
          map=None,
          pos=None,
          stats=None,
          x=0, y=0,
          blend_src=pyglet.gl.GL_SRC_ALPHA,
          blend_dest=pyglet.gl.GL_ONE_MINUS_SRC_ALPHA,
          batch=None,
          group=None,
          usage='dynamic'):
     if stats is None:
         self.stats = Stats(self)
     else:
         self.stats = stats
     self.map = map
     self.pos = pos
     self.blocked = True
     self.oldPos = pos
     self.playerOldPos = None
     self.dead = False
     self.currentPath = []
     Sprite.__init__(self, img,
                     x, y, blend_src,
                     blend_dest, batch,
                     group, usage)
开发者ID:codelurker,项目名称:UGUIR,代码行数:25,代码来源:monsters.py


示例3: _draw_overlay

 def _draw_overlay(self):
     pattern = SolidColorImagePattern((0, 0, 0, 200))
     overlay_image = pattern.create_image(1000, 1000)
     overlay_image.anchor_x = overlay_image.width / 2
     overlay_image.anchor_y = overlay_image.height / 2
     overlay = Sprite(overlay_image, self.camera.x, self.camera.y)
     overlay.draw()
开发者ID:johnmendel,项目名称:python-tactics,代码行数:7,代码来源:scene.py


示例4: Inhabitant

class Inhabitant(object):
    def __init__(self, img, x, y):
        super(Inhabitant, self).__init__()
        register(self)
        self.x, self.y = x, y
        self.pathfinder = None
        self.path = []  # extra copy for custom tumbling or alternative path factories
        self.speed = 0.05
        self.image = img
        self.sprite = Sprite(img, batch=batch)
        self.update()

    def update(self):
        grpos = topo.ground_position(self.x, self.y)
        if grpos:
            x, y = grpos
            self.sprite.set_position(x - 10, y)

    def move(self):
        dx = self.path[0].x - self.x
        dy = self.path[0].y - self.y
        if dx ** 2 + dy ** 2 < 0.01:
            self.path.pop(0)
            if len(self.path) < 1:
                self.pathfinder = None
        else:
            r = math.sqrt(dx ** 2 + dy ** 2)
            dx *= self.speed / r
            dy *= self.speed / r
            self.x += dx
            self.y += dy
            self.update()
开发者ID:JKatzwinkel,项目名称:sym_comm,代码行数:32,代码来源:__init__.py


示例5: Button

class Button(Rectangle):
    def __init__(self, x, y, width, height, image=None, caption=None, batch=None, group=None):
        super(Button, self).__init__(x, y, width, height)
        self.batch = batch
        self.group = group
        self.sprite = None
        self.label = None
        if image:
            self.sprite = Sprite(image.get_region(0, 0, self.width, self.height), batch=self.batch, group=self.group)
        if caption:
            self.label = Label(caption, font_name='Arial', font_size=12,
                anchor_x='center', anchor_y='center', color=(255, 255, 255, 255), batch=self.batch,
                group=self.group)
        self.set_position(x, y)
	
    def set_position(self, x, y):
        super(Button, self).set_position(x, y)
        if self.sprite:
            self.sprite.x, self.sprite.y = x, y
        if self.label:
            self.label.x, self.label.y = self.get_center()

    def draw(self):
        if self.sprite:
            self.sprite.draw()
        if self.label:
            self.label.draw()
开发者ID:caront,项目名称:Minecraft,代码行数:27,代码来源:gui.py


示例6: __init__

    def __init__(self, x, y, dx, dy, goo_batch):
        image = pyglet.image.load(data.filepath('goo.png'))
        self.sequence = pyglet.image.ImageGrid(image, 1, 4)

        self.splat_image = pyglet.image.load(data.filepath('splat.png'))
        self.splat_image.anchor_x = self.splat_image.width / 2

        for sequence_image in self.sequence:
            sequence_image.anchor_x = sequence_image.width / 2
            sequence_image.anchor_y = sequence_image.height / 2

        Sprite.__init__(self, image, batch=goo_batch)
        self.x = self.xpos = x
        self.y = self.ypos = y

        self.speedx = dx
        self.speedy = dy

        self.animation_time = 0
        self.animation_frame = 0
        self.animation_speed = 0.25

        self.splat = False

        self.hitbox = (0, 0, self.splat_image.width, self.splat_image.height)
开发者ID:puffnfresh,项目名称:blank_page,代码行数:25,代码来源:main.py


示例7: sprites

 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)
开发者ID:MichaMucha,项目名称:geoplotlib,代码行数:8,代码来源:core.py


示例8: fire

    def fire(self):
        """Create a new bullet"""
        bullet = Sprite(images['bullet'], batch=self.bullet_batch)
        
        bullet.x = self.player.x + self.player.width  
        bullet.y = self.player.y + self.player.height / 2 - bullet.height / 2

        self.bullets.append(bullet)
开发者ID:Goggles,项目名称:SideScroll,代码行数:8,代码来源:game.py


示例9: players_lives

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
开发者ID:ThomasGuy,项目名称:Asteroids,代码行数:8,代码来源:spawn.py


示例10: _draw_action_menu

    def _draw_action_menu(self):
        pattern = SolidColorImagePattern((0, 0, 150, 200))
        overlay_image = pattern.create_image(1000, 200)
        overlay_image.anchor_x = overlay_image.width / 2
        overlay_image.anchor_y = overlay_image.height + 100
        overlay = Sprite(overlay_image, self.camera.x, self.camera.y)
        overlay.draw()

        self._generate_text()
开发者ID:johnmendel,项目名称:python-tactics,代码行数:9,代码来源:scene.py


示例11: Game

class Game(Window):
    def __init__(self):
        """This is run when the game is created"""
        super(Game, self).__init__()

        # Create the sprites
        self.arch = Sprite(images['arch'], x=50, y=50)
        self.bullet = Sprite(images['bullet'], x=-50, y=-50)

        # A handler that watches the keyboard state
        self.keyboard = key.KeyStateHandler()
        self.set_handlers(self.keyboard)

        # Call update() 60 times a second
        clock.schedule_interval(self.update, 1/60.0)

        # Display the current FPS on screen
        self.fps_display = clock.ClockDisplay()

    def on_draw(self):
        """Clear the window, draw the sprites and display framerate"""
        self.clear()
        self.arch.draw()
        self.bullet.draw()
        self.fps_display.draw()

    def on_mouse_press(self, x, y, button, modifiers):
        """This is run when a mouse button is pressed"""
        if button == mouse.LEFT:
            print "The left mouse button was pressed."
        elif button == mouse.RIGHT:
            print "The right mouse button was pressed."

    def update(self, dt):
        """This is called on every update

        It uses the keyboard input to move the player
        at around 200 pixels per second"""

        if self.keyboard[key.RIGHT]:
            self.arch.x += dt * 200

        if self.keyboard[key.LEFT]:
            self.arch.x -= dt * 200

        if self.keyboard[key.UP]:
            self.arch.y += dt * 200

        if self.keyboard[key.DOWN]:
            self.arch.y -= dt * 200

        # Fire if spce bar pressed
        if self.keyboard[key.SPACE]:
            self.fire()

    def fire(self):
        print "Fire!"
开发者ID:borntyping,项目名称:SideScroll,代码行数:57,代码来源:game.py


示例12: background_2

    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)
开发者ID:Goggles,项目名称:SideScroll,代码行数:10,代码来源:game.py


示例13: enemy

    def enemy(self, dt):
	"""creates enemies """
        enemy = Sprite(images['windows'], batch=self.enemy_batch)

	enemy.y = random.uniform(0, self.width)
	enemy.x = self.width
	enemy.startX = enemy.x
	enemy.startY = enemy.y

	self.win_enemy.append(enemy)	
开发者ID:Goggles,项目名称:SideScroll,代码行数:10,代码来源:game.py


示例14: on_draw

    def on_draw(self):
        from pyglet.sprite import Sprite

        if not self.initialized:
            self.initialized = True
            self.init_gl()

        width, height = self.get_size()
        x_max = width // 32 + 1
        y_max = height // 32 + 1

        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
        gl.glEnable(gl.GL_BLEND)

        fov = towel.FieldOfVision(self.passable.__contains__)
        fov.place_viewer(self.player, self.player_view)
        x, y = self.player

        x_offset = x - x_max // 2
        y_offset = y - y_max // 2

        x_range = range(0, x_max + 1)
        y_range = range(0, y_max + 1)

        self.clear()
        batch = pyglet.graphics.Batch()
        sprites = []

        player_screen_pos = None

        for iy in y_range:
            for ix in x_range:
                p = (ix + x_offset, iy + y_offset)
                image = None
                color = (255, 255, 255)
                if fov.is_visible(p):
                    if p in self.passable:
                       image = self.image_floor 
                    else:
                       image = self.image_wall 
                    self.remembered[p] = image
                else:
                    image = self.remembered.get(p, None)
                    color = (128, 128, 128)
                if image:
                    sprite = Sprite(image, ix*32, iy*32, batch=batch)
                    sprite.color = color
                    sprites.append(sprite)
                if p == self.player:
                    player_screen_pos = (ix*32, iy*32)

        batch.draw()
        if player_screen_pos:
            self.image_player.blit(*player_screen_pos)
        self.invalid = False
开发者ID:stephanh42,项目名称:towel,代码行数:55,代码来源:simplerogue_pyglet.py


示例15: player_icons

 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
开发者ID:ThomasGuy,项目名称:Asteroids,代码行数:11,代码来源:game_state.py


示例16: background_1

    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) 
开发者ID:Goggles,项目名称:SideScroll,代码行数:11,代码来源:game.py


示例17: add_button

    def add_button(self, b_type):
        if b_type == "1":
            x = 20
            y = 20
            category = "tower"
            texture = self.w.textures["tower_wood"]
            active = True
            b_price = self.w.game.available_towers[b_type]
        elif b_type == "2":
            x = 20
            y = 20 + self.b_size
            category = "tower"
            texture = self.w.textures["tower_poison"]
            active = True
            b_price = self.w.game.available_towers[b_type]
        elif b_type == "3":
            x = 20
            y = 20 + self.b_size * 2
            category = "tower"
            texture = self.w.textures["tower_splash"]
            active = True
            b_price = self.w.game.available_towers[b_type]
        elif b_type == "4":
            x = 20
            y = 20 + self.b_size * 3
            category = "tower"
            texture = self.w.textures["tower_chain"]
            active = True
            b_price = self.w.game.available_towers[b_type]
        elif b_type == "gold_icon":
            texture = image.load(RES_PATH + 'ui/gold.png')
            texture = center_image(texture)
            x = texture.width + 2
            y = self.w.height - (texture.height + 2)
            category = "ui"
            active = False
            b_price = False
            b_type = "icon"
        else:
            return False

        b_sprite = Sprite(
                        texture,
                        x=x, y=y,
                        batch=self.w.batches["buttons"],
                        group=self.w.ui_group
                    )

        b_sprite.category = category
        b_sprite.b_type = b_type
        b_sprite.active = active
        b_sprite.b_price = b_price
        self.sprites.append(b_sprite)
开发者ID:NiclasEriksen,项目名称:py-towerwars,代码行数:53,代码来源:ui.py


示例18: __init__

 def __init__(self):
     frames.basicFrame.__init__(self)        
     
     self.background = Sprite(assets.mainMenuBackground,0,0)
     self.background.scale = float(setting.SCREEN_HEIGHT) / self.background.height
     self.playButton = Sprite(assets.mainMenuPlay,0,0)
     self.optionsButton = Sprite(assets.mainMenuOptions,0,0)
     self.playButton.scale = self.optionsButton.scale = self.background.scale
     self.optionsButton.tx = self.optionsButton.x = self.playButton.x = self.playButton.tx = 1385 * self.playButton.scale
     self.playButton.ty = 520 * self.playButton.scale
     self.playButton.y = self.playButton.ty + 2000
     self.optionsButton.ty = 300 * self.optionsButton.scale
     self.optionsButton.y = self.optionsButton.y + 1000
开发者ID:Cucumbis,项目名称:proposal01,代码行数:13,代码来源:mainMenuFrame.py


示例19: __init__

    def __init__(self):
        """This is run when the game is created"""
        super(Game, self).__init__()

        # Create the sprites
        self.arch = Sprite(images['arch'], x=50, y=50)
        self.bullet = Sprite(images['bullet'], x=-50, y=-50)

        # A handler that watches the keyboard state
        self.keyboard = KeyStateHandler()
        self.set_handlers(self.keyboard)

        # Call update() 60 times a second
        clock.schedule_interval(self.update, 1/60.0)
开发者ID:MentalMarriott,项目名称:SideScroll-1,代码行数:14,代码来源:game.py


示例20: value

 def value(self, value):
     new = min(self.display_max, value)
     delta = new - self.value
     self._value = value
     while delta > 0:
         sprite = Sprite(self.__class__.icon_img, y=self.y)
         self.icons.append(sprite)
         self.add_sprite(sprite, self.__class__.sprite_group)
         self.x = self.x
         delta -= 1
     while delta < 0:
         sprite = self.icons.pop()
         sprite.delete()
         delta += 1
开发者ID:darkfeline,项目名称:TouhouS,代码行数:14,代码来源:ui.py



注:本文中的pyglet.sprite.Sprite类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python text.Label类代码示例发布时间:2022-05-25
下一篇:
Python resource.image函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap