Commits

Dominic Kexel committed 1eeb07a Draft

better checking for _target using vector length
faster gameplay

Comments (0)

Files changed (2)

     super(Rocket, self).__init__(**kwargs)
     self._start = kwargs['start_pos']
     self._current = kwargs['start_pos']
-    self._vector = list(starmap(operator.mul, zip(kwargs['vector'], repeat(speed*0.2))))
-    self._target = target
+    self._vector = mul_scalar(kwargs['vector'], speed*0.5)
+    self._target = magnitude(sub(target, self._start)) if target else None
     self._moving = True
     self.z = -1
 
     c = map(int, self._current)
     explode = False
 
-    if self._target:
-      x, y = map(int, self._target)
-      r = 3
-      if c in starmap(lambda a,b: [x+a, y+b], product(xrange(-r, r+1), xrange(-r, r+1))):
+    if self._target and magnitude(sub(self._current, self._start)) > self._target:
         explode = True
     if self._current[1] >= SCREEN_HEIGHT:
         explode = True
 import math
 
+from itertools import starmap, repeat
+from operator import mul
+
 def magnitude(v):
   return math.sqrt(sum(v[i]*v[i] for i in range(len(v))))
 
 def normalize(v):
   vmag = magnitude(v)
   return [ v[i]/vmag  for i in range(len(v)) ]
+
+def mul_scalar(v, scalar):
+  return list(starmap(mul, zip(v, repeat(scalar))))