Exemplo n.º 1
0
    def switch_scene_with_bgm(self, newScene, newBgmFilePath, newBgmExt):
        """"Switch to the new scene with background music."""

        # check if new scene good memory space.
        if newScene is None:
            JCSPyGm_Debug.Error(
                "Scene u trying to switch is null references...")
            return

        # check if still switching the scene.
        if self.__switchingScene or self.__fadingBackIntheScene:
            JCSPyGm_Debug.Log("Still switching the scene, plz wait...")
            return

        # -----------------------------------------
        # IMPORTANT(jenchieh): first assign
        if self.currentScene is None:
            self.currentScene = newScene

            # call initialize for the scene.
            self.currentScene.on_enable_scene()

            self.currentBgmFilePath = newBgmFilePath
            self.currentBgmExt = newBgmExt
            self.get_black_screen().fade_out(
                JCSPyGm_SceneManager.SCENE_FADEOUT_TIME)

            # enable the switching scene trigger.
            self.__fadingBackIntheScene = True
            return
        # -----------------------------------------

        # save the next scene
        self.__nextScene = newScene
        self.__nextBgmFilePath = newBgmFilePath
        self.__nextBgmExt = newBgmExt

        # initialize the next scene.
        self.__nextScene.on_enable_scene()

        # fade out the background music.
        self.soundManager.stop_bgm(JCSPyGm_SceneManager.BGM_SOUND_FADEOUT_TIME)

        # start fading in the black screen
        self.get_black_screen().fade_in(JCSPyGm_SceneManager.SCENE_FADEIN_TIME)

        # enable the switching scene trigger.
        self.__switchingScene = True
Exemplo n.º 2
0
    def load_animation(self, filePath, baseName, ext, frameCount):
        """Load the animation from path.
        
        filePath : string to the file
        baseName: base file name of the animation.
        ext : extension string
        frameCount : how many frame in the animation? = sprite count
        """

        # check the frame count.
        if frameCount <= 0:
            JCSPyGm_Debug.Error("Frame count cannot be lower "
                                "than/equal to zero...")

        self.__frameCount = frameCount

        # this will loop through 0 - frame count.
        for index in range(frameCount):

            # setup the full path
            fullPath = filePath + baseName + str(index)

            # Place new column in the grid.
            self.__sprites.append([])

            # create sprite instance
            self.__sprites[index] = JCSPyGm_Sprite(self.gameObject)

            # load the sprite base on the full file path
            self.__sprites[index].load_sprite(fullPath, ext)
Exemplo n.º 3
0
    def switch_animation(self, newAnimIndex):
        """Switch the current animation to new animation."""

        if self.__animations[newAnimIndex] is None:
            JCSPyGm_Debug.Error("Animation index u pass in does not exists.")
            return

        # switch the current animation to new animations.
        self.__currentAnimation = self.__animations[newAnimIndex]
Exemplo n.º 4
0
    def update(self, deltaTime):
        """"Update camera object."""

        # check if component active?
        if not self.active:
            return

        sceneManager = JCSPyGm_SceneManager.get_instance()
        self.__currentScene = sceneManager.get_current_scene()

        # check if current scene good to be render.
        if self.__currentScene is None:
            JCSPyGm_Debug.Error("No current scene can be render by camera.")
            return

        deltaSpeedX = self.velX * deltaTime
        deltaSpeedY = self.velY * deltaTime

        self.__realX += deltaSpeedX
        self.__realY += deltaSpeedY

        self.recordX += deltaSpeedX
        self.recordY += deltaSpeedY

        # get the interface length from the current scene.
        interLen = self.__currentScene.get_interfaces_len()

        for index in range(interLen):

            # get the each interface
            inter = self.__currentScene.get_interface_by_index(index)

            # get the game object len from the interface' game
            # object array.
            gameObjectLen = inter.get_game_objects_len()

            for innerIndex in range(gameObjectLen):

                # get the game object from the interface array.
                gameObj = inter.get_game_object_by_index(innerIndex)

                gameObj.camX -= self.recordX * JCSPyGm_Math.abs(
                    inter.get_friction())
                gameObj.camY -= self.recordY * JCSPyGm_Math.abs(
                    inter.get_friction())

        # reset force
        self.recordX = 0
        self.recordY = 0

        cameraOffsetX = -(JCSPyGm_Window.WINDOW_WIDTH / 2) + self.offsetX
        cameraOffsetY = -(JCSPyGm_Window.WINDOW_HEIGHT / 2) + self.offsetY

        self.__do_min_max_distance()

        self.set_camera_position_xy(self.x + cameraOffsetX,
                                    self.y + cameraOffsetY)
Exemplo n.º 5
0
    def set_collider_type(self, colliderType):
        """Create instance and set the collider type."""

        if colliderType is "circle":
            self.collider = JCSPyGm_CircleCollider(self)
        elif colliderType is "box":
            self.collider = JCSPyGm_BoxCollider(self)
        else:
            JCSPyGm_Debug.Error("Failed to set collider type... "
                                "No Type: [" + colliderType + "]")
Exemplo n.º 6
0
 def stop_bgm(self, fadeOutMs = 0):
     """Stop background music.
     
     @param fadeOut: fade out before stopping.
     """
     # check if okay to stop background music.
     if self.bgm is None:
         JCSPyGm_Debug.Error("Cannot fade out the sound with null references...")
         return
     
     self.bgm.fadeout(fadeOutMs)
Exemplo n.º 7
0
    def auto_pivot(self):
        """Auto Pivot the image by their own width and height."""

        if self.__spriteRect is None:
            JCSPyGm_Debug.Error(
                "Auto pivot with out the sprite is not legal...")

            return

        self.pivotOffsetX = self.__spriteRect.width / 2
        self.pivotOffsetY = self.__spriteRect.height / 2
Exemplo n.º 8
0
    def __get_interface_by_name(self, interName):
        """Add the game object to the interface 
        by interface's name."""

        for index in range(self.get_interfaces_len()):
            inter = self.get_interface_by_index(index)

            if inter.is_name(interName):
                return inter

        JCSPyGm_Debug.Error("Failed to add game object by name...")

        return None
Exemplo n.º 9
0
    def auto_pivot(self):
        """Auto pivto depend on either animation/sprite we have."""

        if not (self.__animator.get_animations_len() is 0):
            self.__animator.auto_pivot()
        elif not (self.__animation is None):
            self.__animation.auto_pivot()
        elif not (self.__sprite is None):
            self.__sprite.auto_pivot()
        else:
            JCSPyGm_Debug.Error("Failed to auto pivot the game object. "
                                "Make sure they have either animation "
                                "or sprite available.")

        if not (self.collider is None):
            self.collider.auto_pivot()
    def check_collide(self, collider1, collider2):
        """Check the collider. (basic)
        
        @param col: collider
        """

        collide = False

        if collider1.get_type() is "box" and collider2.get_type() is "box":
            collide = JCSPyGm_Collision.rect_to_rect(collider1, collider2)
        elif collider1.get_type() is "circle" and collider2.get_type(
        ) is "circle":
            collide = JCSPyGm_Collision.circle_to_circle(collider1, collider2)
        elif collider1.get_type() is "box" and collider2.get_type(
        ) is "circle":
            collide = JCSPyGm_Collision.rect_to_circle(collider1, collider2)
        elif collider1.get_type() is "circle" and collider2.get_type(
        ) is "box":
            collide = JCSPyGm_Collision.rect_to_circle(collider2, collider1)
        else:
            # this should not happend
            JCSPyGm_Debug.Error("Collider check error...")

        return collide