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

# HG changeset patch
# User Olga Zolotareva
# Date 1293231091 -10800
# Node ID 5cb3fef573f6543583dd20d2b54421034cbc349e
# Parent 5450c97fbc38e32a307f31f1ff5103b5b561f092
UI for two users

diff -r 5450c97fbc38 -r 5cb3fef573f6 body.py
--- a/body.py Fri Dec 24 23:28:21 2010 +0300
+++ b/body.py Sat Dec 25 01:51:31 2010 +0300
@@ -52,7 +52,6 @@


def accelerate(self, speed_delta):
- print 'speed_delta', speed_delta #test
self.velocity += self.base_orientation*speed_delta*delta_t
if abs(self.velocity) > max_velocity:
self.velocity.rho = max_velocity
@@ -77,6 +76,7 @@

def on_collision(self, other):
pass
+ # self.velocity , other.velocity = self.velocity + other.velocity , other.velocity + self.velocity

def on_wall(self):
self.velocity = vector.Vector(0,0)
diff -r 5450c97fbc38 -r 5cb3fef573f6 game.py
--- a/game.py Fri Dec 24 23:28:21 2010 +0300
+++ b/game.py Sat Dec 25 01:51:31 2010 +0300
@@ -23,15 +23,15 @@
self.invoke_ticks()
self.respawn()
self.update_velocities()
- for i in self.bodies :
- print i
- # print 'next position' , i.next_position
- print 'update_position' , i.position
- print 'velocity' , i.velocity
- print 'velocity.rho', i.velocity.rho # test
- if isinstance(i,body.Tank) == True:
- print 'base_orientation' , i.base_orientation
- print '\n'
+ # for i in self.bodies :
+ # print i # test
+ # print 'next position' , i.next_position # test
+ # print 'update_position' , i.position # test
+ # print 'velocity' , i.velocity # test
+ # print 'velocity.rho', i.velocity.rho # test
+ # if isinstance(i,body.Tank) == True: # test
+ # print 'base_orientation' , i.base_orientation # test
+ # print '\n'

def update_velocities(self):
for i in self.bodies:
@@ -55,7 +55,6 @@
def collides(self,body1,body2):
if (abs(body1.next_position - body2.next_position) <= (body1.radius + body2.radius)):
if (body1 != body2):
- print 'collision'
return True
else :
return False
@@ -67,12 +66,14 @@
if isinstance(body2, body.Tank) == True :
body1.on_collision(body2)
else :
- body1.on_hit()
+ body1.on_hit(body2)
body1.on_death()
+ self.bodies.remove(body2)
else :
if isinstance(body2, body.Tank) == True :
- body2.on_hit()
+ body2.on_hit(body2)
body2.on_death()
+ self.bodies.remove(body1)

def check_walls(self):
for i in self.bodies :
@@ -93,13 +94,10 @@
for i in self.users :
if i.tank.strength == 0 :
i.tank.on_spawn()
- print 'respawn'
- print i.tank.strength , i.tank.position
i.tank.strength = 1
i.tank.velocity = vector.null
i.tank.position.x = random.randint(i.tank.radius , width - i.tank.radius)
i.tank.position.y = random.randint(i.tank.radius , height - i.tank.radius)
i.tank.velocity = vector.null
- print i.tank.strength , i.tank.position


\ No newline at end of file
diff -r 5450c97fbc38 -r 5cb3fef573f6 tk_ui.py
--- a/tk_ui.py Fri Dec 24 23:28:21 2010 +0300
+++ b/tk_ui.py Sat Dec 25 01:51:31 2010 +0300
@@ -8,7 +8,7 @@
from vector import Vector

game_size = 500, 500
-keys = {
+keys1 = {
'ocircumflex': 'base_left',
'acircumflex': 'base_right',
'eacute': 'turret_left',
@@ -17,14 +17,36 @@
'ucircumflex': 'decelerate',
'division': 'fire',
}
+
+keys2 = {
+ 'icircumflex': 'base_left',
+ 'adiaeresis': 'base_right',
+ 'atilde': 'turret_left',
+ 'ugrave': 'turret_right',
+ 'oslash': 'accelerate',
+ 'ediaeresis': 'decelerate',
+ 'udiaeresis': 'fire',
+}

welcome = """Press F5 to start

Keys are:
+
+
+User 1 :
+
a, d -- turn tank
q, e -- turn muzzle
w, s -- change speed
-x -- fire"""
+x -- fire
+
+User 2 :
+
+j, l -- turn tank
+u, o -- turn muzzle
+i, k -- change speed
+m -- fire
+"""

class Tank(BaseTank):

@@ -52,11 +74,14 @@
self.display_welcome()

def init_game(self):
- self.user = User(keys)
+ self.user1 = User(keys1)
+ self.user2 = User(keys2)
w, h = game_size
- game = self.game = Game([], [self.user], w, h)
- tank = Tank(Vector(*game_size) * 0.5, self.user, self.game)
- game.bodies.append(tank)
+ game = self.game = Game([], [self.user1, self.user2], w, h)
+ tank1 = Tank(Vector(*game_size) * 0.5, self.user1, self.game)
+ tank2 = Tank(Vector(*game_size) * 0.5, self.user2, self.game)
+ game.bodies.append(tank1)
+ game.bodies.append(tank2)

def init_ui(self):
root = self.root = tk.Tk()
@@ -78,10 +103,12 @@
def on_keypress(self, ev):
if ev.keysym == "F5":
self.step()
- self.user.on_key(ev.keysym, True)
+ self.user1.on_key(ev.keysym, True)
+ self.user2.on_key(ev.keysym, True)

def on_keyrelease(self, ev):
- self.user.on_key(ev.keysym, False)
+ self.user1.on_key(ev.keysym, False)
+ self.user2.on_key(ev.keysym, False)

def step(self):
self.root.after(100, self.step)
@@ -114,4 +141,4 @@
raise AssertionError("Unknown object type: %s" % i.__class__.__name__)

if __name__ == "__main__":
- UI().root.mainloop()
+ UI().root.mainloop()
\ No newline at end of file
diff -r 5450c97fbc38 -r 5cb3fef573f6 user.py
--- a/user.py Fri Dec 24 23:28:21 2010 +0300
+++ b/user.py Sat Dec 25 01:51:31 2010 +0300
@@ -17,7 +17,6 @@
return
else:
action = self.keyset[key]
- print 'action=', action
if hasattr(self, action) and action not in ['tank', 'keyset']:
setattr(self, action, value)