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


Python Sprite.update方法代码示例

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


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

示例1: __init__

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import update [as 别名]
class Entity:
    count = 1
    def __init__(self, stats, ent_type, solid, name = "", id_num=None):
        if not id_num:
            self.id_num = Entity.count
            Entity.count += 1
        else:
            self.id_num = id_num
        self.stats = stats
        self.ent_type = ent_type
        if ent_type == SHEEP:
                self.sprite = Sprite(TYPES[self.ent_type], stats.x, stats.y, 32, 32, False, 3, SHEEP_SPRITES)
        elif ent_type == GHOST1:
            self.sprite = Sprite(TYPES[self.ent_type], stats.x, stats.y, 32, 32, False, 3, GHOST1_SPRITES)
        elif ent_type == GHOST2:
            self.sprite = Sprite(TYPES[self.ent_type], stats.x, stats.y, 32, 32, False, 3, GHOST2_SPRITES)
        elif ent_type == GHOST3:
            self.sprite = Sprite(TYPES[self.ent_type], stats.x, stats.y, 32, 32, False, 3, GHOST3_SPRITES)
        elif ent_type == GHOST4:
            self.sprite = Sprite(TYPES[self.ent_type], stats.x, stats.y, 32, 32, False, 3, GHOST4_SPRITES)

        else:
            self.sprite = Sprite(TYPES[self.ent_type], stats.x, stats.y)
        self.solid = solid
        self.name = name

    def update(self, viewport):
        self.sprite.update(self.stats, viewport)

    def getUpdate(self):
        return Update(self.id_num, self.ent_type, self.stats, self.name)
开发者ID:LindseyB,项目名称:IronTrotter,代码行数:33,代码来源:entity.py

示例2: update

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import update [as 别名]
 def update(self):
     Sprite.update(self)
     self.color=(random.random(),random.random(),random.random())
     if self.lifeTime>0:
         self.lifeTime-=1
     self.posX+=self.velX
     self.posY+=self.velY
开发者ID:Zheroth,项目名称:BiokteriiFuzzy,代码行数:9,代码来源:dyingParticle.py

示例3: update

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import update [as 别名]
	def update(self, dt):
		Sprite.update(self, dt)

		if self.chatTimer > 0:
			self.chatTimer -= dt

		if self.team == 0:
			self.flipHorizontal = False
		else:
			self.flipHorizontal = True			

		if self.hitTimer > 0:
			self.hitTimer -= dt
			self.serverOrSelfPlay("hit")
			self.velocity.zero()
		elif self.charge > 0:
			self.serverOrSelfPlay("charge")
			self.velocity.zero()
		else:
			self.serverOrSelfPlay("stand")
			self.velocity, animname = self.getVelocityAndAnim(self.xDirection, self.yDirection)

		self.collideWalls()

		self.throwTimer -= dt
		if self.throwingWaitForServer or self.throwTimer > 0:
			self.velocity.zero()

		if g.SERVER and self.lastAnimation != self.currentAnimation:
			g.game.net.sendAnimation(self)
		self.lastAnimation = self.currentAnimation
开发者ID:morganq,项目名称:udpgame,代码行数:33,代码来源:player.py

示例4: update

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import update [as 别名]
    def update(self):
        Sprite.update(self)

        if self.size<=0:
            self.isDead=True

        self.color=(random.random(),1,1)
        if self.posX<self.targetCell.posX:
            self.posX+=self.velX
        if self.posX>self.targetCell.posX:
            self.posX-=self.velX

        if self.posY<self.targetCell.posY:
            self.posY+=2
        if self.posY>self.targetCell.posY+self.targetCell.height:
            self.posY-=2

        self.posY+=math.sin(self.degreePosY)
        self.degreePosY+=self.deltaDegree

        distance=self.posX-self.originX
        self.power=self.originPower-(distance*0.012)
        self.size=self.power*self.originSize/self.originPower
        self.alpha=self.size

        if Sprite.is_colliding_with(self,self.targetCell):
            self.isDead=True
            if(self.targetCell.shield>0):
                self.targetCell.shield-=self.power
            else:
                self.targetCell.hp-=self.power
开发者ID:Zheroth,项目名称:BiokteriiFuzzy,代码行数:33,代码来源:attackParticle.py

示例5: ColorChangingBlock

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import update [as 别名]
class ColorChangingBlock(PhysicsObject):

	PATTERN_SIZE = 3

	def __init__(self, pos, interval, exclude_color):
		PhysicsObject.__init__(self, (pos[0] + 16, pos[1] + 16), (0, 0), (32, 32), BODY_STATIC)
		self.sprite = Sprite('./assets/img/blocks.png', (32, 32), 0.1)

		self.id = ID_OBJ

		self.timer = 0.0
		self.interval = float(interval)

		self.colors = ['red', 'green', 'blue']
		self.exclude_color = self.colors.index(exclude_color)

		# create a pattern for changing colors
		self.pattern = []

		while len(self.pattern) < self.PATTERN_SIZE:
			color = random.randint(0, 2)
			if not color == self.exclude_color and self.pattern.count(color) < 2:
				self.pattern.append(color)

		self.pattern_color_pointer = random.randint(0, self.PATTERN_SIZE - 1)
		self.previous_active_color = 0
		self.active_color = self.colors[ self.pattern[self.pattern_color_pointer] ]
		self.sprite.use_frames([ self.pattern[self.pattern_color_pointer] ])

	def on_collide_obj(self, obj):
		return True

	def on_collide_platform(self, plat):
		return True

	def update(self, dt):
		self.sprite.update(dt)
		self.timer += dt

		self.previous_active_color = self.active_color
		
		if self.timer >= self.interval:
			self.timer = 0
			self.previous_pointer = self.pattern_color_pointer
			self.pattern_color_pointer += 1

			if self.pattern_color_pointer >= self.PATTERN_SIZE:
				self.pattern_color_pointer = 0

			next_color = self.pattern[self.pattern_color_pointer]
			self.sprite.use_frames([next_color])
			self.active_color = self.colors[next_color]

	def draw(self, screen, view_rect):
		rect = Rect(self.rect.left, self.rect.top, self.rect.width, self.rect.height)
		rect.left -= view_rect.left - rect.width / 2
		rect.top -= view_rect.top

		self.sprite.draw(screen, rect)
开发者ID:glhrmfrts,项目名称:rgb,代码行数:61,代码来源:play_scene.py

示例6: update

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import update [as 别名]
    def update(self):
        """Update the character each frame."""

        # If the characters shoots, shoot but only when its weapon is reloaded.
        # optional ideas: player can hit a key during reload period to gain a
        #                 save from the wait penalty (instant reload).
        if self.firing:
            self.fire_weapon()

        # Update the character's graphic.
        Sprite.update(self)
开发者ID:derrida,项目名称:shmuppy,代码行数:13,代码来源:character.py

示例7: update

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import update [as 别名]
    def update(self):
        Sprite.update(self)
        self.rot+=self.transDeltaRot*self.rotDirection
        self.degreeRot+=self.deltaDegreeRot

        if abs(self.transDeltaRot-self.deltaRot)<=self.deltaDeltaRot*2:
            self.transDeltaRot=self.deltaRot
        elif self.transDeltaRot < self.deltaRot:
            self.transDeltaRot+=self.deltaDeltaRot
        elif self.transDeltaRot > self.deltaRot:
            self.transDeltaRot-=self.deltaDeltaRot
开发者ID:tucif,项目名称:Biokterii,代码行数:13,代码来源:cell.py

示例8: update

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import update [as 别名]
    def update(self):
        Sprite.update(self)
        self.posX += self.velX
        self.posY += self.velY
        if self.transHp <= 0:
            self.isDead = True

        if self.transHp < self.hp - self.deltaHp:
            self.transHp += self.deltaHp
        elif self.transHp > self.hp + self.deltaHp:
            self.transHp -= self.deltaHp
        elif self.transHp != self.hp:
            self.transHp = self.hp
开发者ID:tucif,项目名称:Biokterii,代码行数:15,代码来源:virus.py

示例9: update

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import update [as 别名]
	def update (self, time):
		
		Sprite.update(self, time)		
		self.light.update(time)
		
		if self.timer is not None and not self.timer.is_complete():

			self.timer.update(time)
			
			self.x = self._prev_x + self.timer.percent_done * self._move_x
			self.y = self._prev_y + self.timer.percent_done * self._move_y

		# adjust player light position
		self.light.x = self.x
		self.light.y = self.y
开发者ID:thiagojobson,项目名称:Maze-Of-Kindred,代码行数:17,代码来源:player.py

示例10: LavaBlock

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import update [as 别名]
class LavaBlock(PhysicsObject):

	def __init__(self, pos):
		PhysicsObject.__init__(self, (pos[0] + 16, pos[1] + 16), (0, 0), (32, 32), BODY_STATIC)
		self.sprite = Sprite('./assets/img/blocks.png', (32, 32), 0.1)
		self.sprite.use_frames([0, 1, 2])
		self.id = ID_OBJ

	def update(self, dt):
		self.sprite.update(dt)

	def draw(self, screen, view_rect):
		rect = Rect(self.rect.left, self.rect.top, self.rect.width, self.rect.height)
		rect.left -= view_rect.left - rect.width / 2
		rect.top -= view_rect.top
		self.sprite.draw(screen, rect)
开发者ID:glhrmfrts,项目名称:rgb,代码行数:18,代码来源:play_scene.py

示例11: ImpulseBlock

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import update [as 别名]
class ImpulseBlock(PhysicsObject):

	BOUNCE_FACTOR = 1.35
	BOUNCE_MIN_INTERVAL = 0.5

	def __init__(self, pos, color, direction):
		PhysicsObject.__init__(self, (pos[0] + 16, pos[1] + 16), (0, 0), (32, 32), BODY_STATIC)
		self.sprite = Sprite('./assets/img/arrow_blocks.png', (32, 32), 0.1)
		self.id = ID_OBJ
		self.colors = COLORS + ['gray']
		color_index = self.colors.index(color)
		self.active_color = self.colors[ color_index ]
		self.sprite.use_frames([color_index])
		self.sprite.update(5)
		self.direction = direction # 1(down) or -1(up)
		self.sprite.set_direction(False, direction)

	def change_obj_velocity(self, obj):
		if obj.active_color != self.active_color:
			if obj.bounce_timer <= 0.0:
				if obj.id == ID_PLAYER:
					PLAY_SOUND(obj.sound_jump)
				obj.bounce_timer = self.BOUNCE_MIN_INTERVAL
				if obj.vel.y < 50:
					obj.vel.y = PLAYER_JUMP_FORCE
				else:
					obj.vel.y = (obj.vel.y * self.BOUNCE_FACTOR) * self.direction
			return True
		return False

	def update(self, dt):
		pass

	def draw(self, screen, view_rect):
		rect = copy.copy(self.rect)
		rect.left -= view_rect.left - rect.width / 2
		rect.top -= view_rect.top
		self.sprite.draw(screen, rect)
开发者ID:glhrmfrts,项目名称:rgb,代码行数:40,代码来源:play_scene.py

示例12: MovableBlock

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import update [as 别名]
class MovableBlock(PhysicsObject):

	def __init__(self, pos, color):
		PhysicsObject.__init__(self, (pos[0] + 16, pos[1] + 16), (0, 0), (32, 32), BODY_DYNAMIC)
		self.set_foot(True)
		self.sprite = Sprite('./assets/img/ground.png', (32, 32), 0.1)
		self.bounce_timer = 0.0

		self.id = ID_MOVABLE_BLOCK
		self.acceleration = 300

		self.colors = COLORS + ['gray']
		self.colors_values = [RED, GREEN, BLUE, GRAY]
		self.color_index = self.colors.index(color)

		self.active_color = self.colors[ self.colors.index(color) ]
		self.previous_active_color = 0

		self.sprite.use_frames([ 12 + self.color_index ])
		self.sprite.update(5)

	def on_collide_obj(self, obj):
		return True

	def on_collide_platform(self, p):
		return p.layer != self.active_color

	def update(self, dt):
		PhysicsObject.update(self, dt)
		self.sprite.update(dt)

		if self.bounce_timer > 0.0:
			self.bounce_timer -= dt

	def draw(self, screen, view_rect):
		rect = copy.copy(self.rect)
		rect.left += rect.width / 2
		self.sprite.draw(screen, rect)
开发者ID:glhrmfrts,项目名称:rgb,代码行数:40,代码来源:play_scene.py

示例13: Player

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

	def __init__ (self, x, y):
		
		Sprite.__init__(self, x, y, 'princess')
		
		self.grid_x = x
		self.grid_y = y

		self.light = Sprite(x, y, 'light')
		self.light.offset_x = -96
		self.light.offset_y = -106
		self.light.play('default', loop=True)
		
		# walk timer
		self.timer = None
		
		# default orientation
		self.ori = 'up'
		
		# animations		
		self.add_anim('walk_up', common.WALK_MOVEMENT_TIME, range(0, 9))
		self.add_anim('walk_left', common.WALK_MOVEMENT_TIME, range(9, 18))
		self.add_anim('walk_down', common.WALK_MOVEMENT_TIME, range(18, 27))
		self.add_anim('walk_right', common.WALK_MOVEMENT_TIME, range(27, 36))
	
	@property
	def grid_x (self):		
		return int(self.x / common.TILE_SIZE)
		
	@property
	def grid_y (self):		
		return int(self.y / common.TILE_SIZE)
	
	@grid_x.setter
	def grid_x (self, x):		
		self.x = x * common.TILE_SIZE
		
	@grid_y.setter
	def grid_y (self, y):		
		self.y = y * common.TILE_SIZE
	
	def walk (self, x, y):
		
		assert(x == 1 or x == -1 or x == 0)
		assert(y == 1 or y == -1 or y == 0)
		
		if x == 0 and y == 0:
			return
		
		elif self.timer is None or self.timer.is_complete():
		
			x *= common.TILE_SIZE
			y *= common.TILE_SIZE
			
			self._prev_x = self.x
			self._prev_y = self.y
			
			self._next_x = self.x + x
			self._next_y = self.y + y
			
			self._move_x = x
			self._move_y = y
			
			if x < 0:
				self.ori = 'left'
			elif x > 0:
				self.ori = 'right'
			elif y > 0:
				self.ori = 'down'
			else:
				self.ori = 'up'

			self.play('walk_' + self.ori)
			self.timer = Timer(common.WALK_MOVEMENT_TIME)
	
	def update (self, time):
		
		Sprite.update(self, time)		
		self.light.update(time)
		
		if self.timer is not None and not self.timer.is_complete():

			self.timer.update(time)
			
			self.x = self._prev_x + self.timer.percent_done * self._move_x
			self.y = self._prev_y + self.timer.percent_done * self._move_y

		# adjust player light position
		self.light.x = self.x
		self.light.y = self.y
开发者ID:thiagojobson,项目名称:Maze-Of-Kindred,代码行数:93,代码来源:player.py

示例14: __init__

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import update [as 别名]
class Perso:
    def __init__(self, x, y, path, difficulty):
        self.HIT_DURATION = 0.8
        self.HURT_DURATION = 0.8
        self.HURT_POWER = 300
        self.hitTime = 0
        self.hurtTime = 0

        self.state = "normal"
        self.sprite = Sprite(path)
        self.sprite.rect.x = x
        self.sprite.rect.y = y

        self.pos = [x,y]
        self.speed = difficulty * 1.5 + 6
        self.life = 1

        self.pushedVector = [0,0]

    def update(self, timeElapsed):
        if self.state == "hit":
            self.hitTime += timeElapsed
            if self.hitTime >= self.HIT_DURATION:
                self.normal()
                self.hitTime = 0
        if self.state == "hurt":
            self.hurtTime += timeElapsed
            if self.hurtTime >= self.HURT_DURATION:
                self.normal()
                self.hurtTime = 0

        self.updatePos(timeElapsed)
        self.sprite.update(timeElapsed)

    def updatePos(self, timeElapsed):
        if self.pos[0] < 25:
            self.pos[0] = 25
            self.pushedVector[0] = -self.pushedVector[0]
        elif self.pos[0] > 725:
            self.pos[0] = 725
            self.pushedVector[0] = -self.pushedVector[0]
        if self.pos[1] < 200:
            self.pos[1] = 200
            self.pushedVector[1] = -self.pushedVector[1]
        elif self.pos[1] > 525:
            self.pos[1] = 525
            self.pushedVector[1] = -self.pushedVector[1]

        self.pos[0] = self.pos[0] + self.pushedVector[0] * timeElapsed / self.HURT_DURATION
        self.pos[1] = self.pos[1] + self.pushedVector[1] * timeElapsed / self.HURT_DURATION
        self.pushedVector[0] = self.pushedVector[0] - self.pushedVector[0] * timeElapsed / self.HURT_DURATION
        self.pushedVector[1] = self.pushedVector[1] - self.pushedVector[1] * timeElapsed / self.HURT_DURATION

    def draw(self, screen):
        self.sprite.draw(screen, self.pos)

    def move(self, direction):
        if direction == "up":
            self.pos[1] -= self.speed
        elif direction == "left":
            self.pos[0] -= self.speed
        elif direction == "right":
            self.pos[0] += self.speed
        elif direction == "down":
            self.pos[1] += self.speed

        if self.state != "hit" and self.state != "hurt":
            self.sprite.changeSprite(direction)

    def normal(self):
        self.state = "normal"
        self.sprite.changeSprite("normal")

    def hit(self):
        if self.state != "hit" and self.state != "hurt":
            self.state = "hit"
            self.sprite.changeSprite("action")

            return True
        else:
            return False

    def isHurt(self):
        return self.state == "hurt"
    
    def hurt(self, pos):
        newPos = [self.pos[0] - pos[0], self.pos[1] - pos[1]]
        if newPos[0] == 0 and newPos[1] == 0:
            newPos[0] = 1
            newPos[1] = 1
        max = abs(newPos[0]) if (abs(newPos[0]) > abs(newPos[1])) else abs(newPos[1])
        self.pushedVector = [self.HURT_POWER * newPos[0] / max, self.HURT_POWER * newPos[1] / max]
        print self.pushedVector
        self.state = "hurt"
        self.sprite.changeSprite("action")
开发者ID:FalconX4,项目名称:Arcade-CS-Games,代码行数:97,代码来源:perso.py

示例15: update

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import update [as 别名]
    def update(self,state):
        Sprite.update(self)
        
        if state=="Running":
            for particle in self.pushParticles:
                particle.update()
            if abs(self.transVelY-self.velY)<=self.deltaTransY*2:
                self.trasnVelY=self.velY
            elif self.transVelY < self.velY:
                self.transVelY+=self.deltaTransY
            elif self.transVelY > self.velY:
                self.transVelY-=self.deltaTransY

            if abs(self.transVelX-self.velX)<=self.deltaTransX*2:
                self.transVelX=self.velX
            elif self.transVelX < self.velX:
                self.transVelX+=self.deltaTransX
            elif self.transVelX > self.velX:
                self.transVelX-=self.deltaTransX

            if abs(self.transDeltaRot-self.deltaRot)<=self.deltaDeltaRot*2:
                self.transDeltaRot=self.deltaRot
            elif self.transDeltaRot < self.deltaRot:
                self.transDeltaRot+=self.deltaDeltaRot
            elif self.transDeltaRot > self.deltaRot:
                self.transDeltaRot-=self.deltaDeltaRot

            self.rot+=self.transDeltaRot*self.rotDirection

            self.degreeRotY+=self.deltaRot
            if self.degreeRotY>360:
                self.degreeRotY=0

            if self.hp<=0:
                self.isDead=True
            else:
                self.isDead=False;

            self.posX+=self.transVelX
            self.posY+=self.transVelY
            self.posY+=math.sin(self.degreeRotY)
            self.posX+=math.sin(self.degreeRotX)

            if self.targetCell:
                #Get close to target
                (myX,myY)=self.get_center()
                (targetX,targetY)=self.targetCell.get_center()
                absX=abs(myX-targetX)
                absY=abs(myY-targetY)

                if absX >self.limitMax:
                    if myX<targetX:
                        self.velX=self.baseVelX
                    elif self.posX+self.width:
                        self.velX=-self.baseVelX

                elif absX<self.limitMin:
                    if myX<targetX:
                        self.velX=-self.baseVelX
                    else:
                        self.velX=+self.baseVelX
                else:
                    self.velX=0

                if absY >self.limitMax:
                    if myY<targetY:
                        self.velY=self.baseVelY
                    else:
                        self.velY=-self.baseVelY
                elif absY<self.limitMin:
                    if myY<targetY:
                        self.velY=-self.baseVelY
                    else:
                        self.velY=+self.baseVelY
                else:
                    self.velY=0
                if self.status=="Analyzing":
                    self.deltaRot=0
                    self.limitMax=100
                    self.limitMin=100
                    if self.degreeRotX==0:
                        self.degreeRotX=random.random()
                    if self.degreeRotY==0:
                        self.degreeRotY=random.random()
                if self.status=="Attacking":
                    self.deltaRot=0.1
                    self.limitMax=40
                    self.limitMin=1
                    self.degreeRotY=0
                    self.degreeRotX=0
                if self.status=="Defending":
                    self.deltaRot=0.2
                    self.limitMax=300
                    self.limitMin=200
                if self.status=="Eating":
                    self.deltaRot=-0.2
                    self.limitMax=30
                    self.limitMin=2
                    self.degreeRotY=0
                    self.degreeRotX=0
#.........这里部分代码省略.........
开发者ID:Zheroth,项目名称:BiokteriiNeural,代码行数:103,代码来源:virus.py


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