예제 #1
0
	def fire(self,currentFrame):
		if (currentFrame - self.lastFired) > self.attackRate:
			self.lastFired = currentFrame
			
			unitDirect = vec.unitdir(self.attackingTarget().locationX, self.attackingTarget().locationY, self.getLocationX(), self.getLocationY(), self.getSpeed())
			self.setRotation(unitDirect)

			for b in self.bulletList:
				if b.isActive == False:
					b.activate(self.attackingTarget())
					b.isActive = True
					b.whenFired = currentFrame
					b.locationX = self.centerX
					b.locationY = self.centerY
					b.moveToTargetX = self.attackingTarget().locationX
					b.moveToTargetY = self.attackingTarget().locationY
예제 #2
0
def main():
	#connect to
	print sys.argv[1]
	#via this port
	print sys.argv[2]
	#wait before moveing around
	print sys.argv[3]

	playerList = []
	pygame.init()
	windowSize = 640,480
	screen = pygame.display.set_mode(windowSize,0,8)

	n = NC.client_thread(sys.argv[1],int(sys.argv[2]))
	n.connect()

	for peer in n.peer_list:
		playerList.append(player.Player(peer[0], peer[1]))

	time.sleep(int(sys.argv[3]))

	sel = False
	DONE = False
	mySelf = None

	n.minput(1,52,52)
	aDelta = time.time()
	elapsedTime = 0

	while not DONE:
		n.send()

		#Bot Logic Goes Here
		push = random.randint(0,4)

		# time deltas to keep track of when to click on the screen
		bDelta = time.time()
		elapsedTime += (bDelta - aDelta)
		aDelta = bDelta
		
		#Game Engine Logic Is Here
		n.recv()
		while not n.recv_queue.empty():
			tempData = n.recv_queue.get()
			if tempData[2] == 7:
				playerList.append(player.Player(tempData[3], tempData[4]))
				for person in playerList:
					if n.info.cid == person.playerID:
						mySelf = person
			for person in playerList:					
				if tempData[0] == person.playerID:
					if tempData[2] == 2:  
						if tempData[3][0] == 1:  # selecting
							for tro in person.troops:
								tro.setSelectVal(False)
							for tro in person.troops:
								dist = vec.subtract(tempData[3][1], tempData[3][2], tro.getLocationX(), tro.getLocationY())
								if fabs(dist[0])< tro.size and fabs(dist[1]) < tro.size:
									tro.setSelectVal(True)
									break
								else:
									tro.setSelectVal(False)
						elif tempData[3][0] == 3:  # orders
							for tro in person.troops:
								if tro.isSelected():
									tro.moveToTargetX = tempData[3][1]
									tro.moveToTargetY = tempData[3][2]

		for person in playerList:
			for tro in person.troops:
				unitDirect = vec.unitdir(tro.getMoveToTargetX(), tro.getMoveToTargetY(), tro.getLocationX(), tro.getLocationY(), tro.getSpeed())
				tro.setRotation(unitDirect)
				tro.locationX = tro.locationX + (tro.speed * unitDirect[0])
				tro.locationY = tro.locationY + (tro.speed * unitDirect[1])

		# Follow player 1's speedster troop
		if mySelf != None and elapsedTime > 0.5:
			elapsedTime = 0
			for person in playerList:
				if person.playerID == 1:
					unitDirect = vec.unitdir(person.troops[0].moveToTargetX, person.troops[0].moveToTargetY,
					                         person.troops[0].locationX, person.troops[0].locationY,
					                         person.troops[0].getSpeed())
					if unitDirect[0] != 0 and unitDirect[1] != 0:
						print "moving, must gettem"
						n.minput(3, person.troops[0].getLocationX(), person.troops[0].getLocationY())
예제 #3
0
def updateUnits(screen, playerList, worldMap, mygui):

	global framesPast
	global building_mode, selected_building

	framesPast += 1
	
	for person in playerList:
		for tro in person.troops:

			if tro.isAlive:


				if tro.attacking:
					distanceToTarget = vec.distance((tro.getLocationX() , tro.getLocationY() ) , (tro.attackingTarget().getLocationX() ,tro.attackingTarget().getLocationY() ))
					unitDirect = vec.unitdir(tro.getMoveToTargetX(), tro.getMoveToTargetY(), tro.getLocationX(), tro.getLocationY(), tro.getSpeed())
					tro.setRotation(unitDirect)
					if distanceToTarget < tro.attackRange:
						tro.moveToTargetX = tro.getLocationX()
						tro.moveToTargetY = tro.getLocationY()
						tro.fire(framesPast)
					else:
						tro.moveToTargetX = tro.attackingTarget().getLocationX()
						tro.moveToTargetY = tro.attackingTarget().getLocationY()
	
	
				unitDirect = vec.unitdir(tro.getMoveToTargetX(), tro.getMoveToTargetY(), tro.getLocationX(), tro.getLocationY(), tro.getSpeed())
				tro.setRotation(unitDirect)
	
				newMoveRect = pygame.Rect(tro.locationX + (tro.speed * unitDirect[0]),tro.locationY + (tro.speed * unitDirect[1]),tro.mySprite.get_rect()[2], tro.mySprite.get_rect()[3])
				for p in playerList:
					for b in p.buildings:
						newRect = pygame.Rect(b.locationX ,b.locationY,b.mySprite.get_rect()[2], b.mySprite.get_rect()[3])
						if newMoveRect.colliderect(newRect):
							tro.moveToTargetX = tro.getLocationX()
							tro.moveToTargetY = tro.getLocationY()
	
				unitDirect = vec.unitdir(tro.getMoveToTargetX(), tro.getMoveToTargetY(), tro.getLocationX(), tro.getLocationY(), tro.getSpeed())
				tro.setRotation(unitDirect)
		
				tro.locationX = tro.locationX + (tro.speed * unitDirect[0])
				tro.locationY = tro.locationY + (tro.speed * unitDirect[1])
				tro.centerX = tro.locationX + (tro.mySprite.get_rect()[2] / 2)
				tro.centerY = tro.locationY + (tro.mySprite.get_rect()[3] / 2)
				translatedX = tro.locationX - worldMap.view.locX
				translatedY = tro.locationY - worldMap.view.locY
				#print translatedX
				#print translatedY
				#print worldMap.view.sizeX
				#print worldMap.view.sizeY
				if translatedX > 0 and translatedY > 0 and translatedX < worldMap.view.sizeX and translatedY < worldMap.view.sizeY:
					screen.blit(tro.mySprite, (translatedX,translatedY))
	
				for b in tro.bulletList:
					if b.isActive:
						if (framesPast - b.whenFired) > b.lifeTime:
							b.disable()
						
						unitDirect = vec.unitdir(b.attackingTarget().locationX, b.attackingTarget().locationY, b.getLocationX(), b.getLocationY(), b.getSpeed())
						b.setRotation(unitDirect)
						b.locationX = b.locationX + (b.speed * unitDirect[0])
						b.locationY = b.locationY + (b.speed * unitDirect[1])
						b.centerX = b.locationX + (b.mySprite.get_rect()[2] / 2)
						b.centerY = b.locationY + (b.mySprite.get_rect()[3] / 2)
						translatedX = b.locationX - worldMap.view.locX
						translatedY = b.locationY - worldMap.view.locY
						newMoveRect = pygame.Rect(b.locationX,b.locationY,b.mySprite.get_rect()[2], b.mySprite.get_rect()[3])
						for p in playerList:
							for t in p.troops:
								if id(tro) != id(t):
									if t.isAlive:
										newRect = pygame.Rect(t.locationX ,t.locationY,t.mySprite.get_rect()[2], t.mySprite.get_rect()[3])
										if newMoveRect.colliderect(newRect):
											b.disable()
											t.takeDamage(tro.attackDamage, tro, p.troops, playerList)
											if t.isAlive == False:
												tro.attacking = False
												tro.attackingTarget = None

							for bild in p.buildings:
								if bild.isAlive:
									newRect = pygame.Rect(bild.locationX, bild.locationY, bild.mySprite.get_rect()[2], bild.mySprite.get_rect()[3])
									if newMoveRect.colliderect(newRect):
										b.disable()
										bild.takeDamage(tro.attackDamage, tro, p.buildings, playerList)
										if bild.isAlive == False:
											tro.attackingTarget = None
									
	
						if translatedX > 0 and translatedY > 0 and translatedX < worldMap.view.sizeX and translatedY < worldMap.view.sizeY:
							screen.blit(b.mySprite, (translatedX,translatedY))
	
	
	
		for b in person.buildings:
			if b.isAlive:
				translatedX = b.locationX - worldMap.view.locX
				translatedY = b.locationY - worldMap.view.locY
				if translatedX > 0 and translatedY > 0 and translatedX < worldMap.view.sizeX and translatedY < worldMap.view.sizeY:
					screen.blit(b.mySprite, (translatedX,translatedY))

	if building_mode:
		loc = pygame.mouse.get_pos()
		if selected_building == 1:
			#print "blit base"
			screen.blit(mygui.base, (loc[0]-45,loc[1]-45))
		elif selected_building == 2:
			#print "blit barracks"
			screen.blit(mygui.barracks, (loc[0]-45,loc[1]-45))
예제 #4
0
def main():
	#connect to
	print sys.argv[1]
	#via this port
	print sys.argv[2]
	#wait before moveing around
	print sys.argv[3]

	playerList = []
	pygame.init()
	windowSize = 640,480
	screen = pygame.display.set_mode(windowSize,0,8)

	n = NC.client_thread(sys.argv[1],int(sys.argv[2]))
	n.connect()

	for peer in n.peer_list:
		playerList.append(player.Player(peer[0], peer[1]))

	time.sleep(int(sys.argv[3]))

	DONE = False

	while not DONE:
		n.send()
		
		#Game Engine Logic Is Here
		n.recv()
		while not n.recv_queue.empty():
			tempData = n.recv_queue.get()
			if tempData[2] == 7:
				playerList.append(player.Player(tempData[3], tempData[4]))
				for person in playerList:
					if n.info.cid == person.playerID:
						mySelf = person
			for person in playerList:					
				if tempData[0] == person.playerID:
					if tempData[2] == 2:
						if tempData[3][0] == 1:
							for tro in person.troops:
								tro.setSelectVal(False)
							for tro in person.troops:
								dist = vec.subtract(tempData[3][1], tempData[3][2], tro.getLocationX(), tro.getLocationY())
								if fabs(dist[0])< tro.size and fabs(dist[1]) < tro.size:
									tro.setSelectVal(True)
									break
								else:
									tro.setSelectVal(False)
						elif tempData[3][0] == 3:
							for tro in person.troops:
								if tro.isSelected():
									tro.moveToTargetX = tempData[3][1]
									tro.moveToTargetY = tempData[3][2]

		for person in playerList:
			for tro in person.troops:
				unitDirect = vec.unitdir(tro.getMoveToTargetX(), tro.getMoveToTargetY(), tro.getLocationX(), tro.getLocationY(), tro.getSpeed())
				tro.setRotation(unitDirect)
				tro.locationX = tro.locationX + (tro.speed * unitDirect[0])
				tro.locationY = tro.locationY + (tro.speed * unitDirect[1])

		
	
		#Bot Logic Goes Here
		#for each unit
		for play in playerList:
			if play.playerID == n.info.cid:
				for tro in play.troops:
					num = random.randint(0,5)
					if num == 1:
						n.minput(1,tro.locationX+1, tro.locationY+1)
						n.minput(3, random.randint(0,1000), random.randint(0,1000))
					if (num == 2):
						n.minput(1, random.randint(0,1000), random.randint(0,1000))
					elif (num == 3):
						n.minput(3, random.randint(0,1000), random.randint(0,1000))