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


Python Sprite.delete方法代码示例

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


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

示例1: value

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

示例2: SpriteItem

# 需要导入模块: from pyglet.sprite import Sprite [as 别名]
# 或者: from pyglet.sprite.Sprite import delete [as 别名]
class SpriteItem(GameItem):
    '''GameItem that is rendered as a single sprite'''

    images = None
    render_layer = 2 # birds and feathers


    def __init__(self, x=0, y=0):
        GameItem.__init__(self)
        self.x = x
        self.y = y
        self.rotation = 0

        self.sprite = None
        self.frame_idx = 0


    def add_to_batch(self, batch, groups):
        self.sprite = Sprite(
            self.images[self.frame_idx],
            batch=batch,
            group=groups[self.render_layer] )


    def remove_from_batch(self, batch):
        self.sprite.batch = None
        self.sprite.delete()


    def animate(self):
        self.sprite._x = self.x
        self.sprite._y = self.y
        self.sprite._rotation = degrees(self.rotation)
        image = self.images[self.frame_idx]
        if self.sprite.image != image:
            self.sprite.image = image
        else:
            self.sprite._update_position()
开发者ID:mjs,项目名称:brokenspell,代码行数:40,代码来源:spriteitem.py

示例3: Player

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

    sprite_img = None
    sprite_group = 'player'
    hb_img = None
    hb_group = 'player_hb'
    _die_invuln = 3

    def __init__(self, x, y, hb=None):
        super().__init__(x, y, hb=hb)
        self._focus = 0
        self.speed_multiplier = 500
        self.focus_multiplier = 0.5
        self.shooting = 0
        self.shot_rate = 20
        self.shot_state = 0
        self.bullets = BulletGroup()
        self.invuln = 0
        self.v = Vector(0, 0)
        self.hbsprite = None

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

    @x.setter
    def x(self, value):
        super(Player, self.__class__).x.fset(self, value)
        if hasattr(self, 'hbsprite') and self.hbsprite is not None:
            self.hbsprite.x = value

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

    @y.setter
    def y(self, value):
        super(Player, self.__class__).y.fset(self, value)
        if hasattr(self, 'hbsprite') and self.hbsprite is not None:
            self.hbsprite.y = value

    @property
    def speed(self):
        if self.focus:
            return self.speed_multiplier * self.focus_multiplier
        else:
            return self.speed_multiplier

    @property
    def focus(self):
        return int(self._focus)

    @focus.setter
    def focus(self, value):
        f = self.focus
        v = bool(value)
        if f != v:
            self._focus = v
            if v:
                cls = self.__class__
                self.hbsprite = Sprite(cls.hb_img, self.x, self.y)
                self.add_sprite(self.hbsprite, cls.hb_group)
            else:
                self.hbsprite.delete()
                self.hbsprite = None

    def die(self):
        if self.invuln > 0:
            return 1
        else:
            self.invuln += Player._die_invuln
            return 0

    def on_key_press(self, symbol, modifiers):
        if symbol == key.LSHIFT:
            self.focus = 1
        elif symbol == key.Z:
            self.shooting = 1

    def on_key_release(self, symbol, modifiers):
        if symbol == key.LSHIFT:
            self.focus = 0
        elif symbol == key.Z:
            self.shooting = 0

    def update(self, dt):
        # movement
        self.x += self.speed * self.v.x * dt
        self.y += self.speed * self.v.y * dt
        # bound movement
        if self.right > GAME_AREA.right:
            self.right = GAME_AREA.right
        elif self.left < GAME_AREA.left:
            self.left = GAME_AREA.left
        if self.bottom < GAME_AREA.bottom:
            self.bottom = GAME_AREA.bottom
        elif self.top > GAME_AREA.top:
            self.top = GAME_AREA.top
        # invuln
        if self.invuln > 0:
#.........这里部分代码省略.........
开发者ID:darkfeline,项目名称:TouhouS,代码行数:103,代码来源:__init__.py

示例4: Object

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

    sprite_img = None
    sprite_group = ''

    def __init__(self, x, y, hb=None):
        super().__init__()
        cls = self.__class__
        self.rect = primitives.Rect(0, 0, cls.sprite_img.width,
                cls.sprite_img.height)
        self.hb = hb
        self.sprite = Sprite(cls.sprite_img)
        self.add_sprite(self.sprite, cls.sprite_group)
        self.x, self.y = x, y

    @property
    def x(self):
        return self.rect.centerx

    @x.setter
    def x(self, value):
        self.rect.centerx = value
        if isinstance(self.hb, primitives.Circle):
            self.hb.x = value
        elif isinstance(self.hb, primitives.Rect):
            self.hb.centerx = value
        self.sprite.x = value

    @property
    def y(self):
        return self.rect.centery

    @y.setter
    def y(self, value):
        self.rect.centery = value
        if isinstance(self.hb, primitives.Circle):
            self.hb.y = value
        elif isinstance(self.hb, primitives.Rect):
            self.hb.centery = value
        self.sprite.y = value

    @property
    def left(self):
        return self.rect.left

    @left.setter
    def left(self, value):
        self.rect.left = value

    @property
    def right(self):
        return self.rect.right

    @right.setter
    def right(self, value):
        self.rect.right = value

    @property
    def top(self):
        return self.rect.top

    @top.setter
    def top(self, value):
        self.rect.top = value

    @property
    def bottom(self):
        return self.rect.bottom

    @bottom.setter
    def bottom(self, value):
        self.rect.bottom = value

    @property
    def center(self):
        return self.rect.center

    @center.setter
    def center(self, value):
        self.rect.center = value

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

    def collide(self, other):
        if isinstance(other, Object):
            return self.hb.collide(other.hb)
        elif isinstance(other, Group):
            x = []
            for object in other:
                if self.collide(object):
                    x.append(object)
            return x
        else:
            raise NotImplementedError
开发者ID:darkfeline,项目名称:TouhouS,代码行数:97,代码来源:object.py

示例5: Player

# 需要导入模块: from pyglet.sprite import Sprite [as 别名]
# 或者: from pyglet.sprite.Sprite import delete [as 别名]
class Player(InertialObject):
    def __init__(self, name="", hull_image=None, engine_image=None,
                 x=0.0, y=0.0, thrust=200.0, maneuvering_thrust=360.0,
                 weapon_projectile_image=None, weapon_projectile_speed=700.0,
                 *args, **kwargs):

        super(Player, self).__init__(img=hull_image, name=name,
                                     vulnerable=True, x=x, y=y,
                                     *args, **kwargs)

        self.engineflame = Sprite(img=engine_image, x=x, y=y, *args, **kwargs)
        self.engineflame.visible = False

        self.thrust = thrust
        self.maneuvering_thrust = maneuvering_thrust

        self.weapon_projectile_image = weapon_projectile_image
        self.weapon_projectile_speed = weapon_projectile_speed

        self.center_x = x
        self.center_y = y

        self.key_handler = key.KeyStateHandler()

    def fire(self):
        angle_radians = math.radians(self.rotation)
        ship_radius = self.image.width/2 + 5.0
        bullet_x = self.x + math.sin(angle_radians) * ship_radius
        bullet_y = self.y + (math.cos(angle_radians) * ship_radius)
        new_bullet = Projectile(name="bullet",
                                img=self.weapon_projectile_image,
                                x=bullet_x, y=bullet_y, batch=self.batch)
        new_bullet.velocity_x = (
            self.velocity_x +
            math.sin(angle_radians) * self.weapon_projectile_speed
        )
        new_bullet.velocity_y = (
            self.velocity_y +
            math.cos(angle_radians) * self.weapon_projectile_speed
        )
        self.new_objects.append(new_bullet)

    def update(self, dt):
        rotational_dv = self.maneuvering_thrust * dt
        propulsive_dv = self.thrust * dt

        modified_rot_speed = self.rotation_speed
        if self.key_handler[key.RIGHT]:
            modified_rot_speed += rotational_dv
        if self.key_handler[key.LEFT]:
            modified_rot_speed -= rotational_dv
        if self.key_handler[key.DOWN]:
            direction = 1.0
            if self.rotation_speed < 0:
                direction = -1.0
            abs_rotation = modified_rot_speed * direction
            modified_rot_speed = direction * (abs_rotation - rotational_dv)
            if (direction * modified_rot_speed) < 0:
                modified_rot_speed = 0.0
        if self.key_handler[key.SPACE]:
            self.fire()

        # interpolate accelerated rotation change
        self.rotation_speed = (modified_rot_speed + self.rotation_speed) / 2.0

        modified_vx = self.velocity_x
        modified_vy = self.velocity_y
        if self.key_handler[key.UP]:
            angle_radians = math.radians(self.rotation)
            modified_vx += math.sin(angle_radians) * propulsive_dv
            modified_vy += math.cos(angle_radians) * propulsive_dv
            self.engineflame.visible = True
        else:
            self.engineflame.visible = False

        # iterpolate accelerated velocity change
        self.velocity_x = (modified_vx + self.velocity_x) / 2.0
        self.velocity_y = (modified_vy + self.velocity_y) / 2.0

        super(Player, self).update(dt)

        # update subsprites
        self.engineflame.x = self.x
        self.engineflame.y = self.y
        self.engineflame.rotation = self.rotation

        self.rotation_speed = modified_rot_speed
        self.velocity_x = modified_vx
        self.velocity_y = modified_vy

        if self.key_handler[key.C]:
            self.x = self.center_x
            self.y = self.center_y
            self.velocity_x = 0.0
            self.velocity_y = 0.0
            self.rotation = 0.0
            self.rotation_speed = 0.0

    def delete(self):
        self.engineflame.delete()
#.........这里部分代码省略.........
开发者ID:hoylemd,项目名称:pysteroids,代码行数:103,代码来源:player.py

示例6: Player

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

#.........这里部分代码省略.........
        # rotate ship
        self.rotation += self.rotation_speed

        if self.key_handler[key.UP]:
            angle_radians = -math.radians(self.rotation)
            force_x = math.cos(angle_radians) * self.thrust * dt
            force_y = math.sin(angle_radians) * self.thrust * dt
            self.velocity_x += force_x
            self.velocity_y += force_y

            self.engine_sprite.rotation = self.rotation
            self.engine_sprite.x = self.x
            self.engine_sprite.y = self.y
            self.engine_sprite.visible = True

            # smooth sound ==
            self.engine_player.play()
            if self.engine_player.volume < 1.8:
                self.engine_player.volume += 1.2 * dt
        else:
            self.engine_sprite.visible = False
            if self.engine_player.volume > 0.01:
                self.engine_player.volume -= 1.5 * dt
            else:
                self.engine_player.pause()
            # ===============



        if self.invulnerable:
            self.shield.up = True
        else:
            self.shield.up = False

        self.shield.x = self.x
        self.shield.y = self.y
        self.shield.update(dt)


        if self.key_handler[key.SPACE]:
            # fires has long has space is held
            self.fire(dt)


    """Methods that control shield invulnerability
    Can take 1 argument, deltatime(dt), invulnerability leght"""
    def set_invulnerable(self, dt=5.0):
        self.shield_sound.play()
        self.invulnerable = True

        # time to vulnerable
        pyglet.clock.schedule_once(self.set_vulnerable, dt)
    def set_vulnerable(self, dt):
        self.invulnerable = False


    def fire(self, dt):
        # fires only if loaded
        if self.loaded:
            angle_radians = -math.radians(self.rotation)
            force_x = math.cos(angle_radians) * self.recoil * dt
            force_y = math.sin(angle_radians) * self.recoil * dt
            self.velocity_x -= force_x
            self.velocity_y -= force_y

            angle_radians = -math.radians(self.rotation)

            ship_radius = self.ship_radius
            bullet_x = self.x + math.cos(angle_radians) * ship_radius
            bullet_y = self.y + math.sin(angle_radians) * ship_radius
            new_bullet = bullet.Bullet(screen_size=self.screen_size,
                                x=bullet_x, y=bullet_y, batch=self.batch)

            bullet_vx = (self.velocity_x +
                math.cos(angle_radians) * self.bullet_speed)
            bullet_vy = (self.velocity_y +
                math.sin(angle_radians) * self.bullet_speed)
            new_bullet.velocity_x = bullet_vx
            new_bullet.velocity_y = bullet_vy

            self.bullet_sound.play()
            self.new_objects.append(new_bullet)

            # unloading gun
            self.loaded = False
            pyglet.clock.schedule_once(self.reload, 0.1)

    def reload(self, dt):
        self.loaded = True

    #def on_key_press(self, symbol, modifiers):
    ## single short fire
    #    if symbol == key.SPACE:
    #        self.fire()

    def delete(self):
        self.shield.delete()
        self.engine_sprite.delete()
        self.engine_player.delete()
        super().delete()
开发者ID:SimonWoodburyForget,项目名称:asteroids,代码行数:104,代码来源:player.py

示例7: Character

# 需要导入模块: from pyglet.sprite import Sprite [as 别名]
# 或者: from pyglet.sprite.Sprite import delete [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

示例8: Window

# 需要导入模块: from pyglet.sprite import Sprite [as 别名]
# 或者: from pyglet.sprite.Sprite import delete [as 别名]
class Window(pyglet.window.Window):
    def __init__(self, *args, **kwargs):
        super(Window, self).__init__(*args, **kwargs)

        self.score = 0
        self.difficulty = self.score + 50
        self.lives = 3
        self.time = 0.5
        self.ships = pyglet.graphics.Batch()
        self.rocks = pyglet.graphics.Batch()
        self.missiles = pyglet.graphics.Batch()
        self.started = False
        self.rock_trigger = 0

        # Images
        self.background = pyglet.image.load('static/images/nebula_blue.s2014.png')

        self.rock_img = pyglet.image.load('static/images/asteroid_blue.png')
        utils.center_image_anchor(self.rock_img)

        ship_sequence = pyglet.image.load('static/images/double_ship.png')
        self.ship_imgs = pyglet.image.ImageGrid(ship_sequence, 1, 2)
        utils.center_image_grid_anchors(self.ship_imgs)
        self.splash_img = pyglet.image.load('static/images/splash.png') 

        # Sounds
        self.thruster_snd = pyglet.media.load('static/sounds/rocket.ogg', streaming=False)
        self.explosion_snd = pyglet.media.load('static/sounds/explosion.ogg', streaming=False)
        self.background_music = pyglet.media.load('static/sounds/space1.mp3', streaming=False)
        self.background_music.play()

        # Sprite Groups
        self.rock_group = set()
        self.missile_group = set()

        # Spites 
        self.ship = PlayerSprite(self.ship_imgs, self.thruster_snd, 400, 250, 0, 0, 270, 35, self.ships, self.missiles)
        self.splash = Sprite(self.splash_img, 200, 125)

        # Screen Text
        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)

        # Keymaps
        self.key_downs = {key.UP:self.accel, key.LEFT:self.left, key.RIGHT:self.right, key.SPACE:self.fire, key.ESCAPE:pyglet.app.exit}
        self.key_ups = {key.UP:self.decel, key.LEFT:self.right, key.RIGHT:self.left}

        pyglet.clock.schedule_interval(self.update, 1/60.0)  # update at 60Hz
    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]()
#.........这里部分代码省略.........
开发者ID:laconic75,项目名称:Asteroids,代码行数:103,代码来源:asteroids.py


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