Exemplo n.º 1
0
 def __createScoreboard(self, location):
   SCOREBOARD_DIMENSIONS = [500, 30]
   entSidewalk = StaticEntity(location, SCOREBOARD_DIMENSIONS, COLOR_WHITE)
   entSidewalk.setGameScreen(self.Surface)
   return entSidewalk    
Exemplo n.º 2
0
    def init(self):
        # Get some constants which we will need later
        self.GameConfig = IniParser("engine.ini")
        intDisplayWidth = int(self.GameConfig.get("EngineCore", "displayWidth"))
        intDisplayHeight = int(self.GameConfig.get("EngineCore", "displayHeight"))

        self.gameWidth = intDisplayWidth
        self.gameHeight = intDisplayHeight

        # a List containing all the safe frogs
        self.safeFrogs = []

        # Cheat sequence
        self.cheatCharInput = []

        # Init the main display engine
        self.engDisplay = DisplayEngine((intDisplayWidth, intDisplayHeight))

        defaultEntityFactory = EntityFactory(self.DisplayEngine)

        listStaticBackgroundEntities = defaultEntityFactory.buildBackground()

        self.engCollision = CollisionEngine(self)
        self.entLifeCounter = defaultEntityFactory.buildLifeCounter()

        entFrog = defaultEntityFactory.buildFrog()
        entFrog.draw()

        # Create the Animated Cars
        entCar1 = defaultEntityFactory.buildCar([20, 189], uniform(2, 7), generateRandomColor())
        entCar2 = defaultEntityFactory.buildCar([20, 219], uniform(2, 7), generateRandomColor())
        entCar3 = defaultEntityFactory.buildCar([20, 249], uniform(2, 7), generateRandomColor())
        entCar4 = defaultEntityFactory.buildCar([20, 279], uniform(2, 7), generateRandomColor())
        entCar5 = defaultEntityFactory.buildCar([20, 309], uniform(2, 7), generateRandomColor())

        # Create an animated Log
        listLastLogCoordinates = [1, 70]
        intLastLogSpeed = 3

        entLastLog = LogEntity(listLastLogCoordinates, intLastLogSpeed, LogEntity.LEFT_TO_RIGHT)
        entLastLog.setGameScreen(self.DisplayEngine)
        contLastLogAnimation = LogController(entLastLog)
        entLastLog.setController(contLastLogAnimation)

        listSecondLogCoordinates = [485, 100]
        intSecondLogSpeed = 2

        entSecondLog = LogEntity(listSecondLogCoordinates, intSecondLogSpeed, LogEntity.RIGHT_TO_LEFT)
        entSecondLog.setGameScreen(self.DisplayEngine)
        contSecondLogAnimation = LogController(entSecondLog)
        entSecondLog.setController(contSecondLogAnimation)

        listFirstLogCoordinates = [1, 130]
        intFirstLogSpeed = 1

        entFirstLog = LogEntity(listFirstLogCoordinates, intFirstLogSpeed, LogEntity.LEFT_TO_RIGHT)
        entFirstLog.setGameScreen(self.DisplayEngine)
        contFirstLogAnimation = LogController(entFirstLog)
        entFirstLog.setController(contFirstLogAnimation)

        # Create the Large Hazard Zone
        listHazardZones = []
        LARGE_HAZARD_LOCATION = [18, 65]
        LARGE_HAZARD_DIMENSIONS = [464, 95]
        entLargeHazardZone = HazardEntity(LARGE_HAZARD_LOCATION, LARGE_HAZARD_DIMENSIONS, COLOR_NAVY_BLUE)
        entLargeHazardZone.setGameScreen(self.DisplayEngine)
        listHazardZones.append(entLargeHazardZone)

        # Create the Smaller Intermediate Hazard Zones
        HAZARD_ZONEA_LOCATION = [80, 30]
        HAZARD_ZONEA_DIMENSIONS = [70, 30]
        entHazardZoneA = HazardEntity(HAZARD_ZONEA_LOCATION, HAZARD_ZONEA_DIMENSIONS, COLOR_BACKGROUND_GREEN)
        entHazardZoneA.setGameScreen(self.DisplayEngine)
        listHazardZones.append(entHazardZoneA)

        HAZARD_ZONEB_LOCATION = [210, 30]
        HAZARD_ZONEB_DIMENSIONS = [90, 30]
        entHazardZoneB = HazardEntity(HAZARD_ZONEB_LOCATION, HAZARD_ZONEB_DIMENSIONS, COLOR_BACKGROUND_GREEN)
        entHazardZoneB.setGameScreen(self.DisplayEngine)
        listHazardZones.append(entHazardZoneB)

        HAZARD_ZONEC_LOCATION = [360, 30]
        HAZARD_ZONEC_DIMENSIONS = [70, 30]
        entHazardZoneC = HazardEntity(HAZARD_ZONEC_LOCATION, HAZARD_ZONEC_DIMENSIONS, COLOR_BACKGROUND_GREEN)
        entHazardZoneC.setGameScreen(self.DisplayEngine)
        listHazardZones.append(entHazardZoneC)

        # Create the SafeZones
        listSafeZones = []
        SAFE_ZONEA_LOCATION = [20, 30]
        SAFE_ZONEA_DIMENSIONS = [60, 30]
        entSafeZoneA = SafeZoneEntity(SAFE_ZONEA_LOCATION, SAFE_ZONEA_DIMENSIONS, COLOR_WHITE)
        entSafeZoneA.setGameScreen(self.DisplayEngine)
        listSafeZones.append(entSafeZoneA)

        SAFE_ZONEB_LOCATION = [150, 30]
        SAFE_ZONEB_DIMENSIONS = [60, 30]
        entSafeZoneB = SafeZoneEntity(SAFE_ZONEB_LOCATION, SAFE_ZONEB_DIMENSIONS, COLOR_WHITE)
        entSafeZoneB.setGameScreen(self.DisplayEngine)
        listSafeZones.append(entSafeZoneB)

        SAFE_ZONEC_LOCATION = [300, 30]
        SAFE_ZONEC_DIMENSIONS = [60, 30]
        entSafeZoneC = SafeZoneEntity(SAFE_ZONEC_LOCATION, SAFE_ZONEC_DIMENSIONS, COLOR_WHITE)
        entSafeZoneC.setGameScreen(self.DisplayEngine)
        listSafeZones.append(entSafeZoneC)

        SAFE_ZONED_LOCATION = [430, 30]
        SAFE_ZONED_DIMENSIONS = [52, 30]
        entSafeZoneD = SafeZoneEntity(SAFE_ZONED_LOCATION, SAFE_ZONED_DIMENSIONS, COLOR_WHITE)
        entSafeZoneD.setGameScreen(self.DisplayEngine)
        listSafeZones.append(entSafeZoneD)

        # The GameEngine should be aware of how many safe zones we have total
        self.listSafeZones = listSafeZones

        # Add the Hazard Boundary Borders
        listHazardBoundaryBorders = []
        LEFT_HAZARD_BOUNDARY_LOCATION = [0, 30]
        LEFT_HAZARD_BOUNDARY_DIMENSIONS = [19, 130]
        entLeftHazardBoundary = StaticEntity(
            LEFT_HAZARD_BOUNDARY_LOCATION, LEFT_HAZARD_BOUNDARY_DIMENSIONS, COLOR_BACKGROUND_GREEN
        )
        entLeftHazardBoundary.setGameScreen(self.DisplayEngine.Surface)
        listHazardBoundaryBorders.append(entLeftHazardBoundary)

        RIGHT_HAZARD_BOUNDARY_LOCATION = [482, 30]
        RIGHT_HAZARD_BOUNDARY_DIMENSIONS = [19, 130]
        entRightHazardBoundary = StaticEntity(
            RIGHT_HAZARD_BOUNDARY_LOCATION, RIGHT_HAZARD_BOUNDARY_DIMENSIONS, COLOR_BACKGROUND_GREEN
        )
        entRightHazardBoundary.setGameScreen(self.DisplayEngine.Surface)
        listHazardBoundaryBorders.append(entRightHazardBoundary)

        # Anything that can collide with the frog should be appended here
        listCollisionEntities = [entCar1, entCar2, entCar3, entCar4, entCar5]
        listCollisionEntities.append(entFirstLog)
        listCollisionEntities.append(entSecondLog)
        listCollisionEntities.append(entLastLog)

        for hazardZone in listHazardZones:
            listCollisionEntities.append(hazardZone)

        for safeZone in listSafeZones:
            listCollisionEntities.append(safeZone)

        # Add a Background Entities to the Game Layer
        self.DisplayEngine.addLayer(listStaticBackgroundEntities)

        # Add the HazardZones to the Game Layer
        self.DisplayEngine.addLayer(listHazardZones)

        # Add the SafeZones to the Game Layer
        self.DisplayEngine.addLayer(listSafeZones)

        # Add the logs to the Game Layer
        self.DisplayEngine.addLayer(entFirstLog)
        self.DisplayEngine.addLayer(entSecondLog)
        self.DisplayEngine.addLayer(entLastLog)

        # Add the Hazard Boundary Borders

        self.DisplayEngine.addLayer(listHazardBoundaryBorders)

        # Add the universal game controller
        UniversalGameController = GameController(self)
        self.DisplayEngine.addUserControlledLayer(entFrog)
        self.DisplayEngine.addGameController(UniversalGameController)

        self.DisplayEngine.addLayer(entCar1)
        self.DisplayEngine.addLayer(entCar2)
        self.DisplayEngine.addLayer(entCar3)
        self.DisplayEngine.addLayer(entCar4)
        self.DisplayEngine.addLayer(entCar5)

        TitleText = Text(FONT_BLOX, "PyFrogger", COLOR_FROG_GREEN, 20)
        TitleText.setGameScreen(self.DisplayEngine.Surface)
        TitleText.draw((400, 4))

        LivesText = Text(FONT_BLOX, "Lives ", COLOR_FROG_GREEN, 20)
        LivesText.setGameScreen(self.DisplayEngine.Surface)
        LivesText.draw((10, 4))

        LivesCounterText = Text(FONT_BLOX, "3", COLOR_FROG_RED, 20)
        LivesCounterText.setGameScreen(self.DisplayEngine.Surface)
        LivesCounterText.draw((70, 4))

        self.entLifeCounter.setLifeTextEntity(LivesCounterText)

        entText = [TitleText, LivesText, LivesCounterText]
        self.DisplayEngine.addLayer(entText)

        self.CollisionEngine.setPlayerLifeCounter(self.entLifeCounter)

        # Adding these entities into the collision engine will let the engine monitor
        # their position and on the action of a rectangle collision, the controlled
        # entity will be handled based on it's collision based methods
        self.CollisionEngine.setControlledEntity(entFrog)
        for collisionEntity in listCollisionEntities:
            self.CollisionEngine.addCollisionEntity(collisionEntity)

        # This variable keeps the run active
        self.running = True
        self.freezeState = False
Exemplo n.º 3
0
 def __createSidewalk(self, location):
   SIDEWALK_DIMENSIONS = [464, 25]
   entSidewalk = StaticEntity(location, SIDEWALK_DIMENSIONS, COLOR_PALE_YELLOW)
   entSidewalk.setGameScreen(self.Surface)
   return entSidewalk    
Exemplo n.º 4
0
 def __createDivider(self, location, dimensions=[70, 30]):
   entSafeZoneDivider = StaticEntity(location, dimensions, COLOR_BACKGROUND_GREEN)
   entSafeZoneDivider.setGameScreen(self.Surface)
   return entSafeZoneDivider
Exemplo n.º 5
0
 def __createWater(self):
   WATER_LOCATION   = [18, 35]
   WATER_DIMENSIONS = [464, 150]
   entWater = StaticEntity(WATER_LOCATION, WATER_DIMENSIONS, COLOR_NAVY_BLUE)
   entWater.setGameScreen(self.Surface)
   return entWater
Exemplo n.º 6
0
 def __createStreet(self):
   STREET_LOCATION   = [18, 150]
   STREET_DIMENSIONS = [464, 210]
   entStreet = StaticEntity(STREET_LOCATION, STREET_DIMENSIONS, COLOR_BLACK)
   entStreet.setGameScreen(self.Surface)
   return entStreet
Exemplo n.º 7
0
 def __createBackground(self):
   BACKGROUND_LOCATION   = [0, 30]
   BACKGROUND_DIMENSIONS = [500, 400]
   entBackGround         = StaticEntity(BACKGROUND_LOCATION, BACKGROUND_DIMENSIONS, COLOR_BACKGROUND_GREEN)
   entBackGround.setGameScreen(self.Surface)
   return entBackGround