本文整理汇总了Python中sprite.Sprite._render方法的典型用法代码示例。如果您正苦于以下问题:Python Sprite._render方法的具体用法?Python Sprite._render怎么用?Python Sprite._render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sprite.Sprite
的用法示例。
在下文中一共展示了Sprite._render方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Dragon
# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import _render [as 别名]
class Dragon(object):
FULL_LIFE = 15.0
ATTACK_CHANCE = 0.4
DEFENSE_CHANCE = 0.7
CHARGE_CHANCE = 0.9
SPELL_CHANCE = 1
def __init__(self, level):
#Character images
self.sprite_attack = Sprite(Consts.DRAGON_ATTACK, 10, 120)
self.sprite = Sprite(Consts.DRAGON_STILL, 10, 100)
self.sprite._play(Consts.PLAY_INFINITY)
self.sprite_defense = Sprite(Consts.SPRITE_DEFENSE, 25, 70)
self.sprite_charge = Sprite(Consts.SPRITE_CHARGE, 11, 90)
#self.sprite_spell = Sprite(Consts.SPELL_DRAGON, 25, 90)
#Attributes
if(level > 1):
self.setAttributes(level, level, 5+level)
else:
self.setAttributes(1, 1, 5)
#life
self.life = self.FULL_LIFE
self.lifebar_rect = pygame.Rect(Consts.DRAGON_POSITION[0]+14,Consts.DRAGON_POSITION[1]+8,225,13)
self.charged = 1
def setAttributes(self, strength, defence, magic):
self.strength = strength
self.defence = defence
self.magic = magic
def update(self):
self.sprite_attack._update()
self.sprite._update()
self.sprite_defense._update()
self.sprite_charge._update()
#self.sprite_spell._update()
def render(self, screen):
#character
if(self.sprite_attack.is_playing()):
self.sprite_attack._render(screen, Consts.DRAGON_POSITION)
else:
self.sprite._render(screen, Consts.DRAGON_POSITION)
if(self.sprite_defense.is_playing()):
self.sprite_defense._render(screen, (Consts.DRAGON_POSITION[0]+30, Consts.DRAGON_POSITION[1]+30))
if(self.sprite_charge.is_playing()):
self.sprite_charge._render(screen, (Consts.DRAGON_POSITION[0]+30,Consts.DRAGON_POSITION[1]+30))
#if(self.sprite_spell.is_playing()):
# self.sprite_spell._render(screen, Consts.CHARACTER_POSITION)
#lifebar
if(self.life>0):
current_lifebar_rect = pygame.Rect(self.lifebar_rect)
current_lifebar_rect.width = (self.life/self.FULL_LIFE)*self.lifebar_rect.width
pygame.draw.rect(screen, Consts.RED_COLOR, current_lifebar_rect)
pygame.draw.rect(screen, Consts.BLACK_COLOR, self.lifebar_rect, 2)
def attack(self):
self.sprite_attack._play(1)
def defense(self):
self.sprite_defense._play(1)
def spell(self): pass
#self.sprite_spell._play(1)
def charge(self):
self.charged *= 2
self.sprite_charge._play(1)
def unCharge(self):
load = self.charged
self.charged = 1
return load
def getMovement(self):
rand = random.random()
result = 0
if(rand<self.ATTACK_CHANCE):
result = Consts.ATTACK
elif(rand<self.DEFENSE_CHANCE):
result = Consts.DEFENSE
elif(rand<self.CHARGE_CHANCE):
result = Consts.SPELL
#.........这里部分代码省略.........
示例2: Character
# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import _render [as 别名]
class Character(object):
FULL_LIFE = 10.0
counter = 0
def __init__(self):
#Character images
self.sprite_attack = Sprite(Consts.CHARACTER_ATTACK, 6, 150)
self.sprite = Sprite(Consts.CHARACTER_STILL, 1, 100)
self.sprite_defense = Sprite(Consts.SPRITE_DEFENSE, 25, 70)
self.sprite_charge = Sprite(Consts.SPRITE_CHARGE, 11, 90)
self.sprite_spell = Sprite(Consts.SPELL_CHARACTER, 30, 70)
self.sprite_spell_dragon = Sprite(Consts.SPELL_DRAGON, 25, 90)
#Attributes
self.strength = self.defence = self.magic = 0
self.setAttributes(1, 1, 0)
#life
self.life = self.FULL_LIFE
self.lifebar_rect = pygame.Rect(Consts.CHARACTER_POSITION[0]-15,Consts.CHARACTER_POSITION[1]+146,150,13)
self.charged = 1
self.level = 1
#self.money = 1000
def setAttributes(self, strength, defence, magic):
self.strength = strength
self.defence = defence
self.magic = magic
def update(self):
self.sprite._update()
self.sprite_attack._update()
self.sprite_defense._update()
self.sprite_charge._update()
self.sprite_spell._update()
self.sprite_spell_dragon._update()
def render(self, screen):
#character
if(self.sprite_attack.is_playing()):
self.sprite_attack._render(screen, (Consts.CHARACTER_POSITION[0]-30,Consts.CHARACTER_POSITION[1]-130))
else:
self.sprite._render(screen, Consts.CHARACTER_POSITION)
if(self.sprite_defense.is_playing()):
self.sprite_defense._render(screen, (Consts.CHARACTER_POSITION[0]-30,Consts.CHARACTER_POSITION[1]-30))
if(self.sprite_charge.is_playing()):
self.sprite_charge._render(screen, (Consts.CHARACTER_POSITION[0]-30,Consts.CHARACTER_POSITION[1]-30))
if(self.sprite_spell.is_playing()):
self.sprite_spell._render(screen, (Consts.DRAGON_POSITION[0]+15, Consts.DRAGON_POSITION[1]+60))
if(self.sprite_spell_dragon.is_playing()):
self.sprite_spell_dragon._render(screen, (Consts.CHARACTER_POSITION[0]-40,Consts.CHARACTER_POSITION[1]-50))
#lifebar
if(self.life>0):
current_lifebar_rect = pygame.Rect(self.lifebar_rect)
current_lifebar_rect.width = (self.life/self.FULL_LIFE)*self.lifebar_rect.width
pygame.draw.rect(screen, Consts.GREEN_COLOR, current_lifebar_rect)
pygame.draw.rect(screen, Consts.WHITE_COLOR, self.lifebar_rect,2)
def attack(self):
self.sprite_attack._play(1)
#self.sprite._play(1)
def defense(self):
self.sprite_defense._play(1)
def spell(self):
self.sprite_spell._play(1)
def receive_spell(self):
self.sprite_spell_dragon._play(1)
def charge(self):
self.charged *=2
self.sprite_charge._play(1)
def unCharge(self):
load = self.charged
self.charged = 1
return load
def beHitted(self, damage):
if(damage>0):
self.life -= damage
self.counter+=1
#.........这里部分代码省略.........