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


Python Terrain.draw方法代码示例

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


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

示例1: Window

# 需要导入模块: from terrain import Terrain [as 别名]
# 或者: from terrain.Terrain import draw [as 别名]

#.........这里部分代码省略.........
                m = 1
            if self.strafe[0] > 0:
                # Moving backwards.
                dy *= -1
            # When you are flying up or down, you have less left and right
            # motion.
            dx = cos(x_angle) * m
            dz = sin(x_angle) * m
            # else:
            #     dy = 0.0
            #     dx = cos(x_angle)
            #     dz = sin(x_angle)
        else:
            dy = 0.0
            dx = 0.0
            dz = 0.0
        return (dx, dy, dz)

    def on_resize(self, width, height):
        """ Called when the window is resized to a new `width` and `height`.

        """
        # label
        #self.label.y = height - 10
        # reticle
        if self.reticle:
            self.reticle.delete()
        x, y = self.width / 2, self.height / 2
        n = 10
        self.reticle = pyglet.graphics.vertex_list(4,
            ('v2i', (x - n, y, x + n, y, x, y - n, x, y + n))
        )

    def on_draw(self):
        self.clear()
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)  
        self.water_line = 1.5
        self.water_color = (0.3,0.3,1,1)
        
        self.set_3d()
        glTranslatef(-16, 0, -16)
        
        # kostka

        self.t.draw(self.position[1])
        self.kostka.draw()

        glPopMatrix() # set_3d camera transf
        self.set_2d()
        glColor3d(0, 0, 0)
        self.fps.draw()

    def set_2d(self):
        """ Configure OpenGL to draw in 2d.

        """
        width, height = self.get_size()
        glDisable(GL_DEPTH_TEST)
        glDisable(GL_LIGHTING)
        glViewport(0, 0, width, height)
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        glOrtho(0, width, 0, height, -1, 1)
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
开发者ID:Dejmas,项目名称:Terrain,代码行数:69,代码来源:main.py

示例2: Robot

# 需要导入模块: from terrain import Terrain [as 别名]
# 或者: from terrain.Terrain import draw [as 别名]

#.........这里部分代码省略.........
        for sensor in sensors:
            if sensor == 0:
                number_of_walls += 1
        return number_of_walls

    # --------------------------------------------
    # MOVEMENT-RELATED
    # --------------------------------------------

    def get_next_move(self, x, y, heading, sensors):

        if self.reached_destination and self.exploring:
            rotation, movement = self.explore(x, y, heading, sensors)
            self.steps_exploring += 1

        elif not self.reached_destination and not self.exploring:

            if self.algorithm.name == 'flood-fill' and self.is_at_a_dead_end(sensors):
                rotation, movement = self.deal_with_dead_end(x, y, heading)

            else:

                adj_distances, adj_visited = self.terrain.get_adj_info(
                    x, y, heading, sensors)
                valid_index = self.algorithm.get_valid_index(adj_distances, adj_visited)
                rotation, movement = self.convert_from_index(valid_index)

            self.steps_first_round += 1

        else:
            # Final round (optimized movements)
            if self.steps_final_round == 0:
                print('******* FINAL REPORT *******')
                self.terrain.draw()
            rotation, movement = self.final_round(x, y, heading, sensors)
            self.steps_final_round += 1

        return rotation, movement

    def get_valid_index(self, x, y, heading, sensors, exploring):

        if not exploring:

            # 1) Get adjacent distances from sensors
            adj_distances, adj_visited = self.terrain.get_adj_info(
                x, y, heading, sensors)

            # Get min index (guaranteed to not be a wall)
            valid_index = adj_distances.index(min(adj_distances))

            # Prefer unvisited cells
            possible_distance = WALL_VALUE
            best_index = WALL_VALUE
            for i, dist in enumerate(adj_distances):
                if dist != WALL_VALUE and adj_visited[i] is '':
                    if dist <= possible_distance:
                        best_index = i
                        if best_index == 1:
                            break

            if best_index != WALL_VALUE:
                valid_index = best_index

        else:

            # 1) Get adjacent distances from sensors
开发者ID:RodrigoVillatoro,项目名称:machine_learning_projects,代码行数:70,代码来源:robot.py

示例3: Game

# 需要导入模块: from terrain import Terrain [as 别名]
# 或者: from terrain.Terrain import draw [as 别名]
class Game(pyglet.event.EventDispatcher):
	def __init__(self):
		self.window = pyglet.window.Window(fullscreen=True)
		self.terrain = Terrain(self.window.width, self.window.height-100)
		self.players = [
			Player(name, self, i)
			for i, name in enumerate(sys.argv[1:])]
		self.moving = []
		
		# Setup events
		self.window.event(self.on_draw)
		Game.register_event_type('next_player')
		Game.register_event_type('start_moving')
		Game.register_event_type('stop_moving')
		Game.register_event_type('explosion')
		
		# Start the game.
		self.reset()
		
		# Run the fucker
		pyglet.app.run()
	
	def reset(self):
		self.terrain.reset()
		for p in self.players:
			p.reset()
		random.shuffle(self.players)
		
		for p in self.players:
			new_x = None
			while not new_x:
				new_x = int(random.uniform(20, self.window.width - 20))
				for other in self.players:
					if other != p and abs(other.pos[0] - new_x) < 50:
						new_x = None
						break
			p.pos = new_x, self.terrain.flatten(new_x)
		
		self.next_player()
	
	def next_round(self):
		for p in self.players:
			p.next_round()
		self.next_player()
	
	def next_player(self):
		live_players = list(filter(lambda p: p.alive, self.players))
		if len(live_players) < 2:
			for p in live_players:
				p.score += 10000
			self.reset()
			return
		
		for p in live_players:
			if not p.ready:
				p.take_turn()
				return
		self.moving = [
			Shot(p.pos, p.angle, p.power, p)
			for p in self.players
			if p.alive]
		pyglet.clock.schedule(self.move, 1/60)
	
	def move(self, *args, **kwargs):
		for s in self.moving:
			s.move(self)
	
	def explosion(self, x, y, r, player=None):
		self.terrain.explosion(x, y, r)
		for p in self.players:
			p.explosion(x, y, r, player)
	
	def stop_moving(self, thing):
		self.moving.remove(thing)
		if not self.moving:
			pyglet.clock.unschedule(self.move)
			self.next_round()
	
	def start_moving(self, thing):
		self.moving.append(thing)
		
	def on_draw(self):
		self.window.clear()
		self.terrain.draw(self.window.width, self.window.height-100, 100)
		for p in self.players:
			p.draw()
		for m in self.moving:
			m.draw(self.window.height-100)
开发者ID:hartfelt,项目名称:kampvogne,代码行数:90,代码来源:kampvogne.py

示例4: Game

# 需要导入模块: from terrain import Terrain [as 别名]
# 或者: from terrain.Terrain import draw [as 别名]

#.........这里部分代码省略.........
        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)
            self.teamsAlive += 1

    def updateGameMode(self):
        """ Update the gamemodes """
        if self.gamemode == GameModes.GAME_PLACING_SNAILS:
            for team in self.teams:
                for snail in team.sprites():
                    if snail.isPlaced == False:
                        return
            self.turnManager.startTimer()
            self.gamemode = GameModes.GAME_PLAYING
        if self.gamemode == GameModes.GAME_PLAYING:
            if self.teamsAlive <= 1:
                self.stopGame()

    def draw(self, surface):
        """
        Draw the game on a surface
        @param surface: The surface the game should be drawed on
        """
        self.terrain.draw(surface)
        for team in self.teams:
            team.draw(surface)

        #self.bullets.draw(surface)
        if self.gamemode == GameModes.GAME_PLAYING:
            self.turnManager.draw(surface)
开发者ID:ryuken,项目名称:gravity-snails,代码行数:104,代码来源:game.py


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