本文整理汇总了Python中level.Level.add_item方法的典型用法代码示例。如果您正苦于以下问题:Python Level.add_item方法的具体用法?Python Level.add_item怎么用?Python Level.add_item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类level.Level
的用法示例。
在下文中一共展示了Level.add_item方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_dungeon
# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import add_item [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
示例2: generate_shop
# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import add_item [as 别名]
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
示例3: Level
# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import add_item [as 别名]
from my_geom import box2d
from level import Level
from level_generators import generate_dungeon, generate_shop
from objects import Item, Portal
import default_items
import item_actions
WELL_DEPTH = 20
town = Level(25, 25, name="town")
well = [generate_dungeon(13+min(12,i), 13+min(12,i), i+1) for i in xrange(100)]
shop = []
town.illuminated = True
town.generate_town()
town.add_item((12,12), Item(spr.WELL, name="well of doom", holdable=False))
default_items.general = [
Item(spr.TORCH, name="torch", value=20, luminosity=3),
Item(spr.LANTERN, name="lantern", value=800, luminosity=5),
Item(spr.POTION_RED, name="lesser health potion", value=15,
desc="In[v]oking it will heal 10 HP.",
action=item_actions.heal_target(10),
),
Item(spr.SCROLL, name="town portal scroll", value=50,
desc="In[v]oking it will return the user to town after channeling.",
action=item_actions.tp_target_to(town, 12, 12),
),
Item(spr.ESSENCE, name="luminescent sphere", value=4000, luminosity=999),
]