本文整理汇总了Python中map.Map.load方法的典型用法代码示例。如果您正苦于以下问题:Python Map.load方法的具体用法?Python Map.load怎么用?Python Map.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类map.Map
的用法示例。
在下文中一共展示了Map.load方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loadMap
# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import load [as 别名]
def loadMap(self, mapname, filename):
"""Loads a map an stores it under the given name in the maps list.
"""
map = Map(self.engine, self.data)
"""Need to set active map before we load it because the map
loader uses call backs that expect to find an active map.
This needs to be reworked.
"""
self.maps[mapname] = map
self.setActiveMap(mapname)
map.load(filename)
示例2: loadMap
# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import load [as 别名]
def loadMap(self, map_name, filename):
"""Loads a map and stores it under the given name in the maps list.
@type map_name: String
@param map_name: The name of the map to load
@type filename: String
@param filename: File which contains the map to be loaded
@return: None"""
if not map_name in self.maps:
map = Map(self.engine, self.data)
self.maps[map_name] = map
map.load(filename)
else:
self.setActiveMap(map_name)
示例3: loadWorldFile
# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import load [as 别名]
def loadWorldFile(self, worldName):
if worldName is None:
raise Exception("world file name is none")
_map = __import__('maps.%s' % worldName, fromlist=['*'])
self.cleanup = True
while len(self.entities) > 0:
self.killEntity(self.entities[0])
# map
worldMap = Map()
worldMap.load(os.path.join("..", "map", _map.map['filename']), _map.map['filename'])
self.addMap(worldMap)
# event
for event in _map.event:
eventEntity = npc.Event(event['action'])
#eventEntity.load_sprite_sheet(os.path.join("..", "graphics", "System", "collision.png"), (32,32), (0,0), (32,32))
eventEntity.load_sprite_sheet(os.path.join("..", "graphics", "Characters", "Actor2.png"), (32,32), (0,0), (96,128))
eventEntity.set_pos(event['pos'][0], event['pos'][1])
# eventEntity.action = lambda:
self.addEntities(eventEntity)
for heroine in _map.heroine:
if random.random() < heroine['probability']:
newHeroine = npc.Npc(heroine['name'], places[_map.map['filename']].name)
newHeroine.load_sprite_sheet(spriteinfo.heroine[heroine['name']]["sprite"], spriteinfo.heroine[heroine['name']]["size"], spriteinfo.heroine[heroine['name']]["startpos"], spriteinfo.heroine[heroine['name']]["sheetsize"])
newHeroine.speed_is(3)
newHeroine.walking_boundary_is(worldMap.size[0], worldMap.size[1])
if "pos" in heroine:
newHeroine.set_pos(heroine["pos"][0], heroine["pos"][1])
else:
newHeroine.set_pos(random.uniform(0, worldMap.size[0]), random.uniform(0, worldMap.size[1]))
self.addEntities(newHeroine)
# player
player = sprite.Hero()
player.load_sprite_sheet(spriteinfo.player["sprite"], spriteinfo.player["size"], spriteinfo.player["startpos"], spriteinfo.player["sheetsize"])
player.speed_is(3)
player.walking_boundary_is(worldMap.size[0], worldMap.size[1])
player.set_pos(_map.player['pos'][0], _map.player['pos'][1])
self.addEntities(player)
cam = Camera()
cam.set_follow(player)
self.setCamera(cam)
self.player = player
示例4: loadMap
# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import load [as 别名]
def loadMap(self, map_name, filename):
"""Loads a map and stores it under the given name in the maps list.
@type map_name: text
@param map_name: The name of the map to load
@type filename: text
@param filename: File which contains the map to be loaded
@return: None
"""
if not map_name in self.maps:
"""Need to set active map before we load it because the map
loader uses call backs that expect to find an active map.
This needs to be reworked.
"""
map = Map(self.engine, self.data)
self.maps[map_name] = map
self.setActiveMap(map_name)
map.load(filename)
示例5: run
# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import load [as 别名]
def run(self):
option = 0
items = ['Play', 'Quit', 'Help']
menu = Menu(400, 200, 25, 40, (255,0,0), (0, 0,0), 'title-background.png', items)
menu.init()
map_number = 0
won = False
while option != 1 and map_number < 4:
self.screen.set_clip(Rect(0, 0, SCREEN_W, SCREEN_H))
if not won:
option = menu.run(self.screen)
if option == 0:
w_map = Map((640, 440))
w_map.load(maps[map_number])
panel = Panel(w_map)
won = self.run_map(w_map, panel)
if won:
map_number += 1
if map_number >= 4:
menu = Menu(300, 200, 18, 40, (255,0,0), (0, 0,0), 'title-background.png', ['You finished the game', 'More levels comming soon...'])
menu.init()
menu.run(self.screen)
示例6: __init__
# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import load [as 别名]
def __init__(self, ax, map_file=None):
self.ax = ax
self.map_width = 20
if map_file is not None:
map = Map()
map.load(map_file)
map.draw_lanes(ax, False, [])
self.path_lines = []
self.path_lines_size = 3
colors = ['b', 'g', 'r', 'k']
for i in range(self.path_lines_size):
line, = ax.plot(
[0], [0],
colors[i % len(colors)],
lw=3 + i * 3,
alpha=0.4)
self.path_lines.append(line)
self.vehicle_position_line, = ax.plot([0], [0], 'go', alpha=0.3)
self.vehicle_polygon_line, = ax.plot([0], [0], 'g-')
self.init_point_line, = ax.plot([0], [0], 'ro', alpha=0.3)
self.set_visible(False)
ax.set_title("PLANNING PATH")
示例7: Map
# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import load [as 别名]
from map import Map
import os
datadir = 'data'
map = Map()
for xml in os.listdir(datadir):
map.load(os.path.join(datadir, xml))
loc = map['dorm_inside']
running = True
while running:
print('You are in ' + loc.text)
print(loc.description)
print()
print('You can go:')
print(' \n'.join([e.label for e in loc.exits.values()]))
print()
command = input('? ').split(' ')
cmd = command[0]
if cmd in ['q', 'quit', 'exit']:
running = False
elif cmd == 'go':
target = loc.exits.get(command[1], None)
if target and map[target.to]:
loc = map[target.to]
else:
print('That is not a place. You got lost and returned to the promenade')
loc = map['promenade']
示例8: sig
# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import load [as 别名]
import os
import sys
from math import tanh
from map import Map
def sig(value):
return tanh(value)
def isig(value):
return 1-tanh(value)
def sigm(value):
return (tanh(value)+1)/2.
def isigm(value):
return 1-sigm(value)
basePath = os.path.dirname(os.path.abspath(__file__))
map = Map.load(os.path.join(basePath, 'points.csv'), os.path.join(basePath, 'connections.csv')) # pylint: disable=redefined-builtin
dist = map.dist
iter_neighbors = map.iter_neighbors
示例9: Map
# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import load [as 别名]
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###############################################################################
import argparse
import matplotlib.pyplot as plt
from map import Map
from localization import Localization
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Raodshow is a tool to display road info on a map.",
prog="roadshow.py")
parser.add_argument(
"-m", "--map", action="store", type=str, required=True,
help="Specify the map file in txt or binary format")
args = parser.parse_args()
map = Map()
map.load(args.map)
map.draw_roads(plt)
plt.axis('equal')
plt.show()
示例10: Level
# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import load [as 别名]
class Level(Completable, Inputable):
def __init__(self, surface, level, **kwargs):
super().__init__(**kwargs)
self._surface = surface
self.map = Map(level[0], level[1])
def start(self):
self.map.load()
self._entity_map = {}
self._position_map = {}
self._entities = {}
self._registered = {}
self._enemySpawns = {}
for x, y in self.map.getMap().keys():
self._position_map[(x, y)] = []
self._total_surface = Surface((self.map.w, self.map.h))
tid = self.addEntity(register=True,
entity=MChar(self,
self.map.getType(Tiles.Start)[0],
inputStream=self.getInputStream()))
self._camera = Viewport(tuple([s * const.res for s in const.screenSize]),
lambda: self.map.getAttr("scale"),
self.get(tid),
(150, 200, 150, 200),
self.map)
self._background = Parallax(const.backgrounds)
self.editor = Editor(self.map,
self._surface,
enabled=False,
inputStream=self.getInputStream())
self._input = Input(inputStream=self.getInputStream())
self._input.set(KEYDOWN, self.editor.toggleEnabled, K_e)
self._input.set(KEYDOWN, self.start, K_r)
# self._sound = Sound("assets\\music.ogg")
# self._sound.play(-1)
try:
self._healthBar = HealthBar(10, 10, self.get(tid))
except AssertionError:
pass
for (x, y), val in self.map.enemies.items():
block = self.map.get(x, y)
self._enemySpawns[block] = EnemySpawn(level=self,
anchor=Object(pos=(block.x, block.y)),
maxEmitted=val,
timeBetween=2)
self._countdown = CountdownTimer(const.screenSize[0] * const.res - 50, 10,
self.map.getAttr("timeLim"))
def addEntity(self, register=False, entity=None):
if not entity:
raise Exception("Entity must not be None.")
tid = entity.getId()
self._entities[tid] = entity
if register:
self._registered[tid] = entity
self._entity_map[tid] = set()
return tid
def removeEntity(self, entity):
del self._entities[entity.id]
def get(self, entityId):
return self._entities.get(entityId)
def process(self):
for entity in self._entities.values():
result = entity.tick()
if not entity.isAlive():
self._entities.pop(entity.getId())
# This should generally only apply to playable characters.
if entity in self._registered.values():
if Tiles.End in result.keys():
self.setFinished()
if not entity.isAlive():
self.setLost()
for s in self._enemySpawns.values():
s.tick()
self._camera.tick()
self._countdown.tick()
if self._countdown.isFinished():
self.setLost()
if self.editor.enabled():
self.editor.tick(self._camera)
if self.isComplete():
pass
#.........这里部分代码省略.........
示例11: __init__
# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import load [as 别名]
class Engine:
#-------------------------------------------------------------------------------------------------------
def __init__( self ):
self.core = Core( 60, 1024, 768, "Ninja" )
self.intro = Intro()
self.menu_background = Texture( "menu/background.png" )
self.menu_title = Menu_title()
self.menu_play_button = Menu_play_button()
self.menu_git_button = Menu_link_button( "menu/git.png", "https://github.com/Adriqun" )
self.menu_google_button = Menu_link_button( "menu/google.png", "https://en.wikipedia.org/wiki/Ninja" )
self.menu_facebook_button = Menu_link_button( "menu/facebook.png", "nothing", True )
self.menu_twitter_button = Menu_link_button( "menu/twitter.png", "nothing", True )
self.menu_music_button = Menu_music_button( "menu/music.png" )
self.menu_chunk_button = Menu_music_button( "menu/chunk.png", 1 )
self.menu_exit_log = Menu_exit_log()
self.menu_author_log = Menu_author_log()
self.menu_game_log = Menu_link_button( "menu/game.png", "nothing", True )
self.menu_settings_log = Menu_link_button( "menu/settings.png", "nothing", True )
self.menu_score_log = Menu_score_log()
self.menu_music = Menu_music( "menu/Rayman Legends OST - Moving Ground.mp3" )
self.wall = Wall()
self.hero = Hero()
self.menu_log = Menu_log()
self.map = Map()
#-------------------------------------------------------------------------------------------------------
def load( self ):
self.core.setState( -1 )
self.intro.load( self.core.getWidth(), self.core.getHeight() )
self.menu_title.load( self.core.getWidth() )
self.menu_play_button.load( self.core.getWidth(), self.core.getHeight() )
self.menu_git_button.load( self.core.getWidth(), 10 )
self.menu_google_button.load( self.core.getWidth(), self.menu_git_button.getBot() )
self.menu_facebook_button.load( self.core.getWidth(), self.menu_google_button.getBot() )
self.menu_twitter_button.load( self.core.getWidth(), self.menu_facebook_button.getBot() )
self.menu_music_button.load( 10 )
self.menu_chunk_button.load( self.menu_music_button.getBot() )
self.menu_exit_log.load( self.core.getWidth(), self.core.getHeight() )
self.menu_author_log.load( self.menu_play_button.getLeft()+5, self.core.getWidth(), self.menu_title.getBot() +150, self.menu_play_button.getBot() )
self.menu_game_log.load( self.menu_author_log.getRight(), self.menu_play_button.getBot() +10, True )
self.menu_settings_log.load( self.menu_game_log.getRight(), self.menu_play_button.getBot() +10, True )
self.menu_score_log.load( self.menu_settings_log.getRight(), self.core.getWidth(), self.menu_title.getBot() +150, self.menu_play_button.getBot() )
self.wall.load()
self.hero.load( self.core.getWidth(), self.core.getHeight() )
self.menu_log.load( self.core.getWidth(), self.core.getHeight() )
self.map.load()
#-------------------------------------------------------------------------------------------------------
def handle( self ):
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.core.setQuit()
#-------------------------------------------------------------------------------------------------------
if self.core.getState() == 0:
if self.menu_play_button.getState() == 0:
self.menu_exit_log.handle( event )
#HANDLE IF AUTHOR BUTTON == OFF AND SCORE BUTTON == OFF
if self.menu_author_log.getState() == 0 and self.menu_score_log.getState() == 0:
self.menu_play_button.handle( event )
self.menu_git_button.handle( event )
self.menu_google_button.handle( event )
self.menu_music_button.handle( event )
self.menu_chunk_button.handle( event )
if self.menu_score_log.getState() == 0:
self.menu_author_log.handle( event )
if self.menu_author_log.getState() == 0:
self.menu_score_log.handle( event )
#-------------------------------------------------------------------------------------------------------
if self.core.getState() == 1:
self.menu_log.handle( event )
#HANDLE IF MENU_LOG == OFF
if self.menu_log.getState() == 0:
self.hero.handle( event )
#-------------------------------------------------------------------------------------------------------
def states( self ):
#-------------------------------------------------------------------------------------------------------STATE -1
if self.core.getState() == -1:
#.........这里部分代码省略.........
示例12: main
# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import load [as 别名]
def main():
import os
import sprite
import world
import npc
pygame.init()
# try:
screen = pygame.display.set_mode((640, 480))
pygame.display.set_caption("Testing")
## background = pygame.Surface((640, 480))
## background.fill((255,255,255))
## img_master = pygame.image.load(os.path.join("..\graphics\Parallaxes", "FinalFantasy.jpg")).convert()
## bgd_rect = pygame.Rect(0,0,640,480)
## background = img_master.subsurface((bgd_rect))
clock = pygame.time.Clock()
keepGoing = True
gameWorld = world.World()
worldMap = Map()
worldMap.load(os.path.join("..\map", "test.tmx"))
gameWorld.addMap(worldMap)
player = sprite.Hero()
player.load_sprite_sheet(os.path.join("..\graphics\Characters", "Actor1.png"), (32,32), (0,0), (96,128))
player.speed_is(3)
player.walking_boundary_is(worldMap.size[0], worldMap.size[1])
player.set_pos(200, 200)
## player.walking_boundary_is(1024, 945)
## npc = sprite.Npc()
## npc.load_sprite_sheet(os.path.join("..\graphics\Characters", "Actor1.png"), (32,32), (96,128), (96,128))
## npc.speed_is(2)
## npc.walking_boundary_is(640, 480)
## npc.set_walking_mode(2)
##
## npc1 = sprite.Npc()
## npc1.load_sprite_sheet(os.path.join("..\graphics\Characters", "Actor1.png"), (32,32), (96,0), (96,128))
## npc1.speed_is(1)
## npc1.walking_boundary_is(640, 480)
## npc1.set_walking_mode(1)
for num in xrange(10):
tempNpc = sprite.Npc()
tempNpc.load_sprite_sheet(os.path.join("..\graphics\Characters", "Actor1.png"), (32,32), (96,0), (96,128))
tempNpc.speed_is(1)
tempNpc.set_walking_mode(1)
gameWorld.addEntities(tempNpc)
for num in xrange(10):
tempNpc = sprite.Npc()
tempNpc.load_sprite_sheet(os.path.join("..\graphics\Characters", "Actor1.png"), (32,32), (288,128), (96,128))
tempNpc.speed_is(1)
tempNpc.set_walking_mode(1)
tempNpc.set_pos(100,800)
gameWorld.addEntities(tempNpc)
for num in xrange(10):
tempNpc = sprite.Npc()
tempNpc.load_sprite_sheet(os.path.join("..\graphics\Characters", "Actor3.png"), (32,32), (96,0), (96,128))
tempNpc.speed_is(1)
tempNpc.set_walking_mode(1)
tempNpc.set_pos(900,100)
gameWorld.addEntities(tempNpc)
for num in xrange(10):
tempNpc = sprite.Npc()
tempNpc.load_sprite_sheet(os.path.join("..\graphics\Characters", "Actor2.png"), (32,32), (96,0), (96,128))
tempNpc.speed_is(3)
tempNpc.set_walking_mode(1)
tempNpc.set_pos(900,800)
gameWorld.addEntities(tempNpc)
myRpgNpc = npc.MyRpg()
myRpgNpc.load_sprite_sheet(os.path.join("..\graphics\Characters", "Actor2.png"), (32,32), (96,0), (96,128))
myRpgNpc.set_pos(700, 400)
gameWorld.addEntities(myRpgNpc)
myRpgNpc = npc.Zelda()
myRpgNpc.set_pos(800,600)
gameWorld.addEntities(myRpgNpc)
gameWorld.addEntities(player)
## gameWorld.addEntities(npc)
## gameWorld.addEntities(npc1)
## player.add_unwalkable_sprite(npc)
## player.add_unwalkable_sprite(npc1)
##
## npc.add_unwalkable_sprite(player)
## npc.add_unwalkable_sprite(npc1)
##
## npc1.add_unwalkable_sprite(player)
## npc1.add_unwalkable_sprite(npc)
##
## npc_group = group.Group()
## player_group = group.Group()
#.........这里部分代码省略.........
示例13: __init__
# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import load [as 别名]
def __init__(self, size, stylesheet):
self._map = mapnik.Map(size, size)
mapnik.load_map(self._map, stylesheet)
def render_to_file(self, xmin, ymin, xmax, ymax, path):
extent = mapnik.Box2d(xmin, ymin, xmax, ymax)
self._map.zoom_to_box(extent)
mapnik.render_to_file(self._map, path)
if __name__ == '__main__':
from map import Map
from heightmap import HeightMap
import os
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('heightmap', type=str, help='Heightmap file to create background for')
parser.add_argument('mapnik_xml', type=str, help='Mapnik XML file to render')
parser.add_argument('output_file', type=str, help='File to output result image to')
args = parser.parse_args()
with open(args.heightmap, 'rb') as f:
hm = Map.load(f)
cwd = os.getcwd()
os.chdir(os.path.dirname(args.mapnik_xml))
renderer = MapRenderer(hm.size, args.mapnik_xml)
xmin, ymin, xmax, ymax = hm.bounds
renderer.render_to_file(xmin, ymin, xmax, ymax, os.path.join(cwd, args.output_file))