Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/tanchiki/raw-rev/c71c27b09bc7
Дата изменения: Unknown
Дата индексирования: Tue Oct 2 10:40:16 2012
Кодировка: UTF-8

# HG changeset patch
# User Peter Zotov
# Date 1292808908 -10800
# Node ID c71c27b09bc798bc2815ac99d7746213dd9e476d
# Parent 3634a208da61d0daa8b0f6fccadfa9faa749d8a0
Fixed and updated overall repository format.

Removed CR's. Changed encoding to UTF-8.
Removed trailing whitespace and unified the rest.
Removed test code from vector.py.

diff -r 3634a208da61 -r c71c27b09bc7 body.py
--- a/body.py Sun Dec 19 16:04:29 2010 +0300
+++ b/body.py Mon Dec 20 04:35:08 2010 +0300
@@ -1,66 +1,64 @@
-import vector
-import math
-delta_phi = math.pi # deltha phi = math.pi
-speed_delta = 1
-delta_t = 1
-max_velocity = 2
-initial_strength = 1
-
-class Body(object):
- def __init__(self, position, velocity = vector.null):
- self.position = position
- self.velocity = velocity
- self.radius = radius
-
-
-class Tank(Body):
- radius = 1
- def __init__(self, position, user):
- Body.__init__(self, position)
- self.strength = 0
- self.turret = vector.i
- self.base_orientation = 1 # 1 or -1
- self.user = user
- user.tank = self # ????????? ???? ? User
-
-
- def rotate_base(tank, angle):
- self.velocity.phi += angle
-
- def rotate_turret(self, angle):
- self.turret.phi += angle
-
- def accelerate(self, speed_delta):
- self.velocity.rho += speed_delta * delta_t
- if self.velocity.rho > max_velocity:
- self.velocity.rho = max_velocity
-
- def fire(self):
- pass
-
- def on_tick(self,other_tanks, bullets):
- if self.user.base_left == True:
- self.rotate_base(delta_phi)
- if self.user.base_right == True:
- self.rotate_base(-1*delta_phi)
- if self.user.accelerate == True:
- self.accelerate(speed_delta)
-
- def on_spawn(self):
- pass
-
- def on_death(self) :
- pass
-
- def on_hit(self,bullet):
- pass
-
- def on_collision(self):
- pass
-
- def on_wall(self):
- pass
-
-class Bullet(Body):
- radius = 0.1
- pass
\ No newline at end of file
+import vector
+import math
+delta_phi = math.pi # deltha phi = math.pi
+speed_delta = 1
+delta_t = 1
+max_velocity = 2
+initial_strength = 1
+
+class Body(object):
+ def __init__(self, position, velocity = vector.null):
+ self.position = position
+ self.velocity = velocity
+ self.radius = radius
+
+class Tank(Body):
+ radius = 1
+ def __init__(self, position, user):
+ Body.__init__(self, position)
+ self.strength = 0
+ self.turret = vector.i
+ self.base_orientation = 1 # 1 or -1
+ self.user = user
+ user.tank = self # добавляет себя в User
+
+ def rotate_base(tank, angle):
+ self.velocity.phi += angle
+
+ def rotate_turret(self, angle):
+ self.turret.phi += angle
+
+ def accelerate(self, speed_delta):
+ self.velocity.rho += speed_delta * delta_t
+ if self.velocity.rho > max_velocity :
+ self.velocity.rho = max_velocity
+
+ def fire(self):
+ pass
+
+ def on_tick(self,other_tanks, bullets):
+ if self.user.base_left == True :
+ self.rotate_base(delta_phi)
+ if self.user.base_right == True :
+ self.rotate_base(-1*delta_phi)
+ if self.user.accelerate == True :
+ self.accelerate(speed_delta)
+
+ def on_spawn(self):
+ pass
+
+ def on_death(self):
+ pass
+
+ def on_hit(self,bullet):
+ pass
+
+ def on_collision(self):
+ pass
+
+ def on_wall(self):
+ pass
+
+class Bullet(Body):
+ radius = 0.1
+ pass
diff -r 3634a208da61 -r c71c27b09bc7 game.py
--- a/game.py Sun Dec 19 16:04:29 2010 +0300
+++ b/game.py Mon Dec 20 04:35:08 2010 +0300
@@ -1,52 +1,50 @@
-other_tanks = []
-bullets = []
-
-class Game(object):
- def __init__(self, bodies, users, width, height):
- self.bodies = bodies
- self.users = users
- self.width = width
- self.height = height
-
- def step(game):
- game.next_positions()
- game.check_collisions()
- game.check_walls()
- game.update_positions()
- game.invoke_ticks()
- game.respawn()
-
- def next_positions(game):
- delta_t = 1
- for i in game.bodies:
- i.next_position = i.position + i.velocity*(delta_t)
-
-
- def check_collisions(game):
- pass
-
- def collides(self,body1,body2):
- pass
-
- def handle_collision(self,body1,body2):
- pass
-
- def check_walls(game):
- for i in game.bodies :
- if ((i.next_position.x - i.radius) <= 0) or ((i.next_position.y - i.radius) <= 0) or ((i.next_position.x + i.radius) >= game.width) or ((i.next_position.y + i.radius) >= game.height) :
- i.on_wall()
-
-
- def update_positions(game):
- for i in game.bodies:
- i.position = i.next_position
-
- def invoke_ticks(game):
- for i in game.users:
- i.tank.on_tick(other_tanks,bullets)
-
- def respawn(game):
- for i in game.users :
- if i.tank.strength == 0 :
- i.tank.on_spawn()
- i.tank.strength = 1
+other_tanks = []
+bullets = []
+
+class Game(object):
+ def __init__(self, bodies, users, width, height):
+ self.bodies = bodies
+ self.users = users
+ self.width = width
+ self.height = height
+
+ def step(game):
+ game.next_positions()
+ game.check_collisions()
+ game.check_walls()
+ game.update_positions()
+ game.invoke_ticks()
+ game.respawn()
+
+ def next_positions(game):
+ delta_t = 1
+ for i in game.bodies :
+ i.next_position = i.position + i.velocity*(delta_t)
+
+ def check_collisions(game):
+ pass
+
+ def collides(self,body1,body2):
+ pass
+
+ def handle_collision(self,body1,body2):
+ pass
+
+ def check_walls(game):
+ for i in game.bodies :
+ if ((i.next_position.x - i.radius) <= 0) or ((i.next_position.y - i.radius) <= 0) or ((i.next_position.x + i.radius) >= game.width) or ((i.next_position.y + i.radius) >= game.height) :
+ i.on_wall()
+
+ def update_positions(game):
+ for i in game.bodies :
+ i.position = i.next_position
+
+ def invoke_ticks(game):
+ for i in game.users :
+ i.tank.on_tick(other_tanks,bullets)
+
+ def respawn(game):
+ for i in game.users :
+ if i.tank.strength == 0 :
+ i.tank.on_spawn()
+ i.tank.strength = 1
diff -r 3634a208da61 -r c71c27b09bc7 user.py
--- a/user.py Sun Dec 19 16:04:29 2010 +0300
+++ b/user.py Mon Dec 20 04:35:08 2010 +0300
@@ -1,12 +1,15 @@
-class User(object):
-
- def __init__(self, base_left = False , base_right = False, turret_left = False, turret_right = False, accelerate = False, decelerate = False, fire = False, tank = 0):
- self.base_left = base_left
- self.base_right = base_right
- self.turret_left = turret_left
- self.turret_right = turret_right
- self.accelerate = accelerate
- self.decelerate = decelerate
- self.fire = fire
- self.tank = tank
-
+class User(object):
+
+ def __init__(self, base_left = False, base_right = False,
+ turret_left = False, turret_right = False,
+ accelerate = False, decelerate = False,
+ fire = False, tank = 0):
+ self.base_left = base_left
+ self.base_right = base_right
+ self.turret_left = turret_left
+ self.turret_right = turret_right
+ self.accelerate = accelerate
+ self.decelerate = decelerate
+ self.fire = fire
+ self.tank = tank
+
diff -r 3634a208da61 -r c71c27b09bc7 vector.py
--- a/vector.py Sun Dec 19 16:04:29 2010 +0300
+++ b/vector.py Mon Dec 20 04:35:08 2010 +0300
@@ -1,61 +1,57 @@
-import math
-
-class Vector(object):
-
- def __init__(self, x=0 , y=0):
- self.x = x
- self.y = y
-
- def __add__(self, other):
- result = Vector(0,0)
- result.x = self.x + other.x
- result.y = self.y + other.y
- return result
-
- def __mul__(self, alpha):
- result = Vector()
- result.x = self.x * alpha
- result.y = self.y * alpha
- return result
-
- def dot_product(self, other):
- return self.x*other.x + self.y*other.y
-
- def __abs__(self):
- return (self.x**2 + self.y**2)**0.5
-
- def __str__(self):
- return "(%s, %s)" % (self.x, self.y)
-
- def is_null(self):
- if abs(self) == 0 :
- return 1
- else :
- return 0
-
- def get_rho(self):
- return abs(self)
-
- def set_rho(self, new_rho):
- if self.is_null() == 1:
- self.x , self.y = new_rho*math.cos(self.phi) , new_rho*math.sin(self.phi)
- else :
- self.x , self.y = self.x*(new_rho/abs(self)) , self.y*(new_rho/abs(self))
-
- rho = property(get_rho, set_rho)
-
- def get_phi(self):
- phi = math.pi/2 - math.atan2(self.x, self.y)
- if self.is_null == 1:
- phi = 0
- return phi
-
- def set_phi(self, new_phi):
- rho = abs(self)
- self.x , self.y = rho*math.cos(new_phi) , rho*math.sin(new_phi)
-
- phi = property(get_phi, set_phi)
-
-i = Vector(1,0)
-j = Vector(0,1)
-null = Vector(0,0)
+import math
+
+class Vector(object):
+
+ def __init__(self, x=0 , y=0):
+ self.x = x
+ self.y = y
+
+ def __add__(self, other):
+ result = Vector(0,0)
+ result.x = self.x + other.x
+ result.y = self.y + other.y
+ return result
+
+ def __mul__(self, alpha):
+ result = Vector()
+ result.x = self.x * alpha
+ result.y = self.y * alpha
+ return result
+
+ def dot_product(self, other):
+ return self.x*other.x + self.y*other.y
+
+ def __abs__(self):
+ return (self.x**2 + self.y**2)**0.5
+
+ def __str__(self):
+ return "(%s, %s)" % (self.x, self.y)
+
+ def is_null(self):
+ if abs(self) == 0 :
+ return 1
+ else :
+ return 0
+
+ def get_rho(self):
+ return abs(self)
+
+ def set_rho(self, new_rho):
+ if self.is_null() == 1 :
+ self.x , self.y = new_rho*math.cos(self.phi) , new_rho*math.sin(self.phi)
+ else :
+ self.x , self.y = self.x*(new_rho/abs(self)) , self.y*(new_rho/abs(self))
+
+ rho = property(get_rho, set_rho)
+
+ def get_phi(self):
+ phi = math.pi/2 - math.atan2(self.x, self.y)
+ if self.is_null == 1:
+ phi = 0
+ return phi
+
+ def set_phi(self, new_phi):
+ rho = abs(self)
+ self.x, self.y = rho*math.cos(new_phi) , rho*math.sin(new_phi)
+
+ phi = property(get_phi, set_phi)