def tower_costs_display(): """Draws a display of tower costs""" # Font font = pygame.font.SysFont('Comic Sans MS', 16, bold=False) # Backdrop pygame.draw.rect(gameDisplay, black, (275, display_height - 110, 175, 100)) # Text helpers.blit_text(gameDisplay, tower_costs, (282, display_height - 106), font, color=white)
def intro_loop(): """First loop seen, explains game story with links to other loops Note: Texts stored in gameText.py """ play_button = generalClass.Button( (450, display_height - 250), message="Play", action=game_loop, font_size=40, width=300, height=60) quit_button = generalClass.Button( (450, display_height - 180), message="Quit", action=sys.exit, font_size=40, width=300, height=60, color1=red, color2=bright_red) tower_info_button = generalClass.Button( (100, display_height - 320), message="Tower Types", action=tower_info_loop, font_size=40, width=300, height=60, color1=teal, color2=bright_teal) enemy_info_button = generalClass.Button( (100, display_height - 250), message="Enemy Types", action=enemy_info_loop, font_size=40, width=300, height=60, color1=yellow, color2=bright_yellow) settings_button = generalClass.Button( (100, display_height - 180), message="Difficulty", action=settings_loop, font_size=40, width=300, height=60, color1=orange, color2=bright_orange) font = pygame.font.SysFont('Comic Sans MS', 20, bold=True) title_font = pygame.font.SysFont('Comic Sans MS', 72, bold=True) while True: # Activate quit button for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() # Draw background gameDisplay.blit(backgroundImage.image, backgroundImage.rect) # Draw title and intro text helpers.blit_text(gameDisplay, title, (100, 25), title_font, margin=50) helpers.blit_text(gameDisplay, intro_text, (100, 150), font, margin=100) # Draw buttons play_button.draw() quit_button.draw() enemy_info_button.draw() tower_info_button.draw() settings_button.draw() # Update game display pygame.display.update() clock.tick(30)
def settings_loop(): """Allow user to adjust difficulty settings with buttons and explanations Note: Texts located in gameText.py """ # Set buttons for difficulty selection and return to into_loop return_button = generalClass.Button( (50, 50), message="Return", action=intro_loop, font_size=40, width=200, height=60, color1=orange, color2=bright_orange) easy_button = generalClass.Button( (50, 200), message="Easy", action=easy_settings, font_size=40, width=200, height=60, color1=green, color2=bright_green, linked=True) medium_button = generalClass.Button( (50, 285), message="Medium", action=medium_settings, font_size=40, width=200, height=60, color1=yellow, color2=bright_yellow, linked=True) hard_button = generalClass.Button( (50, 370), message="Hard", action=hard_settings, font_size=40, width=200, height=60, color1=red, color2=bright_red, linked=True) # Set font for difficulty explanations font = pygame.font.SysFont('Comic Sans MS', 24, bold=True) while True: # Activate quit button for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() # Draw background gameDisplay.blit(backgroundImage.image, backgroundImage.rect) # Draw setting descriptions helpers.blit_text(gameDisplay, easy_text, (275, 190), font, margin=-50) helpers.blit_text(gameDisplay, medium_text, (275, 275), font, margin=50) helpers.blit_text(gameDisplay, hard_text, (275, 360), font, margin=50) # Draw buttons return_button.draw() easy_button.draw(medium_button, hard_button) medium_button.draw(easy_button, hard_button) hard_button.draw(easy_button, medium_button) # Update game display pygame.display.update() clock.tick(30)
def tower_info_loop(): """Shows and explains towers with buttons to navigate Note: Texts located in gameText.py """ # Set buttons return_button = generalClass.Button( (50, 50), message="Return", action=intro_loop, font_size=40, width=200, height=60, color1=orange, color2=bright_orange) previous_button = generalClass.Button( (50, display_height - 100), message="Previous", action="backward", font_size=40, width=200, height=60, color1=red, color2=bright_red) next_button = generalClass.Button( (600, display_height - 100), message="Next", action="forward", font_size=40, width=200, height=60, color1=green, color2=bright_green) # Set font font = pygame.font.SysFont('Comic Sans MS', 18, bold=True) # Set towers basic = towerClass.BasicTower((160, 400), destroy=False) ice1 = towerClass.IceTower1((155, 250), destroy=False) ice2 = towerClass.IceTower2((155, 530), destroy=False) fire1 = towerClass.FireTower1((155, 250), destroy=False) fire2 = towerClass.FireTower2((155, 530), destroy=False) poison1 = towerClass.PoisonTower1((155, 250), destroy=False) poison2 = towerClass.PoisonTower2((155, 530), destroy=False) dark1 = towerClass.DarkTower1((155, 250), destroy=False) dark2 = towerClass.DarkTower2((155, 530), destroy=False) # Define index for navigating pages info_index = 0 while True: # Activate quit button for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() # Draw background gameDisplay.blit(backgroundImage.image, backgroundImage.rect) pygame.draw.rect(gameDisplay, white, (100, 125, 650, 525)) # Draw buttons return_button.draw() next_tower = next_button.draw() previous_tower = previous_button.draw() # Define page navigation with index if next_tower: info_index += 1 if previous_tower: info_index -= 1 if info_index > 4: info_index = 0 if info_index < 0: info_index = 4 # Draw towers and tower info, pages indicated by index if info_index == 0: basic.draw() helpers.blit_text(gameDisplay, basic_tower_text, (225, 300), font, margin=125) if info_index == 1: ice1.draw() ice2.draw() helpers.blit_text(gameDisplay, ice1_text, (225, 135), font, margin=125) helpers.blit_text(gameDisplay, ice2_text, (225, 400), font, margin=125) pygame.draw.rect(gameDisplay, black, (150, 385, 550, 5)) if info_index == 2: fire1.draw() fire2.draw() helpers.blit_text(gameDisplay, fire1_text, (225, 135), font, margin=125) helpers.blit_text(gameDisplay, fire2_text, (225, 400), font, margin=125) pygame.draw.rect(gameDisplay, black, (150, 385, 550, 5)) if info_index == 3: poison1.draw() poison2.draw() helpers.blit_text(gameDisplay, poison1_text, (225, 135), font, margin=125) helpers.blit_text(gameDisplay, poison2_text, (225, 400), font, margin=125) pygame.draw.rect(gameDisplay, black, (150, 385, 550, 5)) if info_index == 4: dark1.draw() dark2.draw() helpers.blit_text(gameDisplay, dark1_text, (225, 135), font, margin=125) helpers.blit_text(gameDisplay, dark2_text, (225, 400), font, margin=125) pygame.draw.rect(gameDisplay, black, (150, 385, 550, 5)) # Update game display pygame.display.update() clock.tick(30)
def enemy_info_loop(): """Show and explain enemies with buttons to navigate Note: Texts located in gameText.py """ # Set buttons for page navigation return_button = generalClass.Button( (50, 50), message="Return", action=intro_loop, font_size=40, width=200, height=60, color1=orange, color2=bright_orange) previous_button = generalClass.Button( (50, display_height - 100), message="Previous", action="backward", font_size=40, width=200, height=60, color1=red, color2=bright_red) next_button = generalClass.Button( (600, display_height - 100), message="Next", action="forward", font_size=40, width=200, height=60, color1=green, color2=bright_green) # Set font font = pygame.font.SysFont('Comic Sans MS', 18, bold=True) # Set enemies, indicating stationary=True and destroy=False spider = enemies.Spider((180, 250), (190, 250), True, False) lizard = enemies.Lizard((180, 530), (190, 530), True, False) wolf = enemies.Wolf((180, 250), (190, 250), True, False) turtle = enemies.Turtle((180, 530), (190, 530), True, False) orc = enemies.Orc((180, 250), (190, 250), True, False) dragon = enemies.Dragon((180, 530), (190, 530), True, False) # Define index for page navigation info_index = 0 while True: # Activate quit button for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() # Draw background gameDisplay.blit(backgroundImage.image, backgroundImage.rect) pygame.draw.rect(gameDisplay, white, (100, 125, 650, 525)) # Draw buttons return_button.draw() next_enemy = next_button.draw() previous_enemy = previous_button.draw() # Define page navigation with index if next_enemy: info_index += 1 if previous_enemy: info_index -= 1 if info_index > 2: info_index = 0 if info_index < 0: info_index = 2 # Draw enemies and enemy info, pages indicated by index if info_index == 0: spider.draw() lizard.draw() helpers.blit_text(gameDisplay, spider_text, (275, 135), font, margin=125) helpers.blit_text(gameDisplay, lizard_text, (275, 400), font, margin=125) pygame.draw.rect(gameDisplay, black, (150, 385, 550, 5)) if info_index == 1: wolf.draw() turtle.draw() helpers.blit_text(gameDisplay, wolf_text, (275, 135), font, margin=125) helpers.blit_text(gameDisplay, turtle_text, (275, 400), font, margin=125) pygame.draw.rect(gameDisplay, black, (150, 385, 550, 5)) if info_index == 2: orc.draw() dragon.draw() helpers.blit_text(gameDisplay, orc_text, (275, 135), font, margin=125) helpers.blit_text(gameDisplay, dragon_text, (275, 400), font, margin=125) pygame.draw.rect(gameDisplay, black, (150, 385, 550, 5)) # Update game display pygame.display.update() clock.tick(30)
def draw(self, game_frames): # Sequence takes ~ 32 seconds until all enemies dead # Sequence takes ~ 58 seconds until game end if game_frames == int((5 * minutes) + (2 * seconds)): self.walking = True if game_frames > int((5 * minutes) + (2 * seconds)): gameDisplay.blit(self.image, (self.x - self.image_width // 2, self.y - self.image_height // 2)) # Walk south if self.walking: # Animation if self.frame_counter > 0: self.frame_counter -= 1 else: self.image = mage_list[0][self.frame] self.frame += 1 if self.frame > len(mage_list[0]) - 1: self.frame = 0 self.frame_counter = self.frames_to_picswap # Motion if self.y < self.end_y: self.y += 1 else: self.walking = False self.wait = True self.image = magestanding if self.wait: self.wait_counter -= 1 if self.wait_counter == 0: self.wait = False self.speech1 = True self.frame = 0 if self.speech1: if self.speech_counter > 0: self.speech_counter -= 1 else: if self.speech_index < len(mage_speech1) - 1: self.speech_index += 1 self.speech_counter = self.speech_timer if self.speech_index == 3 and self.speech_counter == 0.5 * seconds: self.crystal_show = True if self.speech_index == 7 and self.speech_counter == 2 * seconds: grumbling_sound.play() if self.speech_index == 7 and self.speech_counter == 0: self.crystal_away = True if self.speech_index == 9 and \ self.speech_counter == int(3.25 * seconds): pygame.mixer.music.fadeout(2500) if self.speech_index == 9 and self.speech_counter == 0: self.speech1 = False self.start_spell = True self.frame = 0 # White talking bubble pygame.draw.polygon(gameDisplay, white, ( (self.x + 5, self.y - 15), (380, 5), (420, 5), (420, 57), (410, 15), (380, 15))) pygame.draw.rect(gameDisplay, white, (420, 5, 250, 52)) # Text helpers.blit_text(gameDisplay, mage_speech1[self.speech_index], (425, 6), self.font, margin=190) if self.crystal_show: if self.frame_counter > 0: self.frame_counter -= 1 else: self.image = mage_list[1][self.frame] self.frame += 1 self.frame_counter = self.frames_to_picswap if self.frame > 6: self.crystal_show = False if self.crystal_away: if self.frame_counter > 0: self.frame_counter -= 1 else: self.image = mage_list[1][self.frame] self.frame += 1 self.frame_counter = self.frames_to_picswap if self.frame > 18: self.crystal_away = False self.image = magestanding if self.start_spell: if self.frame_counter > 0: self.frame_counter -= 1 else: if self.frame < len(mage_list[2]) - 1: self.frame += 1 self.frame_counter = self.frames_to_picswap self.image = mage_list[2][self.frame] if self.image == mage_list[2][5] and self.frame_counter == 1: mage_spell_sound.play() if self.image == mage_list[2][10]: pygame.mixer.music.load('music/Fall_of_the_Solar_King2.wav') pygame.mixer.music.play() self.stop_spawn = True self.spell_cast = True self.start_spell = False if self.radius < 1000 and self.spell_cast: self.radius += 20 # Draw the expanding spell (4 circles of increasing thickness) # thickness = 0 if self.radius > self.thickness: pygame.draw.circle(gameDisplay, blue, (self.x, self.y), self.radius, self.thickness) # thickness = 1 if self.radius - self.thickness > self.thickness * 2: pygame.draw.circle( gameDisplay, bright_blue, (self.x, self.y), self.radius-self.thickness, self.thickness * 2) # thickness = 1 + 2 = 3 if self.radius - self.thickness * 3 > self.thickness * 3: pygame.draw.circle( gameDisplay, teal, (self.x, self.y), self.radius - self.thickness * 3, self.thickness * 3) # thickness = 1 + 2 + 3 = 6 if self.radius - self.thickness * 6 > self.thickness * 6: pygame.draw.circle( gameDisplay, bright_teal, (self.x, self.y), self.radius - self.thickness * 6, self.thickness * 6) if self.radius >= 1000: self.spell_cast = False self.speech2 = True self.speech_counter = self.speech_timer self.speech_index = 0 self.radius = 0 self.image = magestanding if self.stop_spawn and self.pop_enemies_counter > 0: self.pop_enemies_counter -= 1 if self.speech2: if self.speech_counter > 0: self.speech_counter -= 1 else: if self.speech_index < len(mage_speech2) - 1: self.speech_index += 1 self.speech_counter = self.speech_timer if self.speech_index == 9 and self.speech_counter == 1: self.win = True # White talking bubble pygame.draw.polygon(gameDisplay, white, ( (self.x + 5, self.y - 15), (380, 5), (420, 5), (420, 57), (410, 15), (380, 15))) pygame.draw.rect(gameDisplay, white, (420, 5, 250, 52)) # Text helpers.blit_text(gameDisplay, mage_speech2[self.speech_index], (425, 6), self.font, margin=190)