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


Python Terrain.update方法代码示例

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


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

示例1: __init__

# 需要导入模块: from terrain import Terrain [as 别名]
# 或者: from terrain.Terrain import update [as 别名]
class BattleField:
    def __init__(self, screen, sfx, rand):
        self.level = 1
        self.ship_type = 1 # 0, 1, 2
        self.screen = screen
        self.sfx = sfx
        self.terrain = Terrain()
        self.myship = MyShip(self.ship_type)
        self.enemy_list = []
        self.my_bullet_list = []
        self.enemy_bullet_list = []
        self.powerup_list = []
        self.explosion_list = []
        self.milage = RESOLUTION[1]
        self.rand = rand
        
        self.level_dat_path = LEVEL_PATH + '%02d.dat' % self.level
        self.level_dat = open(self.level_dat_path).readlines()
        self.next_pos = int(self.level_dat[0].split()[0])

        self.status = 'game'

        sfx.play_bgm()
        
        if DEBUG: print 'init : battlefield'


    def update(self):
        if self.milage == 3500:
            self.status = 'win'

        self.spawn_enemy()
        self.update_terrain()
        self.update_myship()
        self.update_my_bullet()
        self.update_enemy()
        self.update_enemy_bullet()
        self.update_powerup()
        self.update_explosion()

        # be cautious about the blit order
        # blit terrain
        self.screen.blit(self.terrain.img, self.terrain.pos)
        # blit shadow
        self.screen.blit(self.myship.shadow_img, self.myship.shadow_pos)
        for enemy in self.enemy_list:
            if enemy.id[:4] == 'ship':
                self.screen.blit(enemy.shadow_img, enemy.shadow_pos)
                if enemy.id[5] == 'c': # heli
                    self.screen.blit(enemy.blade.shadow_img,
                                     enemy.blade.shadow_pos)

        # blit enemy
        for enemy in self.enemy_list:
            self.screen.blit(enemy.img, enemy.pos)
            if enemy.id[:6] == 'ship_c': # is helicopter
                self.screen.blit(enemy.blade.img,
                                 enemy.blade.pos)
            elif enemy.id[:6] == 'turret': # is turret
                self.screen.blit(enemy.barrel.img,
                                 enemy.barrel.pos)

        self.screen.blit(self.myship.img, self.myship.pos)
        # blit bullet
        for bullet in self.my_bullet_list:
            self.screen.blit(bullet.img, bullet.pos)
        for bullet in self.enemy_bullet_list:
            self.screen.blit(bullet.img, bullet.pos)
        # blit explosion
        for explosion in self.explosion_list:
            self.screen.blit(explosion.img, explosion.pos  )
        # blit powerup
        for powerup in self.powerup_list:
            self.screen.blit(powerup.img, powerup.img_pos)
            self.screen.blit(powerup.orb.img, powerup.pos)


    def update_terrain(self):
        self.terrain.update()
        self.milage += TERRAIN_SPEED


    def update_myship(self):
        if self.myship.hp < 0:
            explosion = ExplosionB(self.myship.pos)
            self.explosion_list.append(explosion)
            for x in range(self.myship.fire_level - 1):
                powerup = PowerUp(self.myship.pos[:],
                                  'fire',
                                  self.rand.randint(\
                                  -POWERUP_SCATTER_RANGE_X,
                                  POWERUP_SCATTER_RANGE_X))
                self.powerup_list.append(powerup)
            self.myship.live -= 1
            self.myship.hp = self.myship.max_hp
            self.myship.pos = self.myship.init_pos[:]
            self.myship.fire_level = 1
            if self.myship.live <= 0:
                self.status = 'lose'

#.........这里部分代码省略.........
开发者ID:IndexErrorCoders,项目名称:PygamesCompilation,代码行数:103,代码来源:battlefield.py

示例2: Robot

# 需要导入模块: from terrain import Terrain [as 别名]
# 或者: from terrain.Terrain import update [as 别名]
class Robot(object):
    def __init__(self, maze_dim):
        """
        Used to set up attributes that the robot will use to learn and
        navigate the maze.
        """

        # Position-related attributes
        self.robot_pos = {'location': [0, 0], 'heading': 'up'}  # Current pos
        self.steps_first_round = 0
        self.steps_final_round = 0
        self.maze_dim = maze_dim
        self.maze_representation = None

        # Goal-related attributes
        center = maze_dim/2
        self.center_locations = [
            [center, center], [center - 1, center],
            [center, center - 1], [center - 1, center - 1]]
        self.reached_destination = False

        # For exploring state
        self.exploring = False
        self.steps_exploring = 0
        self.consecutive_explored_cells = 0

        # Initialize terrain
        self.terrain = Terrain(maze_dim)

        # Algorithm to use:
        self.algorithm = None

        if str(sys.argv[2]).lower() == 'ff':
            self.algorithm = FloodFill()
        elif str(sys.argv[2]).lower() == 'ar':
            self.algorithm = AlwaysRight()
        elif str(sys.argv[2]).lower() == 'mr':
            self.algorithm = ModifiedRight()
        else:
            raise ValueError(
                "Incorrect algorithm name. Options are: "
                "\n- 'ff': flood-fill"
                "\n- 'ar': always-right"
                "\n- 'mr': modified-right (prefers unvisited cells)"
            )

        # Explore after reaching center of the maze:
        if str(sys.argv[3]).lower() == 'true':
            self.explore_after_center = True
        elif str(sys.argv[3]).lower() == 'false':
            self.explore_after_center = False
        else:
            raise ValueError(
                "Incorrect explore value: Options are: "
                "\n- 'true': to keep exploring after reaching the center"
                "\n- 'false': to end run immediately after reaching the center"
            )

    def next_move(self, sensors):
        """
        Use this function to determine the next move the robot should make,
        based on the input from the sensors after its previous move. Sensor
        inputs are a list of three distances from the robot's left, front, and
        right-facing sensors, in that order.

        Outputs should be a tuple of two values. The first value indicates
        robot rotation (if any), as a number: 0 for no rotation, +90 for a
        90-degree rotation clockwise, and -90 for a 90-degree rotation
        counterclockwise. Other values will result in no rotation. The second
        value indicates robot movement, and the robot will attempt to move the
        number of indicated squares: a positive number indicates forwards
        movement, while a negative number indicates backwards movement. The
        robot may move a maximum of three units per turn. Any excess movement
        is ignored.

        If the robot wants to end a run (e.g. during the first training run in
        the maze) then returning the tuple ('Reset', 'Reset') will indicate to
        the tester to end the run and return the robot to the start.
        """

        # Store current location and direction
        x, y, heading = self.get_current_position()

        # Get walls for current location
        walls = self.get_walls_for_current_location(x, y, heading, sensors)

        # If we have reached the center of the maze
        if self.is_at_center_of_the_maze(x, y):

            # Move backwards
            rotation = 0
            movement = -1

            # Update terrain (visual representation)
            self.terrain.update(x, y, heading, walls, self.exploring)

            # State that we have reached destination
            self.reached_destination = True

            # Set flags to exploring
#.........这里部分代码省略.........
开发者ID:RodrigoVillatoro,项目名称:machine_learning_projects,代码行数:103,代码来源:robot.py

示例3: Game

# 需要导入模块: from terrain import Terrain [as 别名]
# 或者: from terrain.Terrain import update [as 别名]
class Game(Scene):
    """
    This is the game class, this is the most important scene, and keeps track of the whole game
    """
    def __init__(self):
        """ Initializes the game scene """
        self.mainmenu = None
        self.winscreen = None
        self.initEvents()
        self.initTerrain()
        self.initTeams()

        self.createGameObjects()

        self.startNewGame()

    def initEvents(self):
        """ Initializes the eventreader """
        SceneManager().registerEventReader(self.do_action)

    def do_action(self, event):
        """
        Check the events, and do something when needed
        @param event: The event
        """
        
        # check events
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_SPACE:
                for snail in TurnManager().currentTeam.orderedSnailList:
                    if snail.hasTurn:
                        snail.shoot()
            if event.key == pygame.K_ESCAPE:
                SceneManager().setScene(self.mainmenu)
    def clean(self):
        """ Clean everything up, so that application doesn't crash """
        self.turnManager.stopTimer()
        SceneManager().unregisterEventReader(self.do_action)

    def initTeams(self):
        """ Initializes the team """
        self.teams = []
        self.teamsAlive = 0

    def initTerrain(self):
        """ Initializes the terrain """
        self.terrain = Terrain()

    def createGameObjects(self):
        """ Create the terrain """
        self.terrain.create(15)

    def addTeam(self, name, numberOfSnails, gravity_direction):
        """
        Add a team to the game
        @param name: The name of the team
        @param numberOfSnails: The amount of snails the team has
        @param gravity_direction: The gravity direction of the team
        """
        team = Team(name)
        team.setGravity(gravity_direction)
        team.addSnails(numberOfSnails)
        team.setTeamImage((gravity_direction+1))
        self.teams.append(team)
        
    def startNewGame(self):
        """ Start a new game """
        for i in range(0, Settings.GAME_PLAYERS):
            self.addTeam('team '+str(i+1), Settings.GAME_SNAILS, i)
        self.turnManager = TurnManager()
        self.turnManager.setTeams(self.teams)

        self.gamemode = GameModes.GAME_PLACING_SNAILS

    def stopGame(self):
        """ Stop the game """
        self.turnManager.timer.cancel()
        teamColors = {1:'green', 2:'red', 3:'yellow', 4:'blue'}
        livingTeamColor = str(teamColors[self.teams[0].colorIndex])
        SceneManager().setScene(WinScreen(self.mainmenu, livingTeamColor))
        #SceneManager().scene = self.mainmenu

    def update(self, input):
        """
        Update the game
        @param input: The input class
        """
        self.terrain.update()
        self.updateTeams(input)

        self.updateGameMode()

    def updateTeams(self, input):
        """
        Update every team
        @param input: The input class
        """
        self.teamsAlive = 0
        for team in self.teams:
            team.update(input, self.terrain)
#.........这里部分代码省略.........
开发者ID:ryuken,项目名称:gravity-snails,代码行数:103,代码来源:game.py


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