예제 #1
0
 def __init__(self, x, y, maxHealth=1):
     image = Image([[Tile("["), Tile("#"), Tile("]")]])
     super().__init__(x, y, image)
     self.canFall = True
     self.canHurt = True
     self.maxHealth = maxHealth
     self.health = maxHealth
     self.pushable = True
예제 #2
0
    def __init__(self, world, text):
        self.world = world
        self.text = text
        side = (min(functools.reduce(min, list(map(len, text))), len(text)) -
                1)
        Square.__init__(self, (0, 0, self.world.SIZE * side))
        self.data = {}

        for i in range(side):
            for j in range(side):
                self.data[str((i, j))] = Tile(self.world, self.text[i][j], i,
                                              j)

        self.completeSet = frozenset(self.data.values())

        self.solidTiles = set()
        self.opaqueTiles = set()
        for tile in self[:]:
            if tile.isSolid:
                self.solidTiles.add(tile)
            if tile.isOpaque:
                self.opaqueTiles.add(tile)
        self.completeSet = frozenset(self.data.values())
        self.solidTiles = frozenset(self.solidTiles)
        self.openTiles = tuple(self.completeSet - self.solidTiles)
        self.opaqueTiles = frozenset(self.opaqueTiles)
예제 #3
0
class Dirt(Block):

    FULL = Image([[Tile("▒"), Tile("▒"), Tile("▒")]])
    HALF = Image([[Tile("░"), Tile("░"), Tile("░")]])

    def __init__(self, x, y, maxHealth=2):
        image = self.FULL
        super().__init__(x, y, image)
        self.maxHealth = maxHealth
        self.health = maxHealth
        self.destructable = True

    def __str__(self):
        return "Dirt" + "\t Health: " + str(self.health) + "/" + str(
            self.maxHealth)

    @property
    def health(self):
        return self.__health

    @health.setter
    def health(self, health):
        self.__health = health

        if (self.__health >= 2):
            self.image = self.FULL
        if (self.__health == 1):
            self.image = self.HALF
        if (self.__health <= 0):
            Game.curGame.curScene.removeGameObject(self)

    def update(self):
        super().update()
예제 #4
0
    def update(self):
        super().update()
        scene = Game.curGame.curScene

        if (isinstance(scene, levelEditor.LevelEditor)):
            self.image = Image([[Tile("|"), Tile("P"), Tile("|")]])
        else:
            self.image = Image([[Tile(" "), Tile(" "), Tile(" ")]])
예제 #5
0
 def __init__(self, x, y, maxHealth = 2):
     self.__leftImage = Image([[Tile("<"), Tile("<"), Tile("ö")]])
     self.__rightImage = Image([[Tile("ö"), Tile(">"), Tile(">")]])
     super().__init__(x, y, self.__rightImage, maxHealth)
     self.__health = maxHealth
     self.__walkTimer = 0
     self.__xVel = 3
     self.__canDig = False
     self.__canPush = False
     self.canAttack = True
     self.destructable = True
예제 #6
0
class Gold(Block):

    FULL = Image([[Tile("["), Tile("$"), Tile("]")]])
    HALF = Image([[Tile("("), Tile("$"), Tile(")")]])
    LITTLE = Image([[Tile("{"), Tile("$"), Tile("}")]])

    def __init__(self, x, y, maxHealth=3):
        image = self.FULL
        super().__init__(x, y, image)
        self.maxHealth = maxHealth
        self.health = maxHealth
        self.destructable = True

    def __str__(self):
        return "Gold" + "\t Health: " + str(self.health) + "/" + str(
            self.maxHealth)

    @property
    def health(self):
        return self.__health

    @health.setter
    def health(self, health):
        self.__health = health

        if (self.__health >= 3):
            self.image = self.FULL
        elif (self.__health == 2):
            self.image = self.HALF
        elif (self.__health == 1):
            self.image = self.LITTLE
        elif (self.__health <= 0):
            Game.curGame.curScene.addGameObject(GoldPickup(self.x, self.y))
            Game.curGame.curScene.removeGameObject(self)

    def update(self):
        super().update()
예제 #7
0
 def setTile(self, pos: Pos, tType: TileType):
     self.tiles[pos] = Tile(pos, tType)
예제 #8
0
 def fullFuseTime(self, fullFuseTime):
     self.__fullFuseTime = fullFuseTime
     self.__curFuseTime = self.__fullFuseTime
     self.full = Image([[Tile("["), Tile(str(fullFuseTime)), Tile("]")]])
     self.image = self.full
예제 #9
0
class Bomb(Block):

    full = Image([[Tile("["), Tile("3"), Tile("]")]])
    HALF = Image([[Tile("["), Tile("!"), Tile("]")]])
    THREE = Image([[Tile("["), Tile("3"), Tile("]")]])
    TWO = Image([[Tile("["), Tile("2"), Tile("]")]])
    ONE = Image([[Tile("["), Tile("1"), Tile("]")]])

    def __init__(self, x, y, maxHealth=2):
        self.__fullFuseTime = 3
        self.__curFuseTime = self.__fullFuseTime
        self.__fuseLit = False
        image = self.full
        super().__init__(x, y, image)
        self.maxHealth = maxHealth
        self.health = maxHealth
        self.destructable = True
        self.canHurt = True

    def __str__(self):
        out = "Bomb"
        out += "   (+│-)Health: " + str(self.health) + "/" + str(
            self.maxHealth)
        out += "   (*│/)Fuse Time: " + str(self.fullFuseTime)
        return out

    @property
    def health(self):
        return self.__health

    @health.setter
    def health(self, health):
        self.__health = health

        if (self.__health >= 2):
            self.image = self.full
            self.canFall = False
        elif (self.__health == 1):
            self.image = self.HALF
            self.canFall = True
        elif (self.__health <= 0):
            self.__fuseLit = True
            self.canFall = True
            self.pushable = True

    @property
    def fullFuseTime(self):
        return self.__fullFuseTime

    @fullFuseTime.setter
    def fullFuseTime(self, fullFuseTime):
        self.__fullFuseTime = fullFuseTime
        self.__curFuseTime = self.__fullFuseTime
        self.full = Image([[Tile("["), Tile(str(fullFuseTime)), Tile("]")]])
        self.image = self.full

    def update(self):
        super().update()

        if self.__fuseLit:
            self.__curFuseTime -= Game.curGame.deltaTime

            if self.__curFuseTime >= self.__fullFuseTime * 0.66:
                self.image = self.THREE
            elif self.__curFuseTime >= self.__fullFuseTime * 0.33:
                self.image = self.TWO
            elif self.__curFuseTime >= 0:
                self.image = self.ONE
            else:
                self.blowUp()

    def blowUp(self):
        scene = Game.curGame.curScene
        """
        blockWidth = 3
        blockHeight = 1
        for x in range(self.x - (blockWidth*2), self.x + (blockWidth*3), blockWidth):
            for y in range(self.y - (blockHeight*2), self.y + (blockHeight*3), blockHeight):
                if not ( x == self.x and y == self.y ):
                    gameObjects = scene.getGameObjectsAtPos(x, y)
                    for gO in gameObjects:
                        if gO.destructable:
                            if ( abs(self.x - x) <= blockWidth and abs(self.y - y) <= blockHeight ):
                                gO.health -= 2
                            else:
                                gO.health -= 1

                smoke = Smoke(x, y)
                scene.addGameObject(smoke ,2)
        """
        self.blastDiagonal(1, 1)
        self.blastDiagonal(-1, 1)
        self.blastDiagonal(1, -1)
        self.blastDiagonal(-1, -1)
        self.blastAdjacentX(-1)
        self.blastAdjacentX(1)
        self.blastAdjacentY(1)
        self.blastAdjacentY(-1)

        self.addSmoke(self.x, self.y)

        scene.removeGameObject(self)

    def blastAdjacentX(self, signX):
        scene = Game.curGame.curScene
        x = self.x
        y = self.y
        blockWidth = 3
        blockHeight = 1

        wall = False
        gameObjects = scene.getGameObjectsAtPos(x + (blockWidth * signX), y)
        for gO in gameObjects:
            self.doDamage(gO)
            if isinstance(gO, Wall):
                wall = True

        if not wall:
            self.addSmoke(x + (blockWidth * signX), y)

            wall = False
            gameObjects = scene.getGameObjectsAtPos(
                x + (blockWidth * 2 * signX), y)
            for gO in gameObjects:
                self.doDamage(gO)
                if isinstance(gO, Wall):
                    wall = True
            if not wall:
                self.addSmoke(x + (blockWidth * 2 * signX), y)

    def blastAdjacentY(self, signY):
        scene = Game.curGame.curScene
        x = self.x
        y = self.y
        blockWidth = 3
        blockHeight = 1

        wall = False
        gameObjects = scene.getGameObjectsAtPos(x, y + (blockHeight * signY))
        for gO in gameObjects:
            self.doDamage(gO)
            if isinstance(gO, Wall):
                wall = True

        if not wall:
            self.addSmoke(x, y + (blockHeight * signY))

            wall = False
            gameObjects = scene.getGameObjectsAtPos(
                x, y + (blockHeight * 2 * signY))
            for gO in gameObjects:
                self.doDamage(gO)
                if isinstance(gO, Wall):
                    wall = True
            if not wall:
                self.addSmoke(x, y + (blockHeight * 2 * signY))

    def blastDiagonal(self, signX, signY):
        scene = Game.curGame.curScene
        x = self.x
        y = self.y
        blockWidth = 3
        blockHeight = 1

        wall = False
        gameObjects = scene.getGameObjectsAtPos(x + (blockWidth * signX),
                                                y + (blockHeight * signY))
        for gO in gameObjects:
            self.doDamage(gO)
            if isinstance(gO, Wall):
                wall = True

        if not wall:
            self.addSmoke(x + (blockWidth * signX), y + (blockHeight * signY))

            wall = False
            gameObjects = scene.getGameObjectsAtPos(
                x + (blockWidth * 2 * signX), y + (blockHeight * signY))
            for gO in gameObjects:
                self.doDamage(gO)
                if isinstance(gO, Wall):
                    wall = True
            if not wall:
                self.addSmoke(x + (blockWidth * 2 * signX),
                              y + (blockHeight * signY))

            wall = False
            gameObjects = scene.getGameObjectsAtPos(
                x + (blockWidth * 2 * signX), y + (blockHeight * 2 * signY))
            for gO in gameObjects:
                self.doDamage(gO)
                if isinstance(gO, Wall):
                    wall = True
            if not wall:
                self.addSmoke(x + (blockWidth * 2 * signX),
                              y + (blockHeight * 2 * signY))

            wall = False
            gameObjects = scene.getGameObjectsAtPos(
                x + (blockWidth * signX), y + (blockHeight * 2 * signY))
            for gO in gameObjects:
                self.doDamage(gO)
                if isinstance(gO, Wall):
                    wall = True
            if not wall:
                self.addSmoke(x + (blockWidth * signX),
                              y + (blockHeight * 2 * signY))

    def doDamage(self, gO):
        blockWidth = 3
        blockHeight = 1
        if gO.destructable:
            if (abs(self.x - gO.x) <= blockWidth
                    and abs(self.y - gO.y) <= blockHeight):
                gO.health -= 2
            else:
                gO.health -= 1

    def addSmoke(self, x, y):
        scene = Game.curGame.curScene
        smoke = Smoke(x, y)
        scene.addGameObject(smoke, 3)
예제 #10
0
 def __init__(self, x, y):
     image = Image([[Tile(" "), Tile("+"), Tile(" ")]])
     super().__init__(x, y, image)
     self.collision = False
     self.canFall = True
예제 #11
0
 def __init__(self, x, y):
     image = Image([[Tile(" "), Tile(" "), Tile(" ")]])
     super().__init__(x, y, image)
예제 #12
0
 def updateImage(self):
     if self.canPush:
         self.__leftImage = Image([[Tile("╠"), Tile("═"), Tile("Ö")]])
         self.__rightImage = Image([[Tile("Ö"), Tile("═"), Tile("╣")]])
     elif self.canDig:
         self.__leftImage = Image([[Tile("«"), Tile("«"), Tile("ö")]])
         self.__rightImage = Image([[Tile("ö"), Tile("»"), Tile("»")]])
     else:
         self.__leftImage = Image([[Tile("<"), Tile("<"), Tile("ö")]])
         self.__rightImage = Image([[Tile("ö"), Tile(">"), Tile(">")]])
     if(self.__xVel > 0):
         self.image = self.__rightImage
     elif(self.__xVel < 0):
         self.image = self.__leftImage
예제 #13
0
class Player(Character):

    xVel = 3
    yVel = 1

    NORAML_IMAGE = Image([[Tile("-"), Tile("O"), Tile("-")]])
    FALLING_IMAGE = Image([[Tile("~"), Tile("O"), Tile("~")]])

    def __init__(self, x, y, maxHealth = 3):
        super().__init__(x, y, self.NORAML_IMAGE, maxHealth)
        self.__health = maxHealth
        self.__gold = 0
        self.__level = 1
        self.__falling = False
        self.canAttack = True
        self.destructable = True

    @property
    def health(self):
        return self.__health

    @health.setter
    def health(self, health):
        self.__health = health

        if self.health <= 0:
            self.lose()

    @property
    def gold(self):
        return self.__gold

    @gold.setter
    def gold(self, gold):
        self.__gold = gold

    @property
    def level(self):
        return self.__level

    @level.setter
    def level(self, level):
        self.__level = level

    @property
    def falling(self):
        return self.__falling

    @falling.setter
    def falling(self, falling):
        self.__falling = falling

        if self.falling:
            self.image = self.FALLING_IMAGE
        else:
            self.image = self.NORAML_IMAGE

    def update(self):
        super().update()

        kb = Game.curGame.keyboard

        self.updateFalling()

        if(kb.keyPressed( KeyCode.SPACEBAR )):
            self.jump()
        elif(kb.keyPressed( KeyCode.w )):
            self.hitAboveBlock()
            self.jump()
        elif(kb.keyPressed( KeyCode.s )):
            self.move(0,self.yVel)
        elif(kb.keyPressed( KeyCode.a )):
            self.move(-self.xVel,0)
        elif(kb.keyPressed( KeyCode.d )):
            self.move(self.xVel,0)
        elif(kb.keyPressed( KeyCode.h )):
            self.health += 1

    def hitAboveBlock(self):
        scene = Game.curGame.curScene

        gameObjects = scene.getGameObjectsAtPos(self.x, self.y - 1)
        for gO in gameObjects:
            if gO.destructable:
                gO.health -= 1

    def move(self, x, y):
        super().move(x, y)
        scene = Game.curGame.curScene

        gameArea = scene.gameArea

        x = clamp( self.x + x, gameArea.x, gameArea.width + 1 )
        y = clamp( self.y + y, gameArea.y, gameArea.height + 1)

        canMove = True
        gameObjects = scene.getGameObjectsAtPos(x, y)
        for gO in gameObjects:
            if(gO.collision):
                canMove = False

            if gO.destructable:
                gO.health -= 1

            if(isinstance(gO, blocks.Dirt)):
                pass
            elif(isinstance(gO, blocks.Stone)):
                self.tryToPush(gO)
            elif(isinstance(gO, blocks.Gold)):
                pass
            elif(isinstance(gO, blocks.Wall)):
                pass
            elif(isinstance(gO, blocks.Door)):
                if ( self.level == level.Level.MAX_LEVEL ):
                    self.win()
                else:
                    self.goToNextLevel()
            elif(isinstance(gO, blocks.GoldPickup)):
                scene.removeGameObject(gO)
                self.gold +=1
            elif(isinstance(gO, blocks.HealthPickup)):
                scene.removeGameObject(gO)
                self.health += 1
            elif(isinstance(gO, Enemy)):
                pass
            elif(isinstance(gO, blocks.Bomb)):
                self.tryToPush(gO)

        if(canMove):
            self.x = x
            self.y = y

    def goToNextLevel(self):
        import pickle, shelve, menu
        s = shelve.open(menu.Menu.LEVEL_FILE)

        self.level += 1

        try:
            data = s["level_0" + str(self.__level)]
            l = level.Level()
            l.gameObjects = data
        except:
            l = level.Level()
            l.generateMap()

        l.player = self

        s.close()

        Game.curGame.loadScene(l)

    def win(self):
        import os
        os.system('cls')
        print("""

        __   __           __        ___
        \ \ / /__  _   _  \ \      / (_)_ __
         \ V / _ \| | | |  \ \ /\ / /| | '_ \\
          | | (_) | |_| |   \ V  V / | | | | |
          |_|\___/ \__,_|    \_/\_/  |_|_| |_|

        """)

        print("         ------------------------------------------------------")
        print(" Final Gold: " + str(self.gold))
        input(" Press enter to quit to main menu")

        Game.curGame.curScene.removeGameObjectsByType(DebugDisplay)
        Game.curGame.loadScene(menu.MainMenu())

        Game.curGame.curScene.removeGameObject(self)

    def lose(self):
        import os
        os.system('cls')
        print("""

         _____                        _____
        |  __ \                      |  _  |
        | |  \/ __ _ _ __ ___   ___  | | | |_   _____ _ __
        | | __ / _` | '_ ` _ \ / _ \ | | | \ \ / / _ \ '__|
        | |_\ \ (_| | | | | | |  __/ \ \_/ /\ V /  __/ |
         \____/\__,_|_| |_| |_|\___|  \___/  \_/ \___|_|

        """)

        print("         ------------------------------------------------------")
        print("                     You were killed by the enemy.")
        input(" Press enter to quit to main menu")

        Game.curGame.curScene.removeGameObjectsByType(DebugDisplay)
        Game.curGame.loadScene(menu.MainMenu())

        Game.curGame.curScene.removeGameObject(self)
예제 #14
0
 def __init__(self, width, height):
     self.__width = width
     self.__height = height
     self.__buffer = [[ Tile(" ") for _ in range(width)] for _ in range(height)]
예제 #15
0
 def clear(self):
     self.__buffer = [[ Tile( " " ) for _ in range(self.__width)] for _ in range(self.__height)]