当前位置: 首页>>代码示例>>Python>>正文


Python Sprite.draw方法代码示例

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


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

示例1: Button

# 需要导入模块: from pyglet.sprite import Sprite [as 别名]
# 或者: from pyglet.sprite.Sprite import draw [as 别名]
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,代码行数:29,代码来源:gui.py

示例2: _draw_overlay

# 需要导入模块: from pyglet.sprite import Sprite [as 别名]
# 或者: from pyglet.sprite.Sprite import draw [as 别名]
 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,代码行数:9,代码来源:scene.py

示例3: Game

# 需要导入模块: from pyglet.sprite import Sprite [as 别名]
# 或者: from pyglet.sprite.Sprite import draw [as 别名]
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,代码行数:59,代码来源:game.py

示例4: _draw_action_menu

# 需要导入模块: from pyglet.sprite import Sprite [as 别名]
# 或者: from pyglet.sprite.Sprite import draw [as 别名]
    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,代码行数:11,代码来源:scene.py

示例5: draw

# 需要导入模块: from pyglet.sprite import Sprite [as 别名]
# 或者: from pyglet.sprite.Sprite import draw [as 别名]
    def draw(self):
        if self.xpos > window.width / 2:
            self.x = window.width / 2
        else:
            self.x = self.xpos

        if self.ypos > window.height / 2:
            self.y = window.height / 2
        else:
            self.y = self.ypos

        Sprite.draw(self)

        self.goo_batch.draw()
开发者ID:puffnfresh,项目名称:blank_page,代码行数:16,代码来源:main.py

示例6: Pawn

# 需要导入模块: from pyglet.sprite import Sprite [as 别名]
# 或者: from pyglet.sprite.Sprite import draw [as 别名]
class Pawn(object):
    def __init__(self, image):
        self._sprite = Sprite(image)
        self.position = None

    @property
    def opacity(self):
        return self._sprite.opacity

    @opacity.setter
    def opacity(self, value):
        self._sprite.opacity = value

    def render(self):
        self._sprite.draw()

    def set_position(self, position, offset):
        self.position = position
        self._sprite.x = position.x * STREET_GRID_SIZE + offset.x
        self._sprite.y = position.y * STREET_GRID_SIZE + offset.y
开发者ID:ghostonline,项目名称:ld23,代码行数:22,代码来源:street.py

示例7: MainMenuFrame

# 需要导入模块: from pyglet.sprite import Sprite [as 别名]
# 或者: from pyglet.sprite.Sprite import draw [as 别名]
class MainMenuFrame(frames.basicFrame):
    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
    def update(self):
        self.playButton.x += (self.playButton.tx - self.playButton.x)/10
        if (abs(self.playButton.x - eventManager.mouse.position.x)<self.playButton.width/2):
            self.playButton.y += (self.playButton.ty + (self.playButton.ty - eventManager.mouse.position.y)**3/80000.0 - self.playButton.y)/10
            self.optionsButton.y += (self.optionsButton.ty + (self.optionsButton.ty - eventManager.mouse.position.y)**3/80000.0 - self.optionsButton.y)/10
        else:
            self.playButton.y += (self.playButton.ty - self.playButton.y)/10
            self.optionsButton.y += (self.optionsButton.ty - self.optionsButton.y)/10
        self.optionsButton.x += (self.optionsButton.tx - self.optionsButton.x)/10
        #check if play button pressed
        for event in eventManager.lastEvents:
            if (event.type == "mousedown" and event.value == 0):
                if (eventManager.mouse.position.withinRect(self.playButton,self.playButton.width,self.playButton.height)):
                    frameController.add("game",GameFrame(GameData()))
                    frameController.rem("main")
                    self.finished = 1
    def draw(self):
        self.background.draw()
        self.playButton.draw()
        self.optionsButton.draw()
开发者ID:Cucumbis,项目名称:proposal01,代码行数:36,代码来源:mainMenuFrame.py

示例8: Goal

# 需要导入模块: from pyglet.sprite import Sprite [as 别名]
# 或者: from pyglet.sprite.Sprite import draw [as 别名]
class Goal(object):
    def __init__(self, pos):
        self._sprite = Sprite(FLOORTARGET_IMAGE)
        self._pos = pos
        self._sprite.opacity = FLOORTARGET_OPACITY

    @property
    def pos(self):
        return self._pos

    @pos.setter
    def pos(self, value):
        self._pos = value
        offset = Vector(self._sprite.width / 2, self._sprite.height / 2)
        pos = value * STREET_GRID_SIZE - offset
        self._sprite.set_position(pos.x, pos.y)

    def render(self):
        self._sprite.draw()

    def on_goal(self, position):
        distance = position - self._pos
        return distance.length2 < FLOORTARGET_RANGE ** 2
开发者ID:ghostonline,项目名称:ld23,代码行数:25,代码来源:goal.py

示例9: draw

# 需要导入模块: from pyglet.sprite import Sprite [as 别名]
# 或者: from pyglet.sprite.Sprite import draw [as 别名]
 def draw(self):
     Sprite.draw(self)
开发者ID:ih,项目名称:sort_exp,代码行数:4,代码来源:selectable.py

示例10: __init__

# 需要导入模块: from pyglet.sprite import Sprite [as 别名]
# 或者: from pyglet.sprite.Sprite import draw [as 别名]
class GarbageCan:
    def __init__(self):
        self.image_opened = image.load(data_file('garbagecan-open.png'))
        self.image_closed = image.load(data_file('garbagecan-closed.png'))
        self.image_lid = image.load(data_file('garbagecan-lid.png'))

        self.image_opened.anchor_x = self.image_opened.width/2
        self.image_opened.anchor_y = self.image_opened.height/2
        self.image_closed.anchor_x = self.image_opened.width/2
        self.image_closed.anchor_y = self.image_opened.height/2

        self.candidateLeaves = {}

        self.opened = True
        self.lid_active = False
        self.can_active = False
        self.fallen = False
        self.can_highlighted = False
        self.lid_highlighted = True

        self.can_rect = Rect(0, 0, self.image_closed)
        self.can_rect.center = (80, 90)

        self.can_sprite = Sprite(self.image_opened)
        self.can_sprite.set_position(self.can_rect.x, self.can_rect.y)

        self.lid_rect = Rect(20, 40, self.image_lid)

        window.game_window.push_handlers(self.on_mouse_release)
        window.game_window.push_handlers(self.on_mouse_press)
        window.game_window.push_handlers(self.on_mouse_drag)
        window.game_window.push_handlers(self.on_mouse_motion)

        events.AddListener(self)

    def update(self, timechange):
        pass

    def draw(self):
        if not self.can_active:
            if self.can_highlighted:
                self.can_sprite.color = (255, 20, 25)
            else:
                self.can_sprite.color = (255, 255, 255)
        else:
            self.can_sprite.color = (255, 255, 255)

        self.can_sprite.draw()

        glColor4f(1, 1, 1, 1)

        if not self.lid_active:
            if self.lid_highlighted:
                glColor4f(1, 0.1, 0.1, 1)
            else:
                glColor4f(1, 1, 1, 1)
        
        if self.opened:
            self.image_lid.blit(*self.lid_rect.bottomleft)

        glColor4f(1, 1, 1, 1)

    def on_mouse_press(self, x, y, button, modifiers):
        if self.opened and self.lid_rect.collide_point(x, y):
            self.set_lid_active()
        elif self.collides(x, y):
            self.fallen = False
            self.set_can_active()
            self.can_sprite.rotation = 0

            if self.opened:
                self.can_sprite.image = self.image_opened
            else:
                self.can_sprite.image = self.image_closed

    def set_can_active(self):
        window.game_window.set_mouse_visible(False)
        self.can_active = True
        events.Fire('CanTaken')

    def set_lid_active(self):
        window.game_window.set_mouse_visible(False)
        self.lid_active = True
        events.Fire('LidTaken')

    def collides(self, x,y):
        cs = self.can_sprite
        return (x > cs.x - cs.image.width/2 
            and x < cs.x + cs.image.width/2
            and y > cs.y - cs.image.height/2
            and y < cs.y + cs.image.height/2 )

    def on_mouse_release(self, x, y, button, modifiers):
        window.game_window.set_mouse_visible(True)
        #print "x=%d y=%d" % (x, y)
        if self.lid_active:
            if self.collides(x, y):
                self.can_sprite.image = self.image_closed
                self.opened = False
                events.Fire('LidClosed')
#.........这里部分代码省略.........
开发者ID:pdevine,项目名称:suburbia,代码行数:103,代码来源:garbage.py

示例11: Character

# 需要导入模块: from pyglet.sprite import Sprite [as 别名]
# 或者: from pyglet.sprite.Sprite import draw [as 别名]
class Character(object):

    def __init__(self, x, y, facing=Direction.NORTH):
        self.sprite = Sprite(self.Sprite.faces[facing], x, y)
        self.facing = facing
        self.movement_queue = []
        self.movement_ticks = 0

        self.current_health = self.health

    def draw(self):
        self.sprite.draw()

    def delete(self):
        self.sprite.delete()

    @property
    def x(self):
        return self.sprite.x

    @x.setter
    def x(self, nx):
        self.sprite.x = nx

    @property
    def y(self):
        return self.sprite.y

    @y.setter
    def y(self, ny):
        self.sprite.y = ny

    @property
    def color(self):
        return self.sprite.color

    @color.setter
    def color(self, ncolor):
        self.sprite.color = ncolor

    def look(self, direction):
        self.facing = direction
        self.sprite.image = self.Sprite.faces[direction]

    def move_to(self, x, y, duration=1):
        self.movement_queue.append((x, y, duration))

    def update(self, dt):
        if self.movement_queue:
            if self.movement_ticks == 0:
                self.last_stop = self.x, self.y
            ex, ey, time = self.movement_queue[0]
            sx, sy = self.last_stop
            if ex < sx and ey < sy:
                self.look(Direction.WEST)
            elif ex < sx:
                self.look(Direction.NORTH)
            elif ey < sy:
                self.look(Direction.SOUTH)
            else:
                self.look(Direction.EAST)
            self.movement_ticks += dt
            ex, ey, time = self.movement_queue[0]
            sx, sy = self.last_stop
            self.x += (ex - sx) * (dt / time)
            self.y += (ey - sy) * (dt / time)

            if self.movement_ticks >= time:
                self.x, self.y = int(ex), int(ey)
                del self.movement_queue[0]
                self.movement_ticks = 0
        else:
            self.look(self.facing)


    class Sprite(namedtuple("CharacterSprite", "x y facing moving_to internal_clock")):
#
#        @property
#        def image(self):
#            return self.faces[self.facing]
#
#        def update(self, dt):
#            return self.__class__(self.x, self.y, self.facing, self.moving_to, self.internal_clock + dt)
#
#        def move(self, new_x, new_y):
            pass
开发者ID:johnmendel,项目名称:python-tactics,代码行数:88,代码来源:new_sprite.py

示例12: Window

# 需要导入模块: from pyglet.sprite import Sprite [as 别名]
# 或者: from pyglet.sprite.Sprite import draw [as 别名]

#.........这里部分代码省略.........
    def game_reset(self):
        self.started = False
        self.rock_group = set()
        self.ship = PlayerSprite(self.ship_imgs, self.thruster_snd, 400, 250, 0, 0, 270, 35, self.ships, self.missiles)
        self.lives = 3
        self.score = 0
        # intro screen 
        # self.splash.draw()

    def display_score(self):
        self.text_lives = pyglet.text.Label('Lives=' + str(self.lives),
                                            font_name='Times New Roman',
                                            font_size=36, x=10, y=10)
        self.text_score = pyglet.text.Label('Score=' + str(self.score),
                                            font_name='Times New Roman',
                                            font_size=36, x=10, y=60)
    def start_game(self):
        #Function to start game on initial mouse click
        self.splash.delete()
        self.started = True

    def accel(self):
        self.ship.thrusters = True
    
    def decel(self):
        self.ship.thrusters = False

    def left(self):
        self.ship.angle_vel -= 5

    def right(self):
        self.ship.angle_vel += 5
    
    def fire(self):
        self.ship.shoot(self.missile_group)

    def on_mouse_press(self, x, y, button, modifiers):
        self.start_game()

    def on_key_press(self, symbol, modifiers):
        for key in self.key_downs:
            if key == symbol:
                self.key_downs[symbol]()

    def on_key_release(self, symbol, modifiers):
        for key in self.key_ups:
            if key == symbol:
                self.key_ups[symbol]()

    def put_rock(self):
        rock_position = utils.random_position(WIDTH, HEIGHT)
        rock = MovingSprite (self.rock_img, rock_position[0], rock_position[1],
                             sound=self.explosion_snd, diff=self.difficulty,
                             radius=40, batch=self.rocks)
        self.rock_group.add(rock)

    def trigger_put_rock(self):
        self.rock_trigger += 1
        if self.rock_trigger > 60 and len(self.rock_group) < 10:
            self.put_rock()
            self.rock_trigger = 0
    # TODO Implement Sheilds
    def on_draw(self):
        self.clear()
        self.background.blit(0, 0)
        self.ships.draw()
        self.rocks.draw()
        self.missiles.draw()
        self.text_lives.draw()
        self.text_score.draw()
        if not self.started:
           self.splash = Sprite(self.splash_img, 200, 125)
           self.splash.draw()

    def update(self, dt):
        if self.started:
            self.trigger_put_rock()
            for rock in self.rock_group:
                rock.update(WIDTH, HEIGHT) 
            self.ship.update(WIDTH, HEIGHT) 

            local_missiles = set(self.missile_group)
            for missile in local_missiles:
                if not missile.update(WIDTH, HEIGHT):
                    self.missile_group.remove(missile)
                    missile.delete()

            if group_collide(self.rock_group, self.ship):
                self.lives -= 1
                self.explosion_snd.play()

            if group_group_collide(self.missile_group, self.rock_group):
                self.score += 10
                self.difficulty  += self.score + 50
                self.explosion_snd.play()

            self.display_score()
        
        if self.lives < 0:
            self.game_reset()
开发者ID:laconic75,项目名称:Asteroids,代码行数:104,代码来源:asteroids.py


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