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


Python Graphics.update方法代码示例

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


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

示例1: main

# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import update [as 别名]
def main():
    # Loop until the user clicks the close button.
    done = False
    loopCount = 0
    while not done:
        loopCount += 1
        Input.update()
        if(Input.Trigger(Input.Close)):
            done = True
        map.update()
        Graphics.update()
开发者ID:BearXP,项目名称:Sumo2016_Pi,代码行数:13,代码来源:Game.py

示例2: __init__

# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import update [as 别名]
class Engine:
	def __init__(self, screen_size, fps):
		self._tmx_root = None  # Will be used to store the currently loaded tmx-file:
		self._fps = fps # Save fps
		self._CLOCK = pygame.time.Clock() # Create pygame.Clock for fps-control
		self._draw_tile_ids = False # DEBUG: Draw all ids:

		# Create instance of Graphics-Engine:
		self.graphics = Graphics(self,screen_size)
		# Create instance of World:
		self.world = World(self)
		# Create instance of input-engine
		self.input = Input(self)
		# Create actors-controller
		self.actors = GameActorController(self)
		# Create sound-controller (not jet programmed...)
		self.sound = Sound(self)

		# Finally, first map (temporary):
		self._load_tmx("Forest_N1_1.tmx")

		# Var changed by self.load_new_level. If not false, in the next update cycle, the level gets loaded.
		self._load_new_level = False

	def update(self):
		"""
		Updates everything. Should be called once per frame.
		"""

		# Check if new level should be loaded:
		if self._load_new_level:
			self._load_tmx(self._load_new_level)
			self._load_new_level = False

		# Handle events:
		self._handle_events()
		# Update input:
		self.input.update()
		# Update world:
		self.world.update()
		# Update Game-Actors:
		self.actors.update()
		# Update screen:
		self.graphics.update()
		# Make sure engine doesn't run faster than 60 fps:
		self._CLOCK.tick(self._fps)
	def _load_tmx(self, filepath):
		"""
		Loads the tmx-file 'filepath' and parses it.

		TODO: Maybe it would be better to move the part that parses tile-csv to the world-class....
		"""

		# Empty self.actors:
		self.actors = GameActorController(self)
		# TODO: Find a way to empty self.world
		self.world = World(self)

		# Open and parse the tmx-file
		self._tmx_root = ET.parse(filepath).getroot()

		# Get grid-size (in tiles)
		grid_size = (int(self._tmx_root.attrib["width"]), int(self._tmx_root.attrib["height"]))
		# Set the grid-size in the world:
		self.world.set_gid_size(grid_size)

		# Get tile-size (in pixels)
		tile_size = (int(self._tmx_root.attrib["tilewidth"]), int(self._tmx_root.attrib["tileheight"]))
		# Set the tile-size in the world:
		self.world.set_tile_size(tile_size)

		######
		# Next, process the tilesets:
		# For tileset..
		for tileset in self._tmx_root.findall("tileset"):
			# If tileset is "world":
			if tileset.attrib["name"] == "world":
				# Dor tile in this tileset:
				for tile in tileset.findall("tile"):
					# For property in tile:
					for property in tile.find("properties").findall("property"): 
						# Update tile-property
						self.world.set_tile_property(int(tile.attrib["id"]), property.attrib["name"], property.attrib["value"])

		######
		# Next, process the layers: Where is what tile?
		# For every layer...
		all_layers = self._tmx_root.findall("layer")
		for layer in range(len(all_layers)):
			# Get and save the raw csv data which contains information about where which tile is:
			csv_data = all_layers[layer].find("data").text
			# First, split the csv in rows:
			splitted_data = csv_data.split("\n")
			# For row in csv_data:
			for row in range(len(splitted_data)):
				# Make sure the row isn't empty:
				if not splitted_data[row] == "":
					splitted_row = splitted_data[row].split(",")
					# For column in csv_data (= for tile)
					for column in range(len(splitted_row)):
#.........这里部分代码省略.........
开发者ID:szhowardhuang,项目名称:Wario-Land-3,代码行数:103,代码来源:Engine.py


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