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


Python Level.update方法代码示例

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


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

示例1: start

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import update [as 别名]
    def start(self):
        level = Level()
        level.init()
        (entities, trans) = parse_gsl_file(Config.data_path+'/testfile.gsl')
        
        
#        parse_emdl_file(entities, Config.data_path+'/map/level10.map', level)
        
        
        while True:
            self.console.process_input()
            self.input(pygame.event.get())
            self.screen.fill((0, 0, 0))
            pygame.time.wait(100)
            level.update_on_events()
            level.update()
            
            level.draw(self.screen)
            
            if self.show_states == True:
                level.draw_debug(self.screen)
                
            self.console.draw()    


            #self.screen.blit(surface, (0, 0))
            pygame.display.flip()
开发者ID:denever,项目名称:lettere,代码行数:29,代码来源:game.py

示例2: Game

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import update [as 别名]
class Game(object):

    def next_level(self):
        self.current_level = Level(self.current_level.level_num + 1, self)
        self.current_level.start()

    def main(self, screen):
        self.screen = screen
        clock = pygame.time.Clock()
        pygame.mixer.init()
        pygame.mixer.music.load("resources/music/music.mp3")
        pygame.mixer.music.set_volume(0.5)

        self.current_level = Level(1, self)
        self.current_level.start()
        pygame.mixer.music.play(-1)

        while 1:
            dt = clock.tick(30)

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    return
                if (event.type == pygame.KEYDOWN and
                        event.key == pygame.K_ESCAPE):
                    return

            self.current_level.update(dt / 1000.)
开发者ID:emiliosanchez,项目名称:first-game,代码行数:30,代码来源:game.py

示例3: __init__

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import update [as 别名]
class GameContext:
	def __init__(self, engine):
		self.engine = engine
		self.font = engine.game_data[FONT]
		self.current_level = 0
		self.current_level_id = self.engine.game_data[LEVELS][self.current_level]
		self.level = Level(load(self.engine.game_data[LEVEL_DATA][self.current_level_id][FILE]), engine)
		controls = engine.game_data[CONTROLS]
		self.down_control_map = {
			controls[LEFT]: self.level.player.left_down,
			controls[RIGHT]: self.level.player.right_down,
			controls[JUMP]: self.level.player.jump_start,
		}
		self.up_control_map = {
			controls[LEFT]: self.level.player.left_up,
			controls[RIGHT]: self.level.player.right_up,
			controls[JUMP]: self.level.player.jump_end,
		}
		print "Game Created"
	def handle_mouse_up_event(self, event):
		pass
	def handle_key_down_event(self, event):
		if self.down_control_map.has_key(event.key):
			self.down_control_map[event.key]()
	def handle_key_up_event(self, event):
		if event.key == K_ESCAPE:
			self.engine.context = MenuContext(self.engine)
		elif self.down_control_map.has_key(event.key):
			self.up_control_map[event.key]()
	def update(self, delta):
		self.level.update(delta)
	def display(self):
		self.level.draw(self.engine.screen)
开发者ID:matthewstevens,项目名称:CrazyAnt,代码行数:35,代码来源:engine.py

示例4: Game

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import update [as 别名]
class Game(object):
    fps = 100

    def __init__(self, screen):
        self.screen = screen
        self.level = Level(self.screen.get_size())
    
    def quit(self):
        self.done = True

    def update(self):
        dt = self.clock.tick(self.fps)
        self.level.update(dt)

    def draw(self):
        self.level.draw(self.screen)


    def run(self):
        self.done = False
        self.clock = pygame.time.Clock()
        self.level.restart()

        while not self.done:
            # input
            for event in pygame.event.get():
                if event.type == QUIT:
                    self.quit()
                elif event.type == KEYDOWN and event.key == K_ESCAPE:
                    self.quit()

            self.update()
            self.draw()
            pygame.display.flip()
开发者ID:RMeiselman,项目名称:The-Elements-of-Sundae,代码行数:36,代码来源:game.py

示例5: test_delete_all

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import update [as 别名]
    def test_delete_all(self):
        level = Level(0)

        level.update(to_money(120), to_money(1))
        level.update(to_money(121), to_money(1))
        level.update(to_money(122), to_money(1))

        level.delete_all(lambda x, y: x < y, to_money(122))
        self.assertEquals(1, level.size())
开发者ID:dkgeorge,项目名称:goxgui,代码行数:11,代码来源:level_test.py

示例6: GamePlay

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import update [as 别名]
class GamePlay(GameState):
    def __init__(self):
        super(GamePlay, self).__init__()

        self.level = Level()

    def get_event(self, event):
        if event.type == pg.QUIT:
            self.quit = True

        self.level.get_event(event)

    def update(self, dt):
        self.level.update(dt)

    def draw(self, screen):
        self.level.draw(screen)
开发者ID:ToBaer94,项目名称:PrototypingPlatformer,代码行数:19,代码来源:gameplay_state.py

示例7: Game

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import update [as 别名]
class Game(ApplicationState):
    fps = 60

    def setup(self):
        self.level = Level(self.app.screen.get_size())
        self.level.restart()

    def resume(self):
        self.clock = pygame.time.Clock()
        pygame.mixer.music.unpause()

    def quit(self):
        self.done = True

    def update(self):
        dt = self.clock.tick(self.fps)
        self.level.update(dt)

    def draw(self, screen):
        self.level.draw(screen)
开发者ID:jwsander,项目名称:CS112-Spring2012,代码行数:22,代码来源:game.py

示例8: __init__

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import update [as 别名]
class Main:

	def __init__(self, SCREEN):
		# Initiate pygame and display.
		init()
		display.init()
		display.set_caption('The Platformer')
		# Create fps and set main display.
		self.fpsClock = time.Clock()
		self.mainDisplay = display.set_mode(SCREEN)

		# Level
		self.level_1 = Level()		

	# All events from mouse/keyboard/gamepad?
	def playerEvent(self):
		for eventput in event.get():
			if eventput.type == KEYDOWN and eventput.key == K_ESCAPE:
				return 'QUIT'
			self.level_1.playerEvent(eventput)

	# Updates variables
	def update(self):
		self.level_1.update()

	# Draws to the screen when finished
	def draw(self):

		self.level_1.draw(self.mainDisplay)
		
		
	# Main loop. Everything in order.
	def loop(self,FPS):
		while True:
			if (self.playerEvent() == 'QUIT'):
				quit()
				sys.exit()
			self.update()
			self.draw()
			display.update()
			self.fpsClock.tick(FPS)
开发者ID:vncastanheira,项目名称:platformer,代码行数:43,代码来源:main.py

示例9: Game

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import update [as 别名]
class Game(ApplicationState):
    fps = 60

    def setup(self):
        self.level = Level(self.app.screen.get_size())
        self.level.restart()

    def resume(self):
        self.clock = pygame.time.Clock()
        pygame.mixer.music.unpause()

    def handle_event(self, event):
        if event.type == KEYDOWN and event.key == K_ESCAPE:
            self.app.set_state(PauseMenu)

    def update(self):
        dt = self.clock.tick(self.fps)
        self.level.update(dt)

    def draw(self, screen):
        self.level.draw(screen)
开发者ID:HampshireCS,项目名称:CS112-Spring2012,代码行数:23,代码来源:game.py

示例10: GameState

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import update [as 别名]
class GameState(AppState):
    fps = 60

    def setup(self):
        AppState.setup(self)

        self.level = Level(self.screen.get_size())
        self.level.restart()

    def resume(self):
        self.clock = pygame.time.Clock()

    def handle_event(self, event):
        if event.type == KEYDOWN and event.key == K_ESCAPE:
            self.app.set_state(PauseState)

    def update(self):
        dt = self.clock.tick(self.fps)
        self.level.update(dt)

    def draw(self):
        self.level.draw(self.screen)
        pygame.display.flip()
开发者ID:HampshireCS,项目名称:cs143-Spring2012,代码行数:25,代码来源:game.py

示例11: main

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import update [as 别名]
def main():
    pygame.init()
    pygame.font.init()
    screen = pygame.display.set_mode(DISPLAY, FLAGS, DEPTH)
    pygame.display.set_caption("Use arrows to move!")
    timer = pygame.time.Clock()

    up = down = left = right = running = False
    bg = Surface((16,16))
    bg.convert()
    bg.fill(Color("#FFFFFF"))
    entities = pygame.sprite.Group()

    x = y = 0
    start_level = Level(30, 30)
    controls = Controls(start_level)

    while 1:
        timer.tick(60)
        for e in pygame.event.get():
            if e.type == QUIT: raise SystemExit, "QUIT"
            controls.process_event(e)
        start_level.update(screen)
        pygame.display.update()
开发者ID:brandr,项目名称:Tower_Defense,代码行数:26,代码来源:start.py

示例12: test_update

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import update [as 别名]
    def test_update(self):
        level = Level(0)

        level.update(to_money(120), to_money(1))

        self.assertEquals(to_money(1), level.volume)
        self.assertEquals(to_money(120), level.price)

        level.update(to_money(121), to_money(1))

        self.assertEquals(to_money(2), level.volume)
        self.assertEquals(to_money(120.5), level.price)

        level.update(to_money(120), to_money(0))

        self.assertEquals(to_money(1), level.volume)
        self.assertEquals(to_money(121), level.price)
开发者ID:dkgeorge,项目名称:goxgui,代码行数:19,代码来源:level_test.py

示例13: run

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

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

    if inputs.has_key("PAUSE") and player.current_animation != "dying":
      paused = not paused

    #Decelerates the player, if he doesn't press any movement keys or when he is dead and on the ground
    if ((player.current_animation != "dying" and not moved) or (player.current_animation == "dying" and player.on_ground)) and not paused:
      player.dec((PLAYER_MAX_ACC, 0))

    if trigger != None and trigger.trigger_type == TRIGGER_FLIP:
      if flip_wait == -1:
        flip_wait = 0
        flip_trigger_position = (trigger.x, trigger.y)
        play_sound("woosh")

    if flip_wait != -1 and not paused:
      flip_wait += 1
      if flip_wait > FLIP_DELAY:
        flip_direction = flip_direction_from_position(flip_trigger_position)
        flip_wait = -1
        level.flip(flip_direction)
        for o in objects:
          o.flip(flip_direction)
        for p in particles:
          p.flip()

    #Dust effect rising from the character's feet:

    if (player.current_animation == "walking"):
      particles.append(Particle(screen, 10, player.rect.centerx - player.dx / 2 + random.uniform(-2, 2), player.rect.bottom, -player.dx * 0.1, 0.1, 0.3, level.dust_color))

    #Updating level and objects:

    if scripted_event_trigger == None:
      scripted_event_trigger = level.update()
    else:
      level.update()

    #Objects are only updated when there's not a scripted event going on

    normal_updating = not scripted_event_on and not fading and not paused

    if changing_level:
      player.update(level)
    elif normal_updating:
      for o in objects:
        if o.dead and o.itemclass != "player":
          objects.remove(o)
          continue
        new_particles = o.update(level)
        if o.itemclass == "projectile":
          if player.rect.collidepoint(o.x, o.y) and o.current_animation == "default":
            new_particles = player.take_damage(o.damage)
            o.die()
        if type(new_particles) == list: #Sometimes the type of the return value is int (hackity hack)
          if new_particles != None:
            for p in new_particles:
              particles.append(p)

    if normal_updating or changing_level:
      for p in particles:
        p.update()
        if p.dead:
          particles.remove(p)

    #Rendering level - background and tiles
    level.render()
开发者ID:IndexErrorCoders,项目名称:PygamesCompilation,代码行数:70,代码来源:game.py

示例14: __init__

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import update [as 别名]
class LD26Main:
    def __init__(self, width=800,height=600):
        pygame.init()
        self.width = width
        self.height = height
        self.screen = pygame.display.set_mode((self.width, self.height))
        self.state = "menu"
        pygame.display.set_caption("Shoot Guys")

    def load_sprites(self):
        self.player_group = CameraSpriteGroup()
        self.player_bullet_group = CameraSpriteGroup()
        self.player_max_hp = 20
        self.player_healthbar = HealthBar(self.player_max_hp, self.player_max_hp, "res/player_healthbar.png", (128, 16))
        self.player_healthbar.rect.x = -55
        self.player_healthbar.rect.y = 10
        self.player_hb_group = CameraSpriteGroup()
        self.player_hb_group.add(self.player_healthbar)

        self.enemy_group = CameraSpriteGroup()
        self.enemy_bullet_group = CameraSpriteGroup()
        self.health_bar_sprites = CameraSpriteGroup()
        self.max_badguys = 0
        self.guys_killed = 0

        self.levels = [{"img":"res/levels/level1.png", "badguys":2, "goal":6}, {"img":"res/levels/level2.png", "badguys":5, "goal":10}]
        self.cur_level = 0

        self.load_level(0)
        self.menu = Menu()
        self.win = Win()
        self.die = Die()

    def load_level(self, levelnum):
        if levelnum >= len(self.levels):
            self.state = "win"
        else:
            leveldict = self.levels[levelnum]
            self.player = Player((self.width, self.height))
            self.player_group.add(self.player)
            self.level = Level((self.width, self.height), leveldict["img"])
            self.bdrop1 = Backdrop(self.level.dims, 1)
            self.bdrop2 = Backdrop(self.level.dims, 2)
            self.max_badguys = leveldict["badguys"]
            self.guys_killed = 0
            self.kill_goal = leveldict["goal"]
            self.player_healthbar.set_hp(self.player_max_hp)

    def go(self):
        self.load_sprites()
        self.clock = pygame.time.Clock()
        while 1:
            self.clock.tick(60)
            self.screen.fill((0, 0, 0))

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()
                elif event.type == pygame.KEYDOWN:
                    if event.key == K_ESCAPE:
                        if self.state == "game":
                            self.state = "menu"
                        else:
                            sys.exit()

                    elif event.key == K_RETURN:
                        if self.state == "menu":
                            self.state = "game"
                        elif self.state == "win" or self.state == "die":
                            self.load_level(0)
                            self.state = "game"

            if self.state == "menu":
                self.do_menu()
            elif self.state == "game":
                self.do_main_game()
            elif self.state == "win":
                self.do_win()
            else:
                self.do_die()

            pygame.display.flip()

    def do_die(self):
        self.die.update()
        self.die.draw(self.screen)

    def do_win(self):
        self.win.update()
        self.win.draw(self.screen)

    def do_menu(self):
        self.menu.update()
        self.menu.draw(self.screen)

    def do_main_game(self):
        if self.guys_killed > self.kill_goal:
            self.cur_level += 1
            self.player.kill()
            self.load_level(self.cur_level)
#.........这里部分代码省略.........
开发者ID:larsendt,项目名称:ld26,代码行数:103,代码来源:main.py

示例15: GameInstance

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import update [as 别名]
class GameInstance(object):

    def __init__(self, config, level_name):
        self.config = config
        self.physics_manager = PhysicsManager()
        self.material_manager = MaterialManager(config["material_file"])
        self.transmutation_manager = TransmutationManager(self.material_manager)
        self.transmutation_manager.blow_key = "stone"
        self.level = Level("{0}/{1}.lvl".format(config["levels_dir"], level_name), self.physics_manager, self.material_manager)

        self.main_char = Player.genMainCharacter()
        self.main_char.physical.position = [25, 10]
        self.level.actors.append(self.main_char)

        self.viewport = Viewport(config["width"], config["height"], self.main_char, self.level, 100)
        self.picking_handler = PickingHandler(self.viewport, self.transmutation_manager, self.physics_manager)

        self.ui_overlay = UIOverlay(config["font_file"])
        self.ui_overlay.text_elements["score"] = TextElement((20, 20), 20, (0, 0, 0), "0 pts")

        self.physics_manager.add_actor(self.main_char)
        self._highlight_actors = False

        self.sound_manager = SoundManager()
        self.sound_manager.actors.append(self.main_char)

    """
    Internally sets and returns the tilesize required to display on the given screen
    """
    def _recalc_tilesize(self, screen):
        self.tile_size = screen.get_width() / self.config["width_tiles"]
        return self.tile_size

    """
    Clears the event queue and performs associated actions for the existing events
    """
    def _handle_events(self, events):
        for event in events:

            event_name = event if isinstance(event, int) else event[0]

            if event_name == Actions.START_USER_LEFT:
                self.main_char.physical.velocity[0] -= self.config["user_motion_speed"]
            elif event_name == Actions.START_USER_RIGHT:
                self.main_char.physical.velocity[0] += self.config["user_motion_speed"]
            elif event_name == Actions.START_USER_UP:
                if self.main_char.physical.velocity[1] == 0:
                    self.main_char.physical.velocity[1] -= self.config["user_jump_speed"]
            elif event_name == Actions.STOP_USER_LEFT:
                self.main_char.physical.velocity[0] += self.config["user_motion_speed"]
            elif event_name == Actions.STOP_USER_RIGHT:
                self.main_char.physical.velocity[0] -= self.config["user_motion_speed"]
            elif event_name == Actions.USER_SUCK:
                [self.transmutation_manager.suck(actor) for actor in self.level.actors if self.picking_handler.is_picked(actor, event[1])]
            elif event_name == Actions.USER_BLOW:
                (new_actor, tile_pos, weight) = self.transmutation_manager.blow(event[1], self.tile_size)
                new_actor.physical.position = tile_pos
                self.level.actors.append(new_actor)
                self.physics_manager.add_actor(new_actor)
            elif event_name == Actions.START_BLOW_SELECTION:
                self.picking_handler.start_user_selection(event[1], self.tile_size)
            elif event_name == Actions.STOP_BLOW_SELECTION:
                self.picking_handler.stop_user_selection()
            elif event_name == Actions.START_DISSOLVE_SELECTION:
                self._highlight_actors = True
            elif event_name == Actions.STOP_DISSOLVE_SELECTION:
                self._highlight_actors = False
            elif event_name == Actions.CHOOSE_MATERIAL:
                self.transmutation_manager.blow_key = event[1]
            elif event_name == Actions.MUTE:
                self.sound_manager.mute()
            elif event_name == Actions.UNMUTE:
                self.sound_manager.unmute()

    """
    Updates all game objects and manager systems based on the frame time delta
    """
    def _handle_updates(self, delta):
        self.sound_manager.update(delta)
        self.physics_manager.update(delta, self.tile_size)
        self.picking_handler.update(delta, self.tile_size)
        self.transmutation_manager.update(delta)
        self.ui_overlay.text_elements["score"].value = "{0} pts".format(self.transmutation_manager.current_points)
        self.ui_overlay.update(delta)

        self.level.update(delta, self.tile_size)
        self.viewport.update(delta)

    """
    Renders all game objects to the screen
    """
    def _render(self, screen):
        additional_drawables = []

        mouse_position = pygame.mouse.get_pos()
        for actor in self.level.actors:
            if self._highlight_actors and self.picking_handler.is_picked(actor, mouse_position) and actor.dissolvable:
                picker = (pygame.Surface(actor.surface.get_size()), actor.position, True)
                picker[0].set_colorkey((0,0,0))
                pygame.draw.rect(picker[0], tuple(self.config["picking_color"]), picker[0].get_rect(), 2)
#.........这里部分代码省略.........
开发者ID:Desolace,项目名称:LudumDare32,代码行数:103,代码来源:game_instance.py


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