本文整理汇总了Python中Player.updateSprite方法的典型用法代码示例。如果您正苦于以下问题:Python Player.updateSprite方法的具体用法?Python Player.updateSprite怎么用?Python Player.updateSprite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Player
的用法示例。
在下文中一共展示了Player.updateSprite方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import Player [as 别名]
# 或者: from Player import updateSprite [as 别名]
def __init__(self, lvl, array, attempts, speed, color):
'''
@param lvl: Which level the player will start on.
@param array: The 2 dimensional array that acts as the game's "seed." array[0] = trapCombo #, array[1] = Which level the trap spawns on.
@param attempts: How many "attempts" the player has.
@ivar gameState: True when the whole program, Parallel, is running.
@ivar lvlState: False when the player has failed a level and needs to restart.
@ivar lvlComplete: True when the player has successfully completed a level.
@ivar lvl: Which level the player has reached. (1, 2, or 3)
@ivar attempts: How many times the player has attempted to beat the game.
'''
'''INITIALIZE'''
# Initializes the clock to create a stable frame rate and consistent new frame delay across machines..
clock = pygame.time.Clock()
STARS = pygame.sprite.Group()
# Initialize instance variables
self.speed = speed
self.gameState = True
self.lvlState = True
self.state_1 = True
self.lvlComplete = False
self.lvl = lvl
self.attempts = attempts
self.color = color
# Initialize the soundtrack
soundtrack = pygame.mixer.music
soundtrack.load('Soundtrack2.wav')
soundtrack.play(-1, 0)
if self.color == 0:
ball = "BlueRing.png"
elif self.color == 1:
ball = "YellowRing.png"
elif self.color == 2:
ball = "PinkRing.png"
else:
ball = "BlueRing.png"
# Iterators.
i = 0 # The index of the trap.
t = 5 # The initial trap spawn delay
p = 9 # The initial star spawn delay
# Sound effects
sfx = Sound()
# Play the game with different conditions for each level.
'''Level 1'''
if lvl == 1:
player1 = Player(1, ball, self.speed)
back = pygame.image.load("level1.png")
VIEW.blit(back, [0,0] )
while self.lvlState:
pygame.display.set_caption('Attempts: %d' %attempts)
# Standardizes FPS across platforms.
clock.tick_busy_loop(FPS)
if player1.isJumping:
player1.jump()
# Update the display
player1.updateSprite()
VIEW.fill([255,255,255])
VIEW.blit(back, origin)
VIEW.blit(player1.image, player1.rect.topleft)
for trap in iter(OBS):
trap.move()
# If a trap moves into a player, they lose the level.
if trap.rect.colliderect(player1.rect):
self.attempts += 1
self.lvlState = False
if trap.rect.right+10 < 0:
trap.delete() # Delete traps that move off of the left side.
if len(OBS) <= 0: # End the file when all traps have moved off the left side and advance to next level.
self.lvlState = False
self.lvl += 1
pygame.display.update()
# Spawn traps when appropriate.
if (t <= 0) and (i+1 <= len(array)):
if (array[i][1] < 2):
t = combos(array[i], lvl, self.speed)
t = t*40 + 400
i += 1
t -= self.speed
# Spawn stars randomly
if p <= 0:
p = random.randint(30, 180)
Projectile(STARS)
p -= 1
# Update all stars
for star in iter(STARS):
#.........这里部分代码省略.........
示例2: game
# 需要导入模块: import Player [as 别名]
# 或者: from Player import updateSprite [as 别名]
def game(lvl, array):
'''
Creates a playable instance of a level.
@param lvl: Which level the player will start on.
@param array: The 2 dimensional array that acts as the game's "seed." array[0] = trapCombo #, array[1] = Which level the trap spawns on.
@return: Returns lvl+1 if the player beat the level, or simply lvl if the player lost and must replay the level.
'''
# Initialize variables.
global STATE # State of the entire game.
lvlState = True # Win/lose state of the current level.
global attempts
# Iterators.
i = 0 # The index of the trap.
t = 5 # The initial trap spawn delay
# Play the game with different conditions for each level.
if lvl == 1:
back = pygame.image.load("level1.png")
VIEW.blit(back, [0,0] )
player1 = Player(1, "RealBall.png")
while lvlState:
pygame.display.set_caption('Attempts: %d' %attempts)
# Standardizes FPS across platforms.
clock.tick_busy_loop(FPS)
if player1.isJumping:
player1.jump()
# Update the display
player1.updateSprite()
VIEW.fill([255,255,255])
VIEW.blit(back, [0,0])
VIEW.blit(player1.image, player1.rect.topleft)
for trap in iter(OBS):
trap.move()
# If a trap moves into a player, they lose the level.
if trap.rect.colliderect(player1.rect):
attempts += 1
lvlState = False
if trap.rect.right+10 < 0:
trap.delete() # Delete traps that move off of the left side.
if len(OBS) <= 0: # End the file when all traps have moved off the left side and advance to next level.
lvlState = False
lvl = lvl+1
pygame.display.update()
# Spawn traps when appropriate.
if (t <= 0) and (i+1 <= len(array)):
if (array[i][1] < 2):
t = combos(array[i])
t = t*40 + 400
i += 1
t -= SPEED
# Command list
for event in pygame.event.get():
# If the user quits, the game exits
if event.type == QUIT:
STATE = False
lvlState = False
# Input list
elif event.type == pygame.KEYDOWN:
if (event.key == pygame.K_SPACE) and (player1.isJumping == False):
#sound = pygame.mixer.music
#sound.load('JumpSound.mp3')
#sound.play(1,0)
player1.jumpCount += 1
player1.isJumping = True
player1.velocity = -2.0*SPEED*ARCHEIGHT[1]/ARCHEIGHT[0] #-2SPEED*MAX[y]/MAX[x]
player1.rect.top -= 1
return lvl #End of "if lvl == 1"
elif lvl == 2:
back = pygame.image.load("level2.png")
VIEW.blit(back, [0,0] )
player1 = Player(1, "RealBall.png")
player2 = Player(2, "RealBall.png")
while lvlState:
pygame.display.set_caption('Attempts: %d' %attempts)
# Standardizes FPS across platforms.
#.........这里部分代码省略.........