[game-baker] r317 committed - Extended move_towards to keep a minimum distance from the target

2 views
Skip to first unread message

codesite...@google.com

unread,
Dec 6, 2009, 9:22:48 AM12/6/09
to game-ba...@googlegroups.com
Revision: 317
Author: timwintle
Date: Sun Dec 6 06:22:39 2009
Log: Extended move_towards to keep a minimum distance from the target
http://code.google.com/p/game-baker/source/detail?r=317

Modified:
/trunk/trunk/runtime/script_objects.py

=======================================
--- /trunk/trunk/runtime/script_objects.py Sun Nov 15 09:28:40 2009
+++ /trunk/trunk/runtime/script_objects.py Sun Dec 6 06:22:39 2009
@@ -79,6 +79,12 @@

def keys(self):
return self.dictionary.keys()
+
+ def items(self):
+ return self.dictionary.items()
+
+ def values(self):
+ return self.dictionary.values()



@@ -331,11 +337,13 @@
"""Destroys a game object - removes it from the list"""
self.gamescreenobj.to_delete_scriptgameobjs.append(self)

- def move_towards(self,x,y,speed):
+ def move_towards(self, x, y, speed, keep_distance = None):
"""Moves an object towards a position"""
xdiff = (x - (self.x + 0.5 * self.width ) )
ydiff = (y - (self.y + 0.5 * self.height) )
length = math.sqrt(xdiff*xdiff + ydiff*ydiff)
+ if keep_distance is not None and keep_distance > length:
+ return
if length > 0.00001:
self.vx = xdiff * speed / float(length)
self.vy = ydiff * speed / float(length)
Reply all
Reply to author
Forward
0 new messages