示例#1
0
 def update(self, playerPosition):
     self.position = playerPosition
     self.rect = Rectangle(
         Vec2(self.position.x - math.floor(self.width / 2),
              self.position.y + math.floor(self.height / 2)),
         Vec2(self.position.x + math.floor(self.width / 2),
              self.position.y - math.floor(self.height / 2)))
示例#2
0
 def __init__(self, x, y, width, height):
     self.position = Vec2(x, y)
     self.width = width
     self.height = height
     self.borderCharacter = "/"
     self.rect = Rectangle(
         Vec2(self.position.x - math.floor(self.width / 2),
              self.position.y + math.floor(self.height / 2)),
         Vec2(self.position.x + math.floor(self.width / 2),
              self.position.y - math.floor(self.height / 2)))
示例#3
0
 def __init__(self, data, pos: Vec2, _id):
     self.width = len(data[0])
     self.height = len(data)
     self.overlay = []
     self.data = self._generateMapData(data)
     self.uniqueRoomID = _id
     self.position = pos
     self.rect = Rectangle(
         Vec2(self.position.x, self.position.y + self.height),
         Vec2(self.position.x + self.width, self.position.y))
     self._isColliding = False
示例#4
0
 def GetRandomPointInCircle(self, radius) -> Vec2:
     t = 2 * math.pi * random.random()
     u = random.random() + random.random()
     r = 0
     if u > 1:
         r = 2 - u
     else:
         r = u
     return Vec2(round(radius * r * math.cos(t)),
                 round(radius * r * math.sin(t)))
示例#5
0
 def GenerateLevel(self, roomCap, minMainRooms, maxMainRooms,
                   maxCorridorLength):
     lastX = 0
     lastY = 0
     lastDirection = 0
     numberOfRooms = 0
     numberOfMainRooms = 0
     mainRoomCap = random.randint(minMainRooms, maxMainRooms)
     while numberOfMainRooms < mainRoomCap:
         directionsToGo = random.randint(1, 2)
         direction = 1
         if directionsToGo == 1:
             direction = random.randint(2, 3)
         elif directionsToGo == 2:
             direction = random.randint(1, 2)
         lastDirection = direction
         for d in range(1, 4):
             rand = random.randint(1, 3)
             if rand == 1 or d == direction:
                 corridorLength = random.randint(1, maxCorridorLength)
                 x = lastX
                 y = lastY
                 room = Room(random.choice(self.roomTemplates), Vec2(x, y),
                             numberOfRooms)
                 if len(self.rooms) > 0:
                     if d == 1:
                         room.position.y -= (room.height + corridorLength)
                     elif d == 2:
                         room.position.x += self.rooms[
                             len(self.rooms) - 1].width + corridorLength
                     elif d == 3:
                         room.position.y += self.rooms[
                             len(self.rooms) - 1].height + corridorLength
                 if lastDirection != 0:
                     holeX = 0
                     holeY = 0
                     if lastDirection == 1:
                         holeX = math.ceil(room.width / 2)
                         holeY = room.height - 1
                     elif lastDirection == 2:
                         holeX = 0
                         holeY = math.ceil(room.height / 2)
                     elif lastDirection == 3:
                         holeX = math.ceil(room.width / 2)
                         holeY = 0
                     room.data[holeY][holeX] = " "
                 if d == direction:
                     holeX = 0
                     holeY = 0
                     if d == 1:
                         holeX = math.ceil(room.width / 2)
                         holeY = 0
                     elif d == 2:
                         holeX = room.width - 1
                         holeY = math.ceil(room.height / 2)
                     elif d == 3:
                         holeX = math.ceil(room.width / 2)
                         holeY = room.height - 1
                     room.data[holeY][holeX] = " "
                 if numberOfRooms < roomCap or d == direction:
                     numberOfRooms += 1
                     self.rooms.append(room)
                 if d == direction:
                     lastX = room.position.x
                     lastY = room.position.y
                     lastDirection = d
                     numberOfMainRooms += 1
示例#6
0
 def _updatePosY(self, y: int):
     self.position.y = y
     self.rect = Rectangle(
         Vec2(self.position.x, self.position.y + self.height),
         Vec2(self.position.x + self.width, self.position.y))