本文整理汇总了Python中sprite.Sprite类的典型用法代码示例。如果您正苦于以下问题:Python Sprite类的具体用法?Python Sprite怎么用?Python Sprite使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Sprite类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw
def draw(self, screen):
Sprite.draw(self, screen)
x = self.position.x - 7
y = self.position.y - 20
w = min(max(self.health, 0) / 100.0 * 14, 13)
if self.health > 0:
pygame.draw.rect(screen, (39,65,62), (x-1,y-1, 16, 3), 0)
pygame.draw.line(screen, (255, 255, 255), (x, y), (x + 13, y))
pygame.draw.line(screen, (67,102,125), (x, y), (x + w, y))
if self.charge > 0:
md = 10.0
c = int(min(self.charge+1, 2.0) * 10.0)
#pygame.draw.line(screen, (173,0,0), (x-1,y-2),(x + c, y-2))
p1 = self.position + self.chargeDir * md
p2 = self.position + self.chargeDir * (md + c)
pa1 = p2 - self.chargeDir * 3 + self.chargeDir.sideways() * 3
pa2 = p2 - self.chargeDir * 3 - self.chargeDir.sideways() * 3
r = 100 + self.charge * 155
pygame.draw.line(screen, (r, 0, 0), p1.asIntTuple(), p2.asIntTuple())
pygame.draw.line(screen, (r, 0, 0), p2.asIntTuple(), pa1.asIntTuple())
pygame.draw.line(screen, (r, 0, 0), p2.asIntTuple(), pa2.asIntTuple())
if self.chatTimer > 0:
surf = self.chatFont.render(self.chatText, False, (39, 65, 62))
if self.flipHorizontal:
x = x - 4 - surf.get_width()
else:
x = x + 18
screen.blit(surf, (x, y + 2))
示例2: update
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
示例3: create
def create(self):
bg = Sprite(Vector2(0, 0))
bg.addStaticImage(content.images["background.png"])
self.add(bg)
self.font = pygame.font.Font("visitor1.ttf", 20)
self.playersInGame = 0
示例4: first_scene
class first_scene(Scene):
raspberry_sprite = None
def load(self):
self.raspberry_sprite = Sprite("art/raspberry35.png")
def cleanup(self):
pass
def do_event(self, event):
pass
def update(self):
self.raspberry_sprite.x = 100
self.raspberry_sprite.y = 100
return
max_x = self.s.size[0] - self.raspberry_sprite.width()
x = random.randint(0, max_x)
max_y = self.s.size[0] - self.raspberry_sprite.height()
y = random.randint(0, max_y)
self.raspberry_sprite.x = x
self.raspberry_sprite.y = y
def draw(self):
self.s.screen.fill((0,0,0))
self.raspberry_sprite.blit(self.s)
示例5: update
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
示例6: draw
def draw(self,surface,camera,is_shadow=True):
Sprite.draw(self,surface,camera,is_shadow)
#surface.blit(self.team.image, camera.proj([self.pos[0],self.pos[1],self.pos[2]],self.team.image.get_width(),self.team.image.get_height()*3))
if (self.is_saying_timer>0) and (self.is_saying!=""):
message_pos=[]
message_pos[:]=self.pos[:]
surface.blit(Player.speech_image[self.is_saying], camera.proj(message_pos,-self.image.get_width(),50))
示例7: __init__
def __init__(self, world, obj):
if obj.gid is None:
print >>sys.stderr, 'Player: must be created from tile object'
sys.exit(1)
self.left=False
self.world = world
self.gid = obj.gid
tile = world.data.tiles[self.gid]
Sprite.__init__(self,
world,
obj.kind,
'{} ({},{})'.format(obj.kind, obj.x, obj.y),
tile.get_width(), tile.get_height(),
obj.x, obj.y,
(16.0, 16.0))
self.addForce('friction', (1.0, 0.0), 'slowdown')
self.addForce('gravity', (0.0, 1.0), 'constant')
self.count = 0
self.coins = 0
pygame.font.init()
self.font = pygame.font.SysFont("Helvetica", 36)
self.font2 = pygame.font.SysFont("Courier New", 20)
self.text_color = (255,255,255)
self.score_color = (255, 0, 0)
self.score_x = 10
self.score_y = 30
self.game_x = 230
self.game_y = 240
self.coins = 0
self.lives = 3
self.newlife = 0
self.hurt = False
self.active = True
示例8: __init__
def __init__(self, screen, window_size, title, background, option, **kwargs):
self._screen = screen
self._title = title
self._background = background
self._entries_sprite_dict = {}
self._window_size = window_size
self._arrow_positions = {}
self._arrow_image_left = Sprite("./media/menu_arrow.png")
self._arrow_image_right = Sprite(pygame.transform.rotate(self._arrow_image_left.get_image(), 180))
self._arrow_image_size = self._arrow_image_left.get_size()
self._option = option
self.__add_text = (kwargs["add_text"],None)
entry_size_y = 20
start_y = window_size[1]/2 - len(self._entries) * (entry_size_y/2)
i = 0
item_nr = 0
for key, item in self._entries.iteritems():
if not item == " ":
sprite = Sprite.from_text(item)
size=sprite.get_size()
sprite.move_to(window_size[0]/2 - size[0]/2, start_y + i * entry_size_y)
self._entries_sprite_dict.update({item_nr:sprite})
self._arrow_positions.update({item_nr:[pygame.Rect(sprite.get_pos()[0] - 110, sprite.get_pos()[1] +
size[1]/2 - 6, 104, 12),
pygame.Rect(sprite.get_pos()[0] + size[0] + 6, sprite.get_pos()[1] +
size[1]/2 - 6, 104, 12)]})
self._arrow_image_left.set_rect(self._arrow_positions[0][0])
self._arrow_image_right.set_rect(self._arrow_positions[0][1])
item_nr += 1
i += 1
示例9: draw
def draw(self, surface, camera):
camerax, cameray = camera.getPosition()
pygame.draw.rect(surface, CELL_TYPE_COLORS[self.cell_type_id], (self.x - camerax, self.y - cameray, CELL_SIZE, CELL_SIZE))
if (self.material != None):
Sprite.draw(self, surface, camera)
if (self.treasure != None):
self.treasure.draw(surface, camera)
示例10: DodgeballScene
class DodgeballScene(Scene):
def __init__(self):
Scene.__init__(self)
self.font = pygame.font.Font("visitor1.ttf", 20)
def create(self):
self.bg = Sprite(Vector2(0, 0))
self.bg.addStaticImage(content.images["background.png"])
self.particles = ParticleContainer(100)
self.particles.layerIndex = 0
self.add(self.particles)
self.victoryMessage = ""
def draw(self, screen):
self.bg.draw(screen)
map(lambda x:x.drawShadow(screen), self.sceneEntities)
sortedEntities = sorted(self.sceneEntities, cmp = layeringSort)
map(lambda x:x.draw(screen), sortedEntities)
surf = self.font.render(str(g.game.score[0]) + " - " + str(g.game.score[1]), False, (255, 255, 255))
w, h = surf.get_size()
screen.blit(surf, (160 - w / 2, 9))
if self.victoryMessage != "":
surf = self.font.render(self.victoryMessage, False, (39, 65, 62))
w, h = surf.get_size()
w += 10
pygame.draw.rect(screen, (39, 65, 62), (160 - w / 2 - 1, 100 - h / 2 - 1, w + 2, h + 2), 1)
pygame.draw.rect(screen, (255, 255, 255), (160 - w / 2, 100 - h / 2, w, h), 0)
w -= 10
screen.blit(surf, (160 - w / 2, 100 - h / 2))
示例11: ImageMenuItem
class ImageMenuItem (BaseMenuItem):
""" A menu item that shows a selectable Image """
def __init__ (self, name, callback_func, *args, **kwargs):
self.image = pyglet.resource.image (name)
super (ImageMenuItem, self).__init__(callback_func, *args, **kwargs)
def generateWidgets (self, pos_x, pos_y, font_item, font_item_selected):
anchors = {'left': 0, 'center': 0.5, 'right': 1, 'top': 1, 'bottom': 0}
anchor=(anchors[font_item['anchor_x']] * self.image.width,
anchors[font_item['anchor_y']] * self.image.height)
self.item = Sprite(self.image, anchor=anchor, opacity=255,
color=font_item['color'][:3])
self.item.scale = font_item['font_size'] / float(self.item.height )
self.item.position = int(pos_x), int(pos_y)
self.selected_item = Sprite(self.image, anchor=anchor,
color=font_item_selected['color'][:3])
self.selected_item.scale = (font_item_selected['font_size'] /
float(self.selected_item.height))
self.selected_item.position = int(pos_x), int(pos_y)
def draw (self):
glPushMatrix()
self.transform()
if self.is_selected:
self.selected_item.draw()
else:
self.item.draw()
glPopMatrix()
示例12: __init__
class BackgroundLayer:
"""
Encapsulates a scrolling layer of the background. It will move left
at a given speed, and loop once it exits the screen. Multiple layers
with multiple speeds can be used to create a parallax effect, or to
allow many-layered backgrounds
"""
def __init__(self, filename, scroll_speed):
pos = (0, 0)
self.s1 = Sprite(filename, pos)
self.s2 = Sprite(filename, (1280, pos[1]))
self.filename = filename
self.position = pos
self.speed = scroll_speed
def draw(self):
self.s1.draw()
self.s2.draw()
def update(self):
self.s1.rect.x -= self.speed
if self.s1.rect.x <= 0:
self.s2.rect.x -= self.speed
if self.s2.rect.x <= 0:
self.s1.rect.x = 0
self.s2.rect.x = 1280
示例13: __init__
def __init__(self, imagen, velocidad):
self.image = imagen
Sprite.__init__(self)
self.rect = self.image.get_rect()
self.x = random.randint(-50, int(config.WIDTH))
self.rect.y = random.randint(-20, int(config.HEIGHT * 0.9))
self.velocidad = velocidad
示例14: __init__
class Character:
"""
Represents an in-game character: player, npc, enemy, etc. This class
_should not_ be used directly! It should rather be inherited by the classes
that will use it.
"""
def __init__(self, filename, spawnpoint):
"""
The filename is simply used to generate a sprite
Spawnpoint is used for the initial position
"""
self.spawnpoint = spawnpoint
self.sprite = Sprite(filename, spawnpoint)
self.health = 100
self.alive = True
def draw(self):
self.sprite.draw()
def update(self):
pass
def kill(self):
pass
def hurt(self, dmg):
if self.health - dmg <= 0:
self.alive = 0
self.health = 0
else:
self.health -= dmg
示例15: __init__
def __init__(self):
Sprite.__init__(self)
self.pos=[0,0,5] #like every other thing, pos is at center bottom
self.speed=[0,0,0]
self.size=2 #ball radius, for goal accuracy (used in y, and 2* in z)
self.owner=0 #0 if ball is free
self.anim_index=0
self.direction=1# +1: right, -1: left TODO : add more directions ?
self.state="roll1"
self.anim={}#dictionnary for left and right
self.anim[1]={} #dictionnary of all animation looking to the right
self.anim[1]["roll1"]=[]
self.anim[1]["roll1"].append(pygame.image.load("data/_ball_roll1_A.png"))
self.anim[1]["roll1"].append(pygame.image.load("data/_ball_roll1_B.png"))
self.anim[1]["roll1"].append(pygame.image.load("data/_ball_roll1_C.png"))
self.anim[1]["roll1"].append(pygame.image.load("data/_ball_roll1_D.png"))
self.anim[1]["roll1"].append(pygame.image.load("data/_ball_roll1_E.png"))
self.anim[1]["roll1"].append(pygame.image.load("data/_ball_roll1_F.png"))
#flip all anims to look left
self.anim[-1]={}
for key in self.anim[1]:
self.anim[-1][key]=[]
for img in self.anim[1][key]:
self.anim[-1][key].append(pygame.transform.flip(img, 1, 0))
self.image = self.anim[self.direction][self.state][int(self.anim_index)] #this is how we get the current picture