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


Python level.Level类代码示例

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


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

示例1: generate_level

    def generate_level(self):
        self._level_count += 1
        min_rooms = 5
        size = 20, 20

        # generate the tile types
        tiletypes, rooms = self._level_generator.generate(size, min_rooms)
        level = Level(self.player, tiletypes, self._level_count)

        # generate the objects
        objects = self._object_generator.generate(min_rooms, self._level_count)
        self._object_generator.place_objects(objects, level)

        # generate monsters
        species = self._species_generator.generate_level(self._level_count)
        beings = [Being(self.controller, s) for s in species]
        self._species_generator.place_beings(beings, level)

        # set the player on a up staircase
        tile = level.staircases_up[0]
        level.add_being(tile, self.player)

        self.levels.append(level)
        self._current_level = level

        # housekeeping
        # FIXME this will need to move to change_level
        for being in [b for b in level.beings]:
            being.new_level(level._size)
        self.turn_done(move_monsters=False)

        for being in [t.being for t in level.values() if t.being and self.player.vision.can_see(t)]:
            being.has_been_seen = True

        return level
开发者ID:nate1001,项目名称:vecter_hack,代码行数:35,代码来源:game.py

示例2: run_game

def run_game():
	
	state = StartState() 
	level = Level()	

	while 1:
		for event in pygame.event.get():
			if event.type == STATECHANGE:
				if event.event_id == 'won':
					next_room = level.next_room()
					
					if next_room == 'Win':
						state = Win()
					else:
						state = Room(state.whale, enemies=level.enemies[next_room])

				elif event.event_id == 'lose':
					state = Lose()	
				
				elif event.event_id == 'start_over':
					level = Level()
					state = StartState()
			else:
				state.handle_event(event)
		state.update()
		pygame.time.delay(10)
开发者ID:Orisphere,项目名称:whale,代码行数:26,代码来源:whale_game.py

示例3: __init__

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,代码行数:33,代码来源:engine.py

示例4: main

def main():
    pygame.init()
    screen = display.set_mode(DISPLAY, FLAGS, DEPTH)
    display.set_caption("Use arrows to move!")
    timer = time.Clock()

    up = down = left = right = space = False
    bg = Surface((BLOCK_SIZE, BLOCK_SIZE))
    bg.convert()
    bg.fill(Color("#000000"))

    current_level = Level(LEVEL_W, LEVEL_H)
    player = Player(100, 100)
    entities = pygame.sprite.Group()
    entities.add(player)

    while True:
        timer.tick(FPS)
        for e in pygame.event.get():
            if e.type == QUIT: raise SystemExit, "QUIT"
            if e.type == KEYDOWN and e.key == K_ESCAPE:
                raise SystemExit, "ESCAPE"
            if e.type == KEYDOWN and e.key == K_UP:
                up = True
            if e.type == KEYDOWN and e.key == K_DOWN:
                down = True
            if e.type == KEYDOWN and e.key == K_LEFT:
                left = True
            if e.type == KEYDOWN and e.key == K_RIGHT:
                right = True
            if e.type == KEYDOWN and e.key == K_SPACE:
                space = True

            if e.type == KEYUP and e.key == K_UP:
                up = False
            if e.type == KEYUP and e.key == K_DOWN:
                down = False
            if e.type == KEYUP and e.key == K_LEFT:
                left = False
            if e.type == KEYUP and e.key == K_RIGHT:
                right = False
            if e.type == KEYUP and e.key == K_SPACE:
                space = False

            if e.type == MOUSEBUTTONUP:
                pos = pygame.mouse.get_pos()
                print current_level._identify_img(pos[0]/BLOCK_SIZE, pos[1]/BLOCK_SIZE)

        # draw background
        for y in range(LEVEL_H):
            for x in range(LEVEL_W):
                screen.blit(bg, (x * BLOCK_SIZE, y * BLOCK_SIZE))

        # update player, draw everything else
        player.update(up, down, left, right, space, current_level)
        player.draw(screen)
        #entities.draw(screen)
        current_level.draw(screen)

        pygame.display.flip()
开发者ID:joaompinto,项目名称:Zunga,代码行数:60,代码来源:main.py

示例5: __init__

    def __init__(self):
        Level.__init__(self)
        self.name = "Breakout Minus Bricks 2"

        # Rect that objects are allowed to move inside
        global move_space
        move_space = pygame.Rect(grid_step, grid_step, shared.dim.x - 2*grid_step, shared.dim.y - 2*grid_step)
开发者ID:SamuraiT,项目名称:thegame,代码行数:7,代码来源:__init__.py

示例6: generate_shop

def generate_shop(w, h, shop_items):
	level = Level(w, h, is_shop=True)

	for x,y in range2d(w, h):
		t = level.tiles[x][y]
		if x == 0 or y == 0 or x == w-1 or y == h-1:
			t.img = spr.WOOD_WALL
			t.blocking = True
			t.transparent = False
		else:
			t.img = spr.WOOD_FLOOR
			t.blocking = False
			t.transparent = True

	for a,b in box2d(2, 2, 5, 5):
		level.add_item((a,b), random.choice(shop_items))
	for a,b in box2d(9, 2, 5, 5):
		level.add_item((a,b), random.choice(shop_items))
	for a,b in box2d(2, 9, 5, 5):
		level.add_item((a,b), random.choice(shop_items))
	for a,b in box2d(9, 9, 5, 5):
		level.add_item((a,b), random.choice(shop_items))

	level.illuminated = True
	return level
开发者ID:neynt,项目名称:well-done,代码行数:25,代码来源:level_generators.py

示例7: make_level

 def make_level(self, x, y):
     level = Level(x, y, self)
     #count level from 0 NOT 1
     level.number = len(self.level_list)
     #group for render & collide
     self.platfrom_group.add(level.platform)
     print('level maked!!!')
     return level
开发者ID:txcism,项目名称:pygame,代码行数:8,代码来源:world.py

示例8: __init__

	def __init__(self, player, AI):
		Level.__init__(self,player, AI)
		
		#enemies = [[40, 40, 0, 0, 'Basic_enemy', 0],
		#		[40, 40, 0, 0, 'Basic_enemy', 1]]

		self.parse_map('tutorial_map.txt');
		
		"""
开发者ID:Shuxiao,项目名称:MODACT,代码行数:9,代码来源:tutorial_level.py

示例9: Engine

class Engine(object):

    def __init__(self, world_size=WORLD_SIZE):
        self.world_center = Point((world_size // 2, world_size // 2))
        self.world_size = world_size
        self.snake = Snake(start=self.world_center, start_length=SNAKE_START_LENGTH, growth_pending = GROWTH_PENDING)
        self.level = Level(size=self.world_size, snake=self.snake)
        self.score = 0
        self.controller = Controller(self.level.level_render)

    def reset(self):
        """Start a new game."""
        self.playing = True
        self.score = 0
        self.snake = Snake(start=self.world_center,
                           start_length=SNAKE_START_LENGTH)
        self.level = Level(size=self.world_size, snake=self.snake)
        self.play()

    def update(self, dt):
        """Update the game by dt seconds."""

        self.check_input()
        # time.sleep(dt)
        if self.snake.update():
            self.level.update_level()
            self.level.level_render.draw_text(
                Point((0, 0)), 'Score {}'.format(self.score))
            self.level.show_level()
            head = self.snake.get_head()
            # If snake hits a food block, then consume the food, add new
            # food and grow the snake.
            if head in self.level.food:
                self.eat(head)
            if self.snake.self_intersecting():
                raise GameOver('snake intersecting')
            if head in self.level.blocks:
                raise GameOver('snake try eat block')
        time.sleep(dt)

    def eat(self, head=None):
        print('mmm, tasty')
        self.level.food.remove(head)
        self.snake.grow()
        self.score += len(self.snake) * SEGMENT_SCORE

    def play(self):
        """Play game until the QUIT event is received."""
        while True:
            try:
                self.update(TIME_DELTA)
            except GameOver, err:
                print(str(err))
                print('You score {}'.format(self.score))
                time.sleep(3)
                self.reset()
开发者ID:chaotism,项目名称:python-snake,代码行数:56,代码来源:engine.py

示例10: __init__

 def __init__(self, level, game, raw, *args, name="GenericLoadScreenLevel",distortion_params=False,color=(30,30,30),scroll=0,autoscroll_speed=(0.0,0.0),vis_ofs=0,audio_section="current",**kwargs):
     Level.__init__(self, level, game, raw, *args,
         distortion_params=distortion_params,
         color=color,
         scroll=scroll,
         autoscroll_speed=autoscroll_speed,
         vis_ofs=vis_ofs,
         audio_section=audio_section,
         **kwargs
     )
开发者ID:acgessler,项目名称:yiang,代码行数:10,代码来源:loadscreen.py

示例11: solve_monkey

def solve_monkey(dist = False):
    path = 'screenshots/%s.png' % datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
    print('Taking screenshot')
    call(['monkeyrunner', 'monkeyscreen.py', path])
    print('Rotating')
    call(['convert', '-rotate',  '90', path, path])
    
    print('Starting image solver')
    val, xmarks, ymarks = solve_image(path, dist)
    
    print('Generating solution path')
    pathparts = splitext(path)
    pathsol = '%s.sol_path.txt' % pathparts[0]
    solfile = open(pathsol, 'w')
    
    level = Level()
    level.rows = len(val)
    level.cols = len(val[0]) 
    for x, y in product(range(level.cols), range(level.rows)):
        c, t = val[y][x][0]
        if t != 0:
            continue
        #print('Tracing color', c)
        # Found a dot, start
        cx, cy, ct = x, y, 0
        while True:
            # Print current
            #print(cx, cy, ct)
            solfile.write('%d %d\n' % (avg([xmarks[cx], xmarks[cx+1]]), avg([ymarks[cy], ymarks[cy+1]])))
            # Find next
            cx2, cy2, ct2 = -1, -1, -1
            for nx, ny in level.neighbors(cx, cy):
                nc, nt = val[ny][nx][0]
                if nc >= 0 and connects(cx, cy, ct, nx, ny, nt):
                    cx2 = nx
                    cy2 = ny
                    ct2 = nt
                    break
            # Found nothing - done
            if cx2 == -1:
                break
            # Delete current and replace with next
            val[cy][cx][0] = -1, -1
            cx = cx2
            cy = cy2
            ct = ct2
        # Delete last
        val[cy][cx][0] = -1, -1
        solfile.write('0 0\n')
    solfile.close()
    
    print('Solving on device')
    call(['monkeyrunner', 'monkeypath.py', pathsol])
    
    print('DONE')
开发者ID:lacop,项目名称:FlowSolver,代码行数:55,代码来源:solve_monkey.py

示例12: run_game

def run_game():
  
  pygame.init()
  clock = pygame.time.Clock()
  screen = pygame.display.set_mode((globals['SCREEN_WIDTH'], globals['SCREEN_HEIGHT']), 0, 32)
  
  currently_held_keys = []
  
  #debug stuff
  lvl = Level("testlevel.txt", screen) 
  playerCam = Camera((85,85), globals['SCREEN_WIDTH'], globals['SCREEN_HEIGHT'])
  originCam = Camera((0,0), globals['SCREEN_WIDTH'], globals['SCREEN_HEIGHT'])
  player = Player("resources/robodude.png", screen, (85,85), playerCam)
  currentCam = player.camera
  entities = []
  
  entities.append(player)
 
  while True:
    for event in pygame.event.get():
      if event.type == pygame.QUIT:
        exit_game()
      if event.type == pygame.KEYDOWN:
        currently_held_keys.append(event.key)
      if event.type == pygame.KEYUP:
        currently_held_keys.remove(event.key)
    
    currentCam = player.camera
    do_render_light = True

    for keydown in currently_held_keys:
      if keydown in globals['WASD_KEYS']:
        player.movement_handler(keydown)
      #debug stuff
      if keydown == pygame.K_1:
        currentCam = originCam
      if keydown == pygame.K_2:
        do_render_light = False
    
    time_passed = clock.tick(50)
    screen.fill(globals['BG_COLOR'])

    # debug stuff
    pygame.display.set_caption('Lightgame : %d fps' % clock.get_fps())
    corners = currentCam.get_corners()
    lvl.draw_visible_level(corners[0], corners[1])
    player.update(time_passed, lvl, currentCam)
    player.draw(currentCam)
    
    lights_per_entity = [entity.lights for entity in entities]
    all_lights = [light for lights in lights_per_entity for light in lights]
    if do_render_light:
      currentCam.render_light(screen, all_lights)

    pygame.display.flip()
开发者ID:lucasgallen,项目名称:lightgame,代码行数:55,代码来源:lightgame.py

示例13: load_levels

	def load_levels(self, f, offset):
		"""Load all the levels in turn, and return the new offset."""
		self.levels = list()
		
		for i in range(1):#self.levelCount):
			l = Level(self, f, offset)
			self.levels.append(l)
			offset = l.get_offset()
		
		self.currentLevel = 0
		self.load_level(self.currentLevel)
开发者ID:AtkinsSJ,项目名称:lunaticlib,代码行数:11,代码来源:world.py

示例14: generate_dungeon

def generate_dungeon(w, h, difficulty=1):
	level = Level(w, h)

	new_map = [[0 for _ in xrange(h)] for _ in xrange(w)]
	# initialize new_map to noise (0.43% filled)
	for x,y in range2d(w, h):
		if random.random() < 0.43:
			new_map[x][y] = 1

	# apply cellular automation
	for i in xrange(2):
		temp_map = [[0 for _ in xrange(h)] for _ in xrange(w)]
		for x,y in range2d(w, h):
			wall_count = 0
			for i,j in box2d(x-1, y-1, 3, 3):
				if 0 <= i < w and 0 <= j < h:
					wall_count += new_map[i][j]
				else:
					# sides = instawall
					wall_count += 3

			if wall_count >= 5:
				temp_map[x][y] = 1

		new_map = temp_map

	# apply changes to actual map
	for x,y in range2d(w, h):
		tile = level.tiles[x][y]
		if new_map[x][y] == 1:
			tile.img = spr.ROCK
			tile.blocking = True
			tile.transparent = False
		else:
			tile.img = spr.MUD_FLOOR
			tile.blocking = False
			tile.transparent = True

	# spawn treasures and creatures
	mr = level.get_main_region()

	treasures = random.sample(mr, difficulty)
	for loc in treasures:
		level.add_item(loc, Item(spr.GOLD_NUGGET, name="gold nugget", value=50+difficulty*25))

	mobs = random.sample(mr, difficulty)
	for loc in mobs:
		c = Creature(level, *loc, hp=difficulty*10, maxhp=difficulty*10, name="malicious slime", gold=10+difficulty*5)
		c.min_atk = difficulty
		c.max_atk = difficulty*2

		level.creatures.append(c)
		
	return level
开发者ID:neynt,项目名称:well-done,代码行数:54,代码来源:level_generators.py

示例15: __init__

	def __init__(self, player, AI):
		Level.__init__(self,player, AI)

		enemies = {
			'G': initGhost,
			'S': initSpider,
			'M': initMonkey
		}

		self.parse_map('tutorial_map.txt', enemies, initEnemy)
		self.set_background_image('tutorial_background.png')
		self.music = 'levels/forest.mp3'
开发者ID:450W16,项目名称:MODACT,代码行数:12,代码来源:tutorial_level.py


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