Beispiel #1
0
    def genObjects(self, room):
        """
        Generates stuff in a room.

        TODO: Generalize this for all first-time generation of a room.
        """
        
        numMonsters = randint(0, 0, MAX_ROOM_MONSTERS)
        for i in range(numMonsters):
            x = randint(0, room.x1, room.x2)
            y = randint(0, room.y1, room.y2)
            if not self.isBlocked(x,y):    
                if(randint(0, 0, 100) < 80): #80% chance
                    fighter_component = Fighter(3, 3, 3, death_function=monster_death)
                    ai_component = BasicMonster()
                    monster = Object(self, x, y, 'o', 
                        'orc', libtcod.desaturated_green, blocks=True,
                        fighter=fighter_component,
                        ai=ai_component)
                else:
                    fighter_component = Fighter(4, 4, 4, death_function=monster_death)
                    ai_component = BasicMonster()
                    monster = Object(self, x, y, 'T', 
                        'troll', libtcod.darker_green, blocks=True,
                        fighter=fighter_component,
                        ai=ai_component)
                self.objects.append(monster)
Beispiel #2
0
    def makeMap(self):
        """
        Generates the first map.

        TODO: Generalize this function for successive iterations.
        """
        self.map = [[Tile(True) for y in range(MAP_HEIGHT)] for _ in range(MAP_WIDTH)]

        self.rooms = []
        self.numRooms = 0
    
        for r in range(MAX_ROOMS):
            w = randint(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
            h = randint(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
            x = randint(0, 0, MAP_WIDTH - w - 1)
            y = randint(0, 0, MAP_HEIGHT - h - 1)
   
            new_room = Rect(x, y, w, h)

            failed = False
            for other_room in self.rooms:
                if(new_room.intersect(other_room)):
                    failed = True
                    break
            if not failed:
                self.createRoom(new_room)
                self.genObjects(new_room)
                (new_x, new_y) = new_room.center()
                
                #Special case for first room; puts player in there
                if self.numRooms == 0:
                    self.player.x = new_x
                    self.player.y = new_y 
                else:
                    (prev_x, prev_y) = self.rooms[self.numRooms - 1].center()
                    if(randint(0, 0, 1) == 1):
                        #first move horizontally, then vertically
                        self.createHTunnel(prev_x, new_x, prev_y)
                        self.createVTunnel(prev_y, new_y, new_x)
                    else:
                        #first move vertically, then horizontally
                        self.createVTunnel(prev_y, new_y, prev_x)
                        self.createHTunnel(prev_x, new_x, new_y)
                self.rooms.append(new_room)
                self.numRooms += 1
Beispiel #3
0
def make_map():
    global m, player
    
    #Default map
    m = [[Tile(True) for y in range(MAP_HEIGHT)] for _ in range(MAP_WIDTH)]

    rooms = []
    num_rooms = 0
    

    for r in range(MAX_ROOMS):
        w = randint(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
        h = randint(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
        x = randint(0, 0, MAP_WIDTH - w - 1)
        y = randint(0, 0, MAP_HEIGHT - h - 1)
   
        new_room = Rect(x, y, w, h)

        failed = False
        for other_room in rooms:
            if(new_room.intersect(other_room)):
                failed = True
                break
        if not failed:
            create_room(new_room)
            place_objects(new_room)
            (new_x, new_y) = new_room.center()
            #Special case for first room; puts player in there
            if num_rooms == 0:
                player.x = new_x
                player.y = new_y 
            else:
                (prev_x, prev_y) = rooms[num_rooms - 1].center()
                if(randint(0, 0, 1) == 1):
                    #first move horizontally, then vertically
                    create_h_tunnel(prev_x, new_x, prev_y)
                    create_v_tunnel(prev_y, new_y, new_x)
                else:
                    #first move vertically, then horizontally
                    create_v_tunnel(prev_y, new_y, prev_x)
                    create_h_tunnel(prev_x, new_x, new_y)
            rooms.append(new_room)
            num_rooms += 1
Beispiel #4
0
def place_objects(room):
    global objects
    num_monsters = randint(0, 0, MAX_ROOM_MONSTERS)
    for i in range(num_monsters):
        x = randint(0, room.x1, room.x2)
        y = randint(0, room.y1, room.y2)
        if not is_blocked(x,y):    
            if(randint(0, 0, 100) < 80): #80% chance
                fighter_component = Fighter(3, 3, 3, death_function=monster_death)
                ai_component = BasicMonster()
                monster = Object(x,y, 'o', 'orc', libtcod.desaturated_green, blocks=True,
                    fighter=fighter_component,
                    ai=ai_component)
            else:
                fighter_component = Fighter(4, 4, 4, death_function=monster_death)
                ai_component = BasicMonster()
                monster = Object(x, y, 'T', 'troll', libtcod.darker_green, blocks=True,
                    fighter=fighter_component,
                    ai=ai_component)

            objects.append(monster)