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


Python Map.update方法代码示例

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


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

示例1: __init__

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import update [as 别名]
class PyAction:
    def __init__(self, type=1):
        pygame.init()
        screen = pygame.display.set_mode(SCR_RECT.size)
        pygame.display.set_caption("ROCKMAN WORLD 5")
        
        # load images
        Block.images = split_image(load_image("plute_map.png"), 16, 16, 16)
        Block.image = Block.images[0] #初期化

        # music
#        pygame.mixer.music.load("data/mars.nsf")
#        pygame.mixer.music.play(-1) 
        
        # loading map
        self.map = Map("data/plute.map")
        
        # main loop
        clock = pygame.time.Clock()
        while True:
            clock.tick(60)
            self.update()
            self.draw(screen)
            pygame.display.update()
            self.key_handler()

    def update(self):
        self.map.update()
    
    def draw(self, screen):
        self.map.draw()
        
        # draw part of map by offset
        offsetx, offsety = self.map.calc_offset()
        
        # 端ではスクロールしない
        if offsetx < 0:
            offsetx = 0
        elif offsetx > self.map.width - SCR_RECT.width:
            offsetx = self.map.width - SCR_RECT.width
        
        if offsety < 0:
            offsety = 0
        elif offsety > self.map.height - SCR_RECT.height:
            offsety = self.map.height - SCR_RECT.height
        
        # マップの一部を画面に描画
        screen.blit(self.map.surface, (0,0), (offsetx, offsety, SCR_RECT.width, SCR_RECT.height))
    
    def key_handler(self):
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            elif event.type == KEYDOWN and event.key == K_ESCAPE:
                pygame.quit()
                sys.exit()
开发者ID:flameDH,项目名称:Megaman-World-5-in-FC,代码行数:59,代码来源:rockmanwld5.py

示例2: Game

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import update [as 别名]
class Game(object):
    def __init__(self, zombs, vics, huntrs, ticks, map_x=20, map_y=20):
        self.map = Map(zombs, vics, huntrs, ticks, map_x, map_y)
        self.ticks = ticks

    def update(self):
        self.map.update()

    def draw(self):
        self.map.draw()

    def simulate(self):
        for i in xrange(self.ticks):
            self.update()
            self.draw()
开发者ID:jamtot,项目名称:PyProjects,代码行数:17,代码来源:game.py

示例3: post

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import update [as 别名]
 def post(self):
   try:
     secret = 'men judge generally more by the eye than by the hand, because it belongs to everybody to see you, to few to come in touch with you.'
     mapText = self.request.get("map")
     nameText = self.request.get("name")
     verifyGiven = self.request.get("verify")
     m = hashlib.md5()
     m.update(secret)
     m.update(mapText)
     verifyFound = m.hexdigest()
     if verifyGiven != verifyFound:
       result = urllib.urlencode([('error', 'Map was corrupted in transit')])
     else:
       map = Map(name = nameText, text = db.Text(mapText))
       map.update()
       key = map.put()
       getUrl = re.sub("upload/?$", "get/", self.request.url) + str(key)
       result = urllib.urlencode([('result', getUrl),
                                  ('key', str(key))])
   except Exception, error:
     message = 'Could not find map: ' + str(error)
     result = urllib.urlencode([('error', message)])
开发者ID:Shattered-Colony-Unbound,项目名称:sc-unbound,代码行数:24,代码来源:upload.py

示例4: Game

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import update [as 别名]
class   Game(State):
    """The main state : the Game is run in this class"""
    def __init__(self, parent, machine, level = 1):
        super().__init__(parent, machine)
        self.changeLevel(level)
        self.done = False
        self.map.bind("<Escape>", lambda e: self.machine.push_later(PauseState(self.parent, self.machine)))

    """The function to change the level"""
    def changeLevel(self, level):
        self.level = level
        filename = "Levels/niveau" + str(level) + ".txt"
        try:
            self.map.load(filename)
        except AttributeError:
            self.map = Map(self, filename)
            self.map.pack(fill=tk.BOTH, expand=tk.YES)
        except FileNotFoundError:
            self.machine.push_later(TextState(self.parent, self.machine, "Youuuuuuuuu WIN: No more level!"))
            self.pop()
            self.done = True

    def update(self, dt):
        try:
            self.map.update(dt)
        except Victory:
            self.changeLevel(self.level + 1)
            if not self.done:
                self.machine.push_later(TextState(self.parent, self.machine, "Youuuuuuu WIN! Next level: " + str(self.level)))
        except Death:
            self.machine.push_later(TextState(self.parent, self.machine, "You're dead bitch!"))
            self.pop()

    def focus(self):
        self.map.focus_set()
    
    def show(self):
        self.map.show()
开发者ID:L3nn0x,项目名称:tkinger-game,代码行数:40,代码来源:game.py

示例5: Game

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import update [as 别名]
class Game():
    def __init__(self, title, window_size):
        self.title = title
        self.window_size = window_size

        pygame.init()
        self.window = pygame.display.set_mode(self.window_size)
        pygame.display.set_caption(self.title)
        self.clock = pygame.time.Clock()

        self.world = Map()
        self.player = Player(32, 32, (255, 85, 85), self.world)

    def update(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

        self.player.update()
        self.world.update(self.player)

    def render(self):
        pygame.display.set_caption('Survival - FPS: %d' % self.clock.get_fps())
        self.window.fill((0, 0, 0))

        self.world.render(self.window)

        self.player.render(self.window)

        pygame.display.update()
        self.clock.tick(30)

    def gameloop(self):
        while True:
            self.update()
            self.render()
开发者ID:o0kot0o,项目名称:SurvivalGame,代码行数:39,代码来源:game.py

示例6: usage

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import update [as 别名]

#.........这里部分代码省略.........

    # play a "startup" sound
    self.sound.play('3robobeat')


  def newRandomSeed(self):
    self.crazySeed = random.randint(0, MAX_RANDOM_SEED)
    logging.info("USING RANDOM SEED: {0}".format(self.crazySeed))
    print("USING RANDOM SEED: {0}".format(self.crazySeed))


  def generateWorld(self, start_autonomous):
    now = int(time.time())
    worldage = now - self.last_worldgen
    logging.debug("World regenerated after {} seconds".format(worldage))
    self.last_worldgen = now
    # run garbage collection
    gc.collect()
    # log memory usage
    usage = resource.getrusage(resource.RUSAGE_SELF)
    logging.debug("Process memory usage is: {}".format(usage.ru_maxrss))
    
    self.surface.fill((0,0,0))
    # show notice
    font = pygame.font.Font(None, 52)
    textBitmap = font.render("Flat Flip Friends", True, colors.WHITE)
    textWidth = textBitmap.get_rect().width
    textHeight = textBitmap.get_rect().height
    self.surface.blit(textBitmap, [self.display.getDisplaySize()[0]/2 - textWidth/2, self.display.getDisplaySize()[1]/2 - textHeight*2])
    font = pygame.font.Font(None, 30)
    textBitmap = font.render("Generating world...", True, colors.WHITE)
    textWidth = textBitmap.get_rect().width
    self.surface.blit(textBitmap, [self.display.getDisplaySize()[0]/2 - textWidth/2, self.display.getDisplaySize()[1]/2])
    pygame.display.update()

    # Create the world, passing through the grid size
    theworld = World(self.gridDisplaySize)
    logging.debug("rendered world:\n{0}".format(theworld.to_s()))

    # Create the world map, passing through the display size and world map
    self.map = Map(self.mapSize, self.display, self.character_size, theworld)
    art = theworld.addArt(self.map)
    shapes = self.map.addShapes()
    self.sprites = pygame.sprite.Group(shapes, art)

    # Create the player object and add it's shape to a sprite group
    self.player = Player()
    self.player.selectShape(self.map.shapes[0])  # just grab the first shape for the player
    self.player.shape.autonomous = self.start_autonomous

    self.map.player = self.player

  def get_framespeed_info(self, clock):
    rawtime = clock.get_rawtime()
    if(len(self.frametime) < 30):
      self.frametime.append(rawtime)
    else:
      self.frametime[self.frametime_idx] = rawtime
    self.frametime_idx = (self.frametime_idx + 1) % 30
    average_frametime = int(sum(self.frametime) / len(self.frametime))
    if(average_frametime < self.min_frametime): self.min_frametime = average_frametime
    if(50 < pacglobal.get_frames() and average_frametime > self.max_frametime): self.max_frametime = average_frametime
    return str(self.min_frametime) + ' < ' + str(average_frametime) + ' < ' + str(self.max_frametime)


  def run(self):
开发者ID:benjaminbradley,项目名称:pacworld,代码行数:70,代码来源:pacworld.py

示例7:

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import update [as 别名]
		while window.GetEvent(event):
			if event.Type == sf.Event.Closed:
				running = False
		
		# Move map
		if input.IsKeyDown(sf.Key.Left):
			map.camera.pos[0] -= 5
		if input.IsKeyDown(sf.Key.Right):
			map.camera.pos[0] += 5
		if input.IsKeyDown(sf.Key.Up):
			map.camera.pos[1] -= 5
		if input.IsKeyDown(sf.Key.Down):
			map.camera.pos[1] += 5
		
		if map.isColliding(map.camera.pos):
			pass
		
		# Clear screen
		window.Clear()
				
		# Draw the map
		map.update()
		
		#print n
		n += 1
		
		# Display the window
		window.Display()
		
		print 1 / clock.GetElapsedTime()
开发者ID:bombpersons,项目名称:RPGlibs,代码行数:32,代码来源:sfml_test.py

示例8: Game

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import update [as 别名]

#.........这里部分代码省略.........
            self.catapults[self.player].set_loaded(False)
            self.projectile = item.create('projectile', name='projectile', x=p.x, y=p.y, flip=self.player==0)
            self.projectile.impulse(force, 0.1)

    def projectile_miss(self, projectile):
        self.miss = True # defer so the projectile is rendered one more frame

    def projectile_hit(self, hit):
        # hack: remove all other message
        self.textbuf = []

        # hack: directly inject message
        if self.player != hit:
            self.text = 'Player %d hit the other player and won!' % (self.player+1)
        else:
            self.text = 'Player %d hit himself and lost...' % (self.player+1)
        self.text += '\n\nPress ESC to restart.'

        if hit == self.player:
            self.catapults[self.player].set_broken()
        else:
            self.catapults[1-self.player].set_broken()

        game.over()

    def poll(self):
        global event_table
        for event in pygame.event.get():
            func = event_table.get(event.type, None)
            if func is None:
                continue
            func(self, event)

    def update(self):
        if self.is_over:
            self.clock.tick(60)
            return

        key = pygame.key.get_pressed()

        if self.miss:
            self.message('Player %d missed the target' % (self.player+1,))
            self.old_projectile = self.projectile
            self.projectile = DummyProjectile(4)
            self.miss = False

        if not self.firing and not self.sweep:
            if key[260]: self.camera.x -= 1
            if key[262]: self.camera.x += 1

            if key[273]: self.angle[self.player] += 0.3
            if key[274]: self.angle[self.player] -= 0.3
            if key[275]: self.force[self.player] += 1
            if key[276]: self.force[self.player] -= 1

            self.camera.x = min(max(self.camera.x, 0), self.camera_max)
            self.angle[self.player] = min(max(self.angle[self.player], 0), 90)
            self.force[self.player] = min(max(self.force[self.player], 0), 3000)

        dt = 1.0 / self.clock.tick(60)
        self.map.update()

        # fixed step for better physics "simulation"
        self.projectile.update(self.map, 0.05)

        if self.sweep:
开发者ID:ext,项目名称:nox6_ancient_earth,代码行数:70,代码来源:game.py

示例9: Game

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import update [as 别名]

#.........这里部分代码省略.........
        with self.hud:
            self.hud.clear((0,1,1,1))

    def running(self):
        return self._running

    @event(pygame.QUIT)
    def quit(self, event=None):
        self._running = False

    @event(pygame.KEYDOWN)
    def on_keypress(self, event):
        if event.key == 113 and event.mod & KMOD_CTRL: # ctrl+q
            return self.quit()
        if event.key == 27: # esc
            return self.quit()

        if event.key == 119:
            self.player.jump()

    @event(pygame.KEYUP)
    def on_keyrelease(self, event):
        if event.key == 119:
            self.player.unjump()

    def poll(self):
        global event_table
        for event in pygame.event.get():
            func = event_table.get(event.type, None)
            if func is None:
                continue
            func(self, event)

    def update(self):
        if self.killfade is not None:
            t = pygame.time.get_ticks() / 1000.0
            s = (t - self.killfade) / 2.5
            self.killfade2 = 1.0 - s

            if s > 1.0:
                self.quit()

            # so player keeps falling
            dt = 1.0 / self.clock.tick(60)
            self.player.vel.y = 0
            self.player.update(dt, self.map)

            return

        key = pygame.key.get_pressed()

        self.player.vel.x = 0
        if key[97 ]: self.player.vel.x = -0.15
        if key[100]: self.player.vel.x =  0.15

        if key[260]: self.camera.x -= 0.1
        if key[262]: self.camera.x += 0.1
        if key[258]: self.camera.y -= 0.1
        if key[264]: self.camera.y += 0.1

        dt = 1.0 / self.clock.tick(60)
        self.player.update(dt, self.map)
        self.player.frobnicate(self.map.pickups)
        self.map.update()

    def render(self):
开发者ID:ext,项目名称:scfa,代码行数:70,代码来源:game.py

示例10: Scene

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import update [as 别名]
class Scene(object):
	image = None
	def __init__(self, _engine):
		super(Scene, self).__init__()
		self._ais = []
		self._engine = _engine
		self._resx, self._resy = _engine.getResolution()
		self.surface = pygame.Surface((self._resx, self._resy))
		drawText(self.surface, "Wczytywanie mapy...", 48, (255, 255, 255), (self._resx / 2, self._resy / 2))
		self._map = Map(_engine)
		self._hub = Hub(_engine, self._map)
		self._cursor = Cursor(_engine, self._map)
		self._ais.append(AI(_engine, self._map, _engine.players[0], 0))
		self._ais.append(AI(_engine, self._map, _engine.players[1], 1))

	def screenUpdated(self):
		self._resx, self._resy = self._engine.getResolution()
		self.surface = pygame.transform.smoothscale(self.surface, (self._resx, self._resy))
		self._map.screenUpdated()
		self._hub.screenUpdated()
		self._cursor.screenUpdated()

	def show(self):
		try:
			while self._engine.tick():
				for event in pygame.event.get():
					if event.type == QUIT:
						self._engine.quit()

					elif event.type == KEYUP:
						if event.key == K_ESCAPE:
							raise Pause()

						elif event.key == K_TAB:
							for n, tank in enumerate(self._engine.players[0]['tanks']):
								if tank.focus:
									tank.setFocus(False)
									n = (n + 1) % len(self._engine.players[0]['tanks'])
									self._engine.players[0]['tanks'][n].setFocus(True)
									break

				if self._engine.state & engine.STATE_FAIL:
					self.surface.fill((0, 0, 0))
					drawText(self.surface, "Game Over", 50, (140, 0, 0), (self._resx / 2, self._resy / 2))
					self._engine.show(self.surface)
					continue

				if self._engine.state & engine.STATE_WIN:
					self.surface.fill((0, 0, 0))
					drawText(self.surface, "Gratulacje!", 50, (0, 140, 0), (self._resx / 2, self._resy / 2))
					self._engine.show(self.surface)
					continue

				if self._engine.timeLeft() == (0, 0):
					if self._engine.players[0]['score'] > self._engine.players[1]['score']:
						raise GameWin()

					raise GameOver()

				if not len(self._engine.players[0]['tanks']):
					raise GameOver()

				if not len(self._engine.players[1]['tanks']):
					raise GameWin()

				for tank in self._engine.players[0]['tanks']:
					if tank.focus: break

				else:
					self._engine.players[0]['tanks'][0].setFocus(True)

				keys = pygame.key.get_pressed()
				if keys[K_LEFT]:
					self._map.move(map.DIRECTION_LEFT)

				if keys[K_RIGHT]:
					self._map.move(map.DIRECTION_RIGHT)

				if keys[K_UP]:
					self._map.move(map.DIRECTION_UP)

				if keys[K_DOWN]:
					self._map.move(map.DIRECTION_DOWN)

				for ai in self._ais:
					ai.update()

				self._map.update()
				self._hub.update()
				self._cursor.update()
				self._map.draw(self.surface)
				self._hub.draw(self.surface)
				self._cursor.draw(self.surface)
				self._engine.show(self.surface)

		except Pause:
			self._engine.state ^= engine.STATE_GAME | engine.STATE_MENU

		except GameOver:
			self._engine.state |= engine.STATE_FAIL
#.........这里部分代码省略.........
开发者ID:Neverous,项目名称:ii-python11,代码行数:103,代码来源:scene.py


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