本文整理汇总了Python中Player.velocity方法的典型用法代码示例。如果您正苦于以下问题:Python Player.velocity方法的具体用法?Python Player.velocity怎么用?Python Player.velocity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Player
的用法示例。
在下文中一共展示了Player.velocity方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1:
# 需要导入模块: import Player [as 别名]
# 或者: from Player import velocity [as 别名]
elif event.type == pygame.KEYDOWN:
if (event.key == pygame.K_SPACE) and (player.isJumping == False):
#sound = pygame.mixer.music
#sound.load('JumpSound.mp3')
#sound.play(1,0)
player.jumpCount += 1
player2.jumpCount += 1
player3.jumpCount += 1
player4.jumpCount += 1
player5.jumpCount += 1
player.isJumping = True
player2.isJumping = True
player3.isJumping = True
player4.isJumping = True
player5.isJumping = True
player.velocity = -2.0*SPEED*ARCHEIGHT[1]/ARCHEIGHT[0] #-2SPEED*MAX[y]/MAX[x]
player2.velocity = -2.0*SPEED*ARCHEIGHT[1]/ARCHEIGHT[0]
player3.velocity = -2.0*SPEED*ARCHEIGHT[1]/ARCHEIGHT[0]
player4.velocity = -2.0*SPEED*ARCHEIGHT[1]/ARCHEIGHT[0]
player5.velocity = -2.0*SPEED*ARCHEIGHT[1]/ARCHEIGHT[0]
player.rect.top -= 1
player2.rect.top -= 1
player3.rect.top -= 1
player4.rect.top -= 1
player5.rect.top -= 1
# Give the player a moment to realize they died.
pygame.time.delay(500)
示例2: __init__
# 需要导入模块: import Player [as 别名]
# 或者: from Player import velocity [as 别名]
#.........这里部分代码省略.........
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):
star.move()
# Play sfx when appropriate
sfx.countdown()
# Command list
for event in pygame.event.get():
# If the users quits, the game exits
if event.type == QUIT:
self.gameState = False
self.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.willJump = True
player1.velocity = -2.0*self.speed*ARCHEIGHT[1]/ARCHEIGHT[0] #-2self.speed*MAX[y]/MAX[x]
player1.rect.top -= 1
#PAUSE menu
elif (event.key == pygame.K_p) or (event.key == pygame.K_ESCAPE):
#body
PSTATE = True
iterator = 0
while PSTATE == True:
gm = gameMenu(screen, highlighter_left, highlighter_right)
gm.displayPauseMenu()
gm.displayOptions(pausedmenu_images)
gm.checkInput()
iterator = gm.selectionDisplay(iterator, buttonSound)
select = gm.checkSelect(buttonSound)
if select == True:
if iterator == 0:
PSTATE = False
elif iterator == 1:
arbitrary = 0
elif iterator == 2:
PSTATE = False
self.lvlState = False
self.gameState = False
self.state_1 = False
pygame.display.update()
elif event.type == pygame.KEYUP:
if event.key == pygame.K_SPACE:
player1.willJump = False
示例3: game
# 需要导入模块: import Player [as 别名]
# 或者: from Player import velocity [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.
#.........这里部分代码省略.........