def __init__(self, surface): SPFScreenObject.__init__(self, surface) self.surface = surface self.timeTilDeploy = 5000 self.isDeployed = False self.width = 0 self.height = pygame.display.Info().current_h self.speed = 15 self.increment = 20 self.deployTime = 0 self.accumTime = 0 self.color = (255, 0, 0) self.imageDoor = pygame.image.load( os.path.join( os.path.dirname(__file__), '../../resource/images/game/spf_gameover_door.png')).convert() self.imageDoor = pygame.transform.smoothscale( self.imageDoor, SU.scalePos(self.imageDoor.get_rect().width, self.imageDoor.get_rect().height)) self.imageLogo = pygame.image.load( os.path.join(os.path.dirname(__file__), '../../resource/images/game/spf_gameover_logo.png')) self.imageLogo = pygame.transform.smoothscale( self.imageLogo, SU.scalePos(self.imageLogo.get_rect().width, self.imageLogo.get_rect().height)) self.flippedDoor = pygame.transform.flip(self.imageDoor, True, False)
def __init__(self, surface, scout): self.surface = surface self.scout = scout self.powerTime = 0 self.visible = True self.vol = elements.ConfigUtility.getConfigSetting("volume") self.image = pygame.image.load( os.path.join(os.path.dirname(__file__), '../../../resource/images/game/powerup/slow.png') ).convert_alpha() self.image = pygame.transform.smoothscale(self.image, SU.scalePos(128, 128)) self.startSound = pygame.mixer.Sound( os.path.join(os.path.dirname(__file__), '../../../resource/sound/game/powerupStart.wav')) self.endSound = pygame.mixer.Sound( os.path.join(os.path.dirname(__file__), '../../../resource/sound/game/powerupEnd.wav')) self.startSound.set_volume(self.vol) self.endSound.set_volume(self.vol) self.finished = False self.x, self.y = 0, 0 self.x, self.y = random.randint( 0, SU.scaleValue(1920) - self.getRect()[2]), -random.randint( SU.scaleValue(100), SU.scaleValue(300)) #Gravity in Feet/Second self.gravityAccel = SU.scaleFloatValue(-4) self.prevVol = 0 self.prevPos = 0
def blitLogo(self): BAR_COLOR = (53, 50, 45) PADDING = ScaleUtility.scalePos(10, 10) AREA = ScaleUtility.scaleResSurface(50, 25, 520, 300) pygame.draw.rect(self.screen, BAR_COLOR, AREA) self.screen.blit(self.logoFile, (AREA[0] + PADDING[0], AREA[1] + PADDING[1]))
def blit(self): y = self.y for text in self.texts: text = self.font.render(text['text'], True, text['color']) self.surface.blit(text, (self.surface.get_rect().width - text.get_rect().width - SU.scaleValue(10), y)) y += SU.scaleValue(30)
def __init__(self, screen): # INIT Variables. elements.GameElements.ResourceManager.__init__() self.screen = screen self.vol = elements.ConfigUtility.getConfigSetting("volume") self.scout = SPFScout(screen) self.speed = SU.scaleFloatValue(10) self.score = 0 self.miss = 0 self.gameOver = False self.endGame = False self.FloatText = FloatText(self.screen, 10) pygame.key.set_repeat(1,1) self.pancakes = [SPFPancake(self.screen), SPFPancake(self.screen), SPFPancake(self.screen), SPFPancake(self.screen), SPFPancake(self.screen)] self.powerups = [] self.pointSound = pygame.mixer.Sound(os.path.join(os.path.dirname(__file__), '../../resource/sound/game/hitsound.wav')) self.winSound = pygame.mixer.Sound(os.path.join(os.path.dirname(__file__), '../../resource/sound/game/win_music.wav')) self.loseSound = pygame.mixer.Sound(os.path.join(os.path.dirname(__file__), '../../resource/sound/game/lose_music.wav')) self.missSound = pygame.mixer.Sound(os.path.join(os.path.dirname(__file__), '../../resource/sound/game/miss.wav')) self.pointSound.set_volume(self.vol) self.winSound.set_volume(self.vol) self.loseSound.set_volume(self.vol) self.missSound.set_volume(self.vol) self.levelBackground = pygame.transform.smoothscale(pygame.image.load(os.path.join(os.path.dirname(__file__), '../../resource/images/game/levels/background.png')).convert(), (pygame.display.Info().current_w, pygame.display.Info().current_h)) self.windowSurf = pygame.Surface(SU.scalePos(650, 200)) self.window = PauseWindow(self.windowSurf) self.window.setTitle("Paused") self.gameOverWindow = GameOverDoors(self.screen) self.gameOverStats = GameStatsWindow(self.screen) self.gameState = {} self.pause = False self.logger = logging.getLogger("spf") self.logger.info("Initializing Game") self.streak = 0 #Game Variables self.winScore = 10 #region Joystick # Check if there's a connected joystick. pygame.joystick.init() # NO JOYSTICK IT BREAKS!!!!! self.joystick = None # try: # self.joystick = pygame.joystick.Joystick(0) # self.joystick.init() # except pygame.error: # self.joystick = None # # if self.joystick != None: # self.logger.info("Enabiling joystick in-game") #endregion self.testPowerup = SpeedPowerup(self.screen, self.scout) self.HUD = GameHUD(self.screen)
def __init__(self, surface): self.surface = surface self.x, self.y = SU.scalePos(1000, 25) self.aTime = 0 self.color = 200 self.font = pygame.font.Font( os.path.join(os.path.dirname(__file__), '../../../resource/fonts/tf2build.ttf'), SU.scaleValue(40))
def __init__(self, surface): self.surface = surface self.menuColor = (53, 50, 45) self.menuBackgroundColor = (119,107,95) self.borderThickness = SU.scaleValue(5) self.textColor = (255,255,255) self.surface_w = surface.get_width() self.surface_h = surface.get_height() self.isOpen = False self.buttons = [] if (elements.ConfigUtility.getConfigSetting("ts_music_enable")): self.button = TSButton.TSButton(surface, self.surface_w / 2 - SU.scaleValue(500) / 2, SU.scaleValue(100), SU.scaleValue(500), SU.scaleValue(50), "Music Enabled") else: self.button = TSButton.TSButton(surface, self.surface_w / 2 - SU.scaleValue(500) / 2, SU.scaleValue(100), SU.scaleValue(500), SU.scaleValue(50), "Music Disabled") self.buttons.append(self.button) self.fps_button = TSButton.TSButton(surface, self.surface_w / 2 - SU.scaleValue(500) / 2, SU.scaleValue(160), SU.scaleValue(500), SU.scaleValue(50), "FPS Counter") self.test_button = TSButton.TSButton(surface, self.surface_w / 2 - SU.scaleValue(500) / 2, SU.scaleValue(220), SU.scaleValue(500), SU.scaleValue(50), "Float Test") self.volume_down = TSButton.TSButton(surface, self.surface_w / 2 - SU.scaleValue(500) / 2, SU.scaleValue(280), SU.scaleValue(100), SU.scaleValue(50), "-") self.volume_up = TSButton.TSButton(surface, self.surface_w / 2 + SU.scaleValue(150), SU.scaleValue(280), SU.scaleValue(100), SU.scaleValue(50), "+") self.close_button = TSButton.TSButton(surface, self.surface_w / 2 - SU.scaleValue(250) / 2, self.surface_h - self.surface_h / 10, SU.scaleValue(250), SU.scaleValue(50), "Exit", footerButton=True) self.buttons.append(self.fps_button) self.buttons.append(self.test_button) self.buttons.append(self.close_button) self.buttons.append(self.volume_down) self.buttons.append(self.volume_up) self.vol = elements.ConfigUtility.getConfigSetting("volume") self.title = "" self.mouseClick = False self.FONT_SIZE = SU.scaleValue(60) self.font = pygame.font.Font(os.path.join(os.path.dirname(__file__), '../../resource/fonts/tf2build.ttf'), self.FONT_SIZE)
def update(self, gamestate): try: powerups = gamestate['powerups'] valid = True except KeyError: valid = False self.blit() if valid: if len(powerups) > 0: for powerup in powerups: if not powerup.visible: time = powerup.powerTime text = self.font.render("POWERUP", True, (255, 255, 255)) percentTime = float(time) / 10000.0 pygame.draw.rect( self.surface, (100, 100, 100), (self.x, self.surface.get_rect()[3] / 2 - SU.scaleValue(25), SU.scaleValue(800), SU.scaleValue(50))) pygame.draw.rect( self.surface, (255, 255, 255), (self.x, self.surface.get_rect()[3] / 2 - SU.scaleValue(25), SU.scaleValue(800) - int(SU.scaleFloatValue(800.0) * percentTime), SU.scaleValue(50))) self.surface.blit( text, (self.x + SU.scaleValue(800) / 2 - text.get_width() / 2, self.surface.get_rect()[3] / 2 - text.get_height() / 2 - SU.scaleValue(45)))
def __init__(self, surface): SPFScreenObject.__init__(self, surface) self.surface = surface self.pancake = elements.GameElements.ResourceManager.textureDictionary[ 'pancake'] self.x = random.randint( 0, SU.scaleValue(1920) - self.pancake.get_rect().width) self.y = -random.randint(self.pancake.get_rect().height, SU.scaleValue(300)) #Gravity in Feet/Second self.gravityAccel = SU.scaleFloatValue(128) self.prevVol = 0 self.prevPos = self.y
def update(self, clock, pause): if not pause: if not self.pos == 0 or not self.vel == 0: vel, pos = elements.GameElements.Physics.Gravity( 800, self.pos, self.vel, float(clock.get_time()) / 1000.0) if (pos > 0): pos = 0 vel = 0 self.vel = vel self.y, self.pos = pos + SU.scaleValue(750), pos else: self.jumps = 0 self.y = SU.scaleValue(750) self.blit(clock) self.setSpeed(0)
def applyPowerup(self): speedMultiplier = 0 if self.scout.getSpeed() > 0: speedMultiplier = 4 elif self.scout.getSpeed() < 0: speedMultiplier = -4 self.scout.setSpeed(self.scout.getSpeed() + SU.scaleValue(speedMultiplier))
def addFooter(self): COVERAGE = 8 BAR_COLOR = (53, 50, 45) pygame.draw.rect(self.screen, BAR_COLOR, (0, int(self.SCREEN_H - (self.SCREEN_H / COVERAGE)), self.SCREEN_W, int(self.SCREEN_H / COVERAGE))) font = pygame.font.Font( os.path.join(os.path.dirname(__file__), '../../resource/fonts/tf2secondary.ttf'), ScaleUtility.scaleValue(36)) text = font.render("Version " + self.version + " - made by /u/djfigs1", True, (119, 107, 95)) self.screen.blit(text, ScaleUtility.scalePos(1375, 995))
def update(self, gamestate): fps = gamestate['FPS'] text = self.font.render(str(int(fps)), True, (255, 255, 255)) self.surface.blit(text, (SU.scaleValue(500), self.surface.get_height() / 2 - text.get_height() / 2))
def blitFPS(self, Clock): pygame.draw.rect(self.FPS_SURFACE, (0, 0, 0), ScaleUtility.scaleResSurface(0, 0, 100, 50)) font = pygame.font.Font( os.path.join(os.path.dirname(__file__), '../../resource/fonts/tf2secondary.ttf'), ScaleUtility.scaleValue(36)) text = font.render(str(round(Clock.get_fps(), 2)), True, (255, 255, 0)) text_w = text.get_rect().width text_h = text.get_rect().height self.FPS_SURFACE.blit( text, ((0 + ScaleUtility.scaleValue(100) / 2) - text_w / 2, (0 + ScaleUtility.scaleValue(50) / 2) - text_h / 2)) self.screen.blit(self.FPS_SURFACE, ScaleUtility.scalePos(1750, 25))
def blit(self): if (not self.width >= SU.scaleValue(1920) / 2): if (self.accumTime >= self.speed): self.accumTime = 0 self.width += SU.scaleValue(self.increment) if (self.width >= SU.scaleValue(1920) / 2): slam = pygame.mixer.Sound( os.path.join( os.path.dirname(__file__), '../../resource/sound/game/mm_door_close.wav')) slam.play() #pygame.draw.rect(self.surface, self.color, (0, 0, self.width, self.height)) #.draw.rect(self.surface, self.color, (SU.scaleValue(1920) - self.width, 0, self.width, self.height)) self.surface.blit(self.imageDoor, (self.width - self.imageDoor.get_rect().width, 0)) self.surface.blit(self.flippedDoor, (SU.scaleValue(1920) - self.width, 0))
def __init__(): #region Pancake textureDictionary['pancake'] = pygame.image.load( os.path.join(os.path.dirname(__file__), '../../resource/images/game/pancake.png')).convert() textureDictionary['pancake'] = pygame.transform.scale( textureDictionary['pancake'], (int(float(textureDictionary['pancake'].get_rect()[2]) / 2.5), int(float(textureDictionary['pancake'].get_rect()[3]) / 2.5))) textureDictionary['pancake'] = pygame.transform.scale( textureDictionary['pancake'], SU.scalePos(246, 146)) textureDictionary['pancake'].set_colorkey((0, 0, 0))
def __init__(self, surface, y): self.texts = [] self.surface = surface self.y = y self.FONT_SIZE = SU.scaleValue(24) self.logger = logging.getLogger('spf') self.logger.info("Initalizing FloatText") self.font = pygame.font.Font( os.path.join(os.path.dirname(__file__), '../../resource/fonts/tf2build.ttf'), self.FONT_SIZE)
def __init__(self, surface): self.runPoses = [] self.surface = surface self.speed = 0 self.frame = 0 self.frameTime = 0 self.right = True self.jumps = 0 self.x = 0 self.y = SU.scaleValue(750) self.vel = 0 self.pos = 0 self.loadTextures()
def update(self, xy, instance): if self.isOpen: self.blit() self.blitVolumeSlider(SU.scaleValue(280)) for button in self.buttons: if (button.isMouseTouching(xOffset=-xy[0], yOffset=-xy[1])) and not pygame.mouse.get_pressed()[0] and self.mouseClick and self.isOpen: if (button == self.fps_button): instance.showFPS = not instance.showFPS elements.ConfigUtility.writeConfigSetting("fps_counter", instance.showFPS) elif (button == self.button): if (self.button.isMouseTouching(xOffset=-xy[0], yOffset=-xy[1])) and not pygame.mouse.get_pressed()[ 0] and self.mouseClick: enabled = elements.ConfigUtility.getConfigSetting("ts_music_enable") if (enabled): self.button.text = "Music Disabled" pygame.mixer.music.stop() else: self.button.text = "Music Enabled" instance.playRandomMusic() elements.ConfigUtility.writeConfigSetting("ts_music_enable", not enabled) elif (button == self.test_button): instance.FloatText.addText("--- TESTING ---", 5) elif (button == self.close_button): self.isOpen = False elif (button == self.volume_down): vol = pygame.mixer.music.get_volume() vol -= 0.1 if vol < 0: vol = 0 pygame.mixer.music.set_volume(vol) self.vol = vol elements.ConfigUtility.writeConfigSetting("volume", vol) elif (button == self.volume_up): vol = pygame.mixer.music.get_volume() vol += 0.1 if vol > 1: vol = 1 else: vol = round(vol, 2) pygame.mixer.music.set_volume(vol) self.vol = vol elements.ConfigUtility.writeConfigSetting("volume", vol) button.setVisible(self.isOpen) button.updateButton(xOffset=-xy[0], yOffset=-xy[1]) self.mouseClick = pygame.mouse.get_pressed()[0]
def update(self, clock): if (self.visible): self.gravityBlit(clock.get_time()) if (self.scout.testObjectColosion(self.getRect())): # The scout has picked up the powerup. self.visible = False self.startSound.play() if (self.y >= SU.scaleValue(1080)): self.finished = True else: self.powerTime += clock.get_time() if self.powerTime > 10000: # If the powerup buff has lasted for more than 10 seconds, remove it. self.endSound.play() self.finished = True else: self.applyPowerup()
def loadTextures(self): RUN_DIRECTORY = os.path.join(os.path.dirname(__file__), '../../resource/images/run/') items = len(os.listdir(RUN_DIRECTORY)) for x in range(0, items): self.runPoses.append( pygame.image.load( os.path.join(os.path.dirname(__file__), RUN_DIRECTORY + "run" + str(x) + ".png")).convert_alpha()) rect = self.runPoses[x].get_rect() self.runPoses[x] = pygame.transform.scale( self.runPoses[x], (int(float(rect[2]) / 4.0), int(float(rect[3]) / 4.0))) self.runPoses[x] = pygame.transform.scale( self.runPoses[x], SU.scalePos(self.runPoses[x].get_rect().width, self.runPoses[x].get_rect().height)) self.runPoses[x].set_colorkey((0, 255, 0))
def __init__(self, screen, text, buttons, padding, button_padding, x, y, width, height): self.screen = screen self.text = text self.buttons = buttons self.x = x self.y = y self.width = width self.height = height self.padding = padding self.button_padding = button_padding self.TITLE_TEXT_OFFSET = SU.scaleValue(50) self.y_offset = self.y + self.TITLE_TEXT_OFFSET self.BACKGROUND_COLOR = (53, 50, 45) self.TEXT_COLOR = (245, 234, 212) self.drawBackground() self.fitButtons()
def drawBackground(self): if not self.text == "": font = pygame.font.Font( os.path.join(os.path.dirname(__file__), '../../resource/fonts/tf2build.ttf'), SU.scaleValue(36)) text = font.render(self.text, True, (self.TEXT_COLOR)) text_h = text.get_rect().height pygame.draw.rect( self.screen, self.BACKGROUND_COLOR, (self.x, self.y, self.width, self.TITLE_TEXT_OFFSET)) self.screen.blit( text, (self.x + self.padding[0] + self.button_padding / 2, (self.y + (self.TITLE_TEXT_OFFSET + self.padding[1]) / 2) - text_h / 2)) pygame.draw.rect(self.screen, self.BACKGROUND_COLOR, (self.x, self.y_offset, self.width, self.height))
def __init__(self, surface, x, y, width, height, text, footerButton=False, soundEffects=True): self.surface = surface self.x = x self.y = y self.width = width self.height = height self.text = text self.rect = pygame.Rect(self.x, self.y, self.width, self.height) self.visible = True self.footerButton = footerButton self.soundEffects = soundEffects self.TEXT_COLOR = (74, 69, 60) self.BUTTON_COLOR = (245, 234, 212) self.HIGHLIGHT_COLOR = (127, 63, 51) self.F_BUTTON_COLOR = (119, 107, 95) self.F_HIGHLIGHT_COLOR = (74, 69, 60) self.F_TEXT_COLOR = (119, 107, 95) self.touched = False self.FONT_SIZE = SU.scaleValue(36) self.color = self.BUTTON_COLOR self.textColor = self.TEXT_COLOR self.ROLLOVER = pygame.mixer.Sound( os.path.join(os.path.dirname(__file__), '../../resource/sound/menu/buttonrollover.wav')) self.font = pygame.font.Font( os.path.join(os.path.dirname(__file__), '../../resource/fonts/tf2build.ttf'), self.FONT_SIZE)
def blit(self, score, miss): pygame.draw.circle(self.surface, (244, 161, 66), (0,int(self.surface.get_rect().height / 2)), int(SU.scaleValue(200))) scoreText = self.font.render(str(score), True, (255,255,255)) # missText = self.secondaryFont.render(str(miss), True, (255,0,0) self.surface.blit(scoreText, (self.x, self.y))
def __init__(self, screen): self.screen = screen self.SCREEN_W = pygame.display.Info().current_w self.SCREEN_H = pygame.display.Info().current_h self.didQuit = False self.showFPS = elements.ConfigUtility.getConfigSetting("fps_counter") self.FPS_SURFACE = pygame.Surface(ScaleUtility.scalePos(100, 50)) self.version = "0.1.0" pygame.mouse.set_visible(True) self.logger = logging.getLogger('spf') self.logger.info("Initializing TitleScreen Class") self.FloatText = FloatText(screen, ScaleUtility.scaleValue(25)) pygame.mouse.set_visible(True) self.languageFile = json.load( open(self.getLocalFile('../../resource/language/en_US.json'), 'r')) self.randomBackground = self.returnRandomBackground() self.blitBackground(self.randomBackground) if elements.ConfigUtility.getConfigSetting("ts_music_enable"): self.playRandomMusic() self.addFooter() self.buttonSurface = self.screen #pygame.Surface((self.SCREEN_W, self.SCREEN_H)) # non-containers, actual buttons quitButtonRes = self.scaleResSurface(50, 975, 400, 75) settingsButtonRes = self.scaleResSurface(500, 975, 400, 75) # container buttons playContainerRes = ScaleUtility.scaleResSurface(50, 350, 520, 70) htpContainerRes = ScaleUtility.scaleResSurface(50, 800, 520, 70) customizeContainerRes = ScaleUtility.scaleResSurface(50, 500, 520, 100) supportContainerRes = ScaleUtility.scaleResSurface(50, 725, 520, 70) self.quitButton = TSButton( self.screen, quitButtonRes[0], quitButtonRes[1], quitButtonRes[2], quitButtonRes[3], self.getLanguageString('#SPF_Quit_Button_Title'), footerButton=True) self.settingsButton = TSButton( self.screen, settingsButtonRes[0], settingsButtonRes[1], settingsButtonRes[2], settingsButtonRes[3], self.getLanguageString('#SPF_Settings_Button_Title'), footerButton=True) self.playButton = TSButton( self.buttonSurface, 50, 300, 500, 75, self.getLanguageString('#SPF_Play_Button_Title')) self.htpButton = TSButton( self.buttonSurface, 50, 600, 500, 75, self.getLanguageString('#SPF_HowToPlay_Button_Title')) self.loadoutButton = TSButton( self.buttonSurface, 50, 400, 275, 75, self.getLanguageString('#SPF_Loadout_Button_Title')) self.codeButton = TSButton( self.buttonSurface, 350, 400, 200, 75, self.getLanguageString('#SPF_Code_Button_Title')) self.supportButton = TSButton( self.buttonSurface, 0, 0, 0, 0, self.getLanguageString('#SPF_Support_Button_Title')) self.buttons = [ self.quitButton, self.playButton, self.htpButton, self.settingsButton, self.loadoutButton, self.codeButton, self.supportButton ] self.containButtons = [self.loadoutButton, self.codeButton] padding = (ScaleUtility.scaleValue(8), ScaleUtility.scaleValue(10)) self.playContainer = TSButtonContainer( self.screen, "", self.playButton, padding, 0, playContainerRes[0], playContainerRes[1], playContainerRes[2], playContainerRes[3]) self.customizeContainer = TSButtonContainer( self.screen, "Customize", self.containButtons, (ScaleUtility.scaleValue(5), ScaleUtility.scaleValue(10)), ScaleUtility.scaleValue(10), customizeContainerRes[0], customizeContainerRes[1], customizeContainerRes[2], customizeContainerRes[3]) self.supportContainer = TSButtonContainer(self.screen, "", self.supportButton, padding, 0, supportContainerRes[0], supportContainerRes[1], supportContainerRes[2], supportContainerRes[3]) self.buttonContainer = TSButtonContainer( self.screen, "", self.htpButton, padding, 0, htpContainerRes[0], htpContainerRes[1], htpContainerRes[2], htpContainerRes[3]) self.containers = [ self.playContainer, self.customizeContainer, self.supportContainer, self.buttonContainer ] self.startGame = False self.joystickConnected = False self.buttonClick = pygame.mixer.Sound( os.path.join(os.path.dirname(__file__), '../../resource/sound/menu/buttonclick.wav')) self.buttonRelease = pygame.mixer.Sound( os.path.join(os.path.dirname(__file__), '../../resource/sound/menu/buttonclickrelease.wav')) self.buttonNotSupportedSound = pygame.mixer.Sound( os.path.join(os.path.dirname(__file__), '../../resource/sound/menu/button_fail.wav')) self.notificationSound = pygame.mixer.Sound( os.path.join(os.path.dirname(__file__), '../../resource/sound/menu/notification_alert.wav')) self.notificationImage = pygame.image.load( os.path.join( os.path.dirname(__file__), '../../resource/images/menu/button_alert.png')).convert() self.notificationImage.set_colorkey((255, 255, 255)) self.blitNotificationImage = False self.testSurface = pygame.Surface(ScaleUtility.scalePos(800, 600)) self.testWindow = TSWindow(self.testSurface) self.testWindow.setTitle("Options") logoRes = ScaleUtility.scaleResSurface(50, 25, 520, 300) self.logoFile = pygame.transform.smoothscale( pygame.image.load( os.path.join( os.path.dirname(__file__), '../../resource/images/menu/spf_title.png')).convert(), (logoRes[2] - ScaleUtility.scaleValue(10) * 2, logoRes[3] - ScaleUtility.scaleValue(10) * 2))
def __init__(self, surface): self.surface = surface self.font = pygame.font.Font( os.path.join(os.path.dirname(__file__), '../../../resource/fonts/tf2secondary.ttf'), SU.scaleValue(80))
def __init__(self, surface): self.surface = surface self.font = pygame.font.Font(os.path.join(os.path.dirname(__file__), '../../../resource/fonts/tf2build.ttf'), SU.scaleValue(128)) self.secondaryFont = pygame.font.Font(os.path.join(os.path.dirname(__file__), '../../../resource/fonts/tf2build.ttf'), SU.scaleValue(80)) self.x, self.y = SU.scalePos(50, 25)
def eventLoop(self, Clock): # Reset the Screen self.screen.fill((0,0,0)) # Blit the Level Background self.screen.blit(self.levelBackground, (0,0)) # Keep playing until the Player has reached a score of 20, or they've missed three pancakes. if (not self.pause): if (not self.score >= self.winScore and not self.miss >= 3): for powerup in self.powerups: powerup.update(Clock) if powerup.finished: self.powerups.remove(powerup) for pancake in self.pancakes: pancake.update(Clock) pancakeRect = pancake.getRect() if (self.scout.testObjectColosion(pancakeRect)): self.pointSound.play() self.pancakes.remove(pancake) self.pancakes.append(SPFPancake(self.screen)) self.score += 1 self.streak += 1 if (random.randint(1,20) == 20): self.powerups.append(SlowPowerup(self.screen, self.scout)) self.streak = 0 if (random.randint(1, 20) == 20): self.powerups.append(SpeedPowerup(self.screen, self.scout)) elif (pancakeRect[1] + pancakeRect[3] >= SU.scaleValue(1080)): self.pancakes.remove(pancake) self.streak = 0 self.pancakes.append(SPFPancake(self.screen)) # self.missSound.play() elif (not self.gameOver and self.score >= self.winScore and self.miss < 3): # If they won, meaning they got 20 pancakes, with no more than two misses. self.logger.info("Game victory") self.winSound.play() self.gameOverWindow.deploy() self.gameOverStats.deploy() self.gameOver = True elif (not self.gameOver and self.miss >= 3): # If they didn't fill the above requirement, they've lost the game. self.logger.info("Game defeat") self.loseSound.play() self.gameOver = True self.gameOverWindow.deploy() self.gameOverStats.deploy() elif (self.gameOver): # Draw the appropriate text. if (self.miss >= 3): font = pygame.font.SysFont("TF2", SU.scaleValue(256)) text = font.render("YOU FAILED", True, (255, 0, 0)) text_w = text.get_rect().width text_h = text.get_rect().height self.screen.blit(text, ((SU.scaleValue(1920) / 2) - text_w / 2, SU.scaleValue(400) - text_h / 2)) else: font = pygame.font.SysFont("TF2", SU.scaleValue(256)) text = font.render("VICTORY", True, (0, 255, 0)) text_w = text.get_rect().width text_h = text.get_rect().height self.screen.blit(text, ((SU.scaleValue(1920) / 2) - text_w / 2, SU.scaleValue(400) - text_h / 2)) else: if (not self.gameOver): for pancake in self.pancakes: pancake.blit() # Update the Game State dictionary. self.gameState['score'] = self.score self.gameState['miss'] = self.miss self.gameState['FPS'] = Clock.get_fps() self.gameState['powerups'] = self.powerups self.gameState['time'] = Clock.get_time() # Update Classes self.scout.update(Clock, self.pause) self.gameOverWindow.update(Clock) self.gameOverStats.update(Clock) self.HUD.update(self.gameState) self.window.update((self.screen.get_rect().width / 2 - self.windowSurf.get_rect().width / 2, self.screen.get_rect().height / 2 - self.windowSurf.get_rect().height / 2), self) self.FloatText.update() # Handle Events for event in pygame.event.get(): if event.type == pygame.QUIT: quit() elif event.type == pygame.KEYDOWN: if not (self.pause): if event.key == pygame.K_LEFT or event.key == pygame.K_a: self.scout.setSpeed(-self.speed) if event.key == pygame.K_RIGHT or event.key == pygame.K_d: self.scout.setSpeed(self.speed) elif event.type == pygame.KEYUP: if event.key == pygame.K_ESCAPE: self.window.toggleOpen() self.pause = not self.pause if event.key == pygame.K_SPACE: self.scout.jump() # Handle joystick events ONLY IF there's a joystick initialized. if (self.joystick != None): self.joystick = pygame.joystick.Joystick(0) self.joystick.init() if self.joystick.get_hat(0)[0] > 0: self.scout.setSpeed(self.speed) elif self.joystick.get_hat(0)[0] < 0: self.scout.setSpeed(-self.speed) if (self.window.isOpen): self.screen.blit(self.windowSurf, (self.screen.get_rect().width / 2 - self.windowSurf.get_rect().width / 2, self.screen.get_rect().height / 2 - self.windowSurf.get_rect().height / 2)) else: pygame.mouse.set_visible(False) pygame.display.update()
def blitVolumeSlider(self, y): pygame.draw.rect(self.surface, (100, 100, 100), (self.surface_w / 2 - SU.scaleValue(500) / 2 + SU.scaleValue(107), y, SU.scaleValue(285), SU.scaleValue(50))) pygame.draw.rect(self.surface, (255, 255, 255), (self.surface_w / 2 - SU.scaleValue(500) / 2 + SU.scaleValue(107), y, SU.scaleValue(285) * self.vol, SU.scaleValue(50)))