def __init__(self, screen, music_list, background_image, bounds, title, menu_dictionary, start_selection=0): self.screen = screen self.bounds = bounds self.menu_dictionary = menu_dictionary self.title = title self.music_list = music_list self.background_image = background_image self.cursor = Cursor() pygame.mouse.set_visible(False) self.menu_group = pygame.sprite.Group() self.menu_tooltip_group = pygame.sprite.Group() self.cursor_group = pygame.sprite.Group() self.menu_selection_pointer = [] self.menu_tooltip_pointer = [] self.current_selection = start_selection self.timer = pygame.time.Clock() self.menu_beep_sound = utility.load_sound('menuBeep') self.menu_forward_sound = utility.load_sound('menuForward') self.menu_back_sound = utility.load_sound('menuBack') index = 0 menu_title = text.Text(FONT_PATH, title[1], FONT_COLOR, title[0]) menu_title.position = vector.Vector2d(title[2], title[3]) menu_title.set_alignment(CENTER_MIDDLE) self.menu_group.add(menu_title) for option in menu_dictionary: menu_selection = text.Text(FONT_PATH, 32, FONT_INACTIVE_COLOR, menu_dictionary[option][0], -1, index) menu_selection.set_alignment(CENTER_MIDDLE) menu_selection.position = vector.Vector2d( (((self.bounds[RIGHT] - self.bounds[LEFT]) / 2) + self.bounds[LEFT], ((self.bounds[BOTTOM] - self.bounds[TOP]) / (len(self.menu_dictionary) + 1) * (index + 1)) + self.bounds[TOP])) self.menu_group.add(menu_selection) self.menu_selection_pointer.append(menu_selection) menu_tooltip = text.Text(FONT_PATH, 32, FONT_COLOR, menu_dictionary[option][1]) menu_tooltip.set_alignment(BOTTOM_MIDDLE) menu_tooltip.position = vector.Vector2d( ((SCREEN_WIDTH / 2), SCREEN_HEIGHT)) self.menu_tooltip_group.add(menu_tooltip) self.menu_tooltip_pointer.append(menu_tooltip) index += 1 self.cursor_group.add(self.cursor)
def set_up(self): #set title title = self.title self.menu_title = text.Text(title[TEXT_FONT], title[TEXT_SIZE], title[TEXT_COLOR], title[TEXT_DETIALS][TEXT_TEXT]) self.menu_title.position = vector.objVector(title[TEXT_DETIALS][TEXT_VECTOR]) self.menu_title.alignment = CENTER_MIDDLE #set options if self.option_list: for opt in self.option_list[TEXT_DETIALS]: o = option.Option(self.option_list[TEXT_FONT], self.option_list[TEXT_SIZE], self.option_list[TEXT_COLOR], opt[OPT_TEXT], opt[OPT_EVENT]) o.alignment = self.alignment o.position = vector.objVector(opt[OPT_VECTOR]) self.option_group.add(o) #pictures: if self.image_list: for i in self.image_list: im = image.Image(i[IMAGE_NAME], i[IMAGE_SCALE], i[IMAGE_ROTATION], i[IMAGE_DIM]) im.position = vector.objVector(i[IMAGE_POSITION]) self.image_group.add(im)
def boss_text(self): utility.fade_music() utility.play_music(self.boss_fight_music, True) # Display boss text display_stage = text.Text(FONT_PATH, 64, FONT_COLOR, 'Boss Fight!', 90) display_stage.position = vector.Vector2d( (SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2)) display_stage.set_alignment(CENTER_MIDDLE) self.text_group.add(display_stage)
def give_bonus(self): increment_bonus = self.player.lives * 50 if self.bonus == -1: self.boss_fight = False self.bonus = 0 self.bonus_text = text.Text(FONT_PATH, 64, FONT_COLOR, 'Bonus Points!') self.bonus_text.position = vector.Vector2d( (SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 - 50)) self.bonus_text.set_alignment(CENTER_MIDDLE) self.text_group.add(self.bonus_text) self.bonus_amount = text.Text(FONT_PATH, 48, FONT_COLOR) self.bonus_amount.position = vector.Vector2d( (SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 + 50)) self.bonus_amount.set_alignment(CENTER_MIDDLE) self.text_group.add(self.bonus_amount) if self.bonus < self.player.lives * 5000 - increment_bonus: self.bonus += increment_bonus self.bonus_amount.set_text(self.bonus) else: self.bonus_amount.set_text(self.player.lives * 5000) if self.level < MAX_LEVEL: self.bonus_text.set_timer(FRAMES_PER_SECOND) self.bonus_amount.set_timer(FRAMES_PER_SECOND) self.bonus = -1 self.after_bonus_pause = 1.1 * FRAMES_PER_SECOND if self.level < MAX_LEVEL: self.level += 1 self.boss_fight = False utility.fade_music() utility.play_music(self.music, True) utility.play_sound(self.bonus_tally_sound, BAAKE_CHANNEL) self.player.increment_score_no_text(increment_bonus) self.pause_spawning = 1.5 * FRAMES_PER_SECOND
def load_level(self): if self.done: return utility.fade_music() utility.play_music(self.music, True) self.stage = 0 self.pause_spawning = 3 * FRAMES_PER_SECOND self.player.bullet_bonus = 0 self.player.reflect_bonus = 0 self.powerup_group.empty() self.enemy_group.empty() self.effects_group.empty() # Display Level text display_name = text.Text(FONT_PATH, 64, FONT_COLOR, self.world_name, 90) display_name.set_alignment(CENTER_MIDDLE) display_name.position = vector.Vector2d( (SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2)) self.group_list[TEXT_GROUP].add(display_name) display_level = text.Text(FONT_PATH, 32, FONT_COLOR, 'Level ' + str(self.level + 1), 90) display_level.position = vector.Vector2d( (SCREEN_WIDTH / 2, SCREEN_HEIGHT * (2.0 / 3.0))) display_level.set_alignment(CENTER_MIDDLE) self.group_list[TEXT_GROUP].add(display_level) # Reset all information for the new level self.enemy_list = [] self.load_stage() utility.play_sound(self.get_ready_sound, OW_CHANNEL) temp_image = text.TextSurface(FONT_PATH, 36, FONT_COLOR, 'Get Ready...').image help_bubble = infobubble.InfoBubble(temp_image, self.player, 2 * FRAMES_PER_SECOND) help_bubble.offset = vector.Vector2d(0.0, -100.0) self.effects_group.add(help_bubble)
def increment_score(self, value, textPosition, text_group): if self.combo_bonus and value <= 250: self.combo_bonus += int(.2 * FRAMES_PER_SECOND) self.combo_kills += 1 temp_image = text.Text(FONT_PATH, 30, FONT_COLOR, 'x' + str(self.combo_kills) + '!').image help_bubble = infobubble.InfoBubble(temp_image, self, 0.5 * FRAMES_PER_SECOND) help_bubble.offset = vector.Vector2d(0.0, -100.0) self.bullet_group.add(help_bubble) if self.point_bonus: value *= 2 temp_text = text.Text(FONT_PATH, 36, FONT_COLOR, str(value), 15) temp_text.set_alignment(CENTER_MIDDLE) temp_text.position = vector.Vector2d(textPosition) text_group.add(temp_text) self.score += value self.score_board.set_text(self.score) if self.score >= self.next_bonus: utility.play_sound(self.extraLifeSound, OW_CHANNEL) temp_image = text.TextSurface(FONT_PATH, 30, FONT_COLOR, 'Extra Life!').image help_bubble = infobubble.InfoBubble(temp_image, self, 1.5 * FRAMES_PER_SECOND) help_bubble.offset = vector.Vector2d(0.0, -100.0) text_group.add(help_bubble) self.lives += 1 self.life_board.set_text('x' + str(self.lives)) self.next_bonus += 50000
def die(self): if self.object_collided_with.actor_type == ACTOR_PLAYER: self.object_collided_with.combo_bonus += 5 * FRAMES_PER_SECOND temp_image = text.Text(FONT_PATH, 30, FONT_COLOR, 'Combo Time!', 1).image help_bubble = infobubble.InfoBubble(temp_image, self.object_collided_with, 1.5 * FRAMES_PER_SECOND) help_bubble.offset = vector.Vector2d(0.0, -100.0) self.text_group.add(help_bubble) self.active = False self.kill() del self
def load_stage(self): # Get player's current score self.defeat_stage = DEFEAT_STAGE # Display stage text if self.stage != 0: display_stage = text.Text(FONT_PATH, 32, FONT_COLOR, 'Stage ' + str(self.stage + 1), 90) display_stage.position = vector.Vector2d(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2) display_stage.set_alignment(CENTER_MIDDLE) self.group_list[TEXT_GROUP].add(display_stage) # Enemies spawned here will appear during a level's warm up for enemy in self.level_list[self.level]: if enemy[STAGE_SPAWNED] == self.stage: while enemy[DEFAULT_SPAWN]: enemy[DEFAULT_SPAWN] -= 1 self.create_actor(enemy[ACTOR_TYPE]) if enemy[STAGE_SPAWNED] == self.stage: # Time until spawn, actor type, spawn rate self.enemy_list.append( [0, enemy[ACTOR_TYPE], enemy[SPAWN_RATE]])
pygame.init() utility.read_settings() if settings_list[SETTING_FULLSCREEN]: screen = utility.set_fullscreen() else: screen = utility.set_fullscreen(False) pygame.display.set_icon(utility.load_image('icon')) pygame.display.set_caption('Trouble In CloudLand v1.1') screen.fill((0, 0, 0)) tempText = text.Text(FONT_PATH, 36, (255, 255, 255)) tempText.set_text('Loading...') tempText.position = vector.Vector2d( (SCREEN_WIDTH / 2) - (tempText.image.get_width() / 2), (SCREEN_HEIGHT / 2) - (tempText.image.get_height() / 2)) tempText.update() tempText.draw(screen) pygame.display.flip() try: pygame.mixer.set_reserved(MUSIC_CHANNEL) pygame.mixer.Channel(MUSIC_CHANNEL).set_volume(1) pygame.mixer.set_reserved(PLAYER_CHANNEL) pygame.mixer.Channel(PLAYER_CHANNEL).set_volume(1)
def roll_credits(self): credit_group = pygame.sprite.Group() # Create Text Labels title_credit = text.Text(FONT_PATH, 48, FONT_COLOR, 'Credits') title_credit.set_position((SCREEN_WIDTH / 2, SCREEN_HEIGHT)) big_jony = text.Text(FONT_PATH, 36, FONT_COLOR, 'Jony Fries') big_jony.set_position((SCREEN_WIDTH / 2, SCREEN_HEIGHT + 100)) jony_credit0 = text.Text(FONT_PATH, 24, FONT_COLOR, 'Game Programming') jony_credit0.set_position((SCREEN_WIDTH / 2, SCREEN_HEIGHT + 150)) jony_credit1 = text.Text(FONT_PATH, 24, FONT_COLOR, 'Sound Design') jony_credit1.set_position((SCREEN_WIDTH / 2, SCREEN_HEIGHT + 200)) jony_credit2 = text.Text(FONT_PATH, 24, FONT_COLOR, 'Voice Acting') jony_credit2.set_position((SCREEN_WIDTH / 2, SCREEN_HEIGHT + 250)) big_josh = text.Text(FONT_PATH, 36, FONT_COLOR, 'Joshua Skelton') big_josh.set_position((SCREEN_WIDTH / 2, SCREEN_HEIGHT + 350)) josh_credit0 = text.Text(FONT_PATH, 24, FONT_COLOR, 'Game Programming') josh_credit0.set_position((SCREEN_WIDTH / 2, SCREEN_HEIGHT + 400)) josh_credit1 = text.Text(FONT_PATH, 24, FONT_COLOR, ' Graphic Design') josh_credit1.set_position((SCREEN_WIDTH / 2, SCREEN_HEIGHT + 450)) big_special = text.Text(FONT_PATH, 36, FONT_COLOR, 'Special Thanks To:') big_special.set_position((SCREEN_WIDTH / 2, SCREEN_HEIGHT + 550)) special_credit0 = text.Text(FONT_PATH, 24, FONT_COLOR, 'Python Software Foundation') special_credit0.set_position((SCREEN_WIDTH / 2, SCREEN_HEIGHT + 600)) special_credit1 = text.Text(FONT_PATH, 24, FONT_COLOR, 'PyGame') special_credit1.set_position((SCREEN_WIDTH / 2, SCREEN_HEIGHT + 650)) special_credit2 = text.Text(FONT_PATH, 24, FONT_COLOR, 'ShyFonts Type Foundry') special_credit2.set_position((SCREEN_WIDTH / 2, SCREEN_HEIGHT + 700)) thank_you = text.Text(FONT_PATH, 64, FONT_COLOR, 'Thank You For Playing!') thank_you.set_position((SCREEN_WIDTH / 2, SCREEN_HEIGHT + 800)) # Add Labels to Group credit_group.add(title_credit) credit_group.add(big_jony) credit_group.add(jony_credit0) credit_group.add(jony_credit1) credit_group.add(jony_credit2) credit_group.add(big_josh) credit_group.add(josh_credit0) credit_group.add(josh_credit1) credit_group.add(big_special) credit_group.add(special_credit0) credit_group.add(special_credit1) credit_group.add(special_credit2) credit_group.add(thank_you) timer = 5 * FRAMES_PER_SECOND for credit in credit_group: credit.set_alignment(CENTER_MIDDLE) while self.rolling_credits: utility.play_music(self.music_list) for credit in credit_group: credit_position = credit.get_position() credit.set_position((credit_position[0], credit_position[1] + self.scroll_rate)) credit_group.update() self.new_scene.draw(self.screen) credit_group.draw(self.screen) pygame.display.flip() self.handle_events() if special_credit2.get_position()[1] < 0: if self.finished: self.rolling_credits = False if thank_you.get_position()[1] < (SCREEN_HEIGHT / 2): thank_you.set_position((SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2))
def __init__(self, screen, world_to_start, music_list): self.screen = screen pygame.mouse.set_visible(False) self.done = False self.world_done = False self.high_score = 0 self.bullet_group = pygame.sprite.Group() self.player_group = pygame.sprite.Group() self.powerup_group = pygame.sprite.Group() self.boss_group = pygame.sprite.Group() self.enemy_group = pygame.sprite.Group() self.text_group = pygame.sprite.Group() self.effects_group = pygame.sprite.Group() self.mouse_last_move = MOUSE_DEFAULT_POSITION self.group_list = [ self.powerup_group, self.enemy_group, self.boss_group, self.text_group, self.effects_group ] self.score_board = text.Text(FONT_PATH, 36, FONT_COLOR) self.temp_life_board = text.Text(FONT_PATH, 36, FONT_COLOR) self.temp_life_board.position = vector.Vector2d(48, 40) self.life_board = self.temp_life_board self.life_icon = icon.Icon('life') self.player = player.Player(self.bullet_group, self.effects_group, self.life_board, self.score_board) self.player_group.add(self.player) self.text_group.add(self.score_board) self.text_group.add(self.temp_life_board) self.text_group.add(self.life_icon) self.music_list = music_list self.timer = pygame.time.Clock() # Get rid of the first mouse delta pygame.mouse.get_rel() world1_level0 = [[0, ACTOR_MOONO, 45, 0], [1, ACTOR_MOONO, 120, 0], [2, ACTOR_MOONO, 240, 0], [3, ACTOR_BAAKE, -1, 1], [4, ACTOR_BOSS_TUT, -1, 1], [4, ACTOR_MOONO, 35, 0]] world1_level1 = [[0, ACTOR_MOONO, 40, 0], [1, ACTOR_MOONO, 85, 0], [2, ACTOR_MOONO, 110, 0], [3, ACTOR_BAAKE, -1, 2], [4, ACTOR_BOSS_TUT, -1, 1], [4, ACTOR_MOONO, 30, 0]] world1_level2 = [[0, ACTOR_MOONO, 30, 0], [1, ACTOR_BAAKE, -1, 1], [0, ACTOR_MOONO, 70, 0], [2, ACTOR_BAAKE, -1, 1], [0, ACTOR_MOONO, 130, 0], [3, ACTOR_BAAKE, -1, 1], [0, ACTOR_MOONO, 300, 0], [4, ACTOR_BOSS_TUT, -1, 1], [4, ACTOR_MOONO, 25, 0]] world1_level3 = [[0, ACTOR_MOONO, 25, 0], [1, ACTOR_BAAKE, -1, 1], [1, ACTOR_MOONO, 50, 0], [2, ACTOR_BAAKE, -1, 2], [2, ACTOR_MOONO, 110, 0], [3, ACTOR_BAAKE, -1, 2], [3, ACTOR_MOONO, 210, 0], [4, ACTOR_BOSS_TUT, -1, 1], [4, ACTOR_MOONO, 20, 0]] world2_level0 = [[0, ACTOR_MOONO, 45, 0], [0, ACTOR_HAOYA, 65, 0], [1, ACTOR_BAAKE, -1, 1], [1, ACTOR_MOONO, 70, 0], [2, ACTOR_HAOYA, 75, 0], [3, ACTOR_MOONO, 85, 0], [4, ACTOR_BAAKE_BOSS, -1, 1], [4, ACTOR_HAOYA, 30, 0]] world2_level1 = [[0, ACTOR_BAAKE, -1, 2], [0, ACTOR_BATTO, 150, 0], [0, ACTOR_MOONO, 55, 0], [1, ACTOR_HAOYA, 60, 0], [2, ACTOR_MOONO, 100, 0], [3, ACTOR_BAAKE, -1, 1], [3, ACTOR_BATTO, 280, 0], [4, ACTOR_BAAKE_BOSS, -1, 1], [4, ACTOR_BATTO, 70, 0]] world2_level2 = [[0, ACTOR_ROKUBI, 60, 0], [0, ACTOR_MOONO, 50, 0], [0, ACTOR_BAAKE, -1, 2], [1, ACTOR_BAAKE, -1, 1], [1, ACTOR_BATTO, 160, 0], [2, ACTOR_HAOYA, 60, 0], [3, ACTOR_MOONO, 80, 0], [4, ACTOR_BAAKE_BOSS, -1, 1], [4, ACTOR_ROKUBI, 30, 0]] world2_level3 = [[0, ACTOR_HAOYA, 60, 0], [0, ACTOR_BATTO, 170, 0], [0, ACTOR_ROKUBI, 75, 0], [0, ACTOR_BAAKE, -1, 1], [1, ACTOR_MOONO, 70, 0], [1, ACTOR_BAAKE, -1, 1], [2, ACTOR_BAAKE, -1, 1], [2, ACTOR_ROKUBI, 180, 1], [3, ACTOR_MOONO, 200, 0], [4, ACTOR_BAAKE_BOSS, -1, 1], [4, ACTOR_HAOYA, 100, 0], [4, ACTOR_BATTO, 240, 0], [4, ACTOR_ROKUBI, 90, 0], [4, ACTOR_BAAKE, -1, 1]] world3_level0 = [[0, ACTOR_HAKTA, 35, 0], [0, ACTOR_HAOYA, 65, 0], [1, ACTOR_BOKKO, -1, 1], [2, ACTOR_BOKKO, -1, 1], [2, ACTOR_HAKTA, 75, 0], [3, ACTOR_BOKKO, -1, 1], [4, ACTOR_MOONO_BOSS, -1, 1], [4, ACTOR_HAKTA, 30, 0]] world3_level1 = [[0, ACTOR_RAAYU, 45, 0], [0, ACTOR_HAKTA, 50, 0], [1, ACTOR_BOKKO, -1, 1], [2, ACTOR_RAAYU, 60, 0], [3, ACTOR_BOKKO, -1, 1], [3, ACTOR_ROKUBI, 80, 0], [4, ACTOR_MOONO_BOSS, -1, 1], [4, ACTOR_RAAYU, 25, 0]] world3_level2 = [[0, ACTOR_PAAJO, 95, 0], [0, ACTOR_HAKTA, 40, 0], [1, ACTOR_BOKKO, -1, 2], [2, ACTOR_RAAYU, 80, 0], [3, ACTOR_BOKKO, -1, 1], [4, ACTOR_MOONO_BOSS, -1, 1], [4, ACTOR_PAAJO, 70, 0]] world3_level3 = [[0, ACTOR_HAKTA, 55, 0], [0, ACTOR_RAAYU, 75, 0], [0, ACTOR_PAAJO, 160, 0], [1, ACTOR_BOKKO, -1, 2], [1, ACTOR_ROKUBI, 50, 0], [2, ACTOR_HAOYA, 120, 0], [3, ACTOR_BOKKO, -1, 1], [4, ACTOR_MOONO_BOSS, -1, 1], [4, ACTOR_HAKTA, 60, 0], [4, ACTOR_RAAYU, 50, 0], [4, ACTOR_PAAJO, 110, 0], [4, ACTOR_BOKKO, -1, 1]] tutorial_world = ['Tutorial', self.player, self.group_list] temp_world_1 = [ 'Cloudopolis', self.player, self.group_list, [world1_level0, world1_level1, world1_level2, world1_level3] ] temp_world_2 = [ 'Nightmaria', self.player, self.group_list, [world2_level0, world2_level1, world2_level2, world2_level3] ] temp_world_3 = [ 'Opulent Dream', self.player, self.group_list, [world3_level0, world3_level1, world3_level2, world3_level3] ] self.world_list = [ tutorial_world, temp_world_1, temp_world_2, temp_world_3 ] self.world_number = world_to_start if self.world_number == 0: self.current_world = tutorial.Tutorial( self.world_list[self.world_number]) else: self.current_world = world.World( self.world_list[self.world_number], self.music_list[self.world_number]) self.current_world.load() if self.world_number == 0: self.new_scene = scene.TutorialScene() self.player.lives = 99 self.life_board.set_text('x' + str(self.player.lives)) elif self.world_number == 1: self.new_scene = scene.ForestScene() elif self.world_number == 2: self.new_scene = scene.RockyScene() elif self.world_number == 3: self.new_scene = scene.PinkScene()