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


Python Level.get_main_region方法代码示例

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


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

示例1: generate_dungeon

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import get_main_region [as 别名]
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,代码行数:56,代码来源:level_generators.py

示例2: Item

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import get_main_region [as 别名]
# cheat items
# change to true for cheating
if False:
	town.add_item((11,11), Item(spr.WATER, name="lapis lazuli", value=90019001))
	town.add_item((13,13),
		Item(spr.TRIFORCE, name="triforce", value=0, luminosity=25, equippable=True,
			attr={
			'attack_damage': (9000,9001),
			'attack_haste': 0.4,
			'movement_haste': 0.4,
			'health': 90001,
			}),
	)

# For each shop, generate it, a position for it on the town, then put it there
for loc in random.sample(town.get_main_region(), 16):
	x,y = loc

	shop_type = random.randint(0, 2)

	if shop_type == 0:
		# General store
		shop_items = default_items.general
		shop_img = spr.SHOP
		shop_name = "general store"

	elif shop_type == 1:
		# Weapon shop
		shop_items = default_items.weapons
		shop_img = spr.SHOP_WEAPONS
		shop_name = "weapon shop"
开发者ID:neynt,项目名称:well-done,代码行数:33,代码来源:world.py


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