示例#1
0
 def damage(self, amt):
     """Damages the alien.
     Returns True if the alien is destroyed.
     """
     self.health -= amt
     if self.health <= 0:
         particle.explosion(self.pos, (10,0,0), self.vel)
         return True
     return False
示例#2
0
 def damage(self, damage_amt):
     if not self.is_active():
         return
     if self.health == 0:
         particle.explosion(self.pos, (0, 10, 0), self.speed)
         self.lives -= 1
         self.hud.set_lives(self.lives)
         self._state = 4
         self._reset()
     else:
         self.health = max(0, self.health - damage_amt)
         self.hud.set_health(self.health)
         self._health_vis = 1
示例#3
0
 def split(self):
     particle.explosion(self.pos, (1, 1, 1))
     if self.size == 1:
         return ()
     newasteroids = []
     split_range = self.radius / 2
     for _ in xrange(2):
         newpos = self.pos
         newpos[:2] += numpy.random.uniform(-split_range,
                                            split_range,
                                            size=2)
         newasteroids.append(
             Asteroid(self.size - 1, self.maxvel * 1.1, newpos))
     return newasteroids
示例#4
0
 def split(self):
     """Returns two new asteroids with the same momentum as this one."""
     particle.explosion(self.pos, (1,1,1))
     if self.size == 1:
         return ()
     newasteroids = []
     split_range = self.radius / 2
     for _ in xrange(2):
         newpos = self.pos
         newpos[:2] += numpy.random.uniform(-split_range, split_range, size=2)
         newasteroids.append(
                 Asteroid(
                     self.size-1,
                     self.maxvel*1.1,
                     newpos
                     )
                 )
     return newasteroids
示例#5
0
文件: ship.py 项目: brownan/asteroids
 def damage(self, damage_amt):
     """The ship has taken damage.
     Base damage amount is 1, the amount that hitting an asteroid does, and
     the amount that it takes to split an asteroid
     """
     if not self.is_active():
         return
     if self.shields == 0:
         # KABOOM
         particle.explosion(self.pos, (0,10,0), self.speed)
         self.lives -= 1
         self.hud.set_lives(self.lives)
         self._state = 4
         self._reset()
     else:
         # Be generous, any shields will keep the ship from blowing up
         self.shields = max(0, self.shields-damage_amt)
         self.hud.set_shields(self.shields)
         self._shield_vis = 1
示例#6
0
 def damage(self, amt):
     self.health -= amt
     if self.health <= 0:
         particle.explosion(self.pos, (10, 0, 0), self.vel)
         return True
     return False