Beispiel #1
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()
Beispiel #2
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(" ")]])
Beispiel #3
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
Beispiel #4
0
    def load(self):
        super().load()

        self.drawBoarder()

        self.addGameObject(
            GameObject(self.__titleX, self.__titleY,
                       Image.stringToImage(self.title)))

        if not (isinstance(self, MainMenu)):
            message = "Press ESC to return"
            x = Game.curGame.width - len(message) - 1
            y = Game.curGame.height - 1
            self.addGameObject(GameObject(x, y, Image.stringToImage(message)))
Beispiel #5
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
Beispiel #6
0
    def __init__(self, *options):

        self.__options = options
        self.__activeOption = 0
        self.__focusedOn = True

        image = self.generateCurrentImage()
        image = Image.stringToImage(image)

        super().__init__(18, 15, image)

        self.canPause = False
Beispiel #7
0
    def update(self):
        kb = Game.curGame.keyboard

        if (kb.keyPressed(KeyCode.w)):
            self.__activeOption -= 1
        elif (kb.keyPressed(KeyCode.s)):
            self.__activeOption += 1

        self.__activeOption = clamp(self.__activeOption, 0,
                                    len(self.__options))

        image = self.generateCurrentImage()
        self.image = Image.stringToImage(image)
Beispiel #8
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()
Beispiel #9
0
    def update(self):
        scene = Game.curGame.curScene

        player = scene.player

        image = ""

        if isinstance(scene, level.Level):
            image += "Health: " + str(player.health) + "/" + str(
                player.maxHealth)
            image += " │ Gold: " + str(player.gold) + " │ Level: " + str(
                player.level) + "/" + str(level.Level.MAX_LEVEL)
            image += "\n\n"

            image += "Controls:  W(Up/Jump) │ A(Left)    │ S(Down)    │ D(Right)" + "\n"
            image += "Enemies:   Basic <<Ö  │ Pusher ╠═Ö │ Digger ««ö │" + "\n"
            image += "Blocks:    Dirt  ▒▒▒  │ Gold   [$] │ Stone  [#] │ Bomb  [3]" + "\n"
            image += "Pick ups:  Gold   $   │ Health  +  │ Press ESC for Pause/Menu" + "\n"
            image += "Instructions: Find your way to the exit while collecting gold" + "\n"
            image += "              Moving onto blocks and enemies deals damage" + "\n"

        if isinstance(scene, levelEditor.LevelEditor):

            gameObjects = scene.getGameObjectsAtPos(player.x, player.y)

            gameObject = None
            for gO in gameObjects:
                if gO != player and not isinstance(gO, blocks.EditMarker):
                    gameObject = gO

            if isinstance(gameObject, characters.Enemy):
                pass
            elif isinstance(gameObject, blocks.Block):
                pass

            if gameObject:
                image += str(gameObject)

            image += "\n"
            image += "    Controls:" + "\n"
            image += "    W) (Up)   │ A) (Left)  │ S) (Down) │ D) (Right)" + "\n"
            image += "    0) Delete │ .) [3]     │ ENTER) Explode Bomb " + "\n"
            image += "    1) ███    │ 2) ▒▒▒     │ 3) [#] " + "\n"
            image += "    4) [$]    │ 5)  $      │ 6)  +  " + "\n"
            image += "    7) [P]    │ 8) [D]     │ 9) ö>>    │ Press ESC for Pause/Menu" + "\n"
            image += "Move around and place blocks to make your own custom level"

        self.image = Image.stringToImage(image)
Beispiel #10
0
    def update(self):

        scene = Game.curGame.curScene
        dt = Game.curGame.deltaTime

        #if(isinstance(scene, level.Level)):
        player = scene.player

        image = ""
        image += "Player: (" + str(player.x) + ", " + str(
            player.y) + ") " + "\n"
        image += "Delta Time: " + str(dt) + "\n"
        image += "Game Objects: " + str(scene.len()) + "\n"
        image += "Player isFalling: " + str(player.falling) + "\n"

        self.image = Image.stringToImage(image)
Beispiel #11
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
Beispiel #12
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)
Beispiel #13
0
 def __init__(self, x, y, image=([[]]), collision=False):
     super().__init__(x, y, Image([[]]), collision)
Beispiel #14
0
 def __init__(self, x, y, health=2):
     image = Image.stringToImage("▓▓▓")
     super().__init__(x, y, image)
     self.health = 2
     self.collision = False
Beispiel #15
0
 def fullFuseTime(self, fullFuseTime):
     self.__fullFuseTime = fullFuseTime
     self.__curFuseTime = self.__fullFuseTime
     self.full = Image([[Tile("["), Tile(str(fullFuseTime)), Tile("]")]])
     self.image = self.full
Beispiel #16
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)
Beispiel #17
0
 def __init__(self, x, y):
     image = Image.stringToImage(" *")
     super().__init__(x, y, image)
Beispiel #18
0
 def __init__(self, x, y):
     image = Image([[Tile(" "), Tile("+"), Tile(" ")]])
     super().__init__(x, y, image)
     self.collision = False
     self.canFall = True
Beispiel #19
0
 def __init__(self, x, y):
     image = Image([[Tile(" "), Tile(" "), Tile(" ")]])
     super().__init__(x, y, image)
Beispiel #20
0
 def __init__(self, x, y, health = 10):
     image = Image.stringToImage("{")
     super().__init__(x, y, image, health)
Beispiel #21
0
 def addShape(self, x, y, char):
     image = Image.stringToImage(char)
     gO = GameObject(x, y, image)
     self.addGameObject(gO, 2)
Beispiel #22
0
 def __init__(self, x, y):
     super().__init__(x, y)
     self.image = Image.stringToImage("=>")
Beispiel #23
0
 def __init__(self, x, y, text):
     super().__init__(x, y)
     self.__text = text
     self.image = Image.stringToImage(text)
Beispiel #24
0
 def updateImage(self):
     self.image = Image.stringToImage("Name  :" + self.__text)