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


Python Player.shoot方法代码示例

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


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

示例1: listener

# 需要导入模块: import Player [as 别名]
# 或者: from Player import shoot [as 别名]
 def listener(self, client, packet):
     self.serverSocket.serverLock()
     if isinstance(packet, Packets.PlayerInfoPacket):
         if packet.getHealth() > 0:
             if client not in self.players:
                 player = Player(
                     self.getGame(),
                     color=Color(
                         random.randint(127, 255),
                         random.randint(127, 255),
                         random.randint(127, 255)
                     )
                 )
                 player.setPlayerId(self.pid)
                 player.setPlayerName(packet.getPlayerName())
                 self.pid += 1
                 self.players[client] = player
             else:
                 player = self.players[client]
             player.setPosition(packet.getPosition())
             player.setAngle(packet.getAngle())
         self.packetCount += 1
     elif isinstance(packet, Packets.PlayerGunPacket):
         player = self.players[client]
         bullets = player.shoot()
         for bullet in bullets:
             bullet.setBulletId(self.bid)
             self.bid += 1
         self.bullets += bullets
         self.packetCount += 1
     elif packet is not None:
         self.packetCount += 1
         print("Packet received (type " + str(packet) + ")")
     self.serverSocket.serverUnlock()
开发者ID:spywhere,项目名称:Pew-Pew,代码行数:36,代码来源:GameServerScene.py

示例2:

# 需要导入模块: import Player [as 别名]
# 或者: from Player import shoot [as 别名]
 if event.key == pygame.K_UP:
     player2.go("up")
 if event.key == pygame.K_d:
     player1.go("right")
 if event.key == pygame.K_RIGHT:
     player2.go("right")
 if event.key == pygame.K_s:
     player1.go("down")
 if event.key == pygame.K_DOWN:
     player2.go("down")
 if event.key == pygame.K_a:
     player1.go("left")
 if event.key == pygame.K_LEFT:
     player2.go("left")
 if event.key == pygame.K_SPACE:
     player1.shoot()
 if event.key == pygame.K_RETURN:
     player2.shoot()
 if event.key == pygame.K_1:
     player1.gun = player1.pistol
     player1.shoot("stop")
 if event.key == pygame.K_KP1:
     player2.gun = player2.pistol
     player2.shoot("stop")
 if event.key == pygame.K_2:
     player1.gun = player1.shotGun
     player1.shoot("stop")
 if event.key == pygame.K_KP2:
     player2.gun = player2.shotGun
     player2.shoot("stop")
 if event.key == pygame.K_3:
开发者ID:KRHS-GameProgramming-2014,项目名称:adventure-swag,代码行数:33,代码来源:Game.py

示例3: main

# 需要导入模块: import Player [as 别名]
# 或者: from Player import shoot [as 别名]
def main():
    #setup or define variables and initialize them
    pygame.init()
    Text_color = (0,0,200)
    score = 0
    sound = pygame.mixer.music.load("data/main.ogg")
    frame = pygame.time.Clock()
    screen = Display().createWindow(640, 640)
    player_shoot = True
    enemy_shoot = True
    display_enemy = True
    screen.fill((0,0,234))
    size = pygame.display.get_surface().get_rect().size
    P_pos = [size[0]/2, size[1]-100]
    bullet_speed = 6 #bullet speed for player
    P_image = load_image("player.png", True)
    E_image = load_image("enemy.png", False)
    E_shot = load_image("Enemyshot.png", False)
    P_shot = load_image("Playershot.png", False)
    back = load_image("background.png", True)
    back = pygame.transform.scale(back,(650, 650))
    back_rect = back.get_rect()
    back_rect.topleft = 0, -10
    player = Player(P_image, P_shot, P_pos, bullet_speed)
    player.set_speed(50)
    EnemyList = []
    displayPlayer = True
    EnemyAddCounter = 120
    EnemyOneCounter = 60
    pygame.mouse.set_visible(True)
    bullets = [] #EnemyBullets list
    shot_speed = 8 #bullet speed for enemy
    Display().setTitle("Space Shooter")
    life = 5
    #open the score flat-file
    file = open("data/score.pck", "r")
    f = file.read()
    p_score = int(f)
    file.close()
    if(p_score == 0 or p_score < 20):
        file = open("data/score.pck", "w")
        file.write(str(20))
        p_score = 20
        file.close()
    pygame.mixer.music.play(-1, 0.0)
    while True:
        #the game-loop:
        screen.fill((0,0,234))
        EnemyAddCounter -= 1
        EnemyOneCounter -= 1
        if(EnemyAddCounter == 0):
            EnemyAddCounter = 120
            enemy = Enemy(E_image, E_shot, (random.randint(0, 315), -10), shot_speed)
            enemy.set_speed(5)
            EnemyList.append(enemy)
        
        if(EnemyOneCounter ==0):
            EnemyOneCounter = 60
            enemy = Enemy(E_image, E_shot, (random.randint(320, 575), -10),shot_speed)
            enemy.set_speed(5)
            EnemyList.append(enemy)
        
        screen.blit(back, back_rect)
        createText("Score: " +str(score), 12, (255, 255, 255),10, 10,None )
        createText("Top Score: "+str(p_score), 12, (255,255,255) ,10, 30, None)
        createText("Life: "+str(life), 12, Text_color ,10, 50, None)
        
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            if event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    pygame.quit()
                    sys.exit()
                if event.key == K_LEFT and (player.img_rect.left - 50) >= 0:
                    player.move("left")
                if event.key == K_RIGHT and (player.img_rect.right + 50) <= 670:
                    player.move("right")
                if event.key == K_UP and (player.img_rect.top - 30) >=0:
                    player.move("up")
                if event.key == K_DOWN and (player.img_rect.bottom + 50) <= 640:
                    player.move("down")
                if event.key == K_SPACE and player_shoot:
                    player.shoot()
        for enemy in EnemyList:
            if(random.randint(0, 50) == 2) and enemy_shoot == True:
                enemy.shoot()
            if display_enemy:
                enemy.move_bullets()
                enemy.move()
                enemy.update()
        for enemy in EnemyList:
            if enemy.img_rect.y > 640:
                EnemyList.remove(enemy)
            else:
                for bull in player.bullets:
                    if bull.colliderect(enemy.img_rect):
                        bullets = enemy.bullets
                        EnemyList.remove(enemy)
#.........这里部分代码省略.........
开发者ID:ferguson-abel,项目名称:Space-Shooter,代码行数:103,代码来源:Main.py


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