Exemplo n.º 1
0
    def createObjects(self):
        from mechanics.Ball import Ball
        from mechanics.Level import Level
        from mechanics.Player import Player
        from tools.Sound import Sound
        from tools.Score import Score
        from gui.Text import TextPane

        self.ball = Ball(size=40)
        self.player = Player()
        self.effects = []
        self.level = Level()
        self.level.text.fs = 50
        self.level.text.update()
        self.score = Score(0)
        self.score.fs = 50
        self.score.update()
        self.sound = Sound()
        self.time = default_timer()

        Debug.printMessage("LOADING COMPLETE")
        #Setting GUI position
        self.score.pos = Vec2D(self.size.x - self.score.size.x) + Vec2D(
            -10, 10)
        self.sound.pos = self.size - self.sound.size - Vec2D(20, 10)
        self.sound.fs = 15
        self.sound.update()
        self.level.text.pos = Vec2D(10, 10)
        #Debug features
        if Debug.DEBUGGING:
            self.fpsCounter = TextPane('0 fps', 15)
            self.fpsCounter.pos = Vec2D(
                20, self.size.y - 10 - self.fpsCounter.size.y)
Exemplo n.º 2
0
 def load(self, moreSounds={}):
     from os.path import isfile
     for key, fileName in moreSounds.items():
         if not isfile(fileName):
             Debug.printMessage("Could not load file %s" % fileName)
             continue
         self.sounds[key] = mix.Sound(fileName)
Exemplo n.º 3
0
 def play(self, what="player"):
     if not self.isOn:
         return None
     # Tries to play the sound of the sound array
     try:
         self.sounds[what].play()
     except KeyError:
         Debug.printMessage("Could not find sound")
Exemplo n.º 4
0
 def __init__(self):
     Drawable.__init__(self)
     from gui.Text import TextPane
     self.levelid = 1
     self.time = 30
     self.blocks = []
     self.text = TextPane("", 19)
     self.switchLevel(1)
     Debug.printMessage("Level created")
Exemplo n.º 5
0
 def moveRand(self):
     if self.movement != Vec2D(0, 0):
         return False
     from random import randint
     self.movement = Vec2D(randint(-1, 4), -4)
     while self.movement.x == 0:
         self.movement.x = randint(-1, 4)
     Debug.printMessage("Starting Speed: %s" % self.movement)
     return True
Exemplo n.º 6
0
 def __init__(self, on=False):
     Button.__init__(self, "Sound", self.toggleSound)
     mix.init()
     self.sounds = {}
     self.isOn = bool(on)
     self.load(Sound.DEFAULTSOUNDS)
     self.fc = (255, 0, 0) if on else (0, 0, 0)
     #Printing debug
     Debug.printMessage("Sound created and %i sounds loaded" %
                        len(self.sounds))
Exemplo n.º 7
0
 def __init__(self, size=None):
     if isinstance(size, int) or isinstance(size, float):
         Drawable.__init__(self, pos=Vec2D(0, 0), size=Vec2D(size, size))
     else:
         Drawable.__init__(self,
                           pos=Vec2D(0, 0),
                           size=Vec2D(Ball.DEFAULTSIZE, Ball.DEFAULTSIZE))
     self.movement = Vec2D(0, 0)
     self.speed = 1
     Debug.printMessage("Ball created")
Exemplo n.º 8
0
 def __init__(self, size=None):
     from tools.Debug import Debug
     if Vec2D.isVec(size):
         Drawable.__init__(self, None, size)
     else:
         Drawable.__init__(self, None, Player.PLAYERSIZE)
     self.offsetY = 30
     self.speed = 5
     self.sizeScale = 1
     self.movement = Vec2D(0, 0)
     Debug.printMessage("Player created")
Exemplo n.º 9
0
 def gameOverScreen(self):
     from tools.Debug import Debug
     playerName = ''
     blocked = True
     toRender = []
     # Creating text panes
     gameOverText = TextPane("Game Over", 60)
     gameOverText.pos = (self.size - gameOverText.size) / 2
     toRender.append(gameOverText)
     # The text below
     restartText = TextPane("Q to quit or C to play again", 45)
     restartText2 = TextPane("H for highscore", 45)
     restartText.pos = (self.size - restartText.size) / 2 + Vec2D(0, 50)
     restartText2.pos = (self.size - restartText2.size) / 2 + Vec2D(0, 100)
     toRender.append(restartText)
     toRender.append(restartText2)
     # Playername
     playerNameText = TextPane(playerName, 90)
     playerNameText.pos.y = (self.size - playerNameText.size).y
     toRender.append(playerNameText)
     # Updating the screen and doing the event loop
     while True:
         for gameOverEvent in pygame.event.get():
             if gameOverEvent.type == pygame.QUIT:
                 return SceneManager.QUIT
             if gameOverEvent.type == pygame.KEYDOWN:
                 key = gameOverEvent.key
                 if key == pygame.K_ESCAPE: return SceneManager.QUIT
                 if key == pygame.K_q and not blocked:
                     return SceneManager.QUIT
                 elif key == pygame.K_c and not blocked:
                     return SceneManager.RESTART
                 elif 97 <= key <= 122:
                     playerName += chr(key)
                 elif key == pygame.K_SPACE:
                     playerName += ' '
                 elif key == pygame.K_BACKSPACE:
                     playerName = playerName[:-1]
                 elif key == pygame.K_RETURN and blocked:
                     blocked = False
                     Debug.printMessage(playerName)
                     Highscore.saveToFile(playerName, self.score.score,
                                          self.level.levelid)
         #Drawing objects
         self.screen.fill(SceneManager.BACKGROUND_COLOR)
         playerNameText.setText("Enter your name" if playerName ==
                                '' else playerName)
         for obj in toRender:
             obj.draw(self.screen)
         pygame.display.update()
Exemplo n.º 10
0
 def switchLevel(self, newLevel):
     self.levelid = newLevel
     self.setPattern()
     self.text.setText("Level: " + str(self.levelid))
     Debug.printMessage("Level %s" % self.levelid)