def test_blow_up(): a = Spaceship(params['SPACE']) assert not hasattr(a, 'debris') assert a.intact a.blow_up(100) assert len(a.debris) == 3 assert not a.intact
def main(): first = Spaceship( "Corsair", 3, 20, 465, [TitaniumArmor(), FlareEngine(), EmpCannon(), MolecularMirror()]) second = Spaceship( "Phoenix", 2, 15, 480, [AbsorptionShield(), ProtonTorpedoes(), TeleportingModule()]) print(f"{first.get_name()} ({first.get_remaining_hp()}/{first.get_max_hp()})") print(f"{second.get_name()} ({second.get_remaining_hp()}/{second.get_max_hp()})") game = Game(first, second) if game.is_stalemate(): print("Neither of the ships can attack! This is a stalemate!") else: print("Beginning battle!") turn = 1 while not game.game_over(): print(f"\n====== Turn {turn}: ======") game.execute_turn() print(f"{first.get_name()} ({first.get_remaining_hp()}/{first.get_max_hp()})") print(f"{second.get_name()} ({second.get_remaining_hp()}/{second.get_max_hp()})") turn += 1 winner = first if second.is_destroyed() else second loser = second if winner == first else first print(f"{loser.get_name()} has been destroyed! {winner.get_name()} wins!")
class Eschanton: def __init__(self, config): self.spaceship = Spaceship(0) self.rule = EscapeEschatonRule() self.size = 0 self.obstacle = [EschantonPlant(config["t_per_blast_move"])] + [ Asteroid(offset = asteroid["offset"], freq = asteroid["t_per_asteroid_cycle"]) for asteroid in config["asteroids"] ] self.size = len(self.obstacle) def update(self, accerlate): self.spaceship.move() self.spaceship.accerlate(accerlate) for asteroid in self.obstacle: asteroid.move() def valid_move(self): return self.rule.valid(self.spaceship, self.obstacle) def win(self): return self.rule.escape(self.size, self.spaceship.radius) def game_over(self): return self.rule.fail(self.size, self.obstacle[0].radius) def __repr__(self): return "Spaceship: %r\nSize: %d\nAsteroids:\n%s" % (self.spaceship, self.size, ", ".join(["%r" % asteroid for asteroid in self.obstacle ]))
def __init__(self, width, height, frame_rate): self.font = pygame.font.SysFont("Times New Roman", 36) self.font2 = pygame.font.SysFont("Courier New", 20) self.frame_rate = frame_rate self.text_color = (255, 0, 0) self.width = width self.height = height self.upper_limit = self.width / 3 self.spaceship_width = 20 self.spaceship_height = 10 self.spaceship = Spaceship(self.spaceship_width, self.spaceship_height, 0, (self.height / 2) - 10, (255, 255, 255)) self.spaceship_speed = 5 self.bullets = [] self.bullet_width = 2 self.bullet_height = 80 self.bullet_color = (255, 50, 50) self.powerups = [] self.powerup_width = 20 self.powerup_height = 20 self.powerup_color = (50, 255, 50) self.destroyers = [] self.destroyer_width = 200 self.destroyer_height = 200 self.destroyer_color = (255, 0, 0) self.baddies = [] self.baddie_width = 20 self.baddie_height = 20 self.baddie_color = (255, 0, 0) self.score = 0 self.baddie_kills = 0 self.life = 5 return
def run_game(): """Initialize game and create a screen object""" pygame.init() # Initialize the settings settings = Settings(1.5) # Initialize the game statistics stats = GameStats(settings) game_screen = pygame.display.set_mode( (settings.screen_width, settings.screen_height)) pygame.display.set_caption("Alien Attack") # Make the Play button play_button = Button(settings, game_screen, "Play") # Initialize the spaceship spaceship = Spaceship(game_screen, settings) # Play the background music pygame.mixer.music.load("background_music.mp3") # Set volume from zero to one pygame.mixer.music.set_volume(0.5) # endless loop pygame.mixer.music.play(-1) # Make a group to store bullets in # list but with extra functionality bullets = Group() # Initialize alien fleet then update it aliens = Group() gf.create_fleet(settings, game_screen, aliens, spaceship) # Initialize the scoreboard scoreboard = Scoreboard(settings, game_screen, stats) # Beginning of the main loop that starts the game while True: # Handling of keyboard and mouse events gf.check_events(settings, spaceship, bullets, game_screen, stats, play_button, aliens, scoreboard) if stats.game_active: # Updating ship position after checking key events spaceship.update() # Update bullet positions(update() call on elements) bullets.update() # Getting rid of bullets outside of game screen gf.update_bullets(settings, game_screen, spaceship, bullets, aliens, stats, scoreboard) # Update the positions of the aliens gf.update_aliens(aliens, settings, spaceship, bullets, stats, game_screen, scoreboard) # Updating screen gf.update_screen(game_screen, spaceship, settings, bullets, aliens, play_button, stats, scoreboard)
def __init__(self,width,height,frame_rate): self.font = pygame.font.SysFont("Times New Roman",36) self.font2 = pygame.font.SysFont("Courier New",20) self.frame_rate = frame_rate self.text_color = (255,0,0) self.width = width self.height = height self.upper_limit = self.width/1 self.spaceship_width = 20 self.spaceship_height = 10 self.spaceship = Spaceship(self.spaceship_width,self.spaceship_height,0,(self.height / 2) - 50, (255,255,255)) self.spaceship_speed = 10 self.spaceship2_width = 20 self.spaceship2_height = 10 self.spaceship2 = Spaceship2(self.spaceship2_width,self.spaceship2_height,0,(self.height / 2) - 10, (255,255,0)) self.spaceship2_speed = 10 self.spaceship3_width = 20 self.spaceship3_height = 10 self.spaceship3 = Spaceship(self.spaceship_width,self.spaceship_height,0,(self.height / 2) - 10, (255,255,255)) self.spaceship3_speed = 10 self.spaceship4_width = 20 self.spaceship4_height = 10 self.spaceship4 = Spaceship4(self.spaceship4_width,self.spaceship4_height,0,(self.height / 2) - 10, (255,255,0)) self.spaceship4_speed = 10 self.bullets = [] self.bullet_width = 5 self.bullet_height = 10 self.bullet_color = (255,255,255) self.baddies = [] self.baddie_width = 121 self.baddie_height = 95 self.baddie_color = (255,0,0) self.baddie2_width = 121 self.baddie2_height = 95 self.baddie2_color = (255,0,0) self.baddie3_width = 121 self.baddie3_height = 95 self.baddie3_color = (255,0,0) self.kills = 0 self.score_color = (255, 255, 255) self.score_x = 10 self.score_y = 30 self.money = 0 self.gold_color = (255, 255, 255) self.gold_x = 10 self.gold_y = 60 self.Img = pygame.image.load("background.png") self.lives = 30 self.lives_color = (255, 255, 255) self.lives_x = 10 self.lives_y = 90 self.a_counter = 0 return
def __init__(self, SPACE, fadeout): """Initialize the game controller""" self.SPACE = SPACE self.fadeout = fadeout self.spaceship_hit = False self.asteroid_destroyed = False self.asteroids = [Asteroid(self.SPACE)] self.laser_beams = [] self.spaceship = Spaceship(self.SPACE)
def reset(self): self.ship = Spaceship(scale=.3, speed=0.06, rotationspeed=10) self.asteroids = [] self.bullets = [] self.frame = np.zeros((config.SCREEN_HEIGHT, config.SCREEN_WIDTH, 3), dtype="uint8") self.last_astroid = utils.get_now() self.now = utils.get_now() self.score = 0 self.stars = [] self.add_stars()
def _reset(self): self.spaceship = Spaceship() self.aliens.reset() self.barricades = Barricades() self.score = Score() self.life_counter = LifeCounter() self.is_game_over = False self.delay_since_game_over = 0 self.is_playing = True
def __init__(self, num): """initializes a player instance""" self.num = num if num == 2: self.textpos = (100, 50) self.spaceship = Spaceship(Config.platform2[0] + 100, Config.platform2[1] + 20, num, -1, -1) else: self.textpos = (Config.height - 100, 50) self.spaceship = Spaceship(Config.platform1[0] + 100, Config.platform1[1] + 20, num, -1, -1) self.shots = pygame.sprite.Group() self.lock = False self.lockthrust = False self.stats = self.init_stats()
def __init__(self, SPACE, fadeout): """Initialize the game controller""" self.SPACE = SPACE self.fadeout = fadeout self.spaceship_hit = False self.asteroid_destroyed = False self.asteroids = [Asteroid(self.SPACE)] self.laser_beams = [] self.spaceship = Spaceship(self.SPACE) # Problem 3: set lifespan for passing to laserbeam class self.lifespan = 100 # magic number for laser beam run out of lifespan self.DIE = 0
def run_game(): pygame.init() r_settings = Settings() screen = pygame.display.set_mode( (r_settings.screen_width, r_settings.screen_height)) pygame.display.set_caption("WIELKA KURWA RAKIETA") spaceship = Spaceship(screen) while True: f.check_events(spaceship) spaceship.update(r_settings.speed_factor) f.update_screen(r_settings.background, screen, spaceship)
def _create_spaceship(self, number_spaceship, number_column): # Creatings spaceship and setting the position spaceship = Spaceship(self) spaceship_width, spaceship_height = spaceship.rect.size spaceship.y = spaceship_height + (2 * spaceship_height * number_spaceship) spaceship.rect.y = spaceship.y spaceship.x = (self.settings.screen_width - (2 * spaceship_width + (2 * spaceship_width * number_column))) spaceship.rect.x = spaceship.x self.spaceships.add(spaceship)
def __init__(self, initial_lives, screen_dims, invader_icons, spaceship_img): self.lives = initial_lives self.screen_dims = screen_dims self.invader_manager = InvaderManager(screen_dims=screen_dims, invader_icons_x=invader_icons) self.spaceship = Spaceship(spaceship_img=spaceship_img) self.laser_manager = LaserManager(screen_dims=screen_dims) self.score_board = ScoreBoard(screen_dims=screen_dims) self.lives_board = PlayerLives(screen_dims=screen_dims, initial_lives=self.lives) self.game_over = False self.space_invader_collective_pos = 0 random.seed() self.space_invader_move_direction = random.choice(["Left", "Right"])
def run_game(): pygame.init() ai_settings = Settings() screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) pygame.display.set_caption('Alien Invasion') spaceship = Spaceship(ai_settings, screen) bullets = Group() bg_color = (230, 230, 230) while True: gf.check_events(ai_settings, screen, spaceship, bullets) spaceship.update() bullets.update() gf.update_screen(ai_settings, screen, spaceship, bullets)
def main(): # load in the images for all the planets # like hitting ctrl+r and loading your blitz suni = load_image("sun.png") merci = load_image("mercury.gif") venusi = load_image("venus.gif") earthi = load_image("earth.png") marsi = load_image("mars.png") # initialize all the planets as an object # hope that the values are all correct sun = Body(1.98892e30, 0, 0, 0, 0, 12, 1, 1, 0,suni,17,17,0,17,17) mercury = Body(.06*EM,0,.3871*AU,47890,0,3,1,0,0,merci,8,8,.2,16,16) venus = Body(.82*EM,0,-.7233*AU,-35040,0,8,0,1,0,venusi,10,9,.3,20,18) earth = Body(EM,AU,0,0,-29790,6,0,0,1,earthi,13,13,.4,26,26) mars = Body(.11*EM,-1.524*AU,0,0,24140,4,0,1,1,marsi,10,10,.3,20,20) listp = [sun,mercury,venus,earth,mars] # put em in a list, for safekeeping # as of now, the planets are still sleeping solar = System(listp) # kill the backlights, set up the stage, # draw things inside the page set_clear_color(0, 0, 0) enable_smoothing() player = Spaceship(3*WINDOW_HEIGHT/4,3*WINDOW_HEIGHT/4) while not window_closed(): # draw the spaceship yo clear() player.spaceshipupdate() player.draw() # Draw the system in its current state. solar.draw(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2, PIXELS_PER_METER) # Update the system for its next state. solar.update(SEC_PER_FRAME) # Draw the frame and take a brief nap. request_redraw() sleep(TIMESTEP)
def enter(): global player, spaceship, timer, count gfw.world.init(['bg','spaceship','enemy_bullet','enemy','flying_enemy','bullet','player','timer']) player = Player() timer = Timer() bg.init(player) spaceship = Spaceship() gfw.world.add(gfw.layer.bg,bg) gfw.world.add(gfw.layer.spaceship, spaceship) gfw.world.add(gfw.layer.player, player) gfw.world.add(gfw.layer.timer, timer) count = 0 Enemy.load_all_images() Flying_Enemy.load_all_images() global bg_music, flip_wav, enemy_die_wav, spaceship_wav bg_music = load_music('./res/main_state_sound.mp3') bg_music.set_volume(60) bg_music.repeat_play() flip_wav = load_wav('./res/beshot.wav') enemy_die_wav = load_wav('./res/enemy_die.wav') spaceship_wav = load_wav('./res/spaceship_die.wav') flip_wav.set_volume(100) enemy_die_wav.set_volume(200)
def __init__(self,width,height,frame_rate): self.font = pygame.font.SysFont("Times New Roman",36) self.font2 = pygame.font.SysFont("Castellar",20) self.frame_rate = frame_rate self.text_color = (255,0,0) self.width = width self.height = height self.upper_limit = self.width/3 self.spaceship_width = 20 self.spaceship_height = 10 self.spaceship = Spaceship(self.spaceship_width,self.spaceship_height,0,(self.height / 2) - 10, (255,255,255)) self.spaceship_speed = 5 self.bullets = [] self.bullet_width = 10 self.bullet_height = 5 self.bullet_color = (255,255,255) self.baddies = [] self.baddie_width = 20 self.baddie_height = 20 self.baddie_color = (255,0,0) #SCORE self.kills = 0 self.score_color = (0, 212, 83) self.score_x = 10 self.score_y = 30 #/SCORE return
def __init__(self,width,height,frame_rate): self.font = pygame.font.SysFont("Times New Roman",36) self.font2 = pygame.font.SysFont("Courier New",20) self.frame_rate = frame_rate self.text_color = (255,0,0) self.width = width self.height = height self.upper_limit = self.width - 20 self.spaceship_width = 20 self.spaceship_height = 20 self.spaceship = Spaceship(self.spaceship_width,self.spaceship_height,0,(self.height / 2) - 10, (255,240,0)) self.spaceship_speed = 15 self.bullets = [] self.bullet_width = 12 self.bullet_height = 12 self.bullet_color = (255,255,255) self.baddies = [] self.baddie_width = 20 self.baddie_height = 20 self.baddie_color = (0,201,87) self.kill = 0 self.score_color = (255, 255, 255) self.score_x = 20 self.score_y = 30 return
def run_game(): # 初始化游戏 pygame.init() # 设置屏幕分辨率 setting = Settings() screen = pygame.display.set_mode( (setting.screen_width, setting.screen_height)) pygame.display.set_caption("飞机大战") # 创建小飞机 plane = Plane(screen, setting) # print(bg_img) spaceship = Spaceship(setting, screen) # 开始游戏的主循环 while True: # 不关闭窗口 fg.check_events() # 绘制图像 fg.update_screen(screen, setting.bg_img, plane)
def __init__(self,width,height,frame_rate): self.font = pygame.font.Font("resources/Fipps-Regular.otf",16) self.frame_rate = frame_rate self.text_color = (255,0,0) self.width = width self.height = height self.upper_limit = self.width/3 self.spaceship_width = 10 self.spaceship_height = 20 self.spaceship = Spaceship(self.spaceship_width,self.spaceship_height,(self.width / 2), (self.height) -10, (255,255,255)) self.bullets = [] self.bullet_width = 5 self.bullet_height = 10 self.bullet_color = (255,255,255) self.baddies = [] self.baddie_width = 20 self.baddie_height = 20 self.baddie_color = (255,0,0) self.score = 0 self.baddies_killed = 0 self.current_level = 0 self.resources_path = "resources" self.window_x = 1280 self.window_y = 720 return
def __init__(self, window, alien_spawn_adress): self.window = window self.alien_spawn_adress = alien_spawn_adress self.spaceship = Spaceship(window) self.enemy = Enemy(window, alien_spawn_adress) self.bullet = Bullet(window) self.border = { "left": 0, "right": 0, "up": 0, "down": 0 } self.clock = 0 self.level = 1 self.point_total = 0 self.life = GVar.LIVES
def __init__(self): pygame.init() self.settings = st() self.clock = pygame.time.Clock() self.screen = pygame.display.set_mode( (self.settings.screen_width, self.settings.screen_height)) self.surf_rect = self.screen.get_rect() self.ship = Spaceship(self.screen, self.settings) self.bullets = Group() self.aliens = Group() self.create_aliens_flot() self.stats = Stats(self.settings) self.button = Button(self.settings, self.screen, 'To start new game press "n" button') self.active_game = True
def __init__(self,width,height,frame_rate): self.font = pygame.font.SysFont("Times New Roman",36) self.font2 = pygame.font.SysFont("Courier New",20) self.frame_rate = frame_rate self.text_color = (255,0,0) self.width = width self.height = height self.upper_limit = self.width/3 self.spaceship_width = 48 self.spaceship_height = 48 self.spaceship = Spaceship(self.spaceship_width,self.spaceship_height,0,(self.height / 2) - 10, (255,255,255)) self.spaceship_speed = 5 self.bullets = [] self.bullet_width = 20 self.bullet_height = 20 self.bullet_color = (255,255,255) self.baddies = [] self.baddie_width = 48 self.baddie_height = 48 self.baddie_color = (255,0,0) self.kills = 0 self.score_color = (72,255,0) self.score_x = 10 self.score_y = 30 self.game_over_x = 300 self.game_over_y = 250 self.hit_points = 1 self.bg = Background('background.png', width) return
def prepare_spaceships(self): self.spaceships = pygame.sprite.Group() for spaceship_number in range(self.stats.spaceship_left): spaceship = Spaceship(self.ai_game) spaceship.rect.x = 20 + spaceship_number * spaceship.rect.width spaceship.rect.y = 10 self.rect.left = self.screen_rect.left self.spaceships.add(spaceship)
def reset(self): """ Reset the population and asteroids """ if d.solo: # Only reset the player self.spaceship = Spaceship(NeuralNetWork(d.INPUT_COUNT, d.HIDDEN_LAYERS, 1)) d.alive_ships = [self.spaceship] else: # Load the new generation d.best_ship = None d.spaceships = d.next_gen d.alive_ships = d.spaceships d.dead_ships = [] # Reset the asteroids d.asteroids = [] for _ in range(d.AST_COUNT): d.asteroids.append(Asteroid(random.randint(1, 4)))
def test_constructor(): # Test minimal required constructor args a = Spaceship(params['SPACE']) assert a.SPACE['w'] == 100 and \ a.SPACE['h'] == 200 and \ hasattr(a, "intact") and \ hasattr(a, "x") and hasattr(a, "y") and\ hasattr(a, "x_vel") and hasattr(a, "y_vel")
def __init__(self): pg.init() if os.path.exists('ExoFont.otf'): d.FONT = pg.font.Font("ExoFont.otf", 18) else: d.FONT = pg.font.Font(None, 18) if not d.solo: d.spaceships = [Spaceship(NeuralNetWork(d.INPUT_COUNT, d.HIDDEN_LAYERS, 1)) for _ in range(d.POPULATION_COUNT)] d.alive_ships = d.spaceships[:] else: self.spaceship = Spaceship(NeuralNetWork(d.INPUT_COUNT, d.HIDDEN_LAYERS, 1)) d.alive_ships = [self.spaceship] # Setup asteroids d.asteroids = [] for _ in range(d.AST_COUNT): d.asteroids.append(Asteroid(random.randint(1, 4))) self.update_text()
def run(self): pygame.init() """Game's settings initialized""" game_settings = Settings() screen = pygame.display.set_mode((game_settings.screen_width, game_settings.screen_height)) pygame.display.set_caption(game_settings.caption_display) # Ship spaceship = Spaceship(screen) # Event monitoring while True: for event in pygame.event.get(): screen.fill(game_settings.background_color) spaceship.blit_ss() if event.type == pygame.QUIT: print("You just exited the game.") sys.exit() # Latest screen frame pygame.display.flip()
def __init__(self, pygameInstance, windowScreen): self.pygameLib = pygameInstance self.window = windowScreen self.screenSize = self.window.get_size() self.myfont = self.pygameLib.font.SysFont('Comic Sans MS', 30) self.screenTitle = self.myfont.render('Game Screen', False, (255, 0, 0)) self.gameHero = Spaceship() self.gameHero.image = pygame.image.load( self.gameHero.imagePath).convert_alpha() self.gameHero.x = (self.screenSize[0] / 2) - (self.gameHero.imageWidth / 2) self.gameHero.y = self.screenSize[1] - self.gameHero.imageHeight for i in range(0, 3): enemy = EnemyShip() enemy.image = pygame.image.load(enemy.imagePath).convert_alpha() enemy.x = (enemy.imageWidth * i) + 5 enemy.y = 50 self.enemyShips.append(enemy)
def __init__(self): """Inicializa o jogo e cria os recursos do mesmo""" pygame.init() self.settings = Settings() self.clock = pygame.time.Clock() # Carregando a janela do jogo self.screen = pygame.display.set_mode( (self.settings.width, self.settings.height)) pygame.display.set_caption('Alien Invasion') self.game_stats = GameStats(self) self.scoreboard = Scoreboard(self) self.easy_game_button = button.EasyModeButton(self, 'Easy') self.normal_game_button = button.NormalModeButton(self, 'Normal') self.hard_game_button = button.HardModeButton(self, 'Hard') self.spaceship = Spaceship(self) self.bullets = pygame.sprite.Group() self.aliens = pygame.sprite.Group() self._create_fleet()
def nextLevel(self): self.level += 1 try: self.invaders, self.asteroids = level.load('data/level'+str(self.level)+'.dat', self) except: return False self.invaders = pygame.sprite.Group(self.invaders) self.asteroids = pygame.sprite.Group(self.asteroids) self.explosions = pygame.sprite.Group() self.bullets = pygame.sprite.Group() self.player = pygame.sprite.GroupSingle(Spaceship(self, 12 * 32 + 16, 18 * 32 + 16)) return True
def __init__(self): pygame.init() self.settings = settings() self.screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) self.settings.screen_width = self.screen.get_rect().width self.settings.screen_height = self.screen.get_rect().height pygame.display.set_caption("Alien Invasion") self.spaceship = Spaceship(self) self.game_screen = gamescreen(self) self.bullets = pygame.sprite.Group() self.aliens = pygame.sprite.Group() self.music = Music_button(self) self.create_fleet() self.settings.increase_speed() self.stats = gamestats(self) self.scoreboard = scoreboard(self) self.play_button = button(self, "play") self.clock = pygame.time.Clock() self.game_music = pygame.mixer.music.load('sounds/theme_song.mp3') pygame.mixer.music.play(-1) self.bullet_sound = pygame.mixer.Sound( "sounds/GunShooting() (online-audio-converter.com).wav") self.alien_destroying = pygame.mixer.Sound('sounds/Explosion.wav')
def __init__(self): # We create a surface in which sprites will be shown self.window_surface = pygame.display.set_mode(WINDOW_SIZE) # Variables for game loop self.update_time_delay = 0 self.draw_time_delay = 0 # Game state variable self.is_game_over = False self.delay_since_game_over = 0 self.is_playing = True # We create the game entities self.spaceship = Spaceship() self.aliens = Aliens() self.ground = Ground() self.barricades = Barricades() self.score = Score() self.high_score = HighScore() self.life_counter = LifeCounter() self.game_over = GameOver()
def update(self): for event in pygame.event.get(): if event.type == QUIT or (event.type == KEYUP and event.key == K_ESCAPE): raise KeyboardInterrupt() if event.type == KEYUP and event.key == K_TAB: pygame.display.toggle_fullscreen() if not self.player.sprite.health: self.dead.play() if not self.lives: raise GameOver() self.lives -= 1 if not len(self.invaders) and not self.nextLevel(): raise GameWin() if not self.player.sprite.health: self.player.add(Spaceship(self, 12 * 32 + 16, 18 * 32 + 16, cooldown = 80)) toRemove = [] for explosion in self.explosions: if explosion.health <= 0: toRemove.append(explosion) self.explosions.remove(toRemove) toRemove = [] for bullet in self.bullets: if bullet.health <= 0: toRemove.append(bullet) self.bullets.remove(toRemove) toRemove = [] for invader in self.invaders: if invader.health <= 0: toRemove.append(invader) self.invaders.remove(toRemove) toRemove = [] for asteroid in self.asteroids: if asteroid.health <= 0: toRemove.append(asteroid) self.asteroids.remove(toRemove) self.explosions.update() self.bullets.update() self.invaders.update() self.asteroids.update() self.player.update()
def __init__(self, width, height, frame_rate): self.font = pygame.font.SysFont("Times New Roman", 36) self.font2 = pygame.font.SysFont("Courier New", 20) self.frame_rate = frame_rate self.text_color = (255, 0, 0) self.width = width self.height = height self.upper_limit = self.width / 3 self.spaceship_width = 20 self.spaceship_height = 20 self.spaceship = Spaceship(self.spaceship_width, self.spaceship_height, (self.width / 2), (self.height / 2) - 10, (255, 255, 255)) self.spaceship_acceleration = .5 self.bullets = [] self.bullet_width = 10 self.bullet_height = 5 self.bullet_color = (255, 255, 255) self.baddies = [] self.baddie_width = 20 self.baddie_height = 20 self.baddie_color = (255, 0, 0) return
def create_ship(self): '''Create ship''' ship_image = pyglet.image.load(IMAGES_SHIP[self.ship_img_idx]) ship_image.anchor_x = ship_image.width // 2 ship_image.anchor_y = ship_image.height // 2 ship_sprite = pyglet.sprite.Sprite(ship_image, batch=self.batch) engine_image = pyglet.image.load(IMAGES_ENGINE) engine_image.anchor_x = engine_image.width // 2 engine_image.anchor_y = engine_image.height + ship_image.height // 2 engine_sprite = pyglet.sprite.Sprite(engine_image, batch=self.batch_effects) ship = Spaceship(self.width // 2, self.height // 2, ship_sprite, engine_sprite, self.width, self.height) self.ships.append(ship)
def _create_fleet(self): '''Create a fleet of spaceship''' spaceship = Spaceship(self) spaceship_height, spaceship_width = spaceship.rect.size # Number of spaceships that fit on the screen vertically shooter_width = self.shooter.rect.width available_space_y = self.settings.screen_height - (2 * spaceship_height) number_spaceship_y = available_space_y // (1 * spaceship_height) # Number of spaceships that fit on the screen horizontally available_space_x = (self.settings.screen_width - (3 * spaceship_width) - (shooter_width)) number_columns = available_space_x // (3 * spaceship_width) for number_column in range(number_columns): for number_spaceship in range(number_spaceship_y): self._create_spaceship(number_spaceship, number_column)
def __init__(self,width,height,frame_rate): self.font = pygame.font.SysFont("Times New Roman",36) self.font2 = pygame.font.SysFont("Courier New",20) self.frame_rate = frame_rate self.text_color = (255,0,0) self.width = width self.height = height self.upper_limit = self.width/3 self.spaceship_width = 20 self.spaceship_height = 20 self.spaceship = Spaceship(self.spaceship_width,self.spaceship_height,(self.width / 2),(self.height / 2) - 10, (255,255,255)) self.spaceship_acceleration = .5 self.bullets = [] self.bullet_width = 10 self.bullet_height = 5 self.bullet_color = (255,255,255) self.baddies = [] self.baddie_width = 20 self.baddie_height = 20 self.baddie_color = (255,0,0) return
def __init__(self, width=640, height=400, fps=60, stars=200): self.running = True self.fps = fps self.playtime = 0.0 self.total_stars = stars pygame.init() pygame.display.set_caption("Press ESC to quit") self.width = width self.height = height self.screen = pygame.display.set_mode((self.width, self.height), pygame.DOUBLEBUF) self.background = pygame.Surface(self.screen.get_size()).convert() self.clock = pygame.time.Clock() self.font = pygame.font.SysFont('mono', 20, bold=True) self.stars = Background.generate_stars(self, stars, width, height) self.spaceship = Spaceship() self.main()
def __init__(self, width=640, height=400, fps=60, stars=200): self.running = True self.score = 0 # CONSTANT self.FPS = fps self.PLAYTIME = 0.0 self.TOTAL_STARS = stars self.WIDTH = width self.HEIGHT = height # INITIALIZE SCREEN, CLOCK, FONT self.screen = pygame.display.set_mode((self.WIDTH, self.HEIGHT), pygame.DOUBLEBUF) self.background = pygame.Surface(self.screen.get_size()).convert(self.screen) self.clock = pygame.time.Clock() self.font = pygame.font.SysFont('mono', 20, bold=True) # INITIALIZE SCREEN OBJECTS self.stars = Stars(self.background, self.WIDTH, self.HEIGHT, self.TOTAL_STARS) self.asteroid = Asteroid() self.spaceship = Spaceship() self.main()
def __init__(self,width,height,frame_rate): self.font = pygame.font.SysFont("Times New Roman",36) self.font2 = pygame.font.SysFont("Courier New",20) self.frame_rate = frame_rate self.text_color = (255,0,0) self.width = width self.height = height self.upper_limit = self.width/3 self.spaceship_width = 20 self.spaceship_height = 10 self.spaceship = Spaceship(self.spaceship_width,self.spaceship_height,0,(self.height / 2) - 10, (255,255,255)) self.spaceship_speed = 10 self.bullets = [] self.bullet_width = 6 self.bullet_height = 6 self.bullet_color = random.choice(colors) self.baddies = [] self.baddie_width = 20 self.baddie_height = 20 self.baddie_color = random.choice(colors) self.kills = 0 self.lives = 10 return
class SpaceshipData: def __init__(self,width,height,frame_rate): self.font = pygame.font.SysFont("Times New Roman",36) self.font2 = pygame.font.SysFont("Courier New",20) self.frame_rate = frame_rate self.text_color = (255,0,0) self.width = width self.height = height self.upper_limit = self.width/3 self.spaceship_width = 20 self.spaceship_height = 20 self.spaceship = Spaceship(self.spaceship_width,self.spaceship_height,(self.width / 2),(self.height / 2) - 10, (255,255,255)) self.spaceship_acceleration = .5 self.bullets = [] self.bullet_width = 10 self.bullet_height = 5 self.bullet_color = (255,255,255) self.baddies = [] self.baddie_width = 20 self.baddie_height = 20 self.baddie_color = (255,0,0) return def evolve(self, keys, newkeys, buttons, newbuttons, mouse_position): if pygame.K_LEFT in keys: self.spaceship.moveLeft(self.spaceship_acceleration) if pygame.K_RIGHT in keys: self.spaceship.moveRight(self.spaceship_acceleration) if pygame.K_UP in keys: self.spaceship.jump() if pygame.K_SPACE in newkeys: self.bullets.append(self.spaceship.fire(self.bullet_width,self.bullet_height,self.bullet_color)) if random.randint(1, self.frame_rate/2) == 1: self.addBaddie() for bullet in self.bullets: bullet.moveBullet() bullet.checkBackWall(self.width) for baddie in self.baddies: baddie.tick(0,0,self.height) self.spaceship.tick(self.height, 0) for bullet in self.bullets: if not bullet.alive: continue for baddie in self.baddies: if not baddie.alive: continue x,y,w,h = baddie.getDimensions() bullet.checkHitBaddie(x,y,w,h) if bullet.getHit(): bullet.setAlive(False) baddie.setAlive(False) bullet.hit = False live_bullets = [] live_baddies = [] for bullet in self.bullets: if bullet.alive: live_bullets.append(bullet) for baddie in self.baddies: if baddie.alive: live_baddies.append(baddie) self.bullets = live_bullets self.baddies = live_baddies return def addBaddie(self): new_baddie = Baddie( self.baddie_width, self.baddie_height, self.width, random.randint(0,(self.height-self.baddie_height)), self.baddie_color ) self.baddies.append( new_baddie ) return def draw(self,surface): rect = pygame.Rect(0,0,self.width,self.height) surface.fill((0,0,0),rect ) self.spaceship.draw(surface) for bullet in self.bullets: bullet.draw(surface) for baddie in self.baddies: baddie.draw(surface) return def drawTextLeft(self, surface, text, color, x, y,font): textobj = font.render(text, False, color) textrect = textobj.get_rect() textrect.bottomleft = (x, y) surface.blit(textobj, textrect) return def drawTextRight(self, surface, text, color, x, y,font): textobj = font.render(text, False, color) textrect = textobj.get_rect() textrect.bottomright = (x, y) surface.blit(textobj, textrect) return
class SpaceshipData: def __init__(self,width,height,frame_rate): self.font = pygame.font.SysFont("Times New Roman",36) self.font2 = pygame.font.SysFont("Courier New",20) self.frame_rate = frame_rate self.text_color = (255,0,0) self.width = width self.height = height self.upper_limit = self.width/3 self.spaceship_width = 20 self.spaceship_height = 10 self.spaceship = Spaceship(self.spaceship_width,self.spaceship_height,0,(self.height / 2) - 10, (255,255,255)) self.spaceship_speed = 10 self.bullets = [] self.bullet_width = 6 self.bullet_height = 6 self.bullet_color = random.choice(colors) self.baddies = [] self.baddie_width = 20 self.baddie_height = 20 self.baddie_color = random.choice(colors) self.kills = 0 self.lives = 10 return def evolve(self, keys, newkeys, buttons, newbuttons, mouse_position): if pygame.K_LEFT in keys: self.spaceship.moveLeft(self.spaceship_speed) if pygame.K_RIGHT in keys: self.spaceship.moveRight(self.spaceship_speed,self.upper_limit) if pygame.K_UP in keys: self.spaceship.moveUp(self.spaceship_speed) if pygame.K_DOWN in keys: self.spaceship.moveDown(self.spaceship_speed,self.height) if pygame.K_SPACE in keys: self.bullet_color = random.choice(colors) self.bullets.append(self.spaceship.fire(self.bullet_width,self.bullet_height,self.bullet_color)) if random.randint(1, self.frame_rate/2) == 1: self.addBaddie() for bullet in self.bullets: bullet.moveBullet() bullet.checkBackWall(self.width) for baddie in self.baddies: baddie.tick(0,0,self.height) if not baddie.alive: self.lives += -1 if self.lives == 0: print("You struckout but got %s grills numbers" % self.kills) quit() for bullet in self.bullets: if not bullet.alive: continue for baddie in self.baddies: if not baddie.alive: continue x,y,w,h = baddie.getDimensions() bullet.checkHitBaddie(x,y,w,h) if bullet.getHit(): bullet.setAlive(False) baddie.setAlive(False) bullet.hit = False self.kills += 1 live_bullets = [] live_baddies = [] for bullet in self.bullets: if bullet.alive: live_bullets.append(bullet) for baddie in self.baddies: if baddie.alive: live_baddies.append(baddie) self.bullets = live_bullets self.baddies = live_baddies return def addBaddie(self): self.baddie_color = random.choice(colors) new_baddie = Baddie( self.baddie_width, self.baddie_height, self.width, random.randint(0,(self.height-self.baddie_height)), self.baddie_color ) self.baddies.append( new_baddie ) return def drawTextLeft(self, surface, text, color, x, y,font): textobj = font.render(text, False, color) textrect = textobj.get_rect() textrect.bottomleft = (x, y) surface.blit(textobj, textrect) return def draw(self,surface): background = pygame.image.load("road.jpg") rect = pygame.Rect(0,0,self.width,self.height) surface.fill((0, 0, 0),rect ) surface.blit(background, (0, 0)) self.spaceship.draw(surface) for bullet in self.bullets: bullet.draw(surface) for baddie in self.baddies: baddie.draw(surface) lives = "%s chance(s) left" % self.lives kills = "You have got %s grills numbers" % self.kills self.drawTextLeft(surface, kills, red, 10, 40, self.font) self.drawTextRight(surface, lives, red, 300, 400, self.font) return def drawTextRight(self, surface, text, color, x, y,font): textobj = font.render(text, False, color) textrect = textobj.get_rect() textrect.bottomright = (x, y) surface.blit(textobj, textrect) return
def __init__(self,width,height,frame_rate): # Game Sounds pygame.mixer.init() self.player_killed = pygame.mixer.Sound("spartan_die.wav") self.player_killed.set_volume(.55) self.baddie_killed = pygame.mixer.Sound("grunt_death.wav") self.baddie_killed.set_volume(1.) self.baddie2_killed = pygame.mixer.Sound("elite_killed.wav") self.baddie2_killed.set_volume(.5) self.bullet_sound = pygame.mixer.Sound("assault_rifle.wav") self.bullet_sound.set_volume(1.) self.pelican_shoot = pygame.mixer.Sound("chain_gun.wav") self.pelican_shoot.set_volume(.75) self.battle_theme = pygame.mixer.music.load("battle_theme2.wav") pygame.mixer.music.play() # Game Images self.bg = Background("blood_gulch800x500.png", width) self.baddie_img = pygame.image.load("grunt_100x68.png") self.baddie2_img = pygame.image.load("blue_elite80x109.png") self.player_img = pygame.image.load("master_chief70x79.png") self.player_img2 = pygame.image.load("goku_90x105.png") self.font = pygame.font.SysFont("Times New Roman",36) self.font2 = pygame.font.SysFont("Courier New",20) self.frame_rate = frame_rate self.text_color = (255,0,0) self.width = width self.height = height self.upper_limit = self.width/3 self.spaceship_width = 50 #to compensate for the size of his body self.spaceship_height = 79 #he is not a rectangle self.spaceship = Spaceship(self.spaceship_width, self.spaceship_height, 0, (self.height / 2) - 10, (255,255,255), self.player_img, self.player_killed) self.spaceship.setName('Chief') print self.spaceship.getName() self.spaceship_speed = 10 self.spaceship.setHitPoints(3) self.bullets = [] self.bullet_width = 10 self.bullet_height = 5 self.bullet_color = (255,255,255) ### Delay baddies for 37 seconds ### #time.sleep(17) self.baddies = [] self.baddie_width = 100 self.baddie_height = 68 #self.baddies2 = [] self.baddie2_width = 35 self.baddie2_height = 109 # Code to change the game to DBZ themes # #if self.kills > 25: # self.bg.setImage("cell_games.png") # self.bullet_sound = pygame.mixer.Sound("ki_blast.wav") # self.bullet_img = pygame.mixer.Sound("ki_blast.png") # self.baddie_killed = pygame.mixer.Sound("Cell.wav") # self.baddie_img = pygame.image.load("Cell.png") # self.player_img = pygame.image.load("Goku.png") # self.dbz_theme = pygame.mixer.music.load("DBZ_theme.wav") # self.player_hit_points = 5 # self.baddie_hit_points = 25 # Use code for boss to shoot at random times # # # def boss_shoot(): # time.sleep(random.choice([0, 1, 2]) # Number of Player Health self.health = self.spaceship.getHitPoints() # Kill Points self.kills = 0 # Display the health self.health_color = (255,255,255) self.health_x = self.width/2 self.health_y = self.height - 30 # Display the Score self.score_color = (0,150,0) self.score_x = 20 self.score_y = 50 return
class SpaceshipData: def __init__(self,width,height,frame_rate): self.font = pygame.font.SysFont("Times New Roman",36) self.font2 = pygame.font.SysFont("Courier New",20) self.font3 = pygame.font.SysFont("monospace",10) self.font4 = pygame.font.SysFont("Times New Roman",72) self.frame_rate = frame_rate self.text_color = (255,0,0) self.width = width self.height = height self.upper_limit = self.width/2 self.buttonon = False self.spaceship_width = 20 self.spaceship_height = 10 self.spaceship_health = 300 self.spaceship_speed = 7 self.gamestate = CONFIG.GAME_STATE self.ministate = CONFIG.MINI_STATE self.spaceship = Spaceship(self.spaceship_width,self.spaceship_height,0,(self.height / 2) - 10, (0,255,255),self.spaceship_health) self.spaceship_y = self.spaceship.spaceshipPosition()[1] self.bullets = [] self.bullet_width = 15 self.bullet_height = 5 self.bullet_color = (255,255,255) self.hbullets = [] self.hbullet_width = 5 self.hbullet_height = 5 self.hbullet_color = (255,255,255) self.abullets = [] self.abullet_width = 20 self.abullet_height = 20 self.abullet_color = (255,255,255) self.bombs = 3 self.bomb = False self.boom =False self.bomb_radius = 20 self.ba = 1 self.stars = [] self.star_width = 1 self.star_height = 1 self.star_direction = 'normal' self.star_color = (255,255,255) self.lasers = [] self.laser_width =100 self.laser_height = 5 self.laser_color = (255,55,55) self.bups = [] self.bup_width = 8 self.bup_height = 8 self.bup_color = (144,144,144) self.mups = [] self.mup_width = 8 self.mup_height = 8 self.mup_color = (144,144,144) self.missiles = [] self.misslen = 0 self.missile_width = 30 self.missile_height = 10 self.missile_color = (55,144,144) self.badBullets = [] self.badBullet_width = 20 self.badBullet_height = 20 self.badBullet_color = (0,255,255) self.badLasers = [] self.badLaser_width = 100 self.badLaser_height = 30 self.badLaser_color = (0,255,255) self.baddies = [] self.baddie_width = 40 self.baddie_height = 40 self.baddie_color = (0,155,0) self.baddie_id = 0 self.asteroids = [] self.asteroid_width = random.randint(20, 60) self.asteroid_height = self.asteroid_width self.asteroid_color=(55,55,0) self.boss = [] self.boss1_width = 400 self.boss1_height = 600 self.boss1_color = (55,0,0) self.turret1_width = 60 self.turret1_height = 20 self.turret1_color = (155,50,50) self.turrets = 0 self.particles = [] * 100 self.particle_width = 20 self.particle_height = 20 self.projectiles = [] self.powerups = [] self.particle_color=(255,255,255) self.particle_speed = .3 self.f = ['up', 'down','left','right','upright','upleft','downright','downleft'] self.c = [ORANGE,RED,DRED,BRED,ORANGE,DORANGE,YELLOW ] self.score = 0 self.wave1 = True self.wave2 = False self.wave3 = False self.wave4 = False self.wave5 = False self.wave6 = False self.wave7 = False self.wave8 = False self.wave9 = False self.wave10 = False self.w1 = [1,1,2,2,1,2,1,1,'p','p','p',4,'p','p',99,0] self.w2 = [1,1,2,2,1,2,1,1,'p','p','p',4,'p','p',99,0] self.w3 = [1,1,2,2,1,2,1,1,'p','p','p',4,'p','p',99,0] self.w4 = [1,1,2,2,1,2,1,1,'p','p','p',4,'p','p',99,0] self.w5 = [1,1,2,2,1,2,1,1,'p','p','p',4,'p','p',99,0] self.w6 = [1,1,2,2,1,2,1,1,'p','p','p',4,'p','p',99,0] self.w7 = [1,1,2,2,1,2,1,1,'p','p','p',4,'p','p',99,0] self.w8 = [1,1,2,2,1,2,1,1,'p','p','p',4,'p','p',99,0] self.w9 = [1,1,2,2,1,2,1,1,'p','p','p',4,'p','p',99,0] self.w10 = [1,1,2,2,1,2,1,1,'p','p','p',4,'p','p',99,0] self.endGame = False self.winGame = False self.delay = 0 self.shootDelay = 0 self.laserDelay = 0 self.laser_on = False self.badLaserDelay = 0 self.a = -1 self.ang = 9 self.angby = .1 self.invinsiblen = 0 baddie_list = pygame.sprite.Group all_sprite_list = pygame.sprite.Group self.e = 0 self.e_t = 0 self.e_b = 0 self.exploding = False self.startoggle = 3 self.loadingn = 0 self.paused = False self.millimax = 0 self.fragmentgroup = pygame.sprite.Group() Fragment.groups = self.fragmentgroup return def doNothing(self): return True def evolve(self, keys, newkeys, buttons, newbuttons, mouse_position): if 1 in newbuttons: self.buttonon = True else: self.buttonon = False self.gamestate = CONFIG.GAME_STATE self.ministate = CONFIG.MINI_STATE if self.gamestate == 1: self.loadingn +=1 if self.loadingn == 60: CONFIG.GAME_STATE = 2 self.loadingn = 0 if self.gamestate == 2 or self.gamestate == 3: if pygame.K_ESCAPE in newkeys: self.paused = not self.paused CONFIG.MINI_STATE = 1 if self.paused == False: if pygame.K_LEFT in keys or pygame.K_a in keys: self.spaceship.moveLeft(self.spaceship_speed) if pygame.K_RIGHT in keys or pygame.K_d in keys: self.spaceship.moveRight(self.spaceship_speed,self.upper_limit) if pygame.K_UP in keys or pygame.K_w in keys: self.spaceship.moveUp(self.spaceship_speed+3) if pygame.K_DOWN in keys or pygame.K_s in keys: self.spaceship.moveDown(self.spaceship_speed+3,self.height) if pygame.K_i in newkeys: self.spaceship.invinsiblen = 200 if pygame.K_LCTRL in newkeys: if self.bombs > 0: if self.bomb_radius == 20: self.bomb = True self.bombs -= 1 if self.bomb_radius >= 6000: self.boom = False self.bomb_radius = 20 self.ba = 1 self.particle_direction = random.choice(self.f) self.particle_color = random.choice(self.c) if pygame.K_p in newkeys: self.addBoss1() if pygame.K_u in keys: #for _ in range(random.randint(3,15)): self.spaceship.explode() if pygame.K_o in newkeys: self.spaceship.bullet_up += 1 self.spaceship.missile_up += 1 self.spaceship.laser_up += 1 if self.e > 1: self.e = 0 self.e += self.e_b if self.e == 1: self.e_t += 1 self.particles.append(self.spaceship.explode(self.particle_width,self.particle_height,self.particle_color,self.particle_speed,self.particle_direction)) if self.e_t > 50: self.e= 0 self.e_t = 0 self.e_b = 0 self.shootDelay += 1 self.invinsiblen -= 1 if self.invinsiblen < 0: self.invinsiblen = 0 self.spaceship.invinsible = False if self.invinsiblen > 0: self.spaceship.invinsible = True if self.shootDelay > 30: self.shootDelay = 0 if self.hover(0,50,self.width,self.height-50): if 1 in buttons: self.shootBullet(self.spaceship) self.shootMissile(self.spaceship) self.shootLaser(self.spaceship) self.shootAngledBullet(self.spaceship) if pygame.K_SPACE in keys : self.shootBullet(self.spaceship) self.shootMissile(self.spaceship) self.shootLaser(self.spaceship) #self.shootAngledBullet(self.spaceship) if self.laserDelay >= 60: self.laserDelay = 0 if self.laserDelay <= 0: self.laserDelay = 0 if self.badLaserDelay >= 80: self.badLaserDelay = -30 if self.badLaserDelay <= -30: self.badLaserDelay = -30 """if self.ang > 3: self.angby *= -1 if self.ang < .2: self.angby *= -1""" """if self.ang > 2.8: self.ang = .5 if self.ang < .5: self.ang = 2.8""" self.delay += 1 if self.delay >= 120: self.delay = 0 if self.spaceship.health <= 0: del self.bullets[:] self.spaceship.setAlive(False) if len(self.boss) <= 0: if self.endGame == True: self.winGame = True clock =pygame.time.Clock() milliseconds = clock.tick(self.frame_rate) # milliseconds passed since last frame if milliseconds > self.millimax: self.millimax = milliseconds seconds = milliseconds / 1000.0 self.fragmentgroup.update(seconds) if self.spaceship.health > 0: #wave fucntionality """if self.wave1 == True or self.wave2 == True or self.wave3 == True or self.wave4 == True or self.wave5 == True\ or self.wave6 == True or self.wave7 == True or self.wave8 == True or self.wave9 == True or self.wave10 == True: if self.delay == 60: self.a+=1 if self.wave1 == True: i = self.w1[self.a] elif self.wave2 == True: i = self.w2[self.a] elif self.wave3 == True: i = self.w3[self.a] elif self.wave4 == True: i = self.w4[self.a] elif self.wave5 == True: i = self.w5[self.a] elif self.wave6 == True: i = self.w6[self.a] elif self.wave7 == True: i = self.w7[self.a] elif self.wave8 == True: i = self.w8[self.a] elif self.wave9 == True: i = self.w9[self.a] elif self.wave10 == True: i = self.w10[self.a] if i == 1: self.addBaddie(100) self.addBaddie(200) self.addBaddie(300) self.addBaddie(400) self.addBaddie(500) elif i == 2: self.addStrongBaddie(100) self.addBaddie(200) self.addStrongBaddie(300) self.addBaddie(400) self.addStrongBaddie(500) elif i == 4: self.addBoss1() elif i == 'p': self.doNothing() elif i == 'a': for _ in range(10): if random.randint(1, self.frame_rate/2) == 1: self.addAsteroid() elif i == '1end': self.wave1 = False elif i == '2end': self.wave2 = False elif i == '3end': self.wave3 = False elif i == '4end': self.wave4 = False elif i == '5end': self.wave5 = False elif i == '6end': self.wave6 = False elif i == '7end': self.wave7 = False elif i == '8end': self.wave8 = False elif i == '9end': self.wave9 = False elif i == '10end': self.wave10 = False elif i == '2start': self.wave2 = True elif i == '3start': self.wave3 = True elif i == '4start': self.wave4 = True elif i == '5start': self.wave5 = True elif i == '6start': self.wave6 = True elif i == '7start': self.wave7 = True elif i == '8start': self.wave8 = True elif i == '9start': self.wave9 = True elif i == '10start': self.wave10 = True elif i == 99: self.endGame = True""" self.spaceship.tick() self.starry(self.startoggle) for bullet in self.bullets: bullet.moveBullet() bullet.checkBackWall(self.width) if not bullet.alive: self.bullets.remove(bullet) continue for h in self.hbullets: h.update(self.spaceship_y) for a in self.abullets: a.update(self.spaceship.x,self.spaceship.y) a.checkWall() if not a.alive: self.abullets.remove(a) continue #a.setAngle(self.ang) for b in self.boss: b.tick(0,0,self.height, 400,self.turrets) for star in self.stars: star.move(self.spaceship.x, self.spaceship.y) star.checkBackWall(50) if star.x <= 0: star.alive = False self.stars.remove(star) for p in self.particles: p.move() p.checkWalls(0,50,self.width,self.height) a =int(p.color[0]-p.vel) b= int(p.color[1]-p.vel) c=int(p.color[2]-p.vel) if a < 0: a= 0 if c < 0: c= 0 if b < 0: b= 0 p.color =(a,b,c) for laser in self.lasers: laser.moveLaser() laser.checkBackWall(self.width) for m in self.mups: m.move() m.checkBackwall(0) for b in self.bups: b.move() b.checkBackwall(0) for bbullet in self.badBullets: bbullet.moveBullet() bbullet.checkBackWall(0) for a in self.asteroids: a.move() a.checkBackWall(0) for laz in self.badLasers: laz.moveLaser() laz.checkBackWall(0) for bbullet in self.badBullets: if not bbullet.alive: continue x,y,h,w = bbullet.getDimensions() self.spaceship.checkHit(x,y,h,w) if self.spaceship.hit == True: self.spaceship.hit = False self.spaceship.invinsible = True self.invinsiblen = 30 self.spaceship.health -= 1 bbullet.setAlive(False) self.spaceship_y = self.spaceship.spaceshipPosition()[1] for aster in self.asteroids: if not aster.alive: continue if aster.hit != False: aster.color = (255,55,55) x,y,w,h = aster.getDimensions() if w >= 35: self.spaceship.checkHit(x,y,w,h) if self.spaceship.getHit(): aster.alive = False self.spaceship.health -= 1 self.invinsiblen = 30 self.spaceship.invinsible = True self.spaceship.hit = False for bullet in self.bullets: if not bullet.alive: continue x,y,w,h = aster.getDimensions() bullet.checkHit(x,y,w,h) if bullet.hit == True: bullet.hit = False aster.alive = False if w < 35: aster.alive = False else: self.addSAsteroid(w/2,h/2,x+5,y-h/2,random.uniform(1,1.5)) self.addSAsteroid(w/2,h/2,x+5,y+h/2,random.uniform(1.9,2)) for baddie in self.baddies: baddie.tick(0,0,self.height, self.height/2) #self.homingBullet(baddie) if self.bomb == True: self.bomb = False self.boom = True if self.boom == True: for bae in self.baddies: bae.decreaseHitPoints(30) self.explodeIt(bae) if not baddie.alive: continue if baddie.hit != False: baddie.color = (255,55,55) x,y,w,h = baddie.getDimensions() self.spaceship.checkHit(x,y,w,h) if self.spaceship.getHit(): baddie.decreaseHitPoints(99) self.spaceship.health -= 1 self.invinsiblen = 30 self.spaceship.invinsible = True self.spaceship.hit = False if baddie.behavior == 3 or baddie.behavior == 1: if self.shootDelay == 15: self.badBullets.append(baddie.fire(self.badBullet_width,self.badBullet_height,self.badBullet_color)) if baddie.behavior == 5 or baddie.behavior == 6: if self.shootDelay == 6 or self.shootDelay == 12 or self.shootDelay == 18 or self.shootDelay == 24 or self.shootDelay == 30: self.badBullets.append(baddie.fire(self.badBullet_width,self.badBullet_height,self.badBullet_color)) if baddie.behavior == 4: if self.shootDelay == 30: self.badBullets.append(baddie.bossFire(self.badBullet_width,self.badBullet_height,self.badBullet_color)) for b in self.boss: if not b.alive: del self.boss[:] self.score += 1000 continue self.badLaserDelay += 1 if self.badLaserDelay >20: if self.turrets <= 0: self.badLasers.append(b.beam(self.badLaser_width, self.badLaser_height, self.badLaser_color,0,-b.height/2-50+(self.badLaserDelay*4))) self.badLasers.append(b.beam(self.badLaser_width, self.badLaser_height, self.badLaser_color,0,b.height/2+50-(self.badLaserDelay*4))) self.badLasers.append(b.beam(self.badLaser_width, self.badLaser_height, self.badLaser_color,0,-10)) if self.turrets <= 0: self.shootAngledBullet(b) for bullet in self.bullets: if not bullet.alive: continue x,y,w,h = b.getDimensions() bullet.checkHit(x,y,w,h) if bullet.hit == True: if b.canGetHit == True: b.hit = True self.hurtIt(b,1) else: b.fakeHit = True self.explodeIt(bullet) bullet.hit = False for laser in self.lasers: if not laser.alive: continue x,y,w,h = b.getDimensions() laser.checkHit(x,y,w,h) if laser.hit == True: laser.color = (255,255,255) if b.canGetHit == True: b.hit = True self.hurtIt(b,.2) laser.hit = False if self.isTurret(b) == True: self.turrets -= 1 else: b.fakeHit = True laser.hit=False self.explodeIt(laser) laser.hit = False for missile in self.missiles: if not missile.alive: continue x,y,w,h = b.getDimensions() missile.checkHit(x,y,w,h) if missile.hit == True: if b.canGetHit == True: b.hit = True self.hurtIt(b,3) missile.hit = False else: b.fakeHit = True missile.hit = False self.explodeIt(missile) missile.hit = False for blaser in self.badLasers: if not blaser.alive: continue x,y,w,h = self.spaceship.getDimensions() blaser.checkHit(x,y,w,h) if blaser.hit == True: blaser.hit = False self.spaceship.health -= .02 for bullet in self.abullets: if not bullet.alive: continue x,y,w,h = self.spaceship.getDimensions() bullet.checkHit(x,y,w,h) if bullet.hit == True: bullet.hit = False #self.spaceship.health -= .5 if self.bomb == True: self.bomb = False self.boom = True for l in self.lasers: if not l.alive: continue for baddie in self.baddies: if not baddie.alive: continue x,y,w,h = baddie.getDimensions() l.checkHit(x,y,w,h) if l.getHit(): baddie.hit = True l.setHit(False) self.hurtIt(baddie, .2) baddie.hit = False if baddie.hit_points <= 0: self.explodeIt(baddie) for missile in self.missiles: missile.moveMissile(self.misslen) if self.ifFreindlyCollide(self.mups,self.spaceship): self.score +=0 if self.ifFreindlyCollide(self.bups,self.spaceship): self.score += 0 if self.ifCollide(self.baddies, self.bullets, 1,0): self.score += 15 if self.ifCollide(self.baddies, self.missiles,3,0): self.score += 15 if self.ifFreindlyCollide(self.mups, self.spaceship): self.missile_up += 1 live_mups = [] live_bups = [] live_bullets = [] live_baddies = [] live_missiles = [] live_badBullets = [] live_badLasers = [] live_hBullets = [] live_lasers = [] live_particles = [] live_asteroids = [] for bullet in self.bullets: if bullet.alive: live_bullets.append(bullet) for laser in self.lasers: if laser.alive: live_lasers.append(laser) for bbullet in self.badBullets: if bbullet.alive: live_badBullets.append(bbullet) for baddie in self.baddies: if baddie.alive: live_baddies.append(baddie) for missile in self.missiles: if missile.alive: live_missiles.append(missile) for a in self.asteroids: if a.alive: live_asteroids.append(a) for m in self.mups: if m.alive: live_mups.append(m) for p in self.particles: if p.alive: live_particles.append(p) for b in self.bups: if b.alive: live_bups.append(b) for l in self.badLasers: if l.alive: live_badLasers.append(l) for h in self.hbullets: if h.alive: live_hBullets.append(h) for a in self.abullets: if a.alive: live_hBullets.append(a) self.mups = live_mups self.bups = live_bups self.asteroids = live_asteroids self.badBullets = live_badBullets self.badLasers = live_badLasers self.bullets = live_bullets self.baddies = live_baddies self.missiles = live_missiles self.lasers = live_lasers self.projectiles = live_badBullets + live_missiles + live_bullets + live_lasers self.powerups = live_mups + live_bups self.particles = live_particles return def starry(self, togglenumber): if togglenumber ==4: self.addStar(2,2,self.width,random.randint(50,self.height),(255,255,255),10,'normal') self.addStar(2,2,self.width,random.randint(50,self.height),(155,155,155),7,'normal') self.addStar(2,2,self.width,random.randint(50,self.height),(100,100,100),5,'normal') self.addStar(2,2,self.width,random.randint(50,self.height),(55,55,55),2,'normal') if togglenumber ==3: self.addStar(2,2,self.width,random.randint(50,self.height),(255,255,255),10,'normal') self.addStar(2,2,self.width,random.randint(50,self.height),(155,155,155),7,'normal') self.addStar(2,2,self.width,random.randint(50,self.height),(100,100,100),5,'normal') elif togglenumber == 2: self.addStar(2,2,self.width,random.randint(50,self.height),(255,255,255),10,'normal') self.addStar(2,2,self.width,random.randint(50,self.height),(155,155,155),7,'normal') elif togglenumber ==1: self.addStar(2,2,self.width,random.randint(50,self.height),(255,255,255),10,'normal') def addAsteroid(self): size = random.randint(40,90) new_baddie = Asteroid(size, size, self.width, random.randint(0,(self.height-self.baddie_height)), self.asteroid_color, 5, random.uniform(1,2)) self.asteroids.append( new_baddie ) return def addSAsteroid(self,width,height,x,y,angle): new_baddie = Asteroid(width, height, x, y, self.asteroid_color, 5, angle) self.asteroids.append( new_baddie ) return def addBaddie(self, height): new_baddie = Baddie(self.baddie_id, self.baddie_width, self.baddie_height, self.width, height, self.baddie_color, 3, 0 ) self.baddies.append( new_baddie ) return def addStrongBaddie(self, height): new_baddie = Baddie(self.baddie_id,self.baddie_width, self.baddie_height, self.width, height, (155,0,0), 2, 1) new_baddie.setHitPoints(2) self.baddies.append(new_baddie) return def addBigBaddie(self): new_baddie = Baddie(self.baddie_id,self.baddie_width*5, self.baddie_height*5, self.width, 200, (55,0,0), 1, 3) new_baddie.setHitPoints(15) self.baddies.append(new_baddie) return def addBoss1(self): new_baddie = Boss(10,self.boss1_width, self.boss1_height, self.width, 100, self.boss1_color, 1, 4) new_baddie.setHitPoints(100) new_baddie.canGetHit = False self.boss.append(new_baddie) self.turrets = 0 new_baddie = Baddie(11,self.turret1_width, self.turret1_height, self.width-20, 300, self.turret1_color, 1, 5) new_baddie.setHitPoints(1) new_baddie.isTurret = True self.baddies.append(new_baddie) self.turrets += 1 new_baddie = Baddie(11,self.turret1_width, self.turret1_height, self.width-20, 500, self.turret1_color, 1, 6) new_baddie.setHitPoints(1) new_baddie.isTurret = True self.baddies.append(new_baddie) self.turrets += 1 def addStar(self,width,height,x,y,color,speed,direction): new_star = Star(width,height,x,y,color,speed,direction) self.stars.append(new_star) return def shootBullet(self, who): #self.bullets.append(who.angleFire(0,)) if self.shootDelay == 6 or self.shootDelay == 12 or self.shootDelay == 18 or self.shootDelay == 24 or self.shootDelay == 30: if who.bullet_up ==1: self.bullets.append(who.fire(self.bullet_width,self.bullet_height,self.bullet_color,'normal')) if who.bullet_up == 2: self.bullets.append(who.fire(self.bullet_width,self.bullet_height,self.bullet_color,'normal',0,-5)) self.bullets.append(who.fire(self.bullet_width,self.bullet_height,self.bullet_color,'normal',0,5)) if who.bullet_up == 3 : self.bullets.append( who.fire(self.bullet_width,self.bullet_height,self.bullet_color,'normal')) self.bullets.append(who.fire(self.bullet_width,self.bullet_height,self.bullet_color, 'up')) self.bullets.append(who.fire(self.bullet_width,self.bullet_height,self.bullet_color, 'down')) if who.bullet_up == 4 : self.bullets.append( who.fire(self.bullet_width,self.bullet_height,self.bullet_color,'normal')) self.bullets.append(who.fire(self.bullet_width,self.bullet_height,self.bullet_color, 'up')) self.bullets.append(who.fire(self.bullet_width,self.bullet_height,self.bullet_color, 'down')) self.bullets.append(who.fire(self.bullet_width,self.bullet_height,self.bullet_color, 'up2')) self.bullets.append(who.fire(self.bullet_width,self.bullet_height,self.bullet_color, 'down2')) def shootMissile(self, who): if self.spaceship.missile_up == 1: if self.shootDelay == 15: if self.misslen ==0: self.misslen=1 else: self.misslen = 0 self.missiles.append(self.spaceship.launch(self.missile_width, self.missile_height, self.missile_color,0,-10)) if self.shootDelay == 30 : self.missiles.append(self.spaceship.launch(self.missile_width, self.missile_height, self.missile_color,0,10)) if who.missile_up == 2: if self.shootDelay == 15: if self.misslen ==0: self.misslen=1 else: self.misslen = 0 self.missiles.append(self.spaceship.launch(self.missile_width, self.missile_height, self.missile_color,0,-10)) self.missiles.append(self.spaceship.launch(self.missile_width, self.missile_height, self.missile_color,0,-20,-2)) if self.shootDelay == 30 : self.missiles.append(self.spaceship.launch(self.missile_width, self.missile_height, self.missile_color,0,10)) self.missiles.append(self.spaceship.launch(self.missile_width, self.missile_height, self.missile_color,0, 20,2)) def shootLaser(self,who): if who.laser_up == 1: self.laserDelay += 1 if self.laserDelay >20: self.lasers.append(who.beam(self.laser_width, self.laser_height, self.laser_color)) if who.laser_up == 2: self.laserDelay += 1 if self.laserDelay >20: self.lasers.append(who.beam(self.laser_width, self.laser_height, self.laser_color,0,-10)) self.lasers.append(who.beam(self.laser_width, self.laser_height, self.laser_color,0,10)) def shootAngledBullet(self,who): self.abullets.append(who.angleFire(self.abullet_width,self.abullet_height,self.abullet_color,self.ang)) #self.ang += self.angby def button(self,x,y,w,h): mx, my =pygame.mouse.get_pos() if x <= mx <= x+w and y <= my <= y+h: if self.buttonon == True: return True def hover(self,x,y,w,h): mx, my =pygame.mouse.get_pos() if x <= mx <= x+w and y <= my <= y+h: return True def ifFreindlyCollide(self, collider, collideE): for a in collider: if not a.alive: continue if isinstance(collideE, list) == True: for b in collideE: if not b.alive: continue x,y,h,w = a.getDimensions() b.checkHitFriendly(x,y,w,h) if b.hit == True: a.setAlive(False) return b.hit else: x,y,h,w = a.getDimensions() collideE.checkHitFriendly(x,y,w,h) if collideE.hit == True: a.setAlive(False) a.hit = False return collideE.hit def ifCollide(self, collider, collideE, rhurt, ehurt): for a in collider: if not a.alive: continue if isinstance(collideE, list) == True: for b in collideE: if not b.alive: continue x,y,h,w = a.getDimensions() b.checkHit(x,y,w,h) if b.hit == True: a.hit = True self.hurtIt(a,rhurt) self.hurtIt(b,ehurt) self.explodeIt(a) self.explodeIt(collideE) return b.hit else: x,y,h,w = a.getDimensions() collideE.checkHit(x,y,w,h) if collideE.hit == True: a.hit = True self.hurtIt(collideE,ehurt) self.hurtIt(a,rhurt) self.explodeIt(a) self.explodeIt(collideE) return collideE.hit def explodeIt(self, who): if hasattr(who, 'canBoom')==True: if hasattr(who,'hit_points')==True: if who.hit_points <= 0: self.destroyBlast(who) else: self.explode(who) else: self.destroyBlast(who) def explode(self,who): who.explode((who.x,who.y),random.choice(self.c)) def destroyBlast(self,who): for _ in range(random.randint(3,15)): who.explode((who.x,who.y),random.choice(self.c)) def hurtIt(self, who,much): if hasattr(who,'friendly')==True: pass else: if hasattr(who,'hit_points')==True: who.hit_points -= much if who.hit_points <= 0: if self.isTurret(who) ==True: self.turrets -= 1 else: who.setAlive(False) if self.isTurret(who) ==True: self.turrets -= 1 def isTurret(self,who): if hasattr(who,'isTurret') == True: if who.isTurret == True: return True def newGame(self): del self.baddies[:] del self.bullets[:] del self.stars[:] del self.projectiles[:] del self.badBullets[:] del self.badLasers[:] del self.boss[:] del self.abullets[:] self.wave1 = True self.endGame = False self.winGame = False self.score = 0 self.bombs = 3 self.spaceship.setAlive(True) self.spaceship.health = 3 self.spaceship.x = 0 self.spaceship.y = self.height/2 self.a = 0 self.spaceship.bullet_up = 1 self.spaceship.missile_up = 0 self.spaceship.missile_up = 0 def draw(self,surface): rect = pygame.Rect(0,0,self.width,self.height) surface.fill((0,0,0),rect ) rect = pygame.Surface((self.width,50), pygame.SRCALPHA, 32) rect.fill((255, 255, 255, 50)) surface.blit(rect, (0,0)) self.spaceship.draw(surface) myfont = self.font2 myfont1 = self.font myfont2 = self.font3 label = myfont.render("Score "+str(self.score), 1, (255,255,0)) surface.blit(label, (350, 20)) label3 = myfont.render("Bombs "+str(self.bombs), 1, (255,255,0)) surface.blit(label3, (250, 20)) if self.boom == True: x,y = self.spaceship.spaceshipPosition() self.ba += 2 self.bomb_radius += self.ba*2 pygame.draw.circle(surface, (155,0,0), (x,y), self.bomb_radius,10) pygame.draw.circle(surface, (255,0,0), (x,y), self.bomb_radius/2,5) pygame.draw.circle(surface, (255,255,0), (x,y), self.bomb_radius/3,3) pygame.draw.circle(surface, (255,255,155),(x,y),self.bomb_radius/4,3 ) pygame.draw.circle(surface, (55,0,0), (x+50,y+50), self.bomb_radius, 10) pygame.draw.circle(surface, (255,0,0), (x+50,y-50), self.bomb_radius/2, 5) pygame.draw.circle(surface, (255,255,0), (x-50,y+50), self.bomb_radius/3, 3) pygame.draw.circle(surface, (255,255,155),(x-50,y-50),self.bomb_radius/4,3 ) if self.spaceship.health > 0: rect = pygame.Rect( 20, 20, 50*self.spaceship.health, 20 ) pygame.draw.rect(surface, (255,0,0), rect) for s in self.stars: s.draw(surface) for p in self.powerups: p.draw(surface) for L in self.badLasers: L.draw(surface) for b in self.boss: b.draw(surface) b.drawHealth(surface) for a in self.projectiles: a.draw(surface) for baddie in self.baddies: baddie.draw(surface) # surf = pygame.Surface((baddie.width, baddie.width)) # rotatedSurf = pygame.transform.rotate(surf, ) # rotRect = rotatedSurf.get_rect() # surface.blit(rotatedSurf, rotRect) for l in self.particles: l.draw(surface) for h in self.hbullets: h.draw(surface) for h in self.abullets: h.draw(surface) for a in self.asteroids: a.draw(surface) self.fragmentgroup.draw(surface) if self.winGame == True: rect = pygame.Surface((self.width,self.height), pygame.SRCALPHA, 32) rect.fill((0, 0, 0, 200)) surface.blit(rect, (0,0)) rect = pygame.Surface((self.width,50), pygame.SRCALPHA, 32) rect.fill((255, 255, 255, 50)) surface.blit(rect, (0,self.height/2)) label1 = self.font.render("You Won!", 1, (255,255,0)) surface.blit(label1, (600, self.height/2-200)) rect = pygame.Rect( self.width/4-5, self.height/3, 80, 50 ) x,y,w,h = rect if self.hover(x,y,w,h): pygame.draw.rect(surface, (155,155,155), rect) else: pygame.draw.rect(surface, (55,55,55), rect) if self.button(x,y,w,h): CONFIG.GAME_STATE = 1 self.newGame() label1 = myfont1.render("Play Again", 1, (255,255,0)) surface.blit(label1, (self.width/4, self.height/3)) rect = pygame.Rect( self.width/1.5-5, self.height/3, 80, 50 ) x,y,w,h = rect if self.hover(x,y,w,h): pygame.draw.rect(surface, (155,155,155), rect) else: pygame.draw.rect(surface, (55,55,55), rect) if self.button(x,y,w,h): pygame.quit() label1 = myfont1.render("Quit", 1, (255,255,0)) surface.blit(label1, (self.width/1.5, self.height/3)) if self.spaceship.health <= 0: rect = pygame.Surface((self.width,self.height), pygame.SRCALPHA, 32) rect.fill((0, 0, 0, 200)) surface.blit(rect, (0,0)) rect = pygame.Surface((self.width,50), pygame.SRCALPHA, 32) rect.fill((255, 255, 255, 50)) surface.blit(rect, (0,self.height/2)) label1 = self.font.render("Game Over", 1, (255,255,0)) surface.blit(label1, (600, self.height/2-200)) rect = pygame.Rect( 395, self.height/2, 100, 50 ) x,y,w,h = rect if self.hover(x,y,w,h): pygame.draw.rect(surface, (155,155,155), rect) else: pygame.draw.rect(surface, (55,55,55), rect) if self.button(x,y,w,h): CONFIG.GAME_STATE = 0 self.paused = False self.newGame() label1 = myfont.render("Menu", 1, (255,255,0)) surface.blit(label1, (400, self.height/2)) rect = pygame.Rect( 695, self.height/2, 80, 50 ) x,y,w,h = rect if self.hover(x,y,w,h): pygame.draw.rect(surface, (155,155,155), rect) else: pygame.draw.rect(surface, (55,55,55), rect) if self.button(x,y,w,h): pygame.quit() label1 = myfont.render("Quit", 1, (255,255,0)) surface.blit(label1, (700, self.height/2)) rect = pygame.Rect( 880, 20, 20, 20 ) pygame.draw.rect(surface, (155,155,155), rect) x,y,w,h = rect if self.button(x,y,w,h): self.startoggle += 1 if self.startoggle == 4: self.startoggle = 0 rect = pygame.Rect( 940, 20, 20, 20 ) pygame.draw.rect(surface, (155,155,155), rect) x,y,w,h = rect if self.button(x,y,w,h): self.paused = not self.paused if self.ministate == 0: CONFIG.MINI_STATE = 1 else: CONFIG.MINI_STATE = 0 self.drawPaused(surface) return def menuDraw(self,surface): myfont1 = self.font rect = pygame.Rect(0,0,self.width,self.height) surface.fill((0,0,0),rect ) label1 = myfont1.render("Kimber's Space Adventure", 1, (255,255,0)) surface.blit(label1, (self.width/3, self.height/8)) rect = pygame.Rect( self.width/4-5, self.height/3, 80, 50 ) x,y,w,h = rect if self.hover(x,y,w,h): pygame.draw.rect(surface, (155,155,155), rect) else: pygame.draw.rect(surface, (55,55,55), rect) if self.button(x,y,w,h): CONFIG.GAME_STATE = 1 self.newGame() label1 = myfont1.render("Play", 1, (255,255,0)) surface.blit(label1, (self.width/4, self.height/3)) rect = pygame.Rect( self.width/1.5-5, self.height/3, 80, 50 ) x,y,w,h = rect if self.hover(x,y,w,h): pygame.draw.rect(surface, (155,155,155), rect) else: pygame.draw.rect(surface, (55,55,55), rect) if self.button(x,y,w,h): pygame.quit() label1 = myfont1.render("Quit", 1, (255,255,0)) surface.blit(label1, (self.width/1.5, self.height/3)) def loadDraw(self,surface): myfont = self.font4 rect = pygame.Rect(0,0,self.width,self.height) surface.fill((0,0,0),rect ) label1 = myfont.render("Loading", 1, (255,255,0)) surface.blit(label1, (self.width/4, self.height/3)) def drawPaused(self, surface): myfont = self.font if self.paused == True: rect = pygame.Surface((self.width,self.height-50), pygame.SRCALPHA, 32) rect.fill((0, 0, 0, 200)) surface.blit(rect, (0,50)) rect = pygame.Surface((600,600), pygame.SRCALPHA, 32) rect.fill((255, 255, 255, 50)) surface.blit(rect, (300,200)) #normal pause if self.ministate == 1: label1 = myfont.render("Paused", 1, (255,255,0)) surface.blit(label1, (500, self.height/2-50)) rect = pygame.Rect( 395, self.height/2, 100, 50 ) x,y,w,h = rect if self.hover(x,y,w,h): pygame.draw.rect(surface, (155,155,155), rect) else: pygame.draw.rect(surface, (55,55,55), rect) if self.button(x,y,w,h): CONFIG.GAME_STATE = 0 self.paused = False self.newGame() label1 = myfont.render("Menu", 1, (255,255,0)) surface.blit(label1, (400, self.height/2)) rect = pygame.Rect( 695, self.height/2, 80, 50 ) x,y,w,h = rect if self.hover(x,y,w,h): pygame.draw.rect(surface, (155,155,155), rect) else: pygame.draw.rect(surface, (55,55,55), rect) if self.button(x,y,w,h): pygame.quit() label1 = myfont.render("Quit", 1, (255,255,0)) surface.blit(label1, (700, self.height/2)) rect = pygame.Rect( 700, self.height/2+100, 100, 50 ) x,y,w,h = rect if self.hover(x,y,w,h): pygame.draw.rect(surface, (155,155,155), rect) else: pygame.draw.rect(surface, (55,55,55), rect) if self.button(x,y,w,h): CONFIG.MINI_STATE = 2 label1 = myfont.render("Options", 1, (255,255,0)) surface.blit(label1, (700, self.height/2+100)) rect = pygame.Rect( 400, self.height/2+100, 100, 50 ) x,y,w,h = rect if self.hover(x,y,w,h): pygame.draw.rect(surface, (155,155,155), rect) else: pygame.draw.rect(surface, (55,55,55), rect) if self.button(x,y,w,h): CONFIG.MINI_STATE = 0 self.paused = False label1 = myfont.render("Return", 1, (255,255,0)) surface.blit(label1, (400, self.height/2+100)) #Options elif self.ministate == 2: label1 = myfont.render("Options", 1, (255,255,0)) surface.blit(label1, (500, self.height/2-50)) rect = pygame.Rect( 395, self.height/2, 100, 50 ) x,y,w,h = rect if self.hover(x,y,w,h): pygame.draw.rect(surface, (155,155,155), rect) else: pygame.draw.rect(surface, (55,55,55), rect) if self.button(x,y,w,h): CONFIG.MINI_STATE = 1 label1 = myfont.render("OK", 1, (255,255,0)) surface.blit(label1, (400, self.height/2)) rect = pygame.Rect( 695, self.height/2, 80, 50 ) x,y,w,h = rect if self.hover(x,y,w,h): pygame.draw.rect(surface, (155,155,155), rect) else: pygame.draw.rect(surface, (55,55,55), rect) if self.button(x,y,w,h): pass label1 = myfont.render("Mute", 1, (255,255,0)) surface.blit(label1, (700, self.height/2)) def drawTextLeft(self, surface, text, color, x, y,font): textobj = font.render(text, False, color) textrect = textobj.get_rect() textrect.bottomleft = (x, y) surface.blit(textobj, textrect) return def drawTextRight(self, surface, text, color, x, y,font): textobj = font.render(text, False, color) textrect = textobj.get_rect() textrect.bottomright = (x, y) surface.blit(textobj, textrect) return
def init(self): self.background = MySprite('backgrounds/space.png') self.spaceship = Spaceship(10, 50)
class Asteroids(GameMain): caption = "Asteroids" spaceship_bullets = [] asteroids = [] cur_asteroid_speed = SPEED + 2 increased = False def init(self): self.background = MySprite('backgrounds/space.png') self.spaceship = Spaceship(10, 50) def manage_asteroids(self): for asteroid in self.asteroids: asteroid.move('left', asteroid.speed) self.DISPLAYSURF.blit(asteroid.image, (asteroid.rect.x, asteroid.rect.y)) self.asteroids = [ast for ast in self.asteroids if asteroid.rect.x >= -10] if len(self.asteroids) < NUMBER_ASTEROIDS[LEVEL]: x = self.DISPLAYSURF.get_size()[0] - 30 y = random.randint(0, self.DISPLAYSURF.get_size()[1] - 50) asteroid = Asteroid(x, y, self.cur_asteroid_speed) self.asteroids.append(asteroid) self.increased = False else: if not self.increased: self.cur_asteroid_speed += 1 self.increased = True def objects_collide(self, a, b): if isinstance(a, pygame.Rect): rectA = a else: rectA = a.rect #pygame.Rect(a.obj.x, a.obj.y, a.obj.width, a.obj.height) if isinstance(b, pygame.Rect): rectB = b else: rectB = b.rect #pygame.Rect(b.obj.x, b.obj.y, b.obj.width, b.obj.height) if rectA.colliderect(rectB): return True return False def check_hit_asteroid(self, bullet): self.asteroids = [ast for ast in self.asteroids if not self.objects_collide(bullet, ast)] def did_i_die(self): for asteroid in self.asteroids: if self.objects_collide(asteroid, self.spaceship): return True return False def mainLoop(self): self.background.image = pygame.transform.scale(self.background.image, self.DISPLAYSURF.get_size()) self.DISPLAYSURF.blit(self.background.image, (0, 0)) for bullet in self.spaceship_bullets: bullet.x += SPEED * 3 pygame.draw.rect(self.DISPLAYSURF, (200, 0, 0), (bullet.x, bullet.y, 4, 4)) #Check if the bullet hits any asteroid self.check_hit_asteroid(bullet) self.manage_asteroids() #if self.did_i_die(): # del self.spaceship # pygame.time.wait(2000) # exit(0) if pygame.key.get_pressed()[pygame.K_UP]: self.spaceship.move('up', SPEED) if pygame.key.get_pressed()[pygame.K_DOWN]: self.spaceship.move('down', SPEED) if pygame.key.get_pressed()[pygame.K_LEFT]: self.spaceship.move('left', SPEED) if pygame.key.get_pressed()[pygame.K_RIGHT]: self.spaceship.move('right', SPEED) if pygame.key.get_pressed()[pygame.K_SPACE]: left = self.spaceship.rect.x + self.spaceship.image.get_size()[0] top = self.spaceship.rect.y + self.spaceship.image.get_size()[1]/2 - 1 bullet = pygame.draw.rect(self.DISPLAYSURF, (200, 0, 0), (left, top, 4, 4)) self.spaceship_bullets.append(bullet) self.DISPLAYSURF.blit(self.spaceship.image, (self.spaceship.rect.x, self.spaceship.rect.y))
class Player(): """ Contains the player and manages the actions of the player """ def __init__(self, num): """initializes a player instance""" self.num = num if num == 2: self.textpos = (100, 50) self.spaceship = Spaceship(Config.platform2[0] + 100, Config.platform2[1] + 20, num, -1, -1) else: self.textpos = (Config.height - 100, 50) self.spaceship = Spaceship(Config.platform1[0] + 100, Config.platform1[1] + 20, num, -1, -1) self.shots = pygame.sprite.Group() self.lock = False self.lockthrust = False self.stats = self.init_stats() def init_stats(self): """Adding text""" status = pygame.sprite.Group() self.fuel = Text(self.num, (self.textpos[0],self.textpos[1] + 20), "Fuel", Config.defaultfuel) self.Bullets = Text(self.num, (self.textpos[0], self.textpos[1] + 40), "Bullets",Config.bulletcount ) self.Lives = Text(self.num, (self.textpos[0],self.textpos[1] + 60), "Lives", Config.defaultlives) self.score = Text(self.num, (self.textpos[0],self.textpos[1]), "Score", Config.score) status.add(self.fuel) status.add(self.score) status.add(self.Lives) status.add(self.Bullets) return status def force(self, v): """ Inflicts a force on a spaceship """ self.spaceship.vel += v def fire(self): """ Shooting bullets """ if(self.lock or self.Bullets.value <1): return shot = Lazer(self.spaceship.pos, self.spaceship.angle) self.Bullets.value -= 1 self.shots.add(shot) self.lock = True pygame.time.set_timer(USEREVENT+self.num, 200) #print "player", self.num, "fire" def thrust(self): """ Thrusting forward """ if self.lockthrust: return #print "player", self.num, "thrust" self.spaceship.vel += (self.spaceship.vel + self.spaceship.angle).normalized() def reverse(self): """ Thrusting backwards """ if self.lockthrust: return #print "player", self.num, "thrust" self.spaceship.vel -= (self.spaceship.vel + self.spaceship.angle).normalized() def turn_right(self): """ Moving ship to the right """ #print "player", self.num, "right" self.spaceship.vel = self.spaceship.vel.rotate(math.radians(4)) self.spaceship.angle = self.spaceship.angle.rotate(math.radians(4)) #self.spaceship.vel = Vector(math.cos(tmp.angle()),-math.sin(tmp.angle())) def turn_left(self): """ Moving ship to the left """ #print "player", self.num, "left" self.spaceship.vel = self.spaceship.vel.rotate(math.radians(-4)) self.spaceship.angle = self.spaceship.angle.rotate(math.radians(-4)) # = Vector(math.cos(tmp.angle()),-math.sin(tmp.angle())) def reset(self): """ Reseting all parameters to inital value """ self.spaceship.scale = 1 self.reset_stats() self.lockthrust = False self.spaceship.reset() def reset_stats(self): """ Resetting player status """ list = self.stats.sprites() for stats in list: stats.value = stats.initialvalue
def __init__(self, config): self.spaceship = Spaceship(0) self.rule = EscapeEschatonRule() self.size = 0 self.obstacle = [EschantonPlant(config["t_per_blast_move"])] + [ Asteroid(offset = asteroid["offset"], freq = asteroid["t_per_asteroid_cycle"]) for asteroid in config["asteroids"] ] self.size = len(self.obstacle)
class SpaceshipData: def __init__(self,width,height,frame_rate): self.font = pygame.font.Font("resources/Fipps-Regular.otf",16) self.frame_rate = frame_rate self.text_color = (255,0,0) self.width = width self.height = height self.upper_limit = self.width/3 self.spaceship_width = 10 self.spaceship_height = 20 self.spaceship = Spaceship(self.spaceship_width,self.spaceship_height,(self.width / 2), (self.height) -10, (255,255,255)) self.bullets = [] self.bullet_width = 5 self.bullet_height = 10 self.bullet_color = (255,255,255) self.baddies = [] self.baddie_width = 20 self.baddie_height = 20 self.baddie_color = (255,0,0) self.score = 0 self.baddies_killed = 0 self.current_level = 0 self.resources_path = "resources" self.window_x = 1280 self.window_y = 720 return def evolve(self, keys, newkeys, buttons, newbuttons, mouse_position): if pygame.K_LEFT in keys: self.spaceship.moveLeft(self.spaceship.spaceship_speed) if pygame.K_RIGHT in keys: self.spaceship.moveRight(self.spaceship.spaceship_speed,self.upper_limit) if pygame.K_UP in keys: self.spaceship.moveUp(self.spaceship.spaceship_speed) if pygame.K_DOWN in keys: self.spaceship.moveDown(self.spaceship.spaceship_speed,self.height) if pygame.K_SPACE in newkeys: self.bullets.append(self.spaceship.fire(self.bullet_width,self.bullet_height,self.bullet_color)) if random.randint(1, self.frame_rate) == 1: self.addBaddie() for bullet in self.bullets: bullet.moveBullet() bullet.checkBackWall(self.width) for baddie in self.baddies: baddie.tick(0,0,self.height) for bullet in self.bullets: if not bullet.alive: continue for baddie in self.baddies: if not baddie.alive: continue x,y,w,h = baddie.getDimensions() bullet.checkHitBaddie(x,y,w,h) if bullet.getHit(): bullet.setAlive(False) baddie.setAlive(False) bullet.hit = False self.score += 100 live_bullets = [] live_baddies = [] for bullet in self.bullets: if bullet.alive: live_bullets.append(bullet) for baddie in self.baddies: if baddie.alive: live_baddies.append(baddie) self.bullets = live_bullets self.baddies = live_baddies #Spaceship.update( self.spaceship.x, self.spaceship.y, self.spaceship_width, self.spaceship_height) spaceship_rect = pygame.Rect(self.spaceship.x, self.spaceship.y,self.spaceship.width,self.spaceship.height) for baddie in self.baddies: if baddie.alive: baddie_rect = pygame.Rect(baddie.x, baddie.y, baddie.width, baddie.height) if(baddie_rect.colliderect(spaceship_rect)): self.spaceship.health -=10 baddie.setAlive(False) if(self.spaceship.health<=0): self.spaceship.spaceship_speed == 0 return def addBaddie(self): new_baddie = Baddie( self.baddie_width, self.baddie_height, self.width, random.randint(0,(self.height-self.baddie_height)), self.baddie_color ) self.baddies.append( new_baddie ) return def draw(self,surface): rect = pygame.Rect(0,0,self.width,self.height) surface.fill((0,0,0),rect ) self.spaceship.draw(surface) for bullet in self.bullets: bullet.draw(surface) for baddie in self.baddies: baddie.draw(surface) self.drawTextLeft(surface, str("Score " + str(self.score)), (255, 255, 255), 10, 50, self.font) self.drawTextLeft(surface, str("Health " + str(self.spaceship.health)), (255, 255, 255), 10, 80, self.font) return def drawTextLeft(self, surface, text, color, x, y,font): textobj = font.render(text, False, color) textrect = textobj.get_rect() textrect.bottomleft = (x, y) surface.blit(textobj, textrect) return def drawTextRight(self, surface, text, color, x, y,font): textobj = font.render(text, False, color) textrect = textobj.get_rect() textrect.bottomright = (x, y) surface.blit(textobj, textrect) return
class SpaceshipData: def __init__(self,width,height,frame_rate): self.font = pygame.font.SysFont("Times New Roman",36) self.font2 = pygame.font.SysFont("Courier New",20) self.frame_rate = frame_rate self.text_color = (255,0,0) self.width = width self.height = height self.upper_limit = self.width - 20 self.spaceship_width = 20 self.spaceship_height = 20 self.spaceship = Spaceship(self.spaceship_width,self.spaceship_height,0,(self.height / 2) - 10, (255,240,0)) self.spaceship_speed = 15 self.bullets = [] self.bullet_width = 12 self.bullet_height = 12 self.bullet_color = (255,255,255) self.baddies = [] self.baddie_width = 20 self.baddie_height = 20 self.baddie_color = (0,201,87) self.kill = 0 self.score_color = (255, 255, 255) self.score_x = 20 self.score_y = 30 return def evolve(self, keys, newkeys, buttons, newbuttons, mouse_position): if not self.spaceship.getAlive(): return if pygame.K_a in keys: self.spaceship.moveLeft(self.spaceship_speed) if pygame.K_d in keys: self.spaceship.moveRight(self.spaceship_speed,self.upper_limit) if pygame.K_w in keys: self.spaceship.moveUp(self.spaceship_speed) if pygame.K_s in keys: self.spaceship.moveDown(self.spaceship_speed,self.height) if pygame.K_RIGHT in newkeys: self.bullets.append(self.spaceship.fire(self.bullet_width,self.bullet_height,self.bullet_color, direction = "right")) if pygame.K_LEFT in newkeys: self.bullets.append(self.spaceship.fire(self.bullet_width,self.bullet_height,self.bullet_color, direction = "left")) if pygame.K_UP in newkeys: self.bullets.append(self.spaceship.fire(self.bullet_width,self.bullet_height,self.bullet_color, direction = "down")) if pygame.K_DOWN in newkeys: self.bullets.append(self.spaceship.fire(self.bullet_width,self.bullet_height,self.bullet_color, direction = "up")) for bullet in self.bullets: bullet.moveBullet() bullet.checkBackWall(self.width) if random.randint(1, 1000/(self.kill+1)) == 1: self.addBaddie() elif random.randint(1, 1200/(self.kill+1)) == 1: self.addStrongBaddie() elif random.randint(1, 1500/(self.kill+1)) ==1: self.addStrongerBaddie() for baddie in self.baddies: baddie.tick(0,0,self.height, self.spaceship.x, self.spaceship.y) for bullet in self.bullets: if not bullet.alive: continue for baddie in self.baddies: if not baddie.alive: continue x,y,w,h = baddie.getDimensions() bullet.checkHitBaddie(x,y,w,h) if bullet.getHit(): bullet.setAlive(False) baddie.decreasehitpoints(1) self.kill += 1 bullet.hit = False for baddie in self.baddies: if not baddie.alive: continue if not self.spaceship.Living: continue x,y,w,h = baddie.getDimensions() self.spaceship.checkHitBaddie(x,y,w,h) if self.spaceship.hit == True: self.spaceship.setAlive(False) baddie.setAlive(False) print baddie.alive live_bullets = [] live_baddies = [] for bullet in self.bullets: if bullet.alive: live_bullets.append(bullet) for baddie in self.baddies: if baddie.alive: live_baddies.append(baddie) self.bullets = live_bullets self.baddies = live_baddies return def addBaddie(self): new_baddie = Baddie( self.baddie_width, self.baddie_height, self.width, random.randint(0,(self.height-self.baddie_height)), self.baddie_color ) new_baddie.getAlive() new_baddie.setHitPoints(1) self.baddies.append( new_baddie ) new_baddie = Baddie( self.baddie_width, self.baddie_height, 0, random.randint(0,(self.height-self.baddie_height)), self.baddie_color ) new_baddie.getAlive() new_baddie.setHitPoints(1) self.baddies.append( new_baddie ) new_baddie = Baddie( self.baddie_width, self.baddie_height, random.randint(0,(self.width-self.baddie_width)), 0, self.baddie_color ) new_baddie.getAlive() new_baddie.setHitPoints(1) self.baddies.append( new_baddie ) new_baddie = Baddie( self.baddie_width, self.baddie_height, random.randint(0,(self.width-self.baddie_width)), self.height, self.baddie_color ) new_baddie.getAlive() new_baddie.setHitPoints(1) self.baddies.append( new_baddie ) return def addStrongBaddie(self): new_baddie = Baddie( self.baddie_width + 5, self.baddie_height + 5, self.width, random.randint(0,(self.height-self.baddie_height)), (255,255,0) ) new_baddie.getAlive() new_baddie.setHitPoints(2) self.baddies.append( new_baddie ) new_baddie = Baddie( self.baddie_width + 5, self.baddie_height + 5, 0, random.randint(0,(self.height-self.baddie_height)), (255,255,0) ) new_baddie.getAlive() new_baddie.setHitPoints(2) self.baddies.append( new_baddie ) new_baddie = Baddie( self.baddie_width + 5, self.baddie_height + 5, random.randint(0,(self.width-self.baddie_width)), 0, (255,255,0) ) new_baddie.getAlive() new_baddie.setHitPoints(2) self.baddies.append( new_baddie ) new_baddie = Baddie( self.baddie_width + 5, self.baddie_height + 5, random.randint(0,(self.width-self.baddie_width)), self.height, (255,255,0)) new_baddie.getAlive() new_baddie.setHitPoints(2) self.baddies.append( new_baddie ) def addStrongerBaddie(self): new_baddie = Baddie( self.baddie_width + 10, self.baddie_height + 10, self.width, random.randint(0,(self.height-self.baddie_height)), (220,20,60) ) new_baddie.getAlive() new_baddie.setHitPoints(3) self.baddies.append( new_baddie ) new_baddie = Baddie( self.baddie_width + 10, self.baddie_height + 10, 0, random.randint(0,(self.height-self.baddie_height)), (220,20,60) ) new_baddie.getAlive() new_baddie.setHitPoints(3) self.baddies.append( new_baddie ) new_baddie = Baddie( self.baddie_width + 10, self.baddie_height + 10, random.randint(0,(self.width-self.baddie_width)), 0, (220,20,60) ) new_baddie.getAlive() new_baddie.setHitPoints(3) self.baddies.append( new_baddie ) new_baddie = Baddie( self.baddie_width + 10, self.baddie_height + 10, random.randint(0,(self.width-self.baddie_width)), self.height, (220,20,60)) new_baddie.getAlive() new_baddie.setHitPoints(3) self.baddies.append( new_baddie ) def draw(self,surface): rect = pygame.Rect(0,0,self.width,self.height) surface.fill((0,0,0),rect ) score_str = "Score: " + str(self.kill) self.drawTextLeft(surface, score_str, self.score_color, self.score_x, self.score_y, self.font2) self.spaceship.draw(surface) for bullet in self.bullets: bullet.draw(surface) for baddie in self.baddies: baddie.draw(surface) return def drawTextLeft(self, surface, text, color, x, y,font): textobj = font.render(text, False, color) textrect = textobj.get_rect() textrect.bottomleft = (x, y) surface.blit(textobj, textrect) return def drawTextRight(self, surface, text, color, x, y,font): textobj = font.render(text, False, color) textrect = textobj.get_rect() textrect.bottomright = (x, y) surface.blit(textobj, textrect) return
class Screen(object): def __init__(self, width=640, height=400, fps=60, stars=200): self.running = True self.score = 0 # CONSTANT self.FPS = fps self.PLAYTIME = 0.0 self.TOTAL_STARS = stars self.WIDTH = width self.HEIGHT = height # INITIALIZE SCREEN, CLOCK, FONT self.screen = pygame.display.set_mode((self.WIDTH, self.HEIGHT), pygame.DOUBLEBUF) self.background = pygame.Surface(self.screen.get_size()).convert(self.screen) self.clock = pygame.time.Clock() self.font = pygame.font.SysFont('mono', 20, bold=True) # INITIALIZE SCREEN OBJECTS self.stars = Stars(self.background, self.WIDTH, self.HEIGHT, self.TOTAL_STARS) self.asteroid = Asteroid() self.spaceship = Spaceship() self.main() def exit(self): pygame.quit() sys.exit() def fps_and_playtime_caption(self): text = "FPS: {0:.2f} Playtime: {1:.2f} SCORE: {}".format(self.clock.get_fps(), self.PLAYTIME, self.score) pygame.display.set_caption(text) def is_valid_move(self): return self.spaceship.x in range(0, self.WIDTH) and self.spaceship.y in range(0, self.HEIGHT) def main(self): while self.running: # PLAYTIME milliseconds = self.clock.tick(self.FPS) self.PLAYTIME += milliseconds / 1000.0 # MOVEMENT for event in pygame.event.get(): self.spaceship.move_route(pygame.key.get_pressed()) # DRAW SPACESHIP if self.is_valid_move: self.spaceship.draw(self.screen) # INITIALIZE BACKGROUND, DRAW STARS self.background.fill((0, 0, 0)) for star in self.stars.positions: self.stars.draw(star) # UPDATE CAPTION self.fps_and_playtime_caption() # MAKE SCREEN self.screen.blit(self.background, (0, 0)) # DRAW ASTEROIDS, PROJECTILES self.asteroid.asteroid_list.draw(self.screen) for comet in self.asteroid.asteroid_list: comet.update() self.projectile.projectile_list.draw(self.screen) for ammo in self.projectile.projectile_list: ammo.update() # COLLIDE CHECK asteroid_hit_list = pygame.sprite.spritecollide(ammo, self.asteroid.asteroid_list, True) self.score = len(asteroid_hit_list) pygame.display.update()
class SpaceshipData: def __init__(self,width,height,frame_rate): self.font = pygame.font.SysFont("Times New Roman",36) self.font2 = pygame.font.SysFont("Courier New",20) self.frame_rate = frame_rate self.text_color = (255,0,0) self.width = width self.height = height self.upper_limit = self.width/1 self.spaceship_width = 20 self.spaceship_height = 10 self.spaceship = Spaceship(self.spaceship_width,self.spaceship_height,0,(self.height / 2) - 50, (255,255,255)) self.spaceship_speed = 10 self.spaceship2_width = 20 self.spaceship2_height = 10 self.spaceship2 = Spaceship2(self.spaceship2_width,self.spaceship2_height,0,(self.height / 2) - 10, (255,255,0)) self.spaceship2_speed = 10 self.spaceship3_width = 20 self.spaceship3_height = 10 self.spaceship3 = Spaceship(self.spaceship_width,self.spaceship_height,0,(self.height / 2) - 10, (255,255,255)) self.spaceship3_speed = 10 self.spaceship4_width = 20 self.spaceship4_height = 10 self.spaceship4 = Spaceship4(self.spaceship4_width,self.spaceship4_height,0,(self.height / 2) - 10, (255,255,0)) self.spaceship4_speed = 10 self.bullets = [] self.bullet_width = 5 self.bullet_height = 10 self.bullet_color = (255,255,255) self.baddies = [] self.baddie_width = 121 self.baddie_height = 95 self.baddie_color = (255,0,0) self.baddie2_width = 121 self.baddie2_height = 95 self.baddie2_color = (255,0,0) self.baddie3_width = 121 self.baddie3_height = 95 self.baddie3_color = (255,0,0) self.kills = 0 self.score_color = (255, 255, 255) self.score_x = 10 self.score_y = 30 self.money = 0 self.gold_color = (255, 255, 255) self.gold_x = 10 self.gold_y = 60 self.Img = pygame.image.load("background.png") self.lives = 30 self.lives_color = (255, 255, 255) self.lives_x = 10 self.lives_y = 90 self.a_counter = 0 return def evolve(self, keys, newkeys, buttons, newbuttons, mouse_position, a_clicked, axis_position, left, right, down, up, a_clicked2, left2, right2, down2, up2, a_clicked3, left3, right3, down3, up3, a_clicked4, left4, right4, down4, up4): if self.lives <= 0: return self.a_counter += 1 if left: self.spaceship.moveLeft(self.spaceship_speed) if right: self.spaceship.moveRight(self.spaceship_speed,self.upper_limit) if up: self.spaceship.moveUp(self.spaceship_speed) if down: self.spaceship.moveDown(self.spaceship_speed,self.height) if a_clicked: # if self.a_counter > 0: self.bullets.append(self.spaceship.fire(self.bullet_width,self.bullet_height,self.bullet_color)) # self.a_counter = 0 if left2: self.spaceship2.moveLeft(self.spaceship2_speed) if right2: self.spaceship2.moveRight(self.spaceship2_speed,self.upper_limit) if up2: self.spaceship2.moveUp(self.spaceship2_speed) if down2: self.spaceship2.moveDown(self.spaceship2_speed,self.height) if a_clicked2: # if self.a_counter > 0: self.bullets.append(self.spaceship2.fire(self.bullet_width,self.bullet_height,self.bullet_color)) # self.a_counter = 0 if left3: self.spaceship3.moveLeft(self.spaceship3_speed) if right3: self.spaceship3.moveRight(self.spaceship3_speed,self.upper_limit) if up3: self.spaceship3.moveUp(self.spaceship3_speed) if down3: self.spaceship3.moveDown(self.spaceship3_speed,self.height) if a_clicked3: # if self.a_counter > 0: self.bullets.append(self.spaceship3.fire(self.bullet_width,self.bullet_height,self.bullet_color)) # self.a_counter = 0 if left4: self.spaceship4.moveLeft(self.spaceship4_speed) if right4: self.spaceship4.moveRight(self.spaceship4_speed,self.upper_limit) if up4: self.spaceship4.moveUp(self.spaceship4_speed) if down4: self.spaceship4.moveDown(self.spaceship4_speed,self.height) # if a_clicked4: if self.a_counter > 0: # self.bullets.append(self.spaceship4.fire(self.bullet_width,self.bullet_height,self.bullet_color)) self.a_counter = 0 if pygame.K_LEFT in keys: self.spaceship.moveLeft(self.spaceship_speed) if pygame.K_RIGHT in keys: self.spaceship.moveRight(self.spaceship_speed,self.upper_limit) if pygame.K_UP in keys: self.spaceship.moveUp(self.spaceship_speed) if pygame.K_DOWN in keys: self.spaceship.moveDown(self.spaceship_speed,self.height) if pygame.K_l in newkeys: self.bullets.append(self.spaceship.fire(self.bullet_width,self.bullet_height,self.bullet_color)) if pygame.K_a in keys: self.spaceship2.moveLeft(self.spaceship2_speed) if pygame.K_d in keys: self.spaceship2.moveRight(self.spaceship2_speed,self.upper_limit) if pygame.K_w in keys: self.spaceship2.moveUp(self.spaceship2_speed) if pygame.K_s in keys: self.spaceship2.moveDown(self.spaceship2_speed,self.height) if pygame.K_SPACE in newkeys: self.bullets.append(self.spaceship2.fire(self.bullet_width,self.bullet_height,self.bullet_color)) if pygame.K_a in keys: self.spaceship3.moveLeft(self.spaceship3_speed) if pygame.K_d in keys: self.spaceship3.moveRight(self.spaceship3_speed,self.upper_limit) if pygame.K_w in keys: self.spaceship3.moveUp(self.spaceship3_speed) if pygame.K_s in keys: self.spaceship3.moveDown(self.spaceship3_speed,self.height) if pygame.K_SPACE in newkeys: self.bullets.append(self.spaceship3.fire(self.bullet_width,self.bullet_height,self.bullet_color)) if pygame.K_a in keys: self.spaceship4.moveLeft(self.spaceship4_speed) if pygame.K_d in keys: self.spaceship4.moveRight(self.spaceship4_speed,self.upper_limit) if pygame.K_w in keys: self.spaceship4.moveUp(self.spaceship4_speed) if pygame.K_s in keys: self.spaceship4.moveDown(self.spaceship4_speed,self.height) if pygame.K_SPACE in newkeys: self.bullets.append(self.spaceship4.fire(self.bullet_width,self.bullet_height,self.bullet_color)) if self.kills < 150: if random.randint(1, self.frame_rate/9) == 1: self.addBaddie() if self.kills > 75: if random.randint(1, self.frame_rate/2) == 1: self.addBaddie2() if self.kills > 10: if random.randint(1, self.frame_rate/3) == 1: self.addBaddie() if random.randint(1, self.frame_rate/2) == 1: self.addBaddie3() for bullet in self.bullets: bullet.moveBullet() bullet.checkBackWall(self.width) for baddie in self.baddies: if not baddie.tick(0,0,self.height,self.width): self.lives -= 1 for bullet in self.bullets: if not bullet.alive: continue for baddie in self.baddies: if not baddie.alive: continue x,y,w,h = baddie.getDimensions() bullet.checkHitBaddie(x,y,w,h) if bullet.getHit(): bullet.setAlive(False) baddie.setAlive(False) bullet.hit = False self.kills = self.kills + 1 self.money = self.money + 7 live_bullets = [] live_baddies = [] for bullet in self.bullets: if bullet.alive: live_bullets.append(bullet) for baddie in self.baddies: if baddie.alive: live_baddies.append(baddie) self.bullets = live_bullets self.baddies = live_baddies return def addBaddie(self): new_baddie = Baddie( self.baddie_width, self.baddie_height, random.randint (1,self.width - self.baddie_width) , 0, self.baddie_color ) self.baddies.append( new_baddie ) def addBaddie2(self): new_baddie2 = Baddie2( self.baddie2_width, self.baddie2_height, random.randint (1,self.width - self.baddie2_width) , 0, self.baddie2_color ) self.baddies.append( new_baddie2 ) def addBaddie3(self): new_baddie3 = Baddie3( self.baddie3_width, self.baddie3_height, random.randint (1,self.width - self.baddie3_width) , 0, self.baddie3_color ) self.baddies.append( new_baddie3 ) return def draw(self,surface): surface.blit(self.Img, (0, 0)) score_str = "Dragons Killed: " + str(self.kills) self.drawTextLeft(surface, score_str, self.score_color, self.score_x, self.score_y, self.font2) gold_str = "Gold: " + str(self.money) self.drawTextLeft(surface, gold_str, self.gold_color, self.gold_x, self.gold_y, self.font2) lives_str = "lives: " + str(self.lives) self.drawTextLeft(surface, lives_str, self.lives_color, self.lives_x, self.lives_y, self.font2) self.spaceship.draw(surface) self.spaceship2.draw(surface) self.spaceship3.draw(surface) self.spaceship4.draw(surface) for bullet in self.bullets: bullet.draw(surface) for baddie in self.baddies: baddie.draw(surface) for baddie2 in self.baddies: baddie2.draw(surface) return def drawTextLeft(self, surface, text, color, x, y,font): textobj = font.render(text, False, color) textrect = textobj.get_rect() textrect.bottomleft = (x, y) surface.blit(textobj, textrect) return def drawTextRight(self, surface, text, color, x, y,font): textobj = font.render(text, False, color) textrect = textobj.get_rect() textrect.bottomright = (x, y) surface.blit(textobj, textrect) return
class SpaceshipData: def __init__(self,width,height,frame_rate): # Game Sounds pygame.mixer.init() self.player_killed = pygame.mixer.Sound("spartan_die.wav") self.player_killed.set_volume(.55) self.baddie_killed = pygame.mixer.Sound("grunt_death.wav") self.baddie_killed.set_volume(1.) self.baddie2_killed = pygame.mixer.Sound("elite_killed.wav") self.baddie2_killed.set_volume(.5) self.bullet_sound = pygame.mixer.Sound("assault_rifle.wav") self.bullet_sound.set_volume(1.) self.pelican_shoot = pygame.mixer.Sound("chain_gun.wav") self.pelican_shoot.set_volume(.75) self.battle_theme = pygame.mixer.music.load("battle_theme2.wav") pygame.mixer.music.play() # Game Images self.bg = Background("blood_gulch800x500.png", width) self.baddie_img = pygame.image.load("grunt_100x68.png") self.baddie2_img = pygame.image.load("blue_elite80x109.png") self.player_img = pygame.image.load("master_chief70x79.png") self.player_img2 = pygame.image.load("goku_90x105.png") self.font = pygame.font.SysFont("Times New Roman",36) self.font2 = pygame.font.SysFont("Courier New",20) self.frame_rate = frame_rate self.text_color = (255,0,0) self.width = width self.height = height self.upper_limit = self.width/3 self.spaceship_width = 50 #to compensate for the size of his body self.spaceship_height = 79 #he is not a rectangle self.spaceship = Spaceship(self.spaceship_width, self.spaceship_height, 0, (self.height / 2) - 10, (255,255,255), self.player_img, self.player_killed) self.spaceship.setName('Chief') print self.spaceship.getName() self.spaceship_speed = 10 self.spaceship.setHitPoints(3) self.bullets = [] self.bullet_width = 10 self.bullet_height = 5 self.bullet_color = (255,255,255) ### Delay baddies for 37 seconds ### #time.sleep(17) self.baddies = [] self.baddie_width = 100 self.baddie_height = 68 #self.baddies2 = [] self.baddie2_width = 35 self.baddie2_height = 109 # Code to change the game to DBZ themes # #if self.kills > 25: # self.bg.setImage("cell_games.png") # self.bullet_sound = pygame.mixer.Sound("ki_blast.wav") # self.bullet_img = pygame.mixer.Sound("ki_blast.png") # self.baddie_killed = pygame.mixer.Sound("Cell.wav") # self.baddie_img = pygame.image.load("Cell.png") # self.player_img = pygame.image.load("Goku.png") # self.dbz_theme = pygame.mixer.music.load("DBZ_theme.wav") # self.player_hit_points = 5 # self.baddie_hit_points = 25 # Use code for boss to shoot at random times # # # def boss_shoot(): # time.sleep(random.choice([0, 1, 2]) # Number of Player Health self.health = self.spaceship.getHitPoints() # Kill Points self.kills = 0 # Display the health self.health_color = (255,255,255) self.health_x = self.width/2 self.health_y = self.height - 30 # Display the Score self.score_color = (0,150,0) self.score_x = 20 self.score_y = 50 return def evolve(self, keys, newkeys, buttons, newbuttons, mouse_position): self.bg.update() # Update Background if pygame.K_w in keys: self.spaceship.setHitPoints(10) self.spaceship.setWidth(225) self.spaceship.setHeight(75) self.spaceship.setImage('pelican_250x99.png') self.spaceship.setName('Pelican') self.spaceship_speed = 15 self.health = self.spaceship.getHitPoints() self.bullet_sound = self.pelican_shoot self.bg.setSpeed(-20) if pygame.K_LEFT in keys: self.spaceship.moveLeft(self.spaceship_speed) if pygame.K_RIGHT in keys: self.spaceship.moveRight(self.spaceship_speed,self.upper_limit) if pygame.K_UP in keys: self.spaceship.moveUp(self.spaceship_speed) if pygame.K_DOWN in keys: self.spaceship.moveDown(self.spaceship_speed,self.height) if self.spaceship.getAlive() == True: # If space ship is alive, then # it can fire. if pygame.K_SPACE in newkeys: self.bullet_sound.play() self.bullets.append(self.spaceship.fire(self.bullet_width, self.bullet_height, self.bullet_color)) if pygame.K_q in newkeys: print "PRESSED Q" pygame.quit() return if pygame.K_r in keys: print "GAME RESTARTED" self.__init__(1024, 768, 30) return if random.randint(1, self.frame_rate/2) == 1: self.addBaddie() ## Spawn Baddie elif random.randint(1, self.frame_rate+10) == 2: ## Spawn Baddie2 self.addStrongBaddie() for bullet in self.bullets: bullet.moveBullet() bullet.checkBackWall(self.width) for baddie in self.baddies: baddie.tick(0,0,self.height) ## Checks if the baddie was hit. ## Adds to the kill count each time a baddie dies. for bullet in self.bullets: if not bullet.alive: continue for baddie in self.baddies: if not baddie.alive: continue x,y,w,h = baddie.getDimensions() bullet.checkHitBaddie(x,y,w,h) if bullet.getHit(): print "Baddie hit" bullet.setAlive(False) if self.spaceship.getName() == 'Pelican': baddie.decreaseHitPoints(10) else: baddie.decreaseHitPoints(1) bullet.hit = False if baddie.getAlive() == False: if baddie.getName() == 'Elite': self.baddie2_killed.play() print baddie.getName() elif baddie.getName() == 'Grunt': self.baddie_killed.play() print baddie.getName() self.kills += 1 print "BADDIE KILLED" # Checks if player was hit # If he dies, a pause menu is shown to the user for baddie in self.baddies: if not baddie.alive: continue if self.spaceship.getAlive: if not self.spaceship.alive: continue x,y,w,h = self.spaceship.getDimensions() baddie.checkHitPlayer(x,y,w,h) if baddie.getHit(): print "PLAYER HIT" baddie.setAlive(False) self.spaceship.decreaseHitPoints(1) self.health = self.health - 1 baddie.hit = False if self.spaceship.getName() == 'Pelican': print "Player Hit Points: %s" % (self.spaceship.getHitPoints()) if self.spaceship.getHitPoints() == 1: # When Pelican dies # Set everything back to Master Chief # # "Spawn him" print "You are almost dead." self.spaceship.setHitPoints(3) self.spaceship.setWidth(50) self.spaceship.setHeight(75) self.spaceship.setImage('master_chief70x79.png') self.spaceship.setName('Chief') self.spaceship_speed = 5 self.bullet_sound = pygame.mixer.Sound('assault_rifle.wav') self.bg.setSpeed(-1) self.health = self.spaceship.getHitPoints() if self.spaceship.getAlive() == False: print "PLAYER KILLED" self.player_killed.play() live_bullets = [] live_baddies = [] for bullet in self.bullets: if bullet.alive: live_bullets.append(bullet) for baddie in self.baddies: if baddie.alive: live_baddies.append(baddie) #elif baddie.getAlive() == False: #Every time a baddie dies self.bullets = live_bullets self.baddies = live_baddies return def addStrongBaddie(self): self.new_baddie2 = Baddie( self.baddie2_width, self.baddie2_height, self.width, random.randint(0, (self.height - self.baddie2_height)), self.baddie2_img, self.baddie2_killed ) self.new_baddie2.setName('Elite') self.new_baddie2.setHitPoints(3) self.baddies.append( self.new_baddie2 ) return def addBaddie(self): self.new_baddie = Baddie( self.baddie_width, self.baddie_height, self.width, random.randint(0, (self.height-self.baddie_height)), self.baddie_img, self.baddie_killed ) self.new_baddie.setName('Grunt') self.new_baddie.setHitPoints(2) self.baddies.append( self.new_baddie ) return def draw(self,surface): rect = pygame.Rect(0,0,self.width,self.height) surface.fill((0,0,0),rect ) self.bg.paint(surface) #Paint the Background to the screen if self.spaceship.alive: self.spaceship.draw(surface) else: dead_str = "#you are dead." restart_str = "# r for restart, q for quit." self.drawTextRight(surface, dead_str, white, (self.width/2)+75, self.height/2, self.font2) self.drawTextRight(surface, restart_str, white, (self.width/2)+150, self.height-150, self.font2) for bullet in self.bullets: bullet.draw(surface) for baddie in self.baddies: baddie.draw(surface) score_str = "#score: %s" % (str(self.kills)) self.drawTextLeft(surface, score_str, self.score_color, self.score_x, self.score_y, self.font) health_str = "#health: %s" % str(self.health) self.drawTextRight(surface, health_str, self.health_color, self.health_x, self.health_y, self.font) pelican_str = "#press 'W' for upgraded Spaceship!" self.drawTextRight(surface, pelican_str, (255,255,255), self.health_x+150, self.health_y-50, self.font2) return def drawTextLeft(self, surface, text, color, x, y, font): textobj = font.render(text, False, color) textrect = textobj.get_rect() textrect.bottomleft = (x, y) surface.blit(textobj, textrect) return def drawTextRight(self, surface, text, color, x, y, font): textobj = font.render(text, False, color) textrect = textobj.get_rect() textrect.bottomright = (x, y) surface.blit(textobj, textrect) return
class SpaceshipData: def __init__(self,width,height,frame_rate): self.font = pygame.font.SysFont("Times New Roman",36) self.font2 = pygame.font.SysFont("Courier New",20) self.frame_rate = frame_rate self.text_color = (255,0,0) self.width = width self.height = height self.upper_limit = self.width/3 self.spaceship_width = 48 self.spaceship_height = 48 self.spaceship = Spaceship(self.spaceship_width,self.spaceship_height,0,(self.height / 2) - 10, (255,255,255)) self.spaceship_speed = 5 self.bullets = [] self.bullet_width = 20 self.bullet_height = 20 self.bullet_color = (255,255,255) self.baddies = [] self.baddie_width = 48 self.baddie_height = 48 self.baddie_color = (255,0,0) self.kills = 0 self.score_color = (72,255,0) self.score_x = 10 self.score_y = 30 self.game_over_x = 300 self.game_over_y = 250 self.hit_points = 1 self.bg = Background('background.png', width) return def evolve(self, keys, newkeys, buttons, newbuttons, mouse_position): if pygame.K_w in newkeys: self.bg = Background('background.png', self.width, -15) if pygame.K_n in newkeys: self.bg = Background('background.png', self.width, -5) self.bg.update() if pygame.K_LEFT in keys: self.spaceship.moveLeft(self.spaceship_speed) if pygame.K_RIGHT in keys: self.spaceship.moveRight(self.spaceship_speed,self.upper_limit) if pygame.K_UP in keys: self.spaceship.moveUp(self.spaceship_speed) if pygame.K_DOWN in keys: self.spaceship.moveDown(self.spaceship_speed,self.height) if pygame.K_SPACE in newkeys: if self.kills >= 25: self.bullets.append(self.spaceship.fire(self.bullet_width,self.bullet_height,self.bullet_color)) self.bullets.append(self.spaceship.fire(self.bullet_width,self.bullet_height,self.bullet_color,"up")) self.bullets.append(self.spaceship.fire(self.bullet_width,self.bullet_height,self.bullet_color,"down")) else: self.bullets.append(self.spaceship.fire(self.bullet_width,self.bullet_height,self.bullet_color)) if random.randint(1, self.frame_rate/2) == 1: self.addBaddie() elif random.randint(1, self.frame_rate) == 1: self.addStrongBaddie() for bullet in self.bullets: bullet.moveBullet() bullet.checkBackWall(self.width) for baddie in self.baddies: baddie.tick(0,0,self.height) x,y,w,h = baddie.getDimensions() self.spaceship.checkHitBaddie(x,y,w,h) if self.spaceship.getHit(): self.spaceship.setAlive(False) for bullet in self.bullets: if not bullet.alive: continue for baddie in self.baddies: if not baddie.alive: continue x,y,w,h = baddie.getDimensions() bullet.checkHitBaddie(x,y,w,h) if bullet.getHit(): bullet.setAlive(False) baddie.decreaseHitPoints(1) if not baddie.alive: self.kills = self.kills + 1 bullet.hit = False live_bullets = [] live_baddies = [] for bullet in self.bullets: if bullet.alive: live_bullets.append(bullet) for baddie in self.baddies: if baddie.alive: live_baddies.append(baddie) self.bullets = live_bullets self.baddies = live_baddies return def addBaddie(self): new_baddie = Baddie( self.baddie_width, self.baddie_height, self.width, random.randint(0,(self.height-self.baddie_height)), self.baddie_color ) self.baddies.append( new_baddie ) return def addStrongBaddie(self): if self.kills %20: self.hit_points += 1 new_baddie = Baddie( self.baddie_width, self.baddie_height, self.width, random.randint(0,(self.height-self.baddie_height)), self.baddie_color,self.hit_points ) else: new_baddie = Baddie( self.baddie_width, self.baddie_height, self.width, random.randint(0,(self.height-self.baddie_height)), self.baddie_color,self.hit_points ) self.baddies.append( new_baddie ) return def draw(self,surface): rect = pygame.Rect(0,0,self.width,self.height) surface.fill((0,0,0),rect ) self.bg.paint(surface) if not self.spaceship.alive: gameover_str = "GAME OVER" self.drawTextRight(surface, gameover_str, self.score_color,self.game_over_x, self.game_over_y, self.font2) score_str = "Score: " + str(self.kills) self.drawTextLeft(surface, score_str, self.score_color, self.score_x, self.score_y, self.font2) else: self.spaceship.draw(surface) score_str = "Score: " + str(self.kills) self.drawTextLeft(surface, score_str, self.score_color, self.score_x, self.score_y, self.font2) for bullet in self.bullets: bullet.draw(surface) for baddie in self.baddies: baddie.draw(surface) return def drawTextLeft(self, surface, text, color, x, y,font): textobj = font.render(text, False, color) textrect = textobj.get_rect() textrect.bottomleft = (x, y) surface.blit(textobj, textrect) return def drawTextRight(self, surface, text, color, x, y,font): textobj = font.render(text, False, color) textrect = textobj.get_rect() textrect.bottomright = (x, y) surface.blit(textobj, textrect) return
import musicians from musicians import * from spaceship import Spaceship katy = Musician("katy", "guitar", "pop") falcon = Spaceship("falcon", "buzz aldrin", False, "Red") katy.description() falcon.desc()
class Screen(object): def __init__(self, width=640, height=400, fps=60, stars=200): self.running = True self.fps = fps self.playtime = 0.0 self.total_stars = stars pygame.init() pygame.display.set_caption("Press ESC to quit") self.width = width self.height = height self.screen = pygame.display.set_mode((self.width, self.height), pygame.DOUBLEBUF) self.background = pygame.Surface(self.screen.get_size()).convert() self.clock = pygame.time.Clock() self.font = pygame.font.SysFont('mono', 20, bold=True) self.stars = Background.generate_stars(self, stars, width, height) self.spaceship = Spaceship() self.main() def exit(self): pygame.quit() sys.exit() def fps_and_playtime_caption(self): text = "FPS: {0:.2f} Playtime: {1:.2f}".format(self.clock.get_fps(), self.playtime) pygame.display.set_caption(text) def main(self): keyboard_events = [False, False, False, False, False] while self.running: milliseconds = self.clock.tick(self.fps) self.playtime += milliseconds / 1000.0 for event in pygame.event.get(): if event.type == QUIT: self.running = False self.exit() elif event.type == KEYDOWN and event.key == K_ESCAPE: self.running = False self.exit() keyboard_event_controller(pygame.key.get_pressed(), keyboard_events) self.fps_and_playtime_caption() self.background.fill((0, 0, 0)) Background.draw_stars(self, self.stars, self.background, self.width, self.height) self.screen.blit(self.background, (0, 0)) self.spaceship.move(keyboard_events) self.spaceship.draw(self.screen) self.spaceship.shoot(keyboard_events) for projectile in self.spaceship.projectiles: projectile.update() projectile.draw(self.screen) for laser in self.spaceship.lasers: laser.draw(self.screen) pygame.display.update()
def __init__(self,width,height,frame_rate): self.font = pygame.font.SysFont("Times New Roman",36) self.font2 = pygame.font.SysFont("Courier New",20) self.font3 = pygame.font.SysFont("monospace",10) self.font4 = pygame.font.SysFont("Times New Roman",72) self.frame_rate = frame_rate self.text_color = (255,0,0) self.width = width self.height = height self.upper_limit = self.width/2 self.buttonon = False self.spaceship_width = 20 self.spaceship_height = 10 self.spaceship_health = 300 self.spaceship_speed = 7 self.gamestate = CONFIG.GAME_STATE self.ministate = CONFIG.MINI_STATE self.spaceship = Spaceship(self.spaceship_width,self.spaceship_height,0,(self.height / 2) - 10, (0,255,255),self.spaceship_health) self.spaceship_y = self.spaceship.spaceshipPosition()[1] self.bullets = [] self.bullet_width = 15 self.bullet_height = 5 self.bullet_color = (255,255,255) self.hbullets = [] self.hbullet_width = 5 self.hbullet_height = 5 self.hbullet_color = (255,255,255) self.abullets = [] self.abullet_width = 20 self.abullet_height = 20 self.abullet_color = (255,255,255) self.bombs = 3 self.bomb = False self.boom =False self.bomb_radius = 20 self.ba = 1 self.stars = [] self.star_width = 1 self.star_height = 1 self.star_direction = 'normal' self.star_color = (255,255,255) self.lasers = [] self.laser_width =100 self.laser_height = 5 self.laser_color = (255,55,55) self.bups = [] self.bup_width = 8 self.bup_height = 8 self.bup_color = (144,144,144) self.mups = [] self.mup_width = 8 self.mup_height = 8 self.mup_color = (144,144,144) self.missiles = [] self.misslen = 0 self.missile_width = 30 self.missile_height = 10 self.missile_color = (55,144,144) self.badBullets = [] self.badBullet_width = 20 self.badBullet_height = 20 self.badBullet_color = (0,255,255) self.badLasers = [] self.badLaser_width = 100 self.badLaser_height = 30 self.badLaser_color = (0,255,255) self.baddies = [] self.baddie_width = 40 self.baddie_height = 40 self.baddie_color = (0,155,0) self.baddie_id = 0 self.asteroids = [] self.asteroid_width = random.randint(20, 60) self.asteroid_height = self.asteroid_width self.asteroid_color=(55,55,0) self.boss = [] self.boss1_width = 400 self.boss1_height = 600 self.boss1_color = (55,0,0) self.turret1_width = 60 self.turret1_height = 20 self.turret1_color = (155,50,50) self.turrets = 0 self.particles = [] * 100 self.particle_width = 20 self.particle_height = 20 self.projectiles = [] self.powerups = [] self.particle_color=(255,255,255) self.particle_speed = .3 self.f = ['up', 'down','left','right','upright','upleft','downright','downleft'] self.c = [ORANGE,RED,DRED,BRED,ORANGE,DORANGE,YELLOW ] self.score = 0 self.wave1 = True self.wave2 = False self.wave3 = False self.wave4 = False self.wave5 = False self.wave6 = False self.wave7 = False self.wave8 = False self.wave9 = False self.wave10 = False self.w1 = [1,1,2,2,1,2,1,1,'p','p','p',4,'p','p',99,0] self.w2 = [1,1,2,2,1,2,1,1,'p','p','p',4,'p','p',99,0] self.w3 = [1,1,2,2,1,2,1,1,'p','p','p',4,'p','p',99,0] self.w4 = [1,1,2,2,1,2,1,1,'p','p','p',4,'p','p',99,0] self.w5 = [1,1,2,2,1,2,1,1,'p','p','p',4,'p','p',99,0] self.w6 = [1,1,2,2,1,2,1,1,'p','p','p',4,'p','p',99,0] self.w7 = [1,1,2,2,1,2,1,1,'p','p','p',4,'p','p',99,0] self.w8 = [1,1,2,2,1,2,1,1,'p','p','p',4,'p','p',99,0] self.w9 = [1,1,2,2,1,2,1,1,'p','p','p',4,'p','p',99,0] self.w10 = [1,1,2,2,1,2,1,1,'p','p','p',4,'p','p',99,0] self.endGame = False self.winGame = False self.delay = 0 self.shootDelay = 0 self.laserDelay = 0 self.laser_on = False self.badLaserDelay = 0 self.a = -1 self.ang = 9 self.angby = .1 self.invinsiblen = 0 baddie_list = pygame.sprite.Group all_sprite_list = pygame.sprite.Group self.e = 0 self.e_t = 0 self.e_b = 0 self.exploding = False self.startoggle = 3 self.loadingn = 0 self.paused = False self.millimax = 0 self.fragmentgroup = pygame.sprite.Group() Fragment.groups = self.fragmentgroup return