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


Python Player.jump方法代码示例

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


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

示例1: Game

# 需要导入模块: import Player [as 别名]
# 或者: from Player import jump [as 别名]
class Game(object):
    
    def __init__(self, screen):
        self.deaths = 0
        
        
        self.screen = screen
        self.level = Level('reallevel')
        self.spawn()
        
        self.game_area = screen.subsurface((0, 40, screen.get_width(), screen.get_height() - 40))
        self.cam = Camera(self.player, self.level.bounds, self.game_area.get_size())
        
        self.hud = screen.subsurface((0, 0, screen.get_width(), 40))
        self.deathtext = pygame.font.Font(None, 20)


    def spawn(self):
        self.player = Player((self.level.spawnPoint), self.level, self)
        
            
    def quit(self):
        self.done = True
    
    def loop(self):
        self.done = False
        self.clock = pygame.time.Clock()
        while not self.done:
            dt = self.clock.tick(30)

            #input
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.quit()
                elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
                    self.quit()
                elif event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
                    self.player.jump()

            #update
            self.player.update(dt)
            self.cam.update(self.player.rect)

            #draw
            self.hud.fill((80, 80, 80))
            text = self.deathtext.render("deaths: " + str(self.deaths), True, (0, 255, 0)) 
        
            self.hud.blit(text, (0, 0))

            self.game_area.fill((0,0,0))
            self.cam.draw_background(self.game_area, self.level.background)
            self.cam.draw_sprite(self.game_area, self.player)

            #refresh
            pygame.display.flip()
开发者ID:redbassett,项目名称:Jump,代码行数:57,代码来源:Game.py

示例2: __init__

# 需要导入模块: import Player [as 别名]
# 或者: from Player import jump [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):
#.........这里部分代码省略.........
开发者ID:JosephFranc,项目名称:Parallel-Engineering-100-Team-Project,代码行数:103,代码来源:Parallel.py

示例3:

# 需要导入模块: import Player [as 别名]
# 或者: from Player import jump [as 别名]
        if (gameLevel[y][x] == 1):
            blockList.append(Block(x*32, y*32))

while gameLoop:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            gameLoop=False
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                movex = -10
            
            elif event.key == pygame.K_RIGHT:
                movex = 10
            
            elif event.key == pygame.K_SPACE:
                player.jump()

        if event.type == pygame.KEYUP:
            if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
                movex = 0

    mainWindow.fill((0,100,255))

    for block in blockList:
        block.x -= movex
        block.render(mainWindow)

    if movex >= 0:
        player.x += movex/4 - movex/5
    else:
        player.x += -movex/4 + movex/5
开发者ID:djeof-1,项目名称:2D-Platformer-Game-Engine,代码行数:33,代码来源:main.py

示例4: main

# 需要导入模块: import Player [as 别名]
# 或者: from Player import jump [as 别名]
def main():
    pygame.init()

    # Set the height and width of the screen
    size = [SCREEN_WIDTH, SCREEN_HEIGHT]
    screen = pygame.display.set_mode(size)

    pygame.display.set_caption("niceRice")

    # Create the player
    player = Player()
    enemies = pygame.sprite.Group()

    # Create all the levels
    level_list = []
    level_list.append(Level_01(player))
    level_list.append(Level_02(player))

    # Set the current level
    current_level_no = 0
    current_level = level_list[current_level_no]
    active_sprite_list = pygame.sprite.Group()
    player.level = current_level
    player.rect.x = 340
    player.rect.y = SCREEN_HEIGHT - player.rect.height
    active_sprite_list.add(player)

    # Loop until the user clicks the close button.
    done = False

    # Used to manage how fast the screen updates
    clock = pygame.time.Clock()

    # -------- Main Program Loop -----------
    while not done:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                done = True

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_LEFT:
                    player.go_left()
                if event.key == pygame.K_RIGHT:
                    player.go_right()
                if event.key == pygame.K_UP:
                    player.jump()

            if event.type == pygame.KEYUP:
                if event.key == pygame.K_LEFT and player.change_x < 0:
                    player.stop()
                if event.key == pygame.K_RIGHT and player.change_x > 0:
                    player.stop()

        # Update the player.
        active_sprite_list.update()
        # Update items in the level
        current_level.update()

        # If the player gets near the right side, shift the world left (-x)
        if player.rect.right >= 500:
            diff = player.rect.right - 500
            player.rect.right = 500
            current_level.shift_world(-diff)

        # If the player gets near the left side, shift the world right (+x)
        if player.rect.left <= 120:
            diff = 120 - player.rect.left
            player.rect.left = 120
            current_level.shift_world(diff)

        # If the player gets to the end of the level, go to the next level
        current_position = player.rect.x + current_level.world_shift
        if current_position < current_level.level_limit:
            player.rect.x = 120
            if current_level_no < len(level_list)-1:
                current_level_no += 1
                current_level = level_list[current_level_no]
                player.level = current_level

        # ALL CODE TO DRAW SHOULD GO BELOW THIS COMMENT
        current_level.draw(screen)
        active_sprite_list.draw(screen)

        # ALL CODE TO DRAW SHOULD GO ABOVE THIS COMMENT

        # Limit to 60 frames per second
        clock.tick(60)

        # Go ahead and update the screen with what we've drawn.
        pygame.display.flip()

    # Be IDLE friendly. If you forget this line, the program will 'hang'
    # on exit.
    pygame.quit()
开发者ID:CarletonSLAM,项目名称:NiceRice,代码行数:96,代码来源:main.py

示例5: game

# 需要导入模块: import Player [as 别名]
# 或者: from Player import jump [as 别名]

#.........这里部分代码省略.........
                                    screen = pygame.display.set_mode((gamewidth, gameheight), FULLSCREEN)
                                else:
                                    full_scr = False
                                    screen = pygame.display.set_mode((gamewidth, gameheight))

                            if not sound:
                                pygame.mixer.music.stop()
                            clean = option[2]
                            if option[0] == 0:
                                pygame.mixer.music.stop()
                                state = 3
                                running = False
                            elif option[0] == 2:
                                running = False
                                state = 0
                            
                        if event.key == K_RIGHT: # liigub paremale
                            if player.left_right == 0:
                                player.direction = "R" # suund vaja animatsiooni jaoks
                            player.move(6)
                            if sound:walking.play(-1) # mängib liikumise heli

                        elif event.key == K_LEFT: # liigub vasakule
                            if player.left_right == 0:
                                player.direction = "L"
                            player.move(-6)
                            if sound:walking.play(-1)
                            
                        elif event.key == K_p:
                            print("cheat")
                            cheat = not cheat
                            
                        elif event.key == K_UP:
                            player.jump()
                            
                    elif event.type == KEYUP: # kui klahv üles tõuseb, siis liikumine lõppeb.
                        if event.key == K_RIGHT: # l6petab paremale liikumise
                            player.move(-6) 
                            walking.stop()
                        elif event.key == K_LEFT: # l6petab vasakule liikumise
                            player.move(6)
                            walking.stop()
                            
                    elif event.type == MOUSEBUTTONDOWN and event.button == 1: # bossi pea sihtimine
                        if cx in range(590,675) and cy in range(236,320): 
                            dmg_boss = True # kui hiir on õiges kohas ja vajutada vasakut nuppu, siis võtab bossi eludest maha teatud arv elusid
                        for enemy in current_enemy.enemy_flying: # teiste liikuvate vastaste tapmine
                            if enemy.rect.collidepoint((cx, cy)): # kui collidepoint ühtib hiire positsiooniga 
                                if sound:enemy_flying_wav.play()
                                current_enemy.enemy_flying.remove(enemy)
                                
            else: # kui on level shifti aeg, siis hoiab mängijat ühe koha peal
                if current_level_nr != 0: player.rect.x = 90
                else: player.rect.x = 350 # esimesel levelil on teine alguspunkt
                
	    #--- Level shift lõpp----#
            # vaatab kas uue vastase võib lisada
            if pygame.time.get_ticks() - spawn_timer >= cooldown:
                # esimesel levelil ei ole eritingimusi 
                if current_level_nr == 0:
                    current_enemy.add_enemy()
                # teisel levelil lõpetab vastaste lisamise kui piisavalt kaugel
                elif current_level_nr== 1:
                    if current_level.world_shift > -2300:
                        current_enemy.add_enemy()
                # uue timeri saamine
开发者ID:mpeedosk,项目名称:Projekt,代码行数:70,代码来源:Game.py

示例6: elif

# 需要导入模块: import Player [as 别名]
# 或者: from Player import jump [as 别名]
     if event.key == pygame.K_ESCAPE:
         sys.exit()
     elif (event.key == pygame.K_d) or (event.key == pygame.K_RIGHT):
         player.direction[0] = 1
     elif (event.key == pygame.K_a) or (event.key == pygame.K_LEFT):
         player.direction[1] = 1
     elif (event.key == pygame.K_s) or (event.key == pygame.K_DOWN) and not player.jump and player.direction[0] != 1 and player.direction[1] != 1:
         player.rect = pygame.Rect(player.rect.left,player.rect.top,60,60)
         player.targetRow = 4
         player.frame = 0
         player.duck = True
     if player.jump == False:    
         # jumping
         if (event.key == pygame.K_w) or (event.key == pygame.K_SPACE) or (event.key == pygame.K_UP):
             player.vel_up = -25
             player.jump = True
             player.targetRow = 3
             player.frame = 0
     if len(shots) < 3:
         if event.key == pygame.K_g and not fired:
             shots.append(Spoon(player.rect.centerx, player.rect.midtop[1]+30, player.direction))
             fired = True
             firetime = pygame.time.get_ticks()
 elif event.type == pygame.KEYUP:
     if (event.key == pygame.K_d) or (event.key == pygame.K_RIGHT):
         player.direction[0] = 0
         if not advanceVelocity == 0:
             advanceVelocity += -scrollVelocity
     elif (event.key == pygame.K_a) or (event.key == pygame.K_LEFT):
         player.direction[1] = 0
     elif (event.key == pygame.K_s) or (event.key == pygame.K_DOWN) and not player.jump and player.direction[0] != 1 and player.direction[1] != 1:
开发者ID:LinkCable,项目名称:Spooned,代码行数:33,代码来源:main.py

示例7: len

# 需要导入模块: import Player [as 别名]
# 或者: from Player import jump [as 别名]
 # Controls the framerate on Windows
 pygame.time.delay(FPS/1000)  
 
 # Update the display
 VIEW.fill([255,255,255])
 VIEW.blit(back, [0,270])
 
 VIEW.blit(player.image, player.rect.topleft)
 """VIEW.blit(player2.image, player2.rect.topleft)
 VIEW.blit(player3.image, player3.rect.topleft)
 VIEW.blit(player4.image, player4.rect.topleft)
 VIEW.blit(player5.image, player5.rect.topleft)"""
 
 # Cycle through all active sprites
 if player.isJumping:
     player.jump()
 """#if player2.isJumping:
     player2.jump()
 #if player3.isJumping:
     player3.jump()
 #if player4.isJumping:
     player4.jump()
 #if player5.isJumping:
     player5.jump()"""
 for trap in iter(OBS):
     trap.move()
     if trap.rect.colliderect(player.rect):
         STATE = False
     if trap.rect.right+10 < 0: # Delete traps that move off of the left side.
         trap.delete()
         if len(OBS) <= 0: # End the file when all traps have moved off the left side.
开发者ID:JosephFranc,项目名称:Parallel-Engineering-100-Team-Project,代码行数:33,代码来源:Parallel2.py

示例8: getchar

# 需要导入模块: import Player [as 别名]
# 或者: from Player import jump [as 别名]
            input = getchar()

            if (input == 'd'):
                score = player.move_forward(draw_layout.get_Matrix())

            elif (input == 'a'):
                score = player.move_backward(draw_layout.get_Matrix())

            elif(input == 'w'):
                score = player.ascend_ladder(draw_layout.get_Matrix())

            elif(input == 's'):
                score = player.descend_ladder(draw_layout.get_Matrix())

            elif(input == ' '):
                player.jump(draw_layout.get_Matrix(),donkey)

            elif(input == 'q'):
                os.system('clear')
                print("\n\n\n\n\n\n\n\n\n")
                print "\t\t\t\033[1;41mThanks for playing the game...\033[1;m"
                print("\n\n\n\n\n\n\n\n\n")
                sys.exit(0)





            player.prev_input = input
开发者ID:anirudhdahiya9,项目名称:Open-data-projecy,代码行数:31,代码来源:game.py

示例9: game

# 需要导入模块: import Player [as 别名]
# 或者: from Player import jump [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.
#.........这里部分代码省略.........
开发者ID:JosephFranc,项目名称:Parallel-Engineering-100-Team-Project,代码行数:103,代码来源:Parallel_beta.py


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