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


Python Sprite.setSizeScalar方法代码示例

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


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

示例1: Enemy

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import setSizeScalar [as 别名]
class Enemy():
    def __init__(self, enemyType, **kwargs):
        self.canvas = InstructionGroup()

        self.enemyType = enemyType
        self.sprite = Sprite()

        if self.enemyType == 'normal':
            self.setOffsetTheta(0)
            self.sprite.color.r = 0.0
            self.sprite.color.g = 0.2
            self.sprite.color.b = 0.5
        else:
            self.setOffsetTheta(math.pi / 2)
            self.sprite.color.r = 0.5
            self.sprite.color.g = 0.1
            self.sprite.color.b = 0.1

        self.health = 100

        self.pos = (0, 0)
        self.velocity = [0, 0]

        self.updateAppearance()

        self.canvas.add(self.sprite.canvas)

        self.shouldRemove = False

    def setOffsetTheta(self, offsetTheta):
        self.offsetTheta = offsetTheta
        self.otcos = math.cos(self.offsetTheta)
        self.otsin = math.sin(self.offsetTheta)


    def reset(self, isRespawned):
        sample = random.random()
        theta = math.pi * 2 * sample
        speed = 0.1
        self.isRespawned = isRespawned
        self.velocity = [math.cos(theta) * speed,
                         math.sin(theta) * speed]

    def setWorld(self, world):
        self.world = world

    def setCenterPos(self, centerPos):
    	self.pos = centerPos
        self.sprite.setCenterPos(centerPos)

    def decrement(self, beamState):
        delta = 0
        if beamState == 1:
            self.health -= 10
            if self.enemyType == 'normal':
                delta = 100
            else:
                delta = -500

        if self.health <= 0:
            self.shouldRemove = True
        else:
            self.updateAppearance()

        return delta



    def updateAppearance(self):
        baseSize = 30
        if not self.enemyType == 'normal':
            baseSize = 15

        factor = math.log(100 - self.health + 1)
        self.sprite.setSizeScalar(baseSize + factor * 10)

    def update(self, dt):
        worldVector = (self.world.direction[0] * self.world.speed,
                       self.world.direction[1] * self.world.speed)
        worldOffset = (worldVector[0] * self.otcos - worldVector[1] * self.otsin,
                       worldVector[0] * self.otsin - worldVector[1] * self.otcos)

        centerPos = (self.pos[0] + self.velocity[0] + worldOffset[0],
                     self.pos[1] + self.velocity[1] + worldOffset[1])

        if self.isRespawned:
            self.isRespawned = False

        if centerPos[0] < self.world.left:
            self.shouldRemove = True

        if centerPos[0] > self.world.right:
            self.shouldRemove = True

        if centerPos[1] < self.world.left:
            self.shouldRemove = True

        if centerPos[1] > self.world.right:
            self.shouldRemove = True

#.........这里部分代码省略.........
开发者ID:adparadise,项目名称:pmgj6-harvesters,代码行数:103,代码来源:enemy.py


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