예제 #1
0
    def __init__(self, base, mapNo):
        self.isListening = False

        # Holds rigid bodies, joints, controls global params
        self.world = OdeWorld()
        self.world.setGravity(0, 0, -9.8)

        st = SurfaceType()
        st.load(self.world)
        del st

        self.contactgroup = OdeJointGroup()

        self.space = OdeHashSpace()
        self.space.setAutoCollideWorld(self.world)
        self.space.setAutoCollideJointGroup(self.contactgroup)
        self.space.setCollisionEvent(EventType.ODE_COLLISION)
        base.accept(EventType.ODE_COLLISION, self.onCollision)

        self.ball = Ball(self.world, self.space, "Johanneksen pallo")

        self.level = Level(self, mapNo)
        self.player = Player("Johannes")

        self.camera = Camera(base, self.ball)
예제 #2
0
class BaseMenuScreen(object):
    
    def __init__(self, game, playMusic=True):
        self.mGame = game
        Pgl.app.setUpdaterate(int(Updaterate.FAST))
        pygame.mouse.set_visible(False)
                
        if playMusic: SoundManager.getInstance().playMenuMusic()
    
        #set input & camera
        self.mGame.input = MenuInput(self)
        self.mCamera = Camera(Pgl.width, Pgl.height)
        self.modelsize = self.mCamera.getModelCoords(b2Vec2(Pgl.width, Pgl.height))
        
        #fonts
        self.screenFont = Resources.getInstance().getScaledFont(self.mCamera.scale.x / 3.0)
        self.titleFont = Resources.getInstance().getScaledFont(self.mCamera.scale.x * 2.0)
        self.infoFont = Resources.getInstance().getScaledFont(self.mCamera.scale.x / 2)
        
        #graphics
        self.arrow = Sprite(Resources.getInstance().mArrow) 
        self.arrow.setSize(self.mCamera.getScaledSize((self.arrow.getWidth()/float(self.arrow.getHeight())) * 0.5, 0.5))
        self.menubutton = Animation(Resources.getInstance().mMenuButton, 2, 1, 0, self.mCamera.getScaledSize(1, 1), False, False)
        self.levelbutton = Animation(Resources.getInstance().mLevelButton, 2, 1, 0, self.mCamera.getScaledSize(1, 1), False, False)
        self.checkbutton = Animation(Resources.getInstance().mCheckButton, 2, 1, 0, self.mCamera.getScaledSize(1, 1), False, False)
        self.lock = Sprite(Resources.getInstance().mLock)
        self.lock.setSize(self.mCamera.getScaledSize((self.lock.getWidth()/float(self.lock.getHeight())) * 0.2, 0.2))
        
        
    def update(self, delta):
        if isinstance(self.mGame.input, MenuInput):
            pos = self.mGame.input.getMousePosition()
            self.arrow.setPosition(pos[0], pos[1])
            self.mouseOver(pos)
예제 #3
0
class GameScreen(object):

    mWorld = None
    mCamera = None
    mWorldRender = None

    def __init__(self, game, lvl):
        Pgl.app.setUpdaterate(Pgl.options.updaterate)
        pygame.mouse.set_visible(False)
        SoundManager.getInstance().playMusic(random.randrange(1, SoundManager.getInstance().NUMBER_OF_SONGS + 1))

        self.mGame = game
        self.mCamera = Camera(Pgl.width, Pgl.height)

        #observer
        self.mLuObs = LevelupdateObserver()
        self.mFxObs = FXObserver()

        #gameworld and its renderer
        self.mWorld = WorldModel(self.mCamera, self.mLuObs, self.mFxObs, lvl)
        self.mWorldRender = WorldRender(self.mWorld, self.mCamera)

        #add listeners
        self.mLuObs.addListener(self.mWorldRender)
        self.mFxObs.addListener(self.mWorldRender)

        #input
        self.mGame.input = Input(self, self.mWorld, self.mCamera)

    def update(self, delta):
        self.mCamera.update(delta, self.mWorld.mEntityToFollow.position, self.mWorld.level.mWidth, self.mWorld.level.mHeight)
        self.mWorld.update(delta)

        if self.mWorld.mLevelDone:
            self.mGame.setScreen(screen.LevelTimeScreen.LevelTimeScreen(self.mGame, self.mWorld.level.mCurrentLevel, Time.Time.convertToTimeObject(self.mWorld.mTimer)))

    def render(self, delta):
        self.mWorldRender.render(delta)

    def goBack(self):
        self.mWorld = None
        self.mWorldRender = None
        self.mGame.setScreen(screen.LevelScreen.LevelScreen(self.mGame))
예제 #4
0
    def __init__(self, game, lvl):
        Pgl.app.setUpdaterate(Pgl.options.updaterate)
        pygame.mouse.set_visible(False)
        SoundManager.getInstance().playMusic(random.randrange(1, SoundManager.getInstance().NUMBER_OF_SONGS + 1))

        self.mGame = game
        self.mCamera = Camera(Pgl.width, Pgl.height)

        #observer
        self.mLuObs = LevelupdateObserver()
        self.mFxObs = FXObserver()

        #gameworld and its renderer
        self.mWorld = WorldModel(self.mCamera, self.mLuObs, self.mFxObs, lvl)
        self.mWorldRender = WorldRender(self.mWorld, self.mCamera)

        #add listeners
        self.mLuObs.addListener(self.mWorldRender)
        self.mFxObs.addListener(self.mWorldRender)

        #input
        self.mGame.input = Input(self, self.mWorld, self.mCamera)
예제 #5
0
class GameModel:
    #Represents the world data.

    def __init__(self, base, mapNo):
        self.isListening = False

        # Holds rigid bodies, joints, controls global params
        self.world = OdeWorld()
        self.world.setGravity(0, 0, -9.8)

        st = SurfaceType()
        st.load(self.world)
        del st

        self.contactgroup = OdeJointGroup()

        self.space = OdeHashSpace()
        self.space.setAutoCollideWorld(self.world)
        self.space.setAutoCollideJointGroup(self.contactgroup)
        self.space.setCollisionEvent(EventType.ODE_COLLISION)
        base.accept(EventType.ODE_COLLISION, self.onCollision)

        self.ball = Ball(self.world, self.space, "Johanneksen pallo")

        self.level = Level(self, mapNo)
        self.player = Player("Johannes")

        self.camera = Camera(base, self.ball)

    def turnGravityTask(self):
        ''''''
        g = self.world.getGravity()
        g = -g
        self.world.setGravity(g)
        self.camera.turn()

    def turnGravityTask2(self):
        ''''''
        g = self.world.getGravity()
        g2 = self.ball.perpendicularUnitVec3WithFixedX(g)
        g2 *= g.length()
        self.world.setGravity(g2)

    def updateObjects(self):
        '''
		Update objects after one physics iteration
		@see GameLoop.simulationTask
		'''
        self.level.updateModelNode()
        self.camera.updateModelNode()
        #Has to be last for RESTART to work inside Ball
        self.ball.updateModelNode()

    def getBall(self):
        return self.ball

    def getPlayer(self):
        return self.player

    # http://www.panda3d.org/wiki/index.php/Collision_Detection_with_ODE
    def onCollision(self, entry):
        geom1 = entry.getGeom1()
        geom2 = entry.getGeom2()
        body1 = entry.getBody1()
        body2 = entry.getBody2()

        # Is the ball touching something?
        if body1 == self.ball.getBody() or body2 == self.ball.getBody():
            self.ball.refreshCollisionTime(entry)

        for coin in self.level.getCoins():
            if body1 == coin.getBody() and body2 == self.ball.getBody():
                coin.collect()
                messenger.send(EventType.UPDATE_HUD)

        exit = self.level.getExit()
        if geom1 == exit or geom2 == exit:
            if Coin.collectable == self.level.getGoal():
                # todo: make event based
                messenger.send(EventType.NEXT_LEVEL)

    def cleanUp(self):
        self.level.removeLevel()
        self.ball.removeNode()