本文整理汇总了Python中Map.save方法的典型用法代码示例。如果您正苦于以下问题:Python Map.save方法的具体用法?Python Map.save怎么用?Python Map.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Map
的用法示例。
在下文中一共展示了Map.save方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Editor
# 需要导入模块: import Map [as 别名]
# 或者: from Map import save [as 别名]
class Editor():
pygame.mixer.pre_init(44100, -16, 2, 1024)
pygame.mixer.init()
def __init__(self, levelPreset = "empty"):
self.screen = pygame.display.get_surface()
self.backgroundImage, self.backgroundRect = loadPNG("background.png")
self.blockList = [Object(type = "earth"), Object(type = "boing"), Object(type = "ice")]
self.currentBlockNumber = 0
self.currentBlock = self.blockList[self.currentBlockNumber]
self.currentSpriteBlock = pygame.sprite.RenderPlain(self.currentBlock)
self.buttonSound = pygame.mixer.Sound("resources/sound/button.wav")
self.buttonSound.set_volume(float(Resources.getOptionValue("sound"))/100)
self.grid = False
self.level = Map(True)
self.active = True
self.pauseMenu = PauseEditorMenu()
self.toolbar = EditorToolbar()
if levelPreset != "empty":
self.level.load(levelPreset)
pygame.display.flip()
def update(self):
key = pygame.key.get_pressed()
mouse = pygame.mouse.get_pressed()
if self.active:
pygame.mouse.set_cursor(*pygame.cursors.arrow)
for event in pygame.event.get():
mse = pygame.mouse.get_pos()
self.currentBlock.rect.topleft = ((int(mse[0]) / 50)*50, (int(mse[1]) / 50)*50)
if event.type == QUIT or (key[K_F4] and key[K_LALT]):
return False, self
elif key[K_LCTRL] and key[K_s]:
return True, SaveLevelMenu(self.level)
elif key[K_LCTRL] and key[K_l]:
return True, LoadLevelMenu()
elif event.type == MOUSEBUTTONDOWN:
if event.button == 5:
self.currentBlockNumber = (self.currentBlockNumber - 1) % len(self.blockList)
if event.button == 4:
self.currentBlockNumber = (self.currentBlockNumber + 1) % len(self.blockList)
if event.button == 3:
self.level.removeObjectFromPos(mse)
if event.button == 1:
if not any(obj.rect.collidepoint(mse) for obj in self.level.objectList):
if self.currentBlock.getType() == "boing":
if self.level.getObjectFromPos((mse[0], mse[1] + 50)).getType() != "boing":
if not self.level.isInBlock(mse[0], mse[1] - 50):
self.level.addObject(self.currentBlock.rect.x, self.currentBlock.rect.y, self.currentBlock.getType())
else:
if self.level.getObjectFromPos((mse[0], mse[1] + 50)).getType() != "boing":
self.level.addObject(self.currentBlock.rect.x, self.currentBlock.rect.y, self.currentBlock.getType())
self.currentBlock = self.blockList[self.currentBlockNumber]
self.currentSpriteBlock = pygame.sprite.RenderPlain(self.currentBlock)
self.currentBlock.rect.topleft = ((int(mse[0]) / 50)*50, (int(mse[1]) / 50)*50)
elif event.type == MOUSEMOTION:
if mouse[0]:
if not any(obj.rect.collidepoint(mse) for obj in self.level.objectList):
if self.currentBlock.getType() == "boing":
if self.level.getObjectFromPos((mse[0], mse[1] + 50)).getType() != "boing":
if not self.level.isInBlock(mse[0], mse[1] - 50):
self.level.addObject(self.currentBlock.rect.x, self.currentBlock.rect.y, self.currentBlock.getType())
else:
if self.level.getObjectFromPos((mse[0], mse[1] + 50)).getType() != "boing":
self.level.addObject(self.currentBlock.rect.x, self.currentBlock.rect.y, self.currentBlock.getType())
elif mouse[2]:
self.level.removeObjectFromPos(mse)
elif event.type == KEYDOWN:
if event.key == K_g:
if self.grid:
self.grid = False
else:
self.grid = True
elif event.key == K_ESCAPE:
self.active = False
self.level.save("last")
self.screen.blit(self.backgroundImage, self.backgroundRect, self.backgroundRect)
#.........这里部分代码省略.........