本文整理汇总了Python中Map.update方法的典型用法代码示例。如果您正苦于以下问题:Python Map.update方法的具体用法?Python Map.update怎么用?Python Map.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Map
的用法示例。
在下文中一共展示了Map.update方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MainWindow
# 需要导入模块: import Map [as 别名]
# 或者: from Map import update [as 别名]
class MainWindow(QMainWindow):
'''Wrapper class for...well, the game? Maybe this needs to be called the game engine then'''
def __init__(self):
'''
Only initialize critical components(like opengl) here, use start() for anything else
'''
QMainWindow.__init__(self)
Globals.glwidget = GLWidget(self)
self.setCentralWidget(Globals.glwidget)
Globals.glwidget.makeCurrent()
if Globals.musicOn:
print "Using music"
Globals.mediaobject = Phonon.MediaObject(self)
self.audioOutput = Phonon.AudioOutput(Phonon.MusicCategory, self)
Phonon.createPath(Globals.mediaobject, self.audioOutput)
self.map = Map() #map class
self.drawTimer = QTimer()
self.drawTimer.timeout.connect(self.drawTimerTimeout)
self.drawTimer.start(15)
def start(self):
if Globals.musicOn:
Globals.muspanel = MusPanel(self)
#draw map... set view to ground
Globals.view = self.map.generateMap()
def drawTimerTimeout(self):
self.map.update()
Globals.glwidget.updateGL()
示例2: GameManager
# 需要导入模块: import Map [as 别名]
# 或者: from Map import update [as 别名]
class GameManager(object):
def __init__(self, mapFileName):
self._map = Map(mapFileName, 3);
self._lastTime = time.time();
def start(self):
gevent.spawn(self.update, 0.01);
gevent.spawn(self.spawnMonster, 3);
def update(self, interval):
while True:
gevent.sleep(interval);
elapsedTime = time.time() - self._lastTime;
self._map.update(elapsedTime);
self._map.clearCorpse();
self._lastTime = time.time();
def spawnMonster(self, interval):
while True:
gevent.sleep(interval);
self._map.spawnMonster();
def movePlayer(self, player, direction):
self._map.movePlayer(player, direction);
def addPlayer(self, player):
self._map.playerList.append(player);
def removePlayer(self, player):
self._map.playerList.remove(player);
def getPlayerList(self):
return self._map.playerList;
def getMonsterList(self):
return self._map.monsterList;
def getMap(self):
return self._map.getMap();
示例3: Editor
# 需要导入模块: import Map [as 别名]
# 或者: from Map import update [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)
#.........这里部分代码省略.........
示例4: MultiServerGame
# 需要导入模块: import Map [as 别名]
# 或者: from Map import update [as 别名]
class MultiServerGame():
pygame.mixer.pre_init(44100, -16, 2, 1024)
pygame.mixer.init()
def __init__(self, server, color, levelPreset = "empty"):
self.server = server
self.butterflies = []
self.screen = pygame.display.get_surface()
self.backgroundImage, self.backgroundRect = loadPNG("background.png")
self.buttonSound = pygame.mixer.Sound("resources/sound/button.wav")
self.buttonSound.set_volume(float(Resources.getOptionValue("sound"))/100)
self.active = True
if levelPreset == "empty":
self.level = Map()
else:
self.level = Map(True)
self.toolbar = GameToolbar()
self.regis = Rabbit(1, "regis" , color, self.level.objectList, self.level.objectSpritesList)
self.server.accept()
self.server.send(b"connexion avec client : OK")
msg = self.server.recieve()
mapStr = self.level.getMapStr()
#MAP STRING SEND
self.server.send(struct.pack(str(len(mapStr)) + "s", mapStr))
#SERVER RABBIT COLOR SEND
self.server.send(struct.pack("iii", self.regis.color[0], self.regis.color[1], self.regis.color[2]))
#CLIENT RABBIT COLOR RECIEVE
clientCol = self.server.recieve()
clientCol = struct.unpack("iii", clientCol)
#CREATE CLIENT RABBIT
self.john = Rabbit(2, "john" , clientCol, self.level.objectList, self.level.objectSpritesList, True)
self.regis.appendRabbit(self.john)
self.john.appendRabbit(self.regis)
self.pauseMenu = PauseGameMenu()
self.deltaCarrot = 0
self.timeCarrot = random.randint(1, 4)
# for l in range(0, 6):
# while True:
# randPos = random.randint(0, 16)
# if not self.level.isInBlock(self.level.objectList[randPos].getX() + 10, self.level.objectList[randPos].getY() - 26):
# break
# butterfly = Butterfly(self.level.objectList[randPos].getX() + 10, self.level.objectList[randPos].getY() - 26, (255, 10, 100), self.level.objectList, self.level.objectSpritesList)
# self.butterflies.append(butterfly)
pygame.display.flip()
def update(self):
key = pygame.key.get_pressed()
if self.active:
pygame.mouse.set_visible(0)
for event in pygame.event.get():
if event.type == QUIT or (key[K_F4] and key[K_LALT]):
self.server.close()
return False, self
elif event.type == KEYDOWN:
if event.key == K_UP:
self.regis.jump()
if event.key == K_LEFT:
self.regis.moveLeftStart()
if event.key == K_RIGHT:
self.regis.moveRightStart()
if event.key == K_KP0:
self.regis.throwCarrot()
elif event.type == KEYUP:
if event.key == K_LEFT:
self.regis.moveLeftStop()
if event.key == K_RIGHT:
self.regis.moveRightStop()
# #IF A RABBIT IS TOUCHED
# elif event.type == USEREVENT + 1:
# print "touche"
# if self.john.isTouched():
# self.john.moveLeftStop()
# self.john.moveRightStop()
# elif self.regis.isTouched():
#.........这里部分代码省略.........
示例5: GameScene
# 需要导入模块: import Map [as 别名]
# 或者: from Map import update [as 别名]
class GameScene(Scene):
def __init__(self, game, world, scene_data):
Scene.__init__(self, game)
self.ai = AI(self, game)
self.drawn_images = 0
self.entity_list = []
self.orders = []
self.world = world
self.update_list = []
self.screen = Screen(game)
self.sprite_group = pygame.sprite.LayeredDirty()
self.map = Map(self, world, scene_data.get("grid"))
self.meta_data = scene_data.get("metadata").get("meta")
image = Image("res/img/environment/default.png", game.image_handler, ALIGN_BOTTOM_CENTER)
self.sprite_group.add(image)
self.hud = Hud(self)
self.game.player_handler.add_player_characters(self)
def get_spawn_point(self):
return random.choice(self.map.spawn_list)
def draw(self, view_zoom, view_offset, settings):
rects = []
self.map.update(view_zoom, view_offset, settings)
rects += self.map.sprite_group.draw(self.game.screen)
self.hud.update(settings)
rects += self.hud.sprite_group.draw(self.game.screen)
for entity in self.entity_list:
body = entity.body_handler
if body != 0:
body.update_images(view_zoom, view_offset, settings)
rects += body.sprite_group.draw(self.game.screen)
# print self.drawn_images
self.drawn_images = 0
pygame.display.update(rects)
return
def add_entity(self, entity):
if self.entity_list.__contains__(entity):
return False
self.entity_list.append(entity)
for update in self.update_list:
if update.owner == entity:
return
self.add_update(Update(entity, entity.update))
def remove_entity(self, entity):
if self.entity_list.__contains__(entity) == False:
return False
self.entity_list.remove(entity)
for update in self.update_list:
if update.owner == entity:
self.remove_update(update)
entity.body_handler.destroy()
def add_update(self, update):
if update == None:
return False
if self.update_list.__contains__(update):
return False
self.update_list.append(update)
return True
def remove_update(self, update):
if self.update_list.__contains__(update):
self.update_list.remove(update)
return True
return False
def Step(self):
# self.game.sound_handler.play_sound('shoot')
self.screen.update_camera_center()
for update in self.update_list:
update.run()
self.ai.update()
def destroy(self):
while len(self.entity_list) != 0:
entity = self.entity_list[0]
entity.alive = False
self.remove_entity(entity)
while len(self.orders) != 0:
order = self.orders[0]
self.orders.remove(order)
while len(self.update_list) != 0:
update = self.update_list[0]
self.update_list.remove(update)
self.hud.destroy()
self.map.destroy()
self.update_list = 0
self.map = 0
self.hud = 0
self.screen = 0
self.entity_list = 0
self.orders = 0
self.world.ClearForces()
def defeat(self, type):
if type == DEFEAT_GROUP_AI:
#.........这里部分代码省略.........
示例6: Game
# 需要导入模块: import Map [as 别名]
# 或者: from Map import update [as 别名]
class Game():
pygame.mixer.pre_init(44100, -16, 2, 1024)
pygame.mixer.init()
def __init__(self, color1, color2, levelPreset = "empty"):
self.butterflies = []
self.screen = pygame.display.get_surface()
self.backgroundImage, self.backgroundRect = loadPNG("background.png")
self.buttonSound = pygame.mixer.Sound("resources/sound/button.wav")
self.buttonSound.set_volume(float(Resources.getOptionValue("sound"))/100)
self.active = True
if levelPreset == "empty":
self.level = Map()
else:
self.level = Map(True)
self.toolbar = GameToolbar()
self.regis = Rabbit(1, "regis", color1, self.level.objectList, self.level.objectSpritesList)
self.john = Rabbit(2, "john", color2, self.level.objectList, self.level.objectSpritesList)
self.john.appendRabbit(self.regis)
self.regis.appendRabbit(self.john)
self.pauseMenu = PauseGameMenu()
self.deltaCarrot = 0
self.timeCarrot = random.randint(1, 4)
for l in range(0, 6):
while True:
randPos = random.randint(0, 16)
if not self.level.isInBlock(self.level.objectList[randPos].getX() + 10, self.level.objectList[randPos].getY() - 26):
break
butterfly = Butterfly(self.level.objectList[randPos].getX() + 10, self.level.objectList[randPos].getY() - 26, (255, 10, 100), self.level.objectList, self.level.objectSpritesList)
self.butterflies.append(butterfly)
pygame.display.flip()
def update(self):
key = pygame.key.get_pressed()
if self.active:
pygame.mouse.set_visible(0)
for event in pygame.event.get():
if event.type == QUIT or (key[K_F4] and key[K_LALT]):
return False, self
elif event.type == MOUSEMOTION and (key[K_LSHIFT] or key[K_LCTRL]):
mse = pygame.mouse.get_pos()
if not any(obj.rect.collidepoint(mse) for obj in self.level.objectList):
x = (int(mse[0]) / 50)*50
y = (int(mse[1]) / 50)*50
if key[K_LSHIFT]:
self.level.addObject(x, y, "earth")
else:
self.level.addObject(x, y, "boing")
elif event.type == MOUSEMOTION and key[K_LALT]:
mse = pygame.mouse.get_pos()
self.level.removeObjectFromPos(mse)
elif event.type == KEYDOWN:
#KEYS FOR JOHN
if event.key == K_UP:
self.john.jump()
if event.key == K_LEFT:
self.john.moveLeftStart()
if event.key == K_RIGHT:
self.john.moveRightStart()
if event.key == K_KP0:
self.john.throwCarrot()
#KEYS FOR REGIS
if event.key == K_w:
self.regis.jump()
if event.key == K_a:
self.regis.moveLeftStart()
if event.key == K_d:
self.regis.moveRightStart()
if event.key == K_e:
self.regis.throwCarrot()
if event.key == K_c:
self.level.addCarrot()
if event.key == K_ESCAPE:
self.active = False
self.john.moveLeftStop()
self.john.moveRightStop()
self.regis.moveLeftStop()
self.regis.moveRightStop()
#.........这里部分代码省略.........