Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/tanchiki/rev/5450c97fbc38
Дата изменения: Unknown
Дата индексирования: Tue Oct 2 06:42:24 2012
Кодировка:
tanchiki: 5450c97fbc38

tanchiki

changeset 53:5450c97fbc38 new

check_wall() added
author Olga Zolotareva <olya_zol@inbox.ru>
date Fri, 24 Dec 2010 23:28:21 +0300
parents d740eff76e7e
children 5cb3fef573f6
files body.py game.py
diffstat 2 files changed, 13 insertions(+), 16 deletions(-) [+]
line diff
     1.1 --- a/body.py	Fri Dec 24 22:10:08 2010 +0300
     1.2 +++ b/body.py	Fri Dec 24 23:28:21 2010 +0300
     1.3 @@ -58,7 +58,6 @@
     1.4  			self.velocity.rho = max_velocity
     1.5  
     1.6  	def fire(self):
     1.7 -		print 'fire!'
     1.8                  bullet_position = self.position + self.turret * (self.radius + 0.1)
     1.9  		bullet_velocity = self.turret.normalize() * bullet_speed
    1.10  		bullet = Bullet(bullet_position, bullet_velocity, self)
    1.11 @@ -74,13 +73,14 @@
    1.12  		pass
    1.13  	
    1.14  	def on_hit(self, bullet):
    1.15 -		pass
    1.16 +		self.strength -= 1
    1.17  
    1.18  	def on_collision(self, other):
    1.19  		pass
    1.20  
    1.21  	def on_wall(self):
    1.22 -		pass
    1.23 +		self.velocity = vector.Vector(0,0)
    1.24 +		self.next_position = self.position
    1.25  
    1.26  class Bullet(Body):
    1.27  	radius = 0.1
    1.28 @@ -89,5 +89,4 @@
    1.29  		Body.__init__(self, position, velocity = self.tank.turret*bullet_velocity)
    1.30  
    1.31  	def on_wall(self):
    1.32 -		pass
    1.33 -
    1.34 +		self.tank.game.bodies.remove(self)
     2.1 --- a/game.py	Fri Dec 24 22:10:08 2010 +0300
     2.2 +++ b/game.py	Fri Dec 24 23:28:21 2010 +0300
     2.3 @@ -29,9 +29,9 @@
     2.4  			print 'update_position' ,  i.position
     2.5  			print 'velocity'  , i.velocity
     2.6  			print 'velocity.rho', i.velocity.rho 	# test
     2.7 -			print '\n'
     2.8  			if isinstance(i,body.Tank) == True:
     2.9  				print 'base_orientation' , i.base_orientation
    2.10 +			print '\n'
    2.11  
    2.12  	def update_velocities(self):
    2.13  		for i in self.bodies:
    2.14 @@ -45,8 +45,6 @@
    2.15  		delta_t = 1
    2.16  		for i in self.bodies:
    2.17  				i.next_position = i.position + i.velocity*body.delta_t
    2.18 -				if isinstance(i, body.Bullet) == True:
    2.19 -					print 'Bullet', i
    2.20  
    2.21  	def check_collisions(self):
    2.22  		for i in self.bodies:
    2.23 @@ -55,13 +53,14 @@
    2.24  					self.handle_collision(i,j)			
    2.25  
    2.26  	def collides(self,body1,body2):
    2.27 -#		if (abs(body1.next_position - body2.next_position) <= (body1.radius + body2.radius)):			if (body1 != body2):
    2.28 -#				print 'collision' 
    2.29 -#				return True
    2.30 -#			else :
    2.31 -#				return False
    2.32 -#		else :
    2.33 -		return False
    2.34 +		if (abs(body1.next_position - body2.next_position) <= (body1.radius + body2.radius)):
    2.35 +			if (body1 != body2):
    2.36 +				print 'collision' 
    2.37 +				return True
    2.38 +			else :
    2.39 +				return False
    2.40 +		else :
    2.41 +			return False
    2.42  
    2.43  	def handle_collision(self,body1,body2):
    2.44  		if isinstance(body1, body.Tank) == True : 
    2.45 @@ -79,7 +78,6 @@
    2.46  		for i in self.bodies :
    2.47  			if ((i.next_position.x - i.radius) <= 0) or ((i.next_position.y - i.radius) <= 0) or ((i.next_position.x + i.radius) >= self.width) or ((i.next_position.y + i.radius) >= self.height) :
    2.48  				i.on_wall()
    2.49 -				print 'wall'      #test
    2.50  
    2.51  	def update_positions(self):
    2.52  		for i in self.bodies: