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

# HG changeset patch
# User Peter Zotov
# Date 1292812061 -10800
# Node ID 31ea2608cc39c5aeb8540e27e04f26c73a897579
# Parent 5cb99ccd2a7a770c4cffb75f1a920654ef3d2e5d
Changed repository structure.

diff -r 5cb99ccd2a7a -r 31ea2608cc39 body.py
--- a/body.py Mon Dec 20 05:27:17 2010 +0300
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,64 +0,0 @@
-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 5cb99ccd2a7a -r 31ea2608cc39 game.py
--- a/game.py Mon Dec 20 05:27:17 2010 +0300
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-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, delta_t):
- game.next_positions()
- game.check_collisions()
- game.check_walls()
- game.update_positions()
- game.invoke_ticks()
- game.respawn()
-
- def next_positions(game, delta_t):
- 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 5cb99ccd2a7a -r 31ea2608cc39 tanchiki.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tanchiki.py Mon Dec 20 05:27:41 2010 +0300
@@ -0,0 +1,3 @@
+import tanchiki.ui
+
+ui = tanchiki.ui.Ui()
\ No newline at end of file
diff -r 5cb99ccd2a7a -r 31ea2608cc39 tanchiki/body.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tanchiki/body.py Mon Dec 20 05:27:41 2010 +0300
@@ -0,0 +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
diff -r 5cb99ccd2a7a -r 31ea2608cc39 tanchiki/game.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tanchiki/game.py Mon Dec 20 05:27:41 2010 +0300
@@ -0,0 +1,49 @@
+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, delta_t):
+ game.next_positions()
+ game.check_collisions()
+ game.check_walls()
+ game.update_positions()
+ game.invoke_ticks()
+ game.respawn()
+
+ def next_positions(game, delta_t):
+ 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 5cb99ccd2a7a -r 31ea2608cc39 tanchiki/ui.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tanchiki/ui.py Mon Dec 20 05:27:41 2010 +0300
@@ -0,0 +1,5 @@
+import game
+
+class Ui(object):
+ def __init__(self):
+ pass
\ No newline at end of file
diff -r 5cb99ccd2a7a -r 31ea2608cc39 tanchiki/user.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tanchiki/user.py Mon Dec 20 05:27:41 2010 +0300
@@ -0,0 +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
+
diff -r 5cb99ccd2a7a -r 31ea2608cc39 tanchiki/vector.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tanchiki/vector.py Mon Dec 20 05:27:41 2010 +0300
@@ -0,0 +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)
diff -r 5cb99ccd2a7a -r 31ea2608cc39 user.py
--- a/user.py Mon Dec 20 05:27:17 2010 +0300
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-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 5cb99ccd2a7a -r 31ea2608cc39 vector.py
--- a/vector.py Mon Dec 20 05:27:17 2010 +0300
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,57 +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)