Exemple #1
0
 def draw(self, surface):
     for x in range(self.width):
         for y in range(self.height):
             pos = Pos(x, y)
             self.tiles[pos].draw(surface)
             if self.actors[pos]:
                 self.actors[pos].draw(surface)
Exemple #2
0
 def generate(self) -> Stage:
     self.fill(Tiles.wall)
     for y in range(1, self.stage.height - 1):
         for x in range(1, self.stage.width - 1):
             p = Pos(x, y)
             self.stage.setTile(p, Tiles.floor)
     return self.stage
Exemple #3
0
 def refresh(self, pos):
     for tile in self.fovCache:
         self.stage.setVisible(Pos(tile[0], tile[1]), False)
     self.fovCache.clear()
     for i in range(0, 360):
         x = math.cos(float(i * 0.01745))
         y = math.sin(float(i * 0.01745))
         self.calcFov(pos, x, y)
Exemple #4
0
 def calcFov(self, pos, x, y):
     ox = float(pos.x + 0.5)
     oy = float(pos.y + 0.5)
     if self.radius == -1:
         while True:
             p = Pos(int(ox), int(oy))
             self.fovCache.add((p.x, p.y))
             self.stage.setVisible(p, True)
             if not self.stage.getTile(p).walkable:
                 return
             ox += x
             oy += y
     else:
         for i in range(self.radius):
             p = Pos(int(ox), int(oy))
             self.fovCache.add((p.x, p.y))
             self.stage.setVisible(p, True)
             if not self.stage.getTile(p).walkable:
                 return
             ox += x
             oy += y
Exemple #5
0
 def cleanUpStage(self):
     if self.smoothEdges:
         for i in range(3):
             for x in range(1, self.width - 1):
                 for y in range(1, self.height - 1):
                     pos = Pos(x, y)
                     if (self.stage.getTile(pos) == Tiles.wall
                             and self.getAdjWalls(pos) <= self.smoothing):
                         self.stage.setTile(pos, Tiles.floor)
                     if (self.stage.getTile(pos) == Tiles.floor
                             and self.getAdjWalls(pos) >= self.filling):
                         self.stage.setTile(pos, Tiles.wall)
Exemple #6
0
    def connect(self, room1: Room, room2: Room):
        drunkard = room2.getCenter()
        goal = room1.getCenter()
        while not (room1.x <= drunkard.x <=
                   room1.x2) or not (room1.y <= drunkard.y <= room1.y2):
            north = 1.0
            south = 1.0
            east = 1.0
            west = 1.0

            weight = 1

            if drunkard.x < goal.x:
                east += weight
            elif drunkard.x > goal.x:
                west += weight

            if drunkard.y < goal.y:
                south += weight
            elif drunkard.y > goal.y:
                north += weight

            total = north + south + east + west
            north /= total
            south /= total
            east /= total
            west /= total

            choice = random.random()
            d = Pos(0, 0)
            if 0 <= choice < north:
                d = Directions.N
            elif north <= choice < (north + south):
                d = Directions.S
            elif (north + south) <= choice < (north + south + east):
                d = Directions.E
            else:
                d = Directions.W

            if (0 < drunkard.x + d.x < self.width - 1) and (
                    0 < drunkard.y + d.y < self.height - 1):
                drunkard += d
                if self.stage.getTile(drunkard) == Tiles.wall:
                    self.stage.setTile(drunkard, Tiles.floor)
Exemple #7
0
    def __init__(self, engine):
        self.engine = engine
        self.surf = pg.Surface((self.engine.winHeight * 1.33, self.engine.winHeight))
        self.gameOver = False

        self.currentActor = 0
        self.currentDepth = 1

        self.player = Hero(Pos(1, 1))
        self.player.isVisible = True

        self.actors = [self.player]
        self.stageGenerator = DungeonGenerator(self)
        self.stage = self.stageGenerator.generate()

        self.mobSpawner = MobSpawner(self, self.stage)
        self.mobSpawner.populateStage()

        self.player.setPos(self.stage.getSpawnPosition())
        self.stage.addActor(self.player)
        self.stage.refreshFov(self.player.pos)
Exemple #8
0
 def __init__(self, symbol, color):
     super().__init__(symbol, color, Pos(0, 0))
Exemple #9
0
 def getCenter(self) -> Pos:
     centerx = (self.x + self.x2) // 2
     centery = (self.y + self.y2) // 2
     return Pos(centerx, centery)
Exemple #10
0
 def fill(self, tType):
     for x in range(self.stage.width):
         for y in range(self.stage.height):
             p = Pos(x, y)
             self.stage.setTile(p, tType)
Exemple #11
0
 def fillSpawnPositions(self):
     for x in range(self.width):
         for y in range(self.height):
             pos = Pos(x, y)
             if self.getTile(pos).walkable:
                 self.spawnPositions.append(pos)
Exemple #12
0
 def createRoom(self, room: Room):
     self.rooms.add(room)
     for x in range(room.x + 1, room.x2):
         for y in range(room.y + 1, room.y2):
             pos = Pos(x, y)
             self.stage.setTile(pos, Tiles.floor)