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


Python Map.draw方法代码示例

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


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

示例1: GameScene

# 需要导入模块: from Map import Map [as 别名]
# 或者: from Map.Map import draw [as 别名]
class GameScene(Scene):
    def _start(self):
        self.map = Map("firstMap.map")
        self.map.start(self.display)
    def _draw(self, dt):
        self.display.fill((255,255,255))
        self.map.draw()
    def _event(self, event):
        self.map.event(event)
    def _update(self, dt):
        self.map.update(dt)

#Класс редактора карт
开发者ID:l0dom,项目名称:TeeWorlds,代码行数:15,代码来源:Scene.py

示例2: __init__

# 需要导入模块: from Map import Map [as 别名]
# 或者: from Map.Map import draw [as 别名]
class Game:
	"""Classe que representa o jogo"""
	def __init__(self):
		self.pilha = [] #pilha usada para o desfazer
		self.win = False #True caso tenha finalizado o mapa
		self.fase = 0 #id do mapa que está em jogo
		self.screen = None #Tela principal do jogo
		self.map = None #Map em jogo
		self.person = None #Personagem
			
	def init(self):
		"""Método para iniciar o jogo completo"""
		#inicia a janela 'invisível'
		self.screen = pygame.display.set_mode((1,1),NOFRAME,32)
		
		
		#cria uma instancia para o mapa
		self.map = Map(self.screen)
		pygame.display.set_icon(self.map._getGraf('!'))
		#cria personagem 
		self.person = Character(self.map,self.screen)

		#incia mapa self.fase
		self.mapInit()
		
		#Comeca o jogo
		self.screen = self.update()
		
		
		#laço principal do jogo
		while True:		
			for event in pygame.event.get():
				if event.type == QUIT:
					self.exit()
				if event.type == KEYDOWN:
					
					#movimentos do personagem
					if event.key == K_UP: #cima
						self.win,s = self.person.up()
						self.pushPilha(s)
					elif event.key == K_DOWN: #baixo
						self.win,s = self.person.down()
						self.pushPilha(s)
					elif event.key == K_LEFT: #esquerda
						self.win,s = self.person.left()
						self.pushPilha(s)
					elif event.key == K_RIGHT: #direita
						self.win,s = self.person.right()
						self.pushPilha(s)
						
					elif event.key == K_w: #ganha
						self.win = True
					elif event.key == K_r: #reincia o mapa
						self.mapInit()
						self.screen = self.update()
						
					elif event.key == K_z and pygame.key.get_mods() & KMOD_CTRL: #ctrl + z
						self.desfazer()
						self.screen = self.update()
				
			pygame.display.flip()
			if self.win:
				self.fase = (self.fase+1) % 16
				self.mapInit()
				self.screen = self.update()
	#end init
	
	
	def pushPilha(self,s):
		"""Método adiciona o último estado do jogo a pilha do desfazer. Adiciona no máximo 5 estados.
			obj.pushPilha(estado)
			estado ->  (['mapa'],(x,y))
		"""
		if len(self.pilha) > 5:
			del self.pilha[0]
		self.pilha.append(s)
		
	def popPilha(self):
		"""Método pop do desfazer"""
		if len(self.pilha) > 0:
			return self.pilha.pop()
		return None
		
	def desfazer(self):
		"""Recupera os estados salvos na pilha para desfazer o jogo"""
		ns = self.popPilha()
		if ns:
			self.map._str = ns[0]
			self.map._pos = ns[1]
			self.map.draw()
			
		
	def mapInit(self):
		"""Inicia um mapa"""
		#Marca estado com não vitorioso
		self.win = False
		#zera a pilha do desfazer
		self.pilha = []
		#define o mapa de inicio
		self.map.setID(self.fase)
#.........这里部分代码省略.........
开发者ID:clebertavares,项目名称:boxworld,代码行数:103,代码来源:Game.py

示例3: __init__

# 需要导入模块: from Map import Map [as 别名]
# 或者: from Map.Map import draw [as 别名]
class Arcade:
    def __init__(self):
        #GLOBAL CONSTS
        self.GAME_WIDTH = 600
        self.GAME_HEIGHT = 500

        self.clock = pygame.time.Clock()
        self.frame = 0
        self.logicFrame = 0
        self.mouseX = 0
        self.mouseY = 0
        self.cameraX = int(self.GAME_WIDTH / 2)
        self.cameraY = int(self.GAME_HEIGHT / 2)
        self.running = True
        self.debug = True
        self.map = Map(self)
        self.heldKeys = dict()
        self.checkedKeys = dict()

        self.root = pygame.display.set_mode((self.GAME_WIDTH, self.GAME_HEIGHT), pygame.DOUBLEBUF)
        self.player = Player(self)
        self._keySetup()
        #temp
        self.map.mapArray[0][0].addEntity(self.player)
        self.player.x = 100
        self.player.y = 100
        while self.running:
            self.displayLoop()
        self.quit()
    def quit(self):
        print("Exiting game")
    def _keySetup(self):
        spaceKey = Key(self)
        def spaceAction():
            if self.player.jumpState < 2:
                self.player.jump()
                self.player.jumpState += 1
        spaceKey.action = spaceAction
        self.checkedKeys.update({K_SPACE:spaceKey})
    def displayLoop(self):
        self.root.fill((100,100,100))
        self.clock.tick(LOGIC_PER_SEC)
        self.logicFrame += 1
        if(self.logicFrame % 2 is 0):
            self.frame += 1
            self.mapLogic()
            self.drawMap()
            self.drawUI()
            #force call mouse move to redraw mouse
            self.handleMouseMove()
            self.handleKeyHold()
            self.eventLoop()
            pygame.display.flip() #used in pygame
    def mapLogic(self):
        self.map.logic()
    def drawMap(self):
        self.map.draw()
    def eventLoop(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit(0)
            elif event.type == MOUSEMOTION:
                mouseX, mouseY = event.pos
                self.mouseX = mouseX
                self.mouseY = mouseY
                self.handleMouseMove()
            elif event.type == MOUSEBUTTONUP:
                self.handleMouseClick(event)
            elif event.type == KEYUP:
                self.handleKeyRelease(event)
            elif event.type == KEYDOWN:
                self.handleKeyDown(event)
    def drawText(self, text, pos, background = (40, 40, 40)):
        textSurface = uiFont.render(str(text), 1, uiTextcolor)
        x, y = pos
        if(x + textSurface.get_width() > self.GAME_WIDTH):
            x = self.GAME_WIDTH - textSurface.get_width() 
        if(y + textSurface.get_height() > self.GAME_HEIGHT):
            y = self.GAME_HEIGHT - textSurface.get_height() 
        pos = (x, y)
        if(background is not None):
            self.root.fill(background, (pos[0], pos[1], textSurface.get_width(), textSurface.get_height()))
        self.root.blit(textSurface, (pos[0], pos[1], textSurface.get_width(), textSurface.get_height()))
    def drawUI(self):
        if(self.debug):
            self.drawText("Frame: " + str(self.frame), (0, 0))
            self.drawText("Logic frame: " + str(self.logicFrame), (0, 15))
            self.drawText("Camera: " + str(self.cameraX) + "-" + str(self.cameraY), (0, 30))
            self.drawText("P: " + str(self.player.x) + "-" + str(self.player.y) + ", S:" + str(round(self.player.vx, 2)) + "&" + str(round(self.player.vy)), (self.GAME_WIDTH, 15))
            self.drawText("J: " + str(["Idle","Jump","DoubleJumped"][self.player.jumpState]), (self.GAME_WIDTH, 30))
            self.drawText("F: " + str(self.player.flying), (self.GAME_WIDTH, 45))
            self.drawText("S: " + str(self.player.supported), (self.GAME_WIDTH, 60))
            self.drawText("X:"+str(self.mouseX)+" Y:"+str(self.mouseY), (self.mouseX + 10, self.mouseY + 10))
            self.drawText(self.heldKeys, (self.GAME_WIDTH, 0))
    def handleMouseMove(self):
        pass
    def handleMouseClick(self, event):
        pass 
    def handleMouseRelease(self, event):
        pass
#.........这里部分代码省略.........
开发者ID:Redyz,项目名称:FiddleSticks,代码行数:103,代码来源:arcade.py

示例4: Camera

# 需要导入模块: from Map import Map [as 别名]
# 或者: from Map.Map import draw [as 别名]
class Camera(object):
    def __init__(self, screen_size, player):
        print "this is a camera"

        self.screen_size = screen_size
        self.view = None

        self.player = player
        self.controller = Controller(self.player)
        self.delay_timer = 0

        self.center_box = pygame.Rect(
            self.screen_size[0] / 4, self.screen_size[1] / 4, self.screen_size[0] / 2, self.screen_size[1] / 2
        )

        self.cam_center = (self.screen_size[0] / 2, self.screen_size[1] / 2)
        self.cam_offset_x = 0
        self.cam_offset_y = 0
        self.camera_speed = self.player.speed
        self.map = None
        self.action_map = None

        self.destination_door = None
        self.fade_alpha = 0
        self.fade_speed = 5
        self.fade_out = False
        self.fade_in = False

        self.text_box = None
        self.build_text_box()
        self.blackness = pygame.Surface(self.screen_size)
        self.blackness.fill((0, 0, 0))
        self.blackness.set_alpha(self.fade_alpha)

    def build_text_box(self, left=4, top=500, height=200, color=(20, 30, 200)):
        self.text_box = TextBox(pygame.Rect(left, top, self.screen_size[0] - left * 2, height), "TEXT", color)

    def convert_door_destination(self, cords):
        x = int(cords[0]) * self.map.tileset_data["t_width"]
        y = int(cords[1]) * self.map.tileset_data["t_height"]
        return x, y

    def load_action_map(self, action_map_url):
        self.action_map = ActionMap(action_map_url, self.text_box)

    def load_map(self, map_url):
        real_url = os.path.join("..", "assets", "world", map_url)
        self.map = Map(real_url, self.text_box)
        if self.map.starting_location:
            self.player.teleport(self.map.starting_location)
        self.view = pygame.Surface(self.map.map_size)
        self.cam_offset_x = self.player.sprite_rect.left
        self.cam_offset_y = self.player.sprite_rect.top

    def update(self, screen):
        if not self.fade_in and not self.fade_out:
            # check for door intersection here?
            for d in self.map.door_list:
                if d.door.colliderect(self.player.pass_rect):
                    self.destination_door = d
                    self.fade_alpha = 0
                    self.fade_out = True
            delay = self.controller.poll(self.map, self.text_box, self.delay_timer, self.action_map)
            if delay:
                self.delay_timer += delay
            # check if camera should shift
            if self.player.sprite_rect.left < self.cam_offset_x - self.center_box.left:
                self.cam_offset_x -= self.camera_speed
            elif self.player.sprite_rect.left > self.cam_offset_x + self.center_box.left:
                self.cam_offset_x += self.camera_speed
            if self.player.sprite_rect.top < self.cam_offset_y - self.center_box.top:
                self.cam_offset_y -= self.camera_speed
            elif self.player.sprite_rect.top > self.cam_offset_y + self.center_box.top:
                self.cam_offset_y += self.camera_speed

        # draw things
        self.map.draw(self.view, passmap=False)
        self.player.draw(self.view)
        self.map.draw_upper(self.view)

        screen.blit(self.view, (self.cam_center[0] - self.cam_offset_x, self.cam_center[1] - self.cam_offset_y))
        # screen.blit(self.blackness, (0, 0))
        if self.text_box:
            self.text_box.draw(screen)

        if self.fade_in:
            if self.fade_alpha > 0:
                self.fade_alpha -= self.fade_speed
                self.blackness.set_alpha(self.fade_alpha)
                screen.blit(self.blackness, (0, 0))
            else:
                self.fade_in = False
        elif self.fade_out:
            if self.fade_alpha < 255:
                self.fade_alpha += self.fade_speed
                self.blackness.set_alpha(self.fade_alpha)
                screen.blit(self.blackness, (0, 0))
            else:
                self.fade_out = False
                self.load_map(self.destination_door.destination_map)
#.........这里部分代码省略.........
开发者ID:bearhockey,项目名称:bobgame_py,代码行数:103,代码来源:Camera.py

示例5: __init__

# 需要导入模块: from Map import Map [as 别名]
# 或者: from Map.Map import draw [as 别名]

#.........这里部分代码省略.........

		if self.keys[pygame.K_DOWN]:
			pass
		if self.speed < 1:
			self.speed = 1

		mouse_pos = pygame.mouse.get_pos()

		self.map.viewPos[0] += mouse_pos[0]-self.width/2
		self.map.viewPos[1] += mouse_pos[1]-self.height/2

		pygame.mouse.set_pos([self.width/2, self.height/2])

		if self.frameCount % self.speed == 0:
			self.simUntilDeath()
	def simUntilDeath(self):
		while self.creature._living == True:
			self.creature.sim(self.map)


	def reset(self):
		self.runs += 1
		self.runhistory.append([self.creature, self.map])
		if self.runs > 4:
			self.runhistory.sort(key=lambda x: x[0].ticks, reverse=True)
			print "-----------------------------"

			#for run in self.runhistory:

			print "ticks:", self.creature.ticks
			for neuronRow in self.creature.network.network:
				for neuron in neuronRow:
					print neuron.weights
			print "-----------------------------"

			self.map.generate()
			self.creature = Creature()

			for layerNum in range(len(self.creature.network.network)):
				for neuronNum in range(len(self.creature.network.network[layerNum])):
					randomNum = random.randint(-4,min(32,len(self.runhistory)/2))
					if randomNum < 0:
						self.creature.network.network[layerNum][neuronNum].weights = [random.random(), random.random(), random.random()]
					else:
						self.creature.network.network[layerNum][neuronNum] = self.runhistory[randomNum][0].network.network[layerNum][neuronNum]
			self.creature.place(self.map)

		else:
			self.map.generate()
			self.creature = Creature()
			self.creature.place(self.map)

	def on_render(self):
		self.surf.fill((0, 0, 0))

		self.map.draw(self.surf)
		self.creature.draw(self.surf, self.map)

		self.frameCount += 1

	def on_cleanup(self):
		pygame.quit()
	def setScale(self, scale):
		if scale < 1:
			return
		self.map.viewPos = [
		(self.map.viewPos[0] - self.width/2)*(scale/self.map.scale)+self.width/2,
		(self.map.viewPos[1] - self.height/2)*(scale/self.map.scale)+self.height/2
		]
		self.map.scale = scale

	def main(self):
		if self.on_init() == False:
			self._running = False

		while self._running:
			for event in pygame.event.get():
				if self.keys[pygame.K_ESCAPE]:
					self._running = False
				self.on_event(event)
				if event.type == pygame.KEYDOWN:
					self.keys[event.key] = True
				if event.type == pygame.KEYUP:
					self.keys[event.key] = False
				if event.type == pygame.QUIT:
					self._running = False
				if event.type == MOUSEBUTTONDOWN:
					if event.button == 4:
						self.setScale(self.map.scale * 1.03)
					if event.button == 5:
						self.setScale(self.map.scale * 0.97)
				if event.type == MOUSEBUTTONUP:
					if event.button == 1:
						self.reset()


			self.on_loop()
			self.on_render()
			pygame.display.flip()
		self.on_cleanup()
开发者ID:erlgo,项目名称:NeuralNetworkAI,代码行数:104,代码来源:Main.py


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