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


Python Level.update方法代码示例

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


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

示例1: update

# 需要导入模块: from Level import Level [as 别名]
# 或者: from Level.Level import update [as 别名]
 def update(self, time):
     Level.update(self, time)
     if not self.door.active and self.dead_sub_boss == 3:
         #When all Centurions are dead we open the door
         self.door.setActive(True)
     if len(pygame.sprite.spritecollide(self.player,self.doorGroup,False)) == 1: 
         if self.door.active == False:
             m = MessageScene(self.director, self, 'Warning', 'You shall not pass!', 'Press to continue')
             self.director.setScene(m)
             self.player.rect.y+=25
         if self.door.active == True:
             nextLevel = LevelOneB(self.director, self.player)
             self.director.setScene(nextLevel)    
开发者ID:dgalaktionov,项目名称:Aleph,代码行数:15,代码来源:LevelOneA.py

示例2: update

# 需要导入模块: from Level import Level [as 别名]
# 或者: from Level.Level import update [as 别名]
 def update(self, time):
     Level.update(self, time)
     self.time +=time
     if self.activeLG != 0 and self.time > 1000:
         self.change_lasers()
         self.time = 0
     laser = pygame.sprite.spritecollideany(self.player, self.laserGroup, pygame.sprite.collide_mask)
     if laser != None and laser.active:
         self.player.hp = 0                    
     if len(pygame.sprite.spritecollide(self.player,self.invisibleFloorG,True,pygame.sprite.collide_rect)) == 1: 
         print 'Floor'
         self.disconnect_lasers()
         self.page.rect.x = 414
         self.page.rect.y = 414   
开发者ID:martinaLopez,项目名称:Aleph,代码行数:16,代码来源:LevelFour.py

示例3: WorldModel

# 需要导入模块: from Level import Level [as 别名]
# 或者: from Level.Level import update [as 别名]
class WorldModel(object):
    
    DEBUG = False
    
    physWorld = None
    vel_iters, pos_iters = 6, 2 
    debugRender = None;
    player = None
    body = None
    dynamic_enities = []
    mFirstUpdate = True
    mEntityToFollow = None
    mTimer = None
    mDeathTimer = 1.0
    
    mSwitch = None
    
    
    def __init__(self, camera, luObserver, fxObserver, lvl):
        self.mSwitch = True
        self.mTimer = 0.0
        self.mLevelDone = False
        self.mCamera = camera
        self.mLuObs = luObserver
        self.mFxObs = fxObserver
        self.contactListener = ContactListener()
        self.gravity = Gravity()
        self.physWorld = b2World(gravity=(0,0),doSleep=True, contactListener=self.contactListener)
        self.level = Level(self.physWorld, self.gravity, lvl)
        self.player = Player(self.level.mStartPos, self.physWorld, self.gravity)
        self.mEntityToFollow = self.player
           
    def __resetWorld(self):
        self.mSwitch = True
        self.mDeathTimer = 1.0
        self.mTimer = 0.0
        self.dynamic_enities = []
        self.mFirstUpdate = True
        self.gravity.reset()
        self.player.reset(b2Vec2(self.level.mStartPos.x + self.player.size.x/3, self.level.mStartPos.y + self.player.size.y/2))
        self.mLuObs.levelChanged(self.level)
    
    def restart(self):
        self.level.retryLevel()
        self.__resetWorld()
     
    def update(self, delta):
        self.mTimer += delta
           
        #step the physicsworld
        self.physWorld.Step(delta, self.vel_iters, self.pos_iters)
        self.physWorld.ClearForces()
        
        for body in self.physWorld.bodies:
            #dynamic body
            if body.type == b2_dynamicBody:
                if self.mFirstUpdate:
                    if isinstance(body.userData, Player):
                        self.dynamic_enities.append(body)
                
                if isinstance(body.userData, Player):
                    body.userData.update(delta)
                elif isinstance(body.userData, Enemy):
                    body.userData.update(delta)
                elif isinstance(body.userData, PickableObject):
                    body.userData.update(delta)
                elif isinstance(body.userData, Particle):
                    body.userData.update(delta)
                    
        
        if self.mFirstUpdate == True:          
            self.mFirstUpdate = False
            
        #update level, if level is done, returns true
        if self.level.update(delta, self.player.position):
            self.mLevelDone = True
            
        #is player dead?
        if not self.player.alive:
            
            if self.mSwitch:
                SoundManager.getInstance().playSound(SoundID.FLESHEXPLOSION)
                self.mFxObs.addFx(BloodSplatter(self.physWorld, self.gravity.get(), self.player.position))
                self.mSwitch = False
            
            self.player.stopMovement()
            self.mDeathTimer -= delta
            
            if self.mDeathTimer < 0:
                self.level.retryLevel()
                self.__resetWorld()
        
    
    def changeGravity(self, gravitydirection):
        if self.player.isOnGround() == True:
            self.gravity.set(gravitydirection)
            
            for body in self.dynamic_enities:
                if not body.userData.isInGravityZone():
                    body.userData.flip(gravitydirection)
开发者ID:,项目名称:,代码行数:102,代码来源:

示例4: Game

# 需要导入模块: from Level import Level [as 别名]
# 或者: from Level.Level import update [as 别名]
class Game():
    FPS = 60
    SCREEN_SIZE = (1280, 720)
    WHITE = (255, 255, 255)
    GREEN = (0, 255, 0)
    DARK_GREY = (10, 10, 10)
    MUSIC_FILE = 'data/singsingsing.ogg'
    
    def __init__(self):
        pygame.init()
        self.font = pygame.font.SysFont('sans-serif', 18, True)
        self.surface = pygame.display.set_mode(self.SCREEN_SIZE, 0, 32)
        self.state = 'intro'
        self.hiscores = Score.read_high_score()
        self.menu = Menu(("Start game", "Quit"))
        pygame.mixer.music.load(self.MUSIC_FILE)
        pygame.mixer.music.play(-1)
        
    def start(self):
        while True:
            if self.state == 'intro':
                # Show the intro and when it's done we move directly to game state
                intro = Intro(pygame, self.surface);
                new_state = intro.show()
                self.state = new_state
            elif self.state == 'menu':
                # Show the menu and run the menu loop
                self.hiscores = Score.read_high_score()
                self.show_menu()
            elif self.state == 'game':
                # Run a game and run the game loop
                self.load_level()
                self.game_loop()
            elif self.state == 'quit':
                # Quit, we're done.
                pygame.quit()
                sys.exit()
    
    # Contains the main menu loop and handles starting and quitting while showing the high scores
    def show_menu(self):
        pygame.mouse.set_visible(1)
        self.menu.drawMenu()
        while True:
            pygame.time.Clock().tick(self.FPS)
            for event in pygame.event.get():
                self.menu.handleEvent(event)
                if event.type == Menu.MENUCLICKEDEVENT or event.type == QUIT or event.type == KEYDOWN and event.key == K_ESCAPE:
                    if event.text == "Quit":
                        self.state = 'quit'
                        return
                    elif event.text == 'Start game':
                        self.state = 'game'
                        self.menu.deactivate()
                        return
                elif event.type == KEYDOWN and event.key == K_RETURN:
                    self.state = 'game'
                    self.menu.deactivate()
                    return
                        
            if self.menu.isActive():
                self.menu.drawMenu()
                
            Score.draw_high_scores(self.hiscores, self.surface)
            pygame.display.flip()
        
    # Loads and resets a level    
    def load_level(self):
        self.up = False
        self.speed = 6
        self.nameinput = None
        self.level = Level(self)
    
    # The main game loop that updates the level as the game progresses
    def game_loop(self):
        pygame.mouse.set_visible(0)
        while True:
            pygame.time.Clock().tick(self.FPS)
            events = pygame.event.get()
            for event in events:
                if event.type == QUIT or event.type == KEYDOWN and event.key == K_ESCAPE:
                    self.state = 'quit'
                    return
                elif self.state == 'game':
                    if event.type == KEYDOWN:
                        if event.key == K_UP:
                            self.up = True
                    if event.type == KEYUP:
                        if event.key == K_UP:
                            self.up = False
                elif self.state == 'gameover':
                    if event.type == KEYUP:
                        if event.key == K_RETURN:
                            if self.nameinput != None:
                                name = self.nameinput.value
                                if name == '':
                                    name = 'no name'
                                Score.update_highscore(name, self.level.get_score(), self.hiscores)
                            self.state = 'menu'
                            return
             
#.........这里部分代码省略.........
开发者ID:span,项目名称:taxrunner,代码行数:103,代码来源:Game.py

示例5:

# 需要导入模块: from Level import Level [as 别名]
# 或者: from Level.Level import update [as 别名]
    cursor.update()

    """ Clear and background """
    screen.fill((255, 255, 255))
    screen.blit(background, (0, 0))

    if GameStateEnum.mainmenu == gamestate.getState():
        """ Update """

        """ Draw """
        popup.draw(screen)
        pass
    elif GameStateEnum.running == gamestate.getState():
        """ Update """
        level.update()

        """ Draw """
        level.draw(screen)
        pass
    elif GameStateEnum.shop == gamestate.getState():
        """ Upfdate """

        """ Draw """
        shop.draw(screen)

    cursor.draw(screen)


    # --- Go ahead and update the screen with what we've drawn.
    pygame.display.flip()
开发者ID:thechib12,项目名称:Projectgroep-17,代码行数:32,代码来源:Main.py

示例6: __init__

# 需要导入模块: from Level import Level [as 别名]
# 或者: from Level.Level import update [as 别名]
class World:

    tileSize = 16
    screenWidth = 480
    screenHeight = 320

    worldPosition = 0
    
    def __init__(self):
        self.level = Level()
        self.hero = Hero()
        self.orb = Orb()
        
    def update(self, keystate):

        self.level.update(self.worldPosition)
        self.hero.update(keystate)
        self.orb.update(self.hero)

        # Check for X collision
        firstRow = int(self.hero.rect.top / self.tileSize)
        lastRow = int((self.hero.rect.bottom) / self.tileSize + 1)
        heroColumn = int(self.hero.rect.left / self.tileSize)

        print heroColumn

        if heroColumn % 30 == 0:
            self.worldPosition = heroColumn * 16


        print self.worldPosition / 16

        if(self.hero.speedX >= 0):
            lastColumn = heroColumn + 5
        elif(self.hero.speedX < 0):
            lastColumn = heroColumn - 5
        
        closestCollisionColumn = lastColumn
        
        if(self.hero.speedX > 0):
            for row in range(firstRow, lastRow):
                for column in range(heroColumn, lastColumn):
                    if(self.level.tiles[row, column] != 0):
                        if(column < closestCollisionColumn):
                            closestCollisionColumn = column
                            break

        elif(self.hero.speedX < 0):
            for row in range(firstRow, lastRow):
                for column in range(heroColumn, lastColumn, -1):
                    if(self.level.tiles[row, column] != 0):
                        if(column > closestCollisionColumn):
                            closestCollisionColumn = column + 1
                            break

        if(self.hero.speedX > 0):
            if(self.hero.targetRect.right < closestCollisionColumn * self.tileSize):
                self.hero.rect.left = self.hero.targetRect.left
        elif(self.hero.speedX < 0):
            if(self.hero.targetRect.left >= closestCollisionColumn * self.tileSize):
                self.hero.rect.left = self.hero.targetRect.left

        firstColumn = int(self.hero.rect.left / self.tileSize)
        lastColumn = int((self.hero.rect.right) / self.tileSize + 1)
        heroRow = int(self.hero.rect.top / self.tileSize)

        #falling
        if(self.hero.speedY > 0):
            lastRow = 19
        else:
            lastRow = 0

        closestCollisionRow = lastRow

        # falling
        if(self.hero.speedY > 0):
            for column in range(firstColumn, lastColumn, 1):
                for row in range(heroRow, lastRow, 1):
                    if(self.level.tiles[row, column] != 0):
                        if(row < closestCollisionRow):
                            closestCollisionRow = row
                            break

        elif(self.hero.speedY < 0):
            for column in range(firstColumn, lastColumn):
                for row in range(heroRow, lastRow, -1):
                    if(self.level.tiles[row, column] != 0):
                        if(row > closestCollisionRow):
                            closestCollisionRow = row
                            break

        if(self.hero.speedY > 0):

            if(self.hero.targetRect.bottom < closestCollisionRow * self.tileSize):
                self.hero.rect.top = self.hero.targetRect.top

            else:
                self.hero.rect.top = closestCollisionRow * self.tileSize - self.hero.height - 1
                self.hero.speedY = 0
                self.hero.onGround = True
#.........这里部分代码省略.........
开发者ID:mannion007,项目名称:pygame-platformer,代码行数:103,代码来源:World.py


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