Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rapid Fire Powerup

  • Loading branch information...
commit f85a9397ec838eb9b0cdbd9ad0e9a98579334307 1 parent 42315be
@polmuz polmuz authored
Showing with 52 additions and 1 deletion.
  1. +1 −1  maps/H.svg
  2. +7 −0 spacecraft/map.py
  3. +44 −0 spacecraft/world.py
View
2  maps/H.svg
@@ -151,6 +151,6 @@
sodipodi:ry="2.0203052"
d="m 81.56982,17.167492 a 2.0203052,2.0203052 0 1 1 -4.04061,0 2.0203052,2.0203052 0 1 1 4.04061,0 z"
transform="translate(0,952.36218)"
- game-tag="engine-force-powerup" />
+ game-tag="rapid-fire-powerup" />
</g>
</svg>
View
7 spacecraft/map.py
@@ -45,6 +45,7 @@ def __init__(self, filename):
"{http://www.w3.org/2000/svg}rect": self.open_rect,
"engine-force-powerup": self.open_engine_force_powerup,
"proximity-mine": self.proximity_mine,
+ "rapid-fire-powerup": self.rapid_fire_powerup
}
self.close_methods = {
@@ -101,3 +102,9 @@ def proximity_mine(self, node, game, transform):
world.ProximityMine(game,
float(node.attrib[sodipodi + "cx"]) + transform['translate'][0],
float(node.attrib[sodipodi + "cy"]) + transform['translate'][1])
+
+ def rapid_fire_powerup(self, node, game, transform):
+ sodipodi = "{http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd}"
+ world.RapidFirePowerUp(game,
+ float(node.attrib[sodipodi + "cx"]) + transform['translate'][0],
+ float(node.attrib[sodipodi + "cy"]) + transform['translate'][1])
View
44 spacecraft/world.py
@@ -239,6 +239,34 @@ def contact(self, other):
super(EngineForcePowerUp, self).contact(other)
+class RapidFirePowerUp(PowerUp):
+ ratio = 5
+ duration = 100
+ def contact(self, other):
+ if isinstance(other, PlayerObject):
+ print "reload delay before effect", other.reload_delay
+ other.reload_delay /= self.ratio
+ print other.reload_delay
+ rapid_fire_effect = RapidFireEffect(self.duration, self.ratio)
+ other.callbacks.append(rapid_fire_effect.run)
+ super(RapidFirePowerUp, self).contact(other)
+
+
+class RapidFireEffect:
+ def __init__(self, duration, ratio):
+ self.d = duration
+ self.r = ratio
+
+ def run(self, player):
+ self.d -= 1
+ if self.d == 0:
+ print "finish rapid fire"
+ player.reload_delay *= self.r
+ print "reload delay after finish", player.reload_delay
+ return False
+ return True
+
+
class ProximityMine(PowerUp):
radius = 4
bullets = 50
@@ -382,6 +410,7 @@ class PlayerObject(ObjectBase):
reload_delay = 10
# base health
health = 100
+ callbacks = []
def __init__(self, map, x=None, y=None):
super(PlayerObject, self).__init__(map, x, y)
@@ -438,6 +467,21 @@ def execute(self):
self.reloading = self.reload_delay
self.fire = 0
+ self.run_callbacks()
+
+ def run_callbacks(self):
+ """ Runs callbacks
+
+ If callback returns false it won't be run again.
+ """
+ if self.callbacks:
+ new_callbacks = []
+ for cb in self.callbacks:
+ r = cb(self)
+ if r:
+ new_callbacks.append(cb)
+ self.callbacks = new_callbacks
+
def get_type(self):
return "player"
Please sign in to comment.
Something went wrong with that request. Please try again.