Exemplo n.º 1
0
	def updateFOWVisibility(self):
		self.friendlyFOWVisibility = set()
		self.enemyFOWVisibility = set()
		vessels = [self.kanmusuDict,self.enemyDict]
		for i in xrange(len(vessels)):
			for vessel in vessels[i]:
				vessel = vessels[i][vessel]
				los = vessel.los
				distance = 3 if los<30 else round(los/10.0)
				visibility = reachable.reachable(self.visionCostMap, vessel.pos[0], vessel.pos[1], distance)[1]
				if i == 0: 
					for item in visibility:
						self.friendlyFOWVisibility.add(item)
				if i == 1:
					for item in visibility:
						self.enemyFOWVisibility.add(item)

		self.visibilityMap = pygame.Surface((32*self.size[1],32*self.size[0]), pygame.SRCALPHA, 32)
		gray = pygame.Surface((32,32), pygame.SRCALPHA, 32)
		gray.fill((155,155,155,150))
		for row in xrange(len(self.map)):
			for col in xrange(len(self.map[0])):
				if (col,row) in self.friendlyFOWVisibility: continue
				else:
					pos = (32*col,32*row) #FLIPPING ROW AND COL HERE BECAUSE METHODS TAKE ARGS IN X AND Y, NOT Y AND X
					self.visibilityMap.blit(gray, pos)
Exemplo n.º 2
0
	def playingUpdate(self, key=None, keys=[0]*500):
		self.playerUIGroup.update()
		self.gameInfoPanel2.update(self.currentLevel)
		cursor = self.currentLevel.cursor

		#####################
		# TURN TICK HANDLER #
		#####################

		incrementTurn = True
		for kanmusu in self.currentLevel.kanmusuDict:
			if ((self.currentLevel.turn%self.currentLevel.kanmusuDict[kanmusu].tickSpeed) == 0 and
				not self.currentLevel.kanmusuDict[kanmusu].hasMoved):
				incrementTurn = False
		if incrementTurn:
			self.currentLevel.turn += 1
			for kanmusu in self.currentLevel.kanmusuDict:
				self.currentLevel.kanmusuDict[kanmusu].hasMoved = False

		#################
		# EVENT HANDLER #
		#################

		if self.isAnimationActive: 
			#Will return True if animation is "done". Otherwise will just update normally
			if self.activeAnimation.update() == True:
				self.isAnimationActive = False
		elif key != None:
			up = (key == "up") or keys[self.upKey]
			down = (key == "down") or keys[self.downKey]
			left = (key == "left") or keys[self.leftKey]
			right = (key == "right") or keys[self.rightKey]
			confirm = (key == "confirm")
			cancel = (key == "cancel")
			if down or up or left or right:
				self.sfx.cursorMove.play()
				if down: cursor.moveCursor((0,-1), self.currentLevel)
				if up: cursor.moveCursor((0,+1), self.currentLevel)
				if left: cursor.moveCursor((-1,0), self.currentLevel)
				if right: cursor.moveCursor((+1,0), self.currentLevel)
				tileType = self.currentLevel.map[cursor.truePos[1]][cursor.truePos[0]]
				self.gameInfoPanel3.update(tileType,self)
				for kanmusu in self.currentLevel.kanmusuDict:
					if (self.currentLevel.kanmusuDict[kanmusu].pos == cursor.truePos and
						self.currentLevel.selectedKanmusu == None):
						self.gameInfoPanel4.update(kanmusu, self)
						self.gameInfoPanel5.update(kanmusu, self)
			if confirm:
				######################
				# if no kanmusu are currently selected
				######################
				if self.currentLevel.selectedKanmusu == None:
					#go through each kanmusu and find one that...
					for kanmusu in self.currentLevel.kanmusuDict:
						#matches our current cursor position if any do at all
						if self.currentLevel.kanmusuDict[kanmusu].pos == cursor.truePos:
							# and has not already moved, eg can still move her this turn
							if not self.currentLevel.kanmusuDict[kanmusu].hasMoved:
								# and is her turn (eg, the "turn number" mods to 0.)
								if (self.currentLevel.turn%self.currentLevel.kanmusuDict[kanmusu].tickSpeed)==0:
									#and make that our current "selected" kanmusu
									self.currentLevel.selectedKanmusu = kanmusu
									self.contextMenu.isOn = True
									self.sfx.select.play()
				######################
				# if a kanmusu is already selected (eg, we're moving her)
				######################
				elif self.currentLevel.selectedKanmusu != None:
					self.sfx.select.play()
					kanmusu = self.currentLevel.selectedKanmusu
					#positions is a list of positions we CANNOT move to
					friendlyPositions = list()
					enemyPositions = list()
					for ship in self.currentLevel.kanmusuDict:
						friendlyPositions.append(self.currentLevel.kanmusuDict[ship].pos)
					for enemy in self.currentLevel.enemyDict:
						enemyPositions.append(self.currentLevel.enemyDict[enemy].pos)
					positions = friendlyPositions+enemyPositions

					kanmusuStats = self.currentLevel.kanmusuDict[kanmusu]

					if self.contextMenu.isOn:
						#If you select "move"
						if self.contextMenu.pos == 0: 
							y,x = cursor.truePos
							speed = self.currentLevel.kanmusuDict[kanmusu].speed
							tempMap = self.currentLevel.terrainCostMap
							#Setting enemy positions to impassable. (Because you're not going to be sailing 5m away from an enemy without exchanging fire.)
							for pos in enemyPositions:
								tempMap[pos[1]][pos[0]] = -1
							self.movableTiles = reachable.reachable(tempMap, y, x, speed)[1]
							self.contextMenu.selected = "move"
						#If you select "attack"
						if self.contextMenu.pos == 1:
							self.contextMenu.selected = "attack"
						#If you select "cancel"
						if self.contextMenu.pos == 2:
							self.currentLevel.selectedKanmusu = None
							self.contextMenu.selected = None
						self.contextMenu.reset()
					# We're selected to move and the selected "move" tile is a valid position.
					elif (self.contextMenu.selected == "move" and 
						  tuple(cursor.truePos) in self.movableTiles and 
						  self.currentLevel.cursor.truePos not in positions):
						self.currentLevel.selectedKanmusu = kanmusu
						self.currentLevel.kanmusuDict[kanmusu].pos = cursor.truePos
						# display context menu here for options (move, move and attack, attack, cancel)
						self.currentLevel.selectedKanmusu = None
						self.contextMenu.selected = None
						self.currentLevel.kanmusuDict[kanmusu].hasMoved = True
						self.currentLevel.updateFOWVisibility()

					# We've selected to attack and the selected tile contains an enemy unit
					elif (self.contextMenu.selected == "attack" and
						  cursor.truePos in enemyPositions and
						  getDisplacement(self.currentLevel.kanmusuDict[kanmusu].pos,cursor.truePos)<=self.currentLevel.kanmusuDict[kanmusu].range):
						for enemy in self.currentLevel.enemyDict:
							enemy = self.currentLevel.enemyDict[enemy]
							if enemy.pos == cursor.truePos:
								enemyVessel = enemy
						kanmusuVessel = self.currentLevel.kanmusuDict[kanmusu]
						battle.cannonAttack(self, kanmusuVessel, enemyVessel)
						if random.randint(1,3) == 1: kanmusuVessel.voices.attack.play()
						self.activeAnimation = animations.ShipToShipBattle(kanmusu)
						self.isAnimationActive = True
						self.currentLevel.selectedKanmusu = None
						self.contextMenu.selected = None
						self.currentLevel.kanmusuDict[kanmusu].hasMoved = True

					else:
						self.currentLevel.selectedKanmusu = None
						self.contextMenu.selected = None
			if cancel:
				self.sfx.cancel.play() 
				self.contextMenu.reset()
				self.currentLevel.selectedKanmusu = None
				self.contextMenu.selected = None