Ejemplo n.º 1
0
 def configure(self):
     ServiceLocator.registerGlobalService(ServiceNames.Screen, self.screen)
     ServiceLocator.registerGlobalService(ServiceNames.PyGame, pygame)
     ServiceLocator.registerGlobalService(ServiceNames.ViewController, self.viewController)
     ServiceLocator.registerGlobalService(ServiceNames.Gamestate, self.gameState)
     ServiceLocator.registerGlobalService(ServiceNames.BeamPoints, BeamPointRegistry())
     pass
Ejemplo n.º 2
0
    def changeView(self, viewName):
        """Changes the view by name."""
        if viewName in self.viewList:
            if self._currentView:
                if self._currentView.viewName != viewName:
                    self._currentView.suspendView()

            self.viewList[viewName].unSuspendView()
            self._currentView = self.viewList[viewName]
            ServiceLocator.registerGlobalService(ServiceNames.CurrentView, self._currentView)
            
            return self._currentView
        else:
            try:
                if self._currentView:
                    self._currentView.suspendView()

                newView = self.viewFactory(viewName)
            except Exception as e:
                newView = None
                logging.error(e)
                raise

            if newView:
                self._currentView = newView
                ServiceLocator.registerGlobalService(ServiceNames.CurrentView, self._currentView)
                self.viewList[viewName] = newView
                newView.initializeView()

        return newView
Ejemplo n.º 3
0
    def unSuspendView(self):
        
        if self.__serviceContainer:
            for serviceName in self.__serviceContainer:
                ServiceLocator.registerGlobalService(serviceName, self.__serviceContainer[serviceName])

        pass
Ejemplo n.º 4
0
 def registerSavePoint(self):
     """Saves the current position and camera position."""
     savePoint = SavePoint()
     savePoint.viewName = self.viewName
     savePoint.screenPosition = self._viewPointer.screenPosition.copy()
     savePoint.playerPosition =  ViewPoint(self._viewPointer.playerPositionX, self._viewPointer.playerPositionY)
     ServiceLocator.registerGlobalService(ServiceNames.LastSavePoint, savePoint)
     pass
Ejemplo n.º 5
0
 def __init__(self, parent=None):
     super(CuteMpdMainWindow, self).__init__(parent)
     self.setupUi(self)
     self.mpdViewModel = MpdViewModel(self)
     ServiceLocator.registerGlobalService(ServiceNames.MpdViewModel, self.mpdViewModel)
     self.connectUI()
     self._currentIndex = None
     pass
Ejemplo n.º 6
0
    def setPlayerPosition(self, position):
        if not self._map:
           self._map = ServiceLocator.getGlobalServiceInstance(ServiceNames.Map)
        if not self._collideRect:
            player = ServiceLocator.getGlobalServiceInstance(ServiceNames.Player)
            self._collideRect = player.collideRect

        self.__currentState = self.checkCollideAt(self._map, self._collideRect, position)
        pass
Ejemplo n.º 7
0
 def __init__(self, parent=None):
     super(CuteMpdMainWindow, self).__init__(parent)
     self.setupUi(self)
     self.mpdViewModel = MpdViewModel(self)
     ServiceLocator.registerGlobalService(ServiceNames.MpdViewModel,
                                          self.mpdViewModel)
     self.connectUI()
     self._currentIndex = None
     pass
Ejemplo n.º 8
0
 def initializeObject(self, parent):
     # Destry all view instances
     viewController = ServiceLocator.getGlobalServiceInstance(ServiceNames.ViewController)
     viewController.destroyAllRunningViews()
     
     #Reset the game state
     #newGameState = GameState()
     #ServiceLocator.registerGlobalService(ServiceNames.Gamestate, newGameState)
     gameState = ServiceLocator.getGlobalServiceInstance(ServiceNames.Gamestate)
     gameState.reset()
     return super().initializeObject(parent)
Ejemplo n.º 9
0
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.currentSong = None
        self.currentPlaylist = None
        self._volume = 0

        self.config = ServiceLocator.getGlobalServiceInstance(ServiceNames.Configuration)
        self.mpdViewModel = MpdViewModel(self)
        ServiceLocator.registerGlobalService(ServiceNames.MpdViewModel, self.mpdViewModel)
        self.mpdViewModel.connectPlayListChanged(self, self.songListChanged)
        self.mpdViewModel.connectSongChanged(self, self.songChanged)
        self.mpdViewModel.connectMixerChanged(self, self.mixerHasChanged)
        self.mpdViewModel.connectObserver()
        self.connectUI()
Ejemplo n.º 10
0
 def changeJumpSize(self, jumpSize):
     """Change the jump size."""
     assert jumpSize == 0 or jumpSize == 1, "JumpSitze must be JumpSizeMode.Short or JumpSizeMode.Long."
     # ServiceLocator.getGlobalServiceInstance(ServiceNames.Player).jumpCalculator.horizontalJumpSize = jumpSize
     player = ServiceLocator.getGlobalServiceInstance(ServiceNames.Player)
     calculator = player.jumpCalculator
     calculator.horizontalJumpSize = jumpSize
Ejemplo n.º 11
0
 def __init__(self, parentSprite, properties):
     #assert isinstance(parentSprite, SpriteBase)
     self._parentSprite = parentSprite
     self._viewPointer = ServiceLocator.getGlobalServiceInstance(ServiceNames.ViewPointer)
     self._style = self._parentSprite.style
     self.configureProperties(properties)
     pass
Ejemplo n.º 12
0
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.currentSong = None
        self.currentPlaylist = None
        self._volume = 0

        self.config = ServiceLocator.getGlobalServiceInstance(
            ServiceNames.Configuration)
        self.mpdViewModel = MpdViewModel(self)
        ServiceLocator.registerGlobalService(ServiceNames.MpdViewModel,
                                             self.mpdViewModel)
        self.mpdViewModel.connectPlayListChanged(self, self.songListChanged)
        self.mpdViewModel.connectSongChanged(self, self.songChanged)
        self.mpdViewModel.connectMixerChanged(self, self.mixerHasChanged)
        self.mpdViewModel.connectObserver()
        self.connectUI()
Ejemplo n.º 13
0
 def restartGame(self):
     """Go to savepoint and resume game."""
     savePoint = ServiceLocator.getGlobalServiceInstance(ServiceNames.LastSavePoint)
     if savePoint:
         assert isinstance(savePoint, SavePoint), "Expected to get a SavePoint type."
         changeviewEvent = pygame.event.Event(UserEvents.EVENT_CHANGEVIEW, SavePoint = savePoint)
     pygame.event.post(changeviewEvent)
     pass
Ejemplo n.º 14
0
 def __init__(self, parent = None):
     QtGui.QDialog.__init__(self, parent)
     self.setupUi(self)
     self._config = ServiceLocator.getGlobalServiceInstance(ServiceNames.Configuration)
     self.PlayListsView.clicked.connect(self.onPlayListViewClicked)
     self.selectedList = None
     self.playListModel = PlayListModel(self.loadPlaylists())
     self.PlayListsView.setModel(self.playListModel)
     pass
Ejemplo n.º 15
0
 def __init__(self, viewPointer, collider, jumpCalculator):
     assert isinstance(viewPointer, ViewPointer), "viewPointer must be of type Utils.ViewPointer.ViewPointer."
     #assert isinstance(tilesWatcher, TiledWatcher), "tilesWatcher must be of type Tiled.TiledWatcher.TiledWatcher."
     assert isinstance(collider, TiledSpriteCollider), "Collider must be of type Tiled.TiledSpriteCollider.TiledSpriteCollider."
     self._viewPointer = viewPointer
     #self._tilesWatcher = tilesWatcher
     self._collider = collider
     self._jumpCalculator = jumpCalculator
     self._map = ServiceLocator.getGlobalServiceInstance(ServiceNames.Map)
Ejemplo n.º 16
0
 def __init__(self):
     super().__init__()
     self._map = ServiceLocator.getGlobalServiceInstance(ServiceNames.Map)
     self.cache = {}
     self._buttons = pygame.sprite.Group()
     self.button = TextLabel(620, 150, "Module is OFF")
     self.button.onClick = self.onClickHandler
     self._buttons.add(self.button)
     self.viewMode = 0
Ejemplo n.º 17
0
    def __init__(self, parent = None):
        QtGui.QDialog.__init__(self, parent)
        self.setupUi(self)
        self.configuration = ServiceLocator.getGlobalServiceInstance(ServiceNames.Configuration)
        self.connectButtons()
        self.editHostname.setText(self.configuration.mpdserver)
        self.EditPassword.setText(self.configuration.mpdpassword)
        self.editPort.setText(self.configuration.mpdport)

        pass
Ejemplo n.º 18
0
    def __init__(self, parent=None):
        QtGui.QDialog.__init__(self, parent)
        self.setupUi(self)
        self.configuration = ServiceLocator.getGlobalServiceInstance(
            ServiceNames.Configuration)
        self.connectButtons()
        self.editHostname.setText(self.configuration.mpdserver)
        self.EditPassword.setText(self.configuration.mpdpassword)
        self.editPort.setText(self.configuration.mpdport)

        pass
Ejemplo n.º 19
0
 def __init__(self, parent):
     self._parent = parent
     self._joystickState = None
     self._lastJoystickMove = None
     self._moveCalculator = parent.moveCalculator
     self._moveState = PlayerMoveState.Standing
     currentMap = ServiceLocator.getGlobalServiceInstance(ServiceNames.Map)
     self._mapScanner = MapScanner(currentMap, parent)
     self._targetPosition = None
     
     pass
Ejemplo n.º 20
0
    def initializePlugin(self, parentView):
        super().initializePlugin(parentView)

        if not self._player:
            self._player = ServiceLocator.getGlobalServiceInstance(ServiceNames.Player)
            #self._jumpCalculator.g = self._player.jumpG
            #self._jumpCalculator.v0 = self._player.jumpV0
            #self._jumpCalculator.vx = self._player.jumpVx
            self._jumpCalculator = self._player._JumpCalculator
            self._parameters = self._jumpCalculator.jumpParameters

        self.registerEventHandler()
Ejemplo n.º 21
0
    def suspendView(self):
        """View goes into suspend mode."""
        self.musicPlayer.stop()
        containerServices = [ServiceNames.CurrentView, ServiceNames.Map, ServiceNames.Player, ServiceNames.ViewPointer]
        container = {}

        for service in containerServices:
            if service in ServiceLocator.services:
                container[service] = ServiceLocator.getGlobalServiceInstance(service)
                ServiceLocator.UnregisterService(service)
        
        self.__serviceContainer = container
        
        pass
Ejemplo n.º 22
0
 def __init__(self, viewName):
     """Constructor of the ViewModel base class."""
     self._viewName = viewName
     self._screen = ServiceLocator.getGlobalServiceInstance(ServiceNames.Screen)
     self.__map = None
     self.__mapObjects = []
     self._beamPointRegistry = {}
     self.__drawBackground = None
     self.__drawTilesCall = None
     self.__playerSprite = None
     self.__serviceContainer = None
     self._musicPlayer = None
     self._soundPlayer = None
     self.__plugins = []
     self.__objectSprites = pygame.sprite.Group()
     self.__allSprites = pygame.sprite.Group()
     self.__keyboardEventHandler = self.__initKeyboardManager()
     self.__joystickEventHandler = self.__initJoystickManager()
     self._state = ServiceLocator.getGlobalServiceInstance(ServiceNames.Gamestate)
     self.__eventHandlers = [] # Event handlers for plugins
     self._viewPointer = ViewPointer()
     self._gamePaused = False
     self._lifeLostMessageCallback = None
     ServiceLocator.registerGlobalService(ServiceNames.ViewPointer, self._viewPointer)
Ejemplo n.º 23
0
    def doCollide(self):
        """Changes the View and the position."""
        if self._beamPoint:
            print("Beampoint")
            beamService = ServiceLocator.getGlobalServiceInstance(ServiceNames.BeamPoints)
            beamService.beam(self._beamPoint)
        elif self._targetViewName:
            event = pygame.event.Event(EVENT_CHANGEVIEW, ViewName = self._targetViewName)
            pygame.event.post(event)
        else:
            raise SyntaxError("Missing Beampoint or ViewName on gate or teleporter object.")

        
        
        pass
Ejemplo n.º 24
0
    def __init__(self, row, changeSong=True, parent = None):
        QtGui.QDialog.__init__(self, parent)
        self.setupUi(self)
        self._volume = 0
        self.btnBack.clicked.connect(self.onBtnBackClicked)
        self.btnPlay.clicked.connect(self.onBtnPlayClicked)
        self.btnStop.clicked.connect(self.onBtnStopClicked)
        self.btnNext.clicked.connect(self.onBtnNextClicked)
        self.btnPrev.clicked.connect(self.onBtnPrevClicked)
        self.mpdViewModel = ServiceLocator.getGlobalServiceInstance(ServiceNames.MpdViewModel)
        self.config = ServiceLocator.getGlobalServiceInstance(ServiceNames.Configuration)
        self.mpdViewModel.connectSongChanged(self, self.songHasChanged)
        self.mpdViewModel.connectMixerChanged(self, self.mixerHasChanged)
        #self.VolumeSlider.sliderReleased.connect(self.onVolumeSliderReleased)
        self.btnVolPlus.clicked.connect(self.onBtnVolPlusClicked)
        self.btnVolMinus.clicked.connect(self.onBtnVolMinusClicked)


        self.position = row
        if changeSong:
            self.playSong(self.position)
        else:
            self.requestUpdate()
        pass
Ejemplo n.º 25
0
    def __init__(self, parentPlayer):
        self._moveState = PlayerMoveState.Standing
        self._joystickState = JoystickState()
        self._lastChange = None
        self._lastPosition = None
        self._moveTimeLimit = None
        self._MoveEndFlag = None
        self._getTileInfoCallback = None
        self._getCurrentPositionCallback = None
        self._jumpTimeout = 100
        self._jumpSize = None

        self._backgroundTiles = [0, 28, 29, 30, 31]
        self.__viewPoint = ServiceLocator.getGlobalServiceInstance(ServiceNames.ViewPointer)
        self.__collider = TiledSpriteCollider()

        self._moveTimeCalculator = MoveTimeCalculator(self.__viewPoint, self.__collider, parentPlayer._JumpCalculator)
Ejemplo n.º 26
0
    def __init__(self, spriteName):
        super().__init__()
        self._viewPointer = ServiceLocator.getGlobalServiceInstance(ServiceNames.ViewPointer)
        self.image = pygame.Surface([32,32])
        self.image.fill((0,0,0))
        #self.rect = self._calculateViewPosition(screen, self.image)
        self.rect = pygame.Rect((0,0, 32,32))
        self._spriteName = spriteName
        self._animations = {}
        self._transparenceKey = None
        self.loadAnimations(spriteName)

        self._JumpCalculator = JumpCalculator(jumpUpSpeed = 0.2, jumpUpTime = 500)
        #self._JumpCalculator.jumpUpSpeed = 200
        #self._JumpCalculator.jumpUpTime = 500

        self._moveStateMachine = PlayerMoveStateMachine(self)
Ejemplo n.º 27
0
 def onViewChange(self, event):
     """View is going to be changed."""
     viewController = ServiceLocator.getGlobalServiceInstance(ServiceNames.ViewController)
     if 'ViewName' in event.dict:
         if viewController:
             viewController.changeView(event.ViewName)
             if 'Position' in event.dict:
                 viewController.currentView._viewPointer.playerPositionX = event.Position.left
                 viewController.currentView._viewPointer.playerPositionY = event.Position.top
                 viewController.currentView._viewPointer.centerPlayerPositionToScreen(event.Position)
     elif 'SavePoint' in event.dict:
         sp =  event.SavePoint.screenPosition.copy()
         pp = event.SavePoint.playerPosition.copy()
         viewController.currentView._viewPointer.screenPosition = sp
         viewController.currentView._viewPointer.initPlayerPosition(pp.left, pp.top)
         viewController.currentView.player._moveStateMachine.reset()
     pass
Ejemplo n.º 28
0
    def __init__(self):
        self.image = None
        self.rect = None
        self._menuItems = []
        self._resourcePath = None
        self._margin = 0
        self._soundButton = None
        self._soundMove = None
        #self._fontFile = None
        #self._fontSize = 48
        self._fontProperties = FontProperties()
        self._x = None
        self._y = None
        self._itemIndex = 0
        self._joyState = SelectorJoyState.WaitForJoyButton
        self._viewPointer = ServiceLocator.getGlobalServiceInstance(ServiceNames.ViewPointer)


        super().__init__()
Ejemplo n.º 29
0
 def calculateMaximumFallDownTime(self):
     result = None
     rect = ServiceLocator.getGlobalServiceInstance(ServiceNames.Player).collideRect
     offset = self._getOffset()
     abort = False
     time = 0
     while not abort:
         time += 10
         y = self._jumpCalculator.calcFalling(time)
         position = ViewPoint(offset.left, offset.top + y)
         state = self._collider.checkCollideAt(self._map, rect, position)
         #if self._tilesWatcher.isBarrierOnPosition(position, CheckDirection.Ground):
         if state.isGrounded:
             result = (time, position)
             abort = True
         elif time >= 10000:
             result = (10000, position)
         
     return result
Ejemplo n.º 30
0
 def __init__(self):
     """Constructor of the sprite base class."""
     super().__init__()
     self._name = None
     self._x = None
     self._y = None
     self._assetName = None # The path name for sprite resources.
     self._points = 0 # Points the player gets if this item is touched.
     self._energy = 0 # Energy points the player gets if this is touched.
     self._style = None # The animation style
     self._intelligence = None # artificial intelligence to drive this sprite.
     self._killSprite = True # True if this sprite dies if the player touch it
     self._killPlayer = False # True if the player dies on collision.
     self._sound = None # Contains the sound file that is played on collision.
     self._supplies = None # Items the player gets if sprite is touched.
     self._behavior = None # Special coded behavior that is executed if collided with the player sprite.
     self._viewPointer = ServiceLocator.getGlobalServiceInstance(ServiceNames.ViewPointer)
     self.rect = None
     self._moveState = None
     self._lastCollide = None
     pass
Ejemplo n.º 31
0
    def calculateJumpTime(self, vector):
        result = None
        rect = ServiceLocator.getGlobalServiceInstance(ServiceNames.Player).collideRect
        offset = self._getOffset()
        abort = False
        time = 0
        while not abort:
            time += 10
            x = self._jumpCalculator.calcX(time)
            y = self._jumpCalculator.calcY(time)
            position = ViewPoint(offset.left + x * vector.X, offset.top - y)
            state = self._collider.checkCollideAt(self._map, rect, position)
            #if self._tilesWatcher.isBarrierOnPosition(position, CheckDirection.Ground):
            if state.isGrounded or state.isUpperLayerTouched or state.isLeftTouched or state.isRightToched:
                result = (time, position)
                abort = True
            elif time >= 10000:
                result = (10000, position)
                abort = True

        return result
Ejemplo n.º 32
0
    def __init__(self):
        #Screen Position in map
        self._screenPosition = ViewPoint(0,0)
        self.__playerRect = None
        self.__followStateX = ViewPointerFollowState.FixedPosition
        self.__followStateY = ViewPointerFollowState.FixedPosition

        self._cameraSpeed = 20

        screen = ServiceLocator.getGlobalServiceInstance(ServiceNames.Screen)
        self._screenrect = screen.get_rect()
        self.__innerBorder = self._screenrect.copy()
        
        self.__innerBorder.left = 80
        self.__innerBorder.width -= 160+32
        self.__innerBorder.height -= 160+32
        self.__innerBorder.top += 80

        self.__mapHeight = None
        self.__mapWidth = None

        #Center player
        self._playerOffset = ViewPoint(self._screenrect.centerx, self._screenrect.centery)
Ejemplo n.º 33
0
#!/usr/bin/python3
import sys
from PyQt4 import QtGui, QtCore
import resources_rc
from Views.CuteMpdMainWindow import CuteMpdMainWindow
from Utils.ServiceLocator import ServiceLocator, ServiceNames
from Utils.Configuration import Configuration
from Views.MainWindow import MainWindow

if __name__ == "__main__":
    ServiceLocator.registerGlobalService(ServiceNames.Configuration,
                                         Configuration())
    app = QtGui.QApplication(sys.argv)

    file = QtCore.QFile(':/styles/stylesheet')
    if file.open(QtCore.QFile.ReadOnly):
        styleSheet = str(file.readAll(), 'utf-8')
        app.setStyleSheet(styleSheet)
        file.close()

    gui = MainWindow()
    if sys.platform == 'win32':
        gui.show()
    else:
        gui.showFullScreen()
    sys.exit(app.exec_())
Ejemplo n.º 34
0
 def __init__(self):
     gameState = ServiceLocator.getGlobalServiceInstance(ServiceNames.Gamestate)
     self.clock = gameState.clock
     
     super().__init__()
     self._rect = self._screen.get_rect()
Ejemplo n.º 35
0
    def __init__(self):
        self._config = ServiceLocator.getGlobalServiceInstance(
            ServiceNames.Configuration)
        self.client = MPDClient()

        return QThread.__init__(self)