oventoaster
Still Fresh
- Joined
 - Apr 17, 2012
 
- Messages
 - 7
 
I am currently building a turn based strategy game using Python/pygame. While unit spawning, movement and turn order work perfectly, I have hit a snag in the combat block.
Say for example, I use a Red archer to attack a Blue Archer, as shown here:
	
	
	
		
the (if mouseX in range...) tests if a Blue Archer is being attacked
the (if redA.selected == 1) lets pygame know that a Red archer is attacking a Blue archer
if bluA.rect.center - redA.rect.center >= (50, 50) and bluA.rect.center - redA.rect.center <= (300, 300): print 'The red archer attacks the blue archer'
This should check if the Red archer can attack within it's range - which is between 50 and 300 pixels away. Since in this situation, the Red Archer is in range, I initiate the attack.
When I initiate the attack, this error comes up:
	
	
	
		
and the game freezes.
My question is this: How do I check if the Red archer is in range to attack the Blue Archer? Can the same be done for the Blue archer when he attacks?
				
			Say for example, I use a Red archer to attack a Blue Archer, as shown here:
		Code:
	
	if mouseX in range(bluA.rect.left, bluA.rect.right) and mouseY in range(bluA.rect.top, bluA.rect.bottom):
						-snip-
						if redA.selected == 1:
							if bluA.rect.center - redA.rect.center >= (50, 50) and bluA.rect.center - redA.rect.center <= (300, 300):
								print 'The red archer attacks the blue archer'
						-snip-
	the (if mouseX in range...) tests if a Blue Archer is being attacked
the (if redA.selected == 1) lets pygame know that a Red archer is attacking a Blue archer
if bluA.rect.center - redA.rect.center >= (50, 50) and bluA.rect.center - redA.rect.center <= (300, 300): print 'The red archer attacks the blue archer'
This should check if the Red archer can attack within it's range - which is between 50 and 300 pixels away. Since in this situation, the Red Archer is in range, I initiate the attack.
When I initiate the attack, this error comes up:
		Code:
	
	Traceback (most recent call last):
  File "C:\Users\Oventoaster\Desktop\Table Wars\Table Wars.py", line 770, in <module>
	main()
  File "C:\Users\Oventoaster\Desktop\Table Wars\Table Wars.py", line 152, in main
	if bluA.rect.center - redA.rect.center >= (50, 50) and bluA.rect.center - redA.rect.center <= (300, 300):
TypeError: unsupported operand type(s) for -: 'tuple' and 'tuple'
	and the game freezes.
My question is this: How do I check if the Red archer is in range to attack the Blue Archer? Can the same be done for the Blue archer when he attacks?
	