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)))
예제 #2
0
    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
예제 #3
0
    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)
예제 #4
0
    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