def blow_up(self, fade): """Blow up the spaceship""" # This method is not testable by PyTest if we rely # on Processing's sin, cos, and radians functions, but # it is testable if we use the Python math library's # versions of those functions instead. self.debris = [ # Portside debris piece Debris(self.SPACE, self.rotation, self.port_corner_point, self.tip_point, self.x, self.y, # Direction debris will fly math.sin(math.radians(self.rotation-45))/3, - math.cos(math.radians(self.rotation-45))/3, self.radius, fade), # Starboardside debris piece Debris(self.SPACE, self.rotation, self.tip_point, self.starboard_corner_point, self.x, self.y, # Direction debris will fly math.sin(math.radians(self.rotation+45))/2.7, - math.cos(math.radians(self.rotation+45))/3.0, self.radius, fade), # Stern debris piece Debris(self.SPACE, self.rotation, self.port_corner_point, self.starboard_corner_point, self.x, self.y, # Direction debris will fly math.sin(math.radians(self.rotation+180))/3.5, - math.cos(math.radians(self.rotation+180))/3.7, self.radius, fade)] self.intact = False
def __init__(self, x, y, dx, dy): Debris.__init__(self, x, y, dx, dy) self.r = 9 self.sprite = create_color_circle(Color("#44DDDD"), self.r*self.scaling) self.repr = "AmmoSupply" self.m = 16*BULLET_MASS self.is_circle = True self.soundsys.initsound('ammo', "ammosupply.wav")
def __init__(self, x, y, dx, dy): Debris.__init__(self, x, y, dx, dy) self.r = 9 self.sprite = create_color_circle(Color("#B09050"), self.r*self.scaling) self.repr = "FuelSupply" self.m = 16*FUEL_MASS self.is_circle = True self.soundsys.initsound('fuel', "fuelsupply.wav")
def test_random_rot_vel(): a = Debris(params['SPACE'], params['rotation'], params['endpoint1'], params['endpoint2'], params['x'], params['y'], params['x_vel'], params['y_vel'], params['radius'], params['fade']) n0 = -1 for _ in range(100): n1 = a.random_rot_vel() assert n1 <= 1.5 assert n1 >= -0.5 assert n0 != n1 n0 = n1
def test_random_rot_vel(): a = Debris(params['SPACE'], params['rotation'], params['endpoint1'], params['endpoint2'], params['x'], params['y'], params['x_vel'], params['y_vel'], params['radius'], params['fade']) n0 = -1 # try 100 random numbers and make sure they are all # different and all within the expected range for _ in range(100): n1 = a.random_rot_vel() assert n1 <= 1.5 assert n1 >= -0.5 assert n0 != n1 n0 = n1
def test_constructor(): a = Debris(params['SPACE'], params['rotation'], params['endpoint1'], params['endpoint2'], params['x'], params['y'], params['x_vel'], params['y_vel'], params['radius'], params['fade']) assert a.SPACE['w'] == 100 and \ a.SPACE['h'] == 200 and \ a.rotation == params['rotation'] and \ a.endpoint1 == params['endpoint1'] and \ a.endpoint2 == params['endpoint2'] and \ a.x == params['x'] and a.y == params['y'] and \ a.x_vel == params['x_vel'] and a.y_vel == params['y_vel'] and \ a.lifespan == params['fade'] and \ a.fadeout == params['fade'] and \ hasattr(a, "radius")
# Spawn new mob. def newMob(): m = Mob(ui_settings) all_sprites.add(m) mobs.add(m) # play background music. ui_settings.play_music() # Create instance of the game and statistics. stats = Game_Stats(ui_settings, screen) debris = Debris(ui_settings, screen) # Game loop game_over = True running = True while running: if game_over: screen.blit(background, background_rect) stats.welcome_screen() stats.reset_stats() game_over = False all_sprites = Group() player = Player(ui_settings) mobs = Group() bullets = Group() alien_bullets = Group()
def __init__(self, x, y, dx, dy): Debris.__init__(self, x, y, dx, dy) self.sprite = random.choice(helldebris_sprites)