Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

health powerup and fire pushback

  • Loading branch information...
commit 7e7a0499aeb7392908e0ca84380a6769c2a75845 1 parent be94fa3
@luciotorre authored
Showing with 51 additions and 9 deletions.
  1. +28 −3 bots/maptools.py
  2. +1 −1  bots/navigator.py
  3. +22 −5 spacecraft/world.py
View
31 bots/maptools.py
@@ -83,6 +83,31 @@ def world_to_cell(self, x, y):
ny = int(y / box_w)
return nx, ny
+ def player_world_to_cell(self, x, y):
+ p = self.world_to_cell(x, y)
+ if not self.is_wall((x, y)):
+ return p
+
+ def t((xb, yb)):
+ box_w = self.xsize / self.xbuckets
+
+ x = xb * box_w + box_w / 2
+ y = yb * box_w + box_w / 2
+
+ return euclid.Point2(x, y)
+
+ winner = None
+ distance = float("+inf")
+ for n in self.neighbor_nodes(p):
+ d = abs(t(n) - euclid.Point2(x, y))
+ if d < distance:
+ distance = d
+ winner = n
+
+ if winner is None:
+ raise Exception()
+ return winner
+
def intersects(self, obj):
return any(
w.intersects(obj) for w in self.walls
@@ -218,8 +243,8 @@ def _visible(self, start, end):
def is_wall(self, pos):
x, y = self.world_to_cell(*pos)
if self.grid[x][y] == 1:
- return True
- return False
+ return False
+ return True
def visible(self, start, end):
return not self.intersects(LineString([start, end]))
@@ -269,7 +294,7 @@ def set_goal(self, goal):
D[n] = alt
def towards_goal_from(self, current):
- p = self.world_to_cell(*current)
+ p = self.player_world_to_cell(*current)
#n = winner(self.neighbor_nodes(p), self.goalpath)
#return self.cell_to_world(*n)
View
2  bots/navigator.py
@@ -106,7 +106,7 @@ def messageReceived(self, message):
return
# over wall!!! wander
- if not self.gridmap.is_wall(self.pos):
+ if self.gridmap.is_wall(self.pos):
print "walled, wandering"
self.command("throttle", value=1)
if random.random() < 0.2:
View
27 spacecraft/world.py
@@ -70,11 +70,8 @@ def __init__(self, xsize, ysize, frames=20, start=False):
self.status = STATUS_WAITING
self.winner = None
self.update_loop = task.LoopingCall(self.doStep)
- x, y = self.xsize * random.random(), self.ysize * random.random()
- print "creating powerup at", x, y
- RapidFirePowerUpRespawn(self, x, y)
- print "creating powerup at", x, y
- RapidFirePowerUpRespawn(self, x, y)
+ HealthPowerUpRespawn(self)
+ HealthPowerUpRespawn(self)
def start_game(self):
@@ -246,9 +243,24 @@ def contact(self, other):
super(EngineForcePowerUp, self).contact(other)
+class HealthPowerUp(PowerUp):
+
+ def contact(self, other):
+ if isinstance(other, PlayerObject):
+ other.health += 20
+ super(HealthPowerUp, self).contact(other)
+
+
+class HealthPowerUpRespawn(HealthPowerUp):
+ def contact(self, other):
+ super(HealthPowerUpRespawn, self).contact(other)
+ self.__class__(self.map)
+
+
class RapidFirePowerUp(PowerUp):
ratio = 5
duration = 100
+
def contact(self, other):
if isinstance(other, PlayerObject):
print "reload delay before effect", other.reload_delay
@@ -487,6 +499,11 @@ def execute(self):
self.reloading = self.reload_delay
self.fire = 0
+ # pushback
+ force = euclid.Matrix3.new_rotate(body.angle) * \
+ euclid.Vector2(-1, 0) * self.max_force * 3
+ body.ApplyForce(tuple(force), body.position)
+
self.run_callbacks()
def run_callbacks(self):
Please sign in to comment.
Something went wrong with that request. Please try again.