本文整理汇总了Python中World.update方法的典型用法代码示例。如果您正苦于以下问题:Python World.update方法的具体用法?Python World.update怎么用?Python World.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类World
的用法示例。
在下文中一共展示了World.update方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
# 需要导入模块: import World [as 别名]
# 或者: from World import update [as 别名]
def update(self, time):
if Globals.WIN:
if Globals.CURRENT_LEVEL == "five":
if self.bossWinTimer > 0.0:
self.bossWinTimer -= time
else:
self.exitFinal()
return
else:
if Globals.TIME > 0:
Globals.SCORE = Globals.SCORE + 10 * int(Globals.TIME)
self.exitGame()
return
if Globals.PLAYER.isDead:
self.timer -= time
if self.timer <= 0:
self.deadScreen()
return
if InputManager.getPressed("esc"):
self.exitScreen()
return
Globals.TIME = Globals.TIME - time
World.update(time)
if not Globals.CHECKPOINT_SET and\
Globals.CURRENT_LEVEL in Globals.CHECKPOINT_POS:
if Globals.PLAYER.rect.x > Globals.getCheckpointPos()[0]:
Globals.CHECKPOINT_SET = True
示例2: serialWrite
# 需要导入模块: import World [as 别名]
# 或者: from World import update [as 别名]
lastExplosion = last_ticks
isExploding = 1
serialWrite(s, 'A')
serialWrite(s, 'R')
if isExploding == 1:
# for x in range(0, dims[0]):
# for y in range(0, dims[1]):
c = pygame.Color(0)
c.hsva = ((int(last_ticks)) % 360, 90, 90, 100)
# pygame.draw.rect(screen, c, pygame.Rect(0, 0, width, height))
sur = pygame.Surface((width, height))
sur.set_alpha(128)
sur.fill(c)
screen.blit(sur, (0,0))
if last_ticks - lastExplosion > 1000:
serialWrite(s, 'B')
isExploding = 2
if isExploding == 2 and score % 5 != 0:
isExploding = 0
world.draw(screen)
# if current_milli_time() - lastUpdate >= updateInterval:
world.update()
# lastUpdate = current_milli_time()
if snake.dead:
serialWrite(s, 'K')
gameStage = 1
score = (snake.length - 1) // 2;
pygame.display.flip()
示例3: __init__
# 需要导入模块: import World [as 别名]
# 或者: from World import update [as 别名]
class Game:
def __init__(self, controller, resolution):
self.controller = controller
self.current_frame = 0
self.resolution = resolution
self.font = pygame.font.SysFont("consolas", resolution[0]/20)
self.world = World(resolution)
self.player = Player(self)
self.score = 0
def draw(self, screen):
self.world.draw(screen, self.resolution, self.player)
self.player.draw(screen, self.resolution)
# render text
score_label = self.font.render("Score: " + str(self.score), 0, (0, 0, 0))
screen.blit(score_label, (2, 0))
bullets_label = self.font.render("Bullets: " + str(self.player.bullet_count), 0, (0, 0, 0))
screen.blit(bullets_label, (0, self.resolution[1]/20))
bullets_label = self.font.render("X: " + str(self.player.x) + " Y: " + str(self.player.y), 0, (0, 0, 0))
screen.blit(bullets_label, (0, self.resolution[1]/10))
bullets_label = self.font.render("Angle: " + str(self.player.angle), 0, (0, 0, 0))
screen.blit(bullets_label, (0, 1.5*self.resolution[1]/10))
def update(self, framerate):
self.current_frame += framerate
self.player.action()
self.world.update(framerate, self.player)
def kill(self, animal):
self.score += animal.weight * animal.age
self.world.animals.remove(animal)
def end(self):
self.controller.change_view('main_menu')
return
def key_press(self, key):
#ARROWS
if key == 275:
self.player.add_move_direction('R')
elif key == 273:
self.player.add_move_direction('U')
elif key == 276:
self.player.add_move_direction('L')
elif key == 274:
self.player.add_move_direction('D')
#Z
elif key == 122:
self.player.use('PRIMARY')
#X
elif key == 120:
self.player.use('SECONDARY')
#ENTER
elif key == 13:
return
#SHIFT
elif key == 303:
return
def key_release(self, key):
if key == 275:
self.player.remove_move_direction('R')
elif key == 273:
self.player.remove_move_direction('U')
elif key == 276:
self.player.remove_move_direction('L')
elif key == 274:
self.player.remove_move_direction('D')
示例4: __init__
# 需要导入模块: import World [as 别名]
# 或者: from World 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)):
#.........这里部分代码省略.........