示例#1
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
示例#2
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)
 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
 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
示例#5
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
示例#6
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
示例#7
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)
示例#8
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
示例#9
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
示例#10
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
示例#11
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
示例#12
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()
示例#13
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
示例#14
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
示例#15
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)
示例#16
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
示例#17
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()
示例#18
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)
示例#19
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
示例#20
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()
    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)
示例#22
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
    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__()
示例#24
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
示例#25
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
示例#26
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)
示例#27
0
 def initializeObject(self, parent):
     super().initializeObject(parent)
     self._viewName = parent.viewName
     bpReg = ServiceLocator.getGlobalServiceInstance(ServiceNames.BeamPoints)
     bpReg.registerBeamPoint(self)
示例#28
0
 def __init__(self):
     gameState = ServiceLocator.getGlobalServiceInstance(ServiceNames.Gamestate)
     self.clock = gameState.clock
     
     super().__init__()
     self._rect = self._screen.get_rect()
示例#29
0
    def __init__(self):
        self._config = ServiceLocator.getGlobalServiceInstance(
            ServiceNames.Configuration)
        self.client = MPDClient()

        return QThread.__init__(self)
示例#30
0
 def gameOver(self):
     """Terminate the game and go to game over view."""
     # Change to gameover view.
     gameOverViewName = ServiceLocator.getGlobalServiceInstance(ServiceNames.GameLostTarget)
     changeviewEvent = pygame.event.Event(UserEvents.EVENT_CHANGEVIEW, ViewName=gameOverViewName)
     pygame.event.post(changeviewEvent)
示例#31
0
 def initializePlugin(self, parentView):
     super().initializePlugin(parentView)
     if not self._player:
         self._player = ServiceLocator.getGlobalServiceInstance(ServiceNames.Player)
     self._map = ServiceLocator.getGlobalServiceInstance(ServiceNames.Map)
     self._screenRect = self._screen.get_rect()
示例#32
0
 def __init__(self):
     self.__enabled = True
     self._screen = ServiceLocator.getGlobalServiceInstance(ServiceNames.Screen)
     self._viewPointer = ServiceLocator.getGlobalServiceInstance(ServiceNames.ViewPointer)
     self._curentView = None
示例#33
0
    def __init__(self):
        self._screen = ServiceLocator.getGlobalServiceInstance(ServiceNames.Screen)
        self._dialogInitTime = 0
        self._dialogSprite = None

        return super().__init__()