Beispiel #1
0
def add_items():
    """ Initialize all items to be added to the model"""
    # create all instances of goombas
    model.items.append(Goomba(model, 700, 300, -0.1, 0))
    model.items.append(Goomba(model, 800, 300, -0.1, 0))
    model.items.append(Goomba(model, 1000, 300, -0.1, 0))
    model.items.append(Goomba(model, 1300, 300, -0.1, 0))
    model.items.append(Goomba(model, 1500, 300, -0.1, 0))
    model.items.append(Goomba(model, 1700, 300, -0.1, 0))
    model.items.append(Goomba(model, 2800, 300, -0.1, 0))
    model.items.append(Goomba(model, 3000, 300, -0.1, 0))
    # create all instances of pipes
    model.items.append(Pipe(model, 800, 425, height=125))
    model.items.append(Pipe(model, 2000, 425, height=125))
    # create all instances of bricks in the air
    model.items.append(Air_Bricks(model, 550, 450))
    model.items.append(Air_Bricks(model, 1000, 450))
    model.items.append(Air_Bricks(model, 1400, 450))
    model.items.append(Air_Bricks(model, 2600, 450))
    # create the flag and castle
    model.items.append(Flag(model, length - 275, 250))
    model.items.append(Castle(model, length - 200, 350))
    # add clouds to display
    for n in range(1, length, 400):
        model.items.append(Cloud(x=n, y=random.randint(50, 250)))
Beispiel #2
0
    def generate_hurdles(self):
        '''Set hurdles for the level'''
        hurdles = HURDLES
        options = len(hurdles)
        x = 20
        while x < self.breadth - 35:
            option = randint(0, options - 1)
            if hurdles[option][0] + x < self.breadth - 35:
                hurdles[option][1](x, self.board)
                x += hurdles[option][0]
                x += randint(10, 20)
            else:
                break

        _ = Castle(self.breadth - 33, self.board)
Beispiel #3
0
def create_castle(screen, settings, location, castles):
    for i in range(6):
        castle = Castle(screen, settings)
        castle.rect.x = location
        castle.rect.y = castle.rect.height * i
        castles.add(castle)
    def generate_map(self, settings, screen, objects, background, mario):
        mario.x = 100
        mario.y = settings.ground_level - mario.height
        mario.rect.x = mario.x
        mario.rect.y = mario.y
        self.generate_ground(settings, screen, objects)

        background.add(
            Hill(settings, screen, 0,
                 settings.ground_level - settings.large_hill_height, 2))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 9,
                  settings.brick_lenth * 3, 1))
        background.add(
            Bush(settings, screen, settings.brick_lenth * 12,
                 settings.ground_level - settings.brick_lenth, 3))
        background.add(
            Hill(settings, screen, settings.brick_lenth * 16,
                 settings.ground_level - settings.brick_lenth - 2, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 16,
                  settings.ground_level - settings.brick_lenth * 4, 1))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 20,
                  settings.ground_level - settings.brick_lenth * 15, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 22,
                  settings.ground_level - settings.brick_lenth * 8, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 20,
                  settings.ground_level - settings.brick_lenth * 4, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 21,
                  settings.ground_level - settings.brick_lenth * 4, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 22,
                  settings.ground_level - settings.brick_lenth * 4, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 23,
                  settings.ground_level - settings.brick_lenth * 4, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 24,
                  settings.ground_level - settings.brick_lenth * 4, 3))
        background.add(
            Bush(settings, screen, settings.brick_lenth * 23.5,
                 settings.ground_level - settings.brick_lenth, 1))
        objects.add(
            Pipe(settings, screen, settings.brick_lenth * 29,
                 settings.ground_level - settings.brick_lenth * 2, 1))
        objects.add(
            Pipe(settings, screen, settings.brick_lenth * 39,
                 settings.ground_level - settings.brick_lenth * 3, 2))
        objects.add(
            Pipe(settings, screen, settings.brick_lenth * 47,
                 settings.ground_level - settings.brick_lenth * 4, 3))
        objects.add(
            Pipe(settings, screen, settings.brick_lenth * 58,
                 settings.ground_level - settings.brick_lenth * 4, 3))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 28,
                  settings.ground_level - settings.brick_lenth * 12, 3))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 37,
                  settings.ground_level - settings.brick_lenth * 15, 2))
        background.add(
            Bush(settings, screen, settings.brick_lenth * 41.5,
                 settings.ground_level - settings.brick_lenth, 3))
        background.add(
            Hill(settings, screen, settings.brick_lenth * 49,
                 settings.ground_level - settings.large_hill_height - 2, 2))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 57,
                  settings.ground_level - settings.brick_lenth * 15, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 65,
                  settings.ground_level - settings.brick_lenth * 5, 1))
        background.add(
            Bush(settings, screen, settings.brick_lenth * 60.5,
                 settings.ground_level - settings.brick_lenth, 3))
        background.add(
            Hill(settings, screen, settings.brick_lenth * 65,
                 settings.ground_level - settings.small_hill_height, 1))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 68,
                  settings.ground_level - settings.brick_lenth * 15, 1))
        background.add(
            Bush(settings, screen, settings.brick_lenth * 72.5,
                 settings.ground_level - settings.brick_lenth, 1))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 76,
                  settings.ground_level - settings.brick_lenth * 13, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 78,
                  settings.ground_level - settings.brick_lenth * 4, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 79,
                  settings.ground_level - settings.brick_lenth * 4, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 80,
                  settings.ground_level - settings.brick_lenth * 4, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 81,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 82,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 83,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 84,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 85,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 86,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 87,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 88,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 85,
                  settings.ground_level - settings.brick_lenth * 15, 2))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 92,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 93,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 94,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 95,
                  settings.ground_level - settings.brick_lenth * 8, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 95,
                  settings.ground_level - settings.brick_lenth * 4, 3))
        background.add(
            Bush(settings, screen, settings.brick_lenth * 90.5,
                 settings.ground_level - settings.brick_lenth, 2))
        background.add(
            Hill(settings, screen, settings.brick_lenth * 97,
                 settings.ground_level - settings.large_hill_height - 2, 2))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 101,
                  settings.ground_level - settings.brick_lenth * 4, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 102,
                  settings.ground_level - settings.brick_lenth * 4, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 107,
                  settings.ground_level - settings.brick_lenth * 4, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 110,
                  settings.ground_level - settings.brick_lenth * 4, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 113,
                  settings.ground_level - settings.brick_lenth * 4, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 110,
                  settings.ground_level - settings.brick_lenth * 8, 1))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 106,
                  settings.ground_level - settings.brick_lenth * 11, 1))
        background.add(
            Bush(settings, screen, settings.brick_lenth * 108.5,
                 settings.ground_level - settings.brick_lenth, 3))
        background.add(
            Hill(settings, screen, settings.brick_lenth * 113,
                 settings.ground_level - settings.small_hill_height, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 119,
                  settings.ground_level - settings.brick_lenth * 4, 3))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 116,
                  settings.ground_level - settings.brick_lenth * 12, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 122,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 123,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 124,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 129,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 130,
                  settings.ground_level - settings.brick_lenth * 8, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 131,
                  settings.ground_level - settings.brick_lenth * 8, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 132,
                  settings.ground_level - settings.brick_lenth * 8, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 130,
                  settings.ground_level - settings.brick_lenth * 4, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 131,
                  settings.ground_level - settings.brick_lenth * 4, 3))
        background.add(
            Bush(settings, screen, settings.brick_lenth * 120.5,
                 settings.ground_level - settings.brick_lenth, 1))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 124,
                  settings.ground_level - settings.brick_lenth * 11, 3))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 133,
                  settings.ground_level - settings.brick_lenth * 13, 2))
        background.add(
            Bush(settings, screen, settings.brick_lenth * 138.5,
                 settings.ground_level - settings.brick_lenth, 2))
        background.add(
            Hill(settings, screen, settings.brick_lenth * 145,
                 settings.ground_level - settings.large_hill_height, 2))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 153,
                  settings.ground_level - settings.brick_lenth * 11, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 135,
                  settings.ground_level - settings.brick_lenth, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 136,
                  settings.ground_level - settings.brick_lenth, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 137,
                  settings.ground_level - settings.brick_lenth, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 138,
                  settings.ground_level - settings.brick_lenth, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 136,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 137,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 138,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 137,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 138,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 138,
                  settings.ground_level - settings.brick_lenth * 4, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 141,
                  settings.ground_level - settings.brick_lenth * 4, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 141,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 141,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 141,
                  settings.ground_level - settings.brick_lenth * 1, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 142,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 142,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 142,
                  settings.ground_level - settings.brick_lenth * 1, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 143,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 143,
                  settings.ground_level - settings.brick_lenth * 1, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 144,
                  settings.ground_level - settings.brick_lenth * 1, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 149,
                  settings.ground_level - settings.brick_lenth * 1, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 150,
                  settings.ground_level - settings.brick_lenth * 1, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 150,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 151,
                  settings.ground_level - settings.brick_lenth * 1, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 151,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 151,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 152,
                  settings.ground_level - settings.brick_lenth * 1, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 152,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 152,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 152,
                  settings.ground_level - settings.brick_lenth * 4, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 153,
                  settings.ground_level - settings.brick_lenth * 1, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 153,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 153,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 153,
                  settings.ground_level - settings.brick_lenth * 4, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 156,
                  settings.ground_level - settings.brick_lenth * 1, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 156,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 156,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 156,
                  settings.ground_level - settings.brick_lenth * 4, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 157,
                  settings.ground_level - settings.brick_lenth * 1, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 157,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 157,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 158,
                  settings.ground_level - settings.brick_lenth * 1, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 158,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 159,
                  settings.ground_level - settings.brick_lenth * 1, 4))
        background.add(
            Hill(settings, screen, settings.brick_lenth * 161,
                 settings.ground_level - settings.small_hill_height, 1))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 164,
                  settings.ground_level - settings.brick_lenth * 13, 1))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 172,
                  settings.ground_level - settings.brick_lenth * 11, 3))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 181,
                  settings.ground_level - settings.brick_lenth * 13, 2))
        background.add(
            Cloud(settings, screen, settings.brick_lenth * 201,
                  settings.ground_level - settings.brick_lenth * 11, 1))
        background.add(
            Bush(settings, screen, settings.brick_lenth * 167.5,
                 settings.ground_level - settings.brick_lenth, 1))
        background.add(
            Hill(settings, screen, settings.brick_lenth * 193,
                 settings.ground_level - settings.large_hill_height, 2))
        background.add(
            Hill(settings, screen, settings.brick_lenth * 209,
                 settings.ground_level - settings.small_hill_height, 1))
        objects.add(
            Pipe(settings, screen, settings.brick_lenth * 164,
                 settings.ground_level - settings.brick_lenth * 2, 1))
        objects.add(
            Pipe(settings, screen, settings.brick_lenth * 180,
                 settings.ground_level - settings.brick_lenth * 2, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 169,
                  settings.ground_level - settings.brick_lenth * 4, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 170,
                  settings.ground_level - settings.brick_lenth * 4, 3))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 171,
                  settings.ground_level - settings.brick_lenth * 4, 1))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 172,
                  settings.ground_level - settings.brick_lenth * 4, 3))

        objects.add(
            Brick(settings, screen, settings.brick_lenth * 182,
                  settings.ground_level - settings.brick_lenth, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 183,
                  settings.ground_level - settings.brick_lenth, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 183,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 184,
                  settings.ground_level - settings.brick_lenth, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 184,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 184,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 185,
                  settings.ground_level - settings.brick_lenth, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 185,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 185,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 185,
                  settings.ground_level - settings.brick_lenth * 4, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 186,
                  settings.ground_level - settings.brick_lenth, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 186,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 186,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 186,
                  settings.ground_level - settings.brick_lenth * 4, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 186,
                  settings.ground_level - settings.brick_lenth * 5, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 187,
                  settings.ground_level - settings.brick_lenth, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 187,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 187,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 187,
                  settings.ground_level - settings.brick_lenth * 4, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 187,
                  settings.ground_level - settings.brick_lenth * 5, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 187,
                  settings.ground_level - settings.brick_lenth * 6, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 188,
                  settings.ground_level - settings.brick_lenth, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 188,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 188,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 188,
                  settings.ground_level - settings.brick_lenth * 4, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 188,
                  settings.ground_level - settings.brick_lenth * 5, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 188,
                  settings.ground_level - settings.brick_lenth * 6, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 188,
                  settings.ground_level - settings.brick_lenth * 7, 4))

        objects.add(
            Brick(settings, screen, settings.brick_lenth * 189,
                  settings.ground_level - settings.brick_lenth, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 189,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 189,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 189,
                  settings.ground_level - settings.brick_lenth * 4, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 189,
                  settings.ground_level - settings.brick_lenth * 5, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 189,
                  settings.ground_level - settings.brick_lenth * 6, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 189,
                  settings.ground_level - settings.brick_lenth * 7, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 189,
                  settings.ground_level - settings.brick_lenth * 8, 4))

        objects.add(
            Brick(settings, screen, settings.brick_lenth * 190,
                  settings.ground_level - settings.brick_lenth, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 190,
                  settings.ground_level - settings.brick_lenth * 2, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 190,
                  settings.ground_level - settings.brick_lenth * 3, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 190,
                  settings.ground_level - settings.brick_lenth * 4, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 190,
                  settings.ground_level - settings.brick_lenth * 5, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 190,
                  settings.ground_level - settings.brick_lenth * 6, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 190,
                  settings.ground_level - settings.brick_lenth * 7, 4))
        objects.add(
            Brick(settings, screen, settings.brick_lenth * 190,
                  settings.ground_level - settings.brick_lenth * 8, 4))
        objects.add(
            Flag_Pole(settings, screen, settings.brick_lenth * 199,
                      settings.ground_level - settings.flag_pole_height, 1))
        objects.add(
            Castle(settings, screen, settings.brick_lenth * 203,
                   settings.ground_level - settings.small_castle_height, 1))
Beispiel #5
0
def castle_puzzle(filename,
                  time,
                  when_to_introduce_culling=90,
                  mutation_threshold=0.1):
    ELITE = True
    CULLING = True
    generations = 0
    population = []
    population_size = 100
    pieces = []
    with open(filename, 'r') as f:
        temp = f.readlines()
        for line in temp:
            p = [pi.strip().replace("\n", "") for pi in line.split("\t")]
            pieces.append(Piece(p[0], int(p[1]), int(p[2]), int(p[3])))

    for i in range(population_size):
        shuffle(pieces)
        height = randint(3, len(pieces))
        temp = [choice(pieces) for i in range(height)]
        population.append(Castle(temp, pieces))
    # print(population)

    end = timer.time() + time
    start = timer.time()
    new_population = []
    top_of_population = float('-inf')
    top_solution = ""
    best_generation = 0
    while timer.time() < end:

        for o in population:
            o.validate()
        if max(population).fitness() >= top_of_population:
            top_of_population = max(population).fitness()
            top_solution = str(max(population))
            best_generation = generations
        if generations % 100 == 0:
            print(
                f"Generation {'{:,}'.format(generations)}\t time: {'{:,}'.format(float('{:.1f}'.format(timer.time() - start)))}\t "
                f"best: {'{:,}'.format(float('{:.3f}'.format(top_of_population)))}"
            )

        # get the organisms that will be saved with elitism
        if ELITE:
            elite = elitism(population)
            for e in elite:
                new_population.append(e)
        # get the organisms that will be removed with culling
        if CULLING:
            culled = culling(population)
            # start culling process at given generation
            if generations >= when_to_introduce_culling:
                for c in culled:
                    population.remove(c)
        """
        Fill the population
        """
        pairs = []
        while len(new_population) < population_size:

            # select parents
            select_from = selection(population)
            parent_A = choice(select_from)
            parent_B = choice(select_from)
            # ensure parents are different, and they have not been paired before
            while parent_A == parent_B or (parent_A, parent_B) in pairs:
                parent_B = choice(population)
            pairs.append((parent_A, parent_B))
            # create children and add them to the new population
            children = parent_A.crossover(parent_B)
            new_population.append(children[0])
            new_population.append(children[1])
        # mutate the new population
        for c in new_population:
            chance = random()
            if chance < mutation_threshold:
                c.mutate()
        generations += 1
    population = new_population.copy(
    )  # replace population with new population
    new_population = []  # reset new population
    temp = f"Generation {'{:,}'.format(generations)}\t time: {'{:,}'.format(float('{:.1f}'.format(timer.time() - start)))}\t best: {'{:,}'.format(float('{:.3f}'.format(top_of_population)))}"
    print(f"{'-' * (len(temp) + 5)}")
    print(f"Ran for {'{:.2f}'.format(timer.time() - start)} seconds")
    print(f"Score: {'{:,}'.format(float('{:.3f}'.format(top_of_population)))}")
    print(f"Ran for {'{:,}'.format(generations)} generations")
    print(f"Best generation: {'{:,}'.format(best_generation)}")
    print(top_solution)
    return top_of_population, best_generation, generations
Beispiel #6
0
	def __init__(self, parent, player, castle_x, castle_y):
		self.castle_x = castle_x
		self.castle_y = castle_y
		self.castle_level = 1
		self.gold = 0
		self.dice = 0
		self.h1pos_x = 0
		self.h1pos_y = 0
		self.h2pos_x = 0
		self.h2pos_y = 0
		self.h3pos_x = 0
		self.h3pos_y = 0
		self.available_heroes = [1]
		self.hero = 1
		self.can_move = False
		self.castle_price = 3000

		self.h1units = {
			"level_1": 15,
			"level_2": 10,
			"level_3": 0,
			"level_4": 0,
			"level_5": 0,
		}

		self.h2units = {
			"level_1": 15,
			"level_2": 10,
			"level_3": 0,
			"level_4": 0,
			"level_5": 0
		}

		self.h3units = {
			"level_1": 15,
			"level_2": 10,
			"level_3": 0,
			"level_4": 0,
			"level_5": 0
		}

		self.in_castle_units = {
			"level_1": 10,
			"level_2": 5,
			"level_3": 0,
			"level_4": 0,
			"level_5": 1
		}

		self.available_units = {
			"level_1": 10,
			"level_2": 5,
			"level_3": 0,
			"level_4": 0,
			"level_5": 0
		}# powiedzmy, że od razu może kupić 5, poza poziomem 1

		super(PlayerInfo, self).__init__(parent)
		color = 'darkblue'
		if player == 'Gracz 1':
			color = 'darkred'
		self.color = color
		self.setStyleSheet("""
			QDialog, QLabel, QPushButton {
			background-image: url(UI/brown_background.jpg);
			background-attachment: scroll;
			border: 2px outset %s;
			border-radius: 10px;
			color: white;
			font-size: 18pt;
			font: Arial;
			min-height: 15px;}
			
			QPushButton:pressed {
			background-image: url(UI/darker_brown_background.jpg);}
			""" % color)
		self.grid = QGridLayout(self)
		self.castle = Castle(self)
		castle_image = QPushButton()
		castle_image.setStyleSheet('border-image: url(UI/castle_inside.jpeg); min-height: 200px; ')
		castle_image.clicked.connect(self.show_castle)

		self.grid.addWidget(castle_image, 0, 0)

		self.labels = [QLabel(player), QLabel('Poziom zamku: %d' % self.castle_level), QLabel('Złoto: 0'), QLabel('Wyrzucono oczek: %d' % self.dice), QLabel('Tydzień: %d, Dzień: %d' % (self.parent().week, self.parent().day))]

		i = 1
		for label in self.labels:
			self.grid.addWidget(label, i, 0)
			i += 1

		self.setLayout(self.grid)
		self.update_gold_amount(2500)
Beispiel #7
0
class PlayerInfo(QWidget):
	def __init__(self, parent, player, castle_x, castle_y):
		self.castle_x = castle_x
		self.castle_y = castle_y
		self.castle_level = 1
		self.gold = 0
		self.dice = 0
		self.h1pos_x = 0
		self.h1pos_y = 0
		self.h2pos_x = 0
		self.h2pos_y = 0
		self.h3pos_x = 0
		self.h3pos_y = 0
		self.available_heroes = [1]
		self.hero = 1
		self.can_move = False
		self.castle_price = 3000

		self.h1units = {
			"level_1": 15,
			"level_2": 10,
			"level_3": 0,
			"level_4": 0,
			"level_5": 0,
		}

		self.h2units = {
			"level_1": 15,
			"level_2": 10,
			"level_3": 0,
			"level_4": 0,
			"level_5": 0
		}

		self.h3units = {
			"level_1": 15,
			"level_2": 10,
			"level_3": 0,
			"level_4": 0,
			"level_5": 0
		}

		self.in_castle_units = {
			"level_1": 10,
			"level_2": 5,
			"level_3": 0,
			"level_4": 0,
			"level_5": 1
		}

		self.available_units = {
			"level_1": 10,
			"level_2": 5,
			"level_3": 0,
			"level_4": 0,
			"level_5": 0
		}# powiedzmy, że od razu może kupić 5, poza poziomem 1

		super(PlayerInfo, self).__init__(parent)
		color = 'darkblue'
		if player == 'Gracz 1':
			color = 'darkred'
		self.color = color
		self.setStyleSheet("""
			QDialog, QLabel, QPushButton {
			background-image: url(UI/brown_background.jpg);
			background-attachment: scroll;
			border: 2px outset %s;
			border-radius: 10px;
			color: white;
			font-size: 18pt;
			font: Arial;
			min-height: 15px;}
			
			QPushButton:pressed {
			background-image: url(UI/darker_brown_background.jpg);}
			""" % color)
		self.grid = QGridLayout(self)
		self.castle = Castle(self)
		castle_image = QPushButton()
		castle_image.setStyleSheet('border-image: url(UI/castle_inside.jpeg); min-height: 200px; ')
		castle_image.clicked.connect(self.show_castle)

		self.grid.addWidget(castle_image, 0, 0)

		self.labels = [QLabel(player), QLabel('Poziom zamku: %d' % self.castle_level), QLabel('Złoto: 0'), QLabel('Wyrzucono oczek: %d' % self.dice), QLabel('Tydzień: %d, Dzień: %d' % (self.parent().week, self.parent().day))]

		i = 1
		for label in self.labels:
			self.grid.addWidget(label, i, 0)
			i += 1

		self.setLayout(self.grid)
		self.update_gold_amount(2500)
		#self.update_week_day()

	def show_castle(self):
		self.castle.show_castle()

	def update_castle_level(self, level):
		self.castle_level = level
		text = 'Poziom zamku: ' + str(level)
		self.labels[1] = QLabel(text)
		self.grid.addWidget(self.labels[1], 2, 0)

	def update_gold_amount(self, amount):
		self.gold = amount
		text = 'Złoto: ' + str(amount)
		self.labels[2] = QLabel(text)
		self.grid.addWidget(self.labels[2], 3, 0)

	def update_dice_amount(self, amount):
		self.dice = amount
		text = 'Wyrzucono oczek: ' + str(amount)
		self.labels[3] = QLabel(text)
		self.grid.addWidget(self.labels[3], 4, 0)

	def update_week_day(self, week, day): # z jakiegoś powodu, jak się używa parent() to wywala cały program
		text = 'Tydzień: ' + str(week) + ', Dzień: ' + str(day)
		self.labels[4] = QLabel(text)
		self.grid.addWidget(self.labels[4], 5, 0)

	def clear_hero_pos(self, hero_num):
		if hero_num == 1:
			self.h1pos_x = self.castle_x
			self.h1pos_y = self.castle_y
		elif hero_num == 2:
			self.h2pos_x = self.castle_x
			self.h2pos_y = self.castle_y
		else:
			self.h3pos_x = self.castle_x
			self.h3pos_y = self.castle_y
Beispiel #8
0
def scene(viewer, shader_materials, shader_texture, shader_skinned):
    size = 10000
    """ -------------- create a scene and add objects ------------------- """
    # create ground object and add it to the viewer
    main_ground = ObjectLoadTextured(shader_texture,
                                     'models/models_OBJ/Ground.obj', light_dir)
    viewer.add(add_object(main_ground))

    # create mountain instances and add them to the viewer
    mountain = ObjectLoadTextured(shader_texture,
                                  'models/models_OBJ/Mountain.obj', light_dir)
    x_mountains = [-0.80, -0.80, 0.80, 0.80]
    y_mountains = [-0.80, 0.80, -0.80, 0.80]
    scales = [250, 230, 220, 200]
    rotation = rotate((1, 0, 0), 90)
    for x, y, z in zip(x_mountains, y_mountains, scales):
        viewer.add(
            add_object(
                mountain,
                translate(x * size, y * size, -100) @ rotation @ scale(z)))

    # create skybox and add it to the viewer
    skybox = ObjectLoadTextured(shader_texture, 'models/models_OBJ/SkyBox.obj',
                                light_dir)
    viewer.add(add_object(skybox))

    # create a town and add it to the viewer
    town = Town(shader_texture, shader_materials)
    town.construct_town(shader_texture, shader_materials,
                        translate(-0.2 * size, -0.2 * size, 175))
    viewer.add(*town.children)

    # create town ground and church ground
    town_ground = ObjectLoadTextured(shader_texture,
                                     'models/models_OBJ/GroundTown.obj',
                                     light_dir)
    church_ground = ObjectLoadTextured(shader_texture,
                                       'models/models_OBJ/church_ground.obj',
                                       light_dir)
    viewer.add(add_object(town_ground, translate(-0.2 * size, -0.2 * size, 2)))
    viewer.add(
        add_object(
            church_ground,
            translate(-0.03 * size, 0.06 * size, 5) @ rotate((0, 0, 1), -90)))

    # create forests
    forest = Forest(shader_materials)
    forest.construct_forest(translate(-2500, -6000, 0))
    viewer.add(*forest.children)

    # create a worker
    rotation = rotate((1, 0, 0), 90) @ rotate((0, 1, 0), 90) @ scale(0.5)
    worker = ObjectLoadSkinned(
        shader_skinned, 'models/characters/worker/worker_cutting_down.FBX',
        (-1, 0, 0))
    viewer.add(add_object(worker, transform=rotation))

    # create town's guards
    guard = ObjectLoadSkinned(
        shader_skinned,
        'models/characters/armored_swordman/armored_swordman_standing.FBX',
        (-1, 0, 0))
    transformation = translate(-0.2 * size, -0.2 * size, 0)

    translations = [
        translate(32.5 * 20, 33 * 20 - 50, 0),
        translate(87.5 * 20, 33 * 20 - 50, 0),
        translate(115 * 20, 33 * 20 - 50, 0),
        translate(172.5 * 20, 33 * 20 - 50, 0),
        translate(172.5 * 20 + 100, 105 * 20, 0),
        translate(172.5 * 20 + 100, 129 * 20, 0),
        translate(172.5 * 20 + 100, 159 * 20, 0),
        translate(172.5 * 20 + 100, 187.5 * 20, 0),
        translate(75 * 20, 187.5 * 20 + 50, 0),
        translate(20 * 20, 162.5 * 20 + 50, 0),
        translate(20 * 20, 131.5 * 20 + 50, 0),
        translate(20 * 20, 120.5 * 20 + 50, 0),
        translate(20 * 20 - 100, 92.5 * 20, 0),
        translate(120 * 20 - 100, 185 * 20, 0),
        translate(140 * 20 - 100, 185 * 20, 0)
    ]
    for t in translations:
        viewer.add(add_object(guard, transform=transformation @ t @ rotation))

    # create a non flat ground
    non_flat = ObjectLoadTextured(shader_texture,
                                  'models/models_OBJ/terre_eleve.obj',
                                  light_dir)
    viewer.add(
        add_object(non_flat, transform=translate(0.10 * size, 0.35 * size, 0)))

    # create a castle
    castle = Castle(shader_materials)
    castle.construct_castle(
        transform=translate(0.10 * size, 0.35 * size, 400) @ scale(40))
    viewer.add(*castle.children)

    # add an animated door
    translate_keys = {0: vec(0, 0, 300), 4: vec(0, 0, 100)}
    scale_keys = {0: 1, 4: 1}
    rotate_keys = {0: quaternion(), 4: quaternion()}
    door = ObjectLoadTextured(shader_texture, 'models/models_OBJ/door.obj',
                              light_dir)
    keynode = KeyFrameControlNode(translate_keys, rotate_keys, scale_keys)
    keynode.add(
        add_object(
            door,
            translate(30, -1300, 0) @ rotate((0, 1, 0), 90) @ rotate(
                (1, 0, 0), -90)))
    viewer.add(keynode)
Beispiel #9
0
	def create_castle(self):
		'''Создаёт замок'''
		self.castle = Castle(self.ai_settings)
		self.add_widget(self.castle)
Beispiel #10
0
    def __init__(self):

        self.tile_grid = [[
            9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
            9, 9, 9
        ],
                          [
                              9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 9
                          ],
                          [
                              9, 1, 1, 7, 7, 7, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1,
                              1, 1, 1, 6, 6, 6, 1, 1, 9
                          ],
                          [
                              9, 1, 1, 1, 7, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1,
                              1, 1, 1, 6, 6, 6, 1, 1, 9
                          ],
                          [
                              9, 1, 1, 1, 7, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1,
                              1, 1, 1, 6, 6, 6, 1, 1, 9
                          ],
                          [
                              9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 9
                          ],
                          [
                              9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 9
                          ],
                          [
                              9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 0, 2, 2, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 9
                          ],
                          [
                              9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 9
                          ],
                          [
                              9, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 2, 2, 2, 0, 3,
                              3, 3, 3, 3, 3, 3, 3, 3, 9
                          ],
                          [
                              9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 9
                          ],
                          [
                              9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 0, 2, 2, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 9
                          ],
                          [
                              9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 9
                          ],
                          [
                              9, 8, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 9
                          ],
                          [
                              9, 1, 8, 8, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1,
                              1, 1, 1, 5, 5, 1, 1, 1, 9
                          ],
                          [
                              9, 1, 1, 8, 8, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1,
                              1, 1, 5, 5, 5, 5, 1, 1, 9
                          ],
                          [
                              9, 1, 1, 1, 8, 8, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1,
                              1, 5, 5, 5, 5, 5, 5, 1, 9
                          ],
                          [
                              9, 1, 1, 1, 1, 8, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1,
                              1, 1, 1, 1, 1, 1, 1, 1, 9
                          ],
                          [
                              9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
                              9, 9, 9, 9, 9, 9, 9, 9, 9
                          ]]

        map_dict = {
            9: Tile_Highgrass,
            8: Tile_Water,
            7: Tile_Tree,
            6: Tile_Farm,
            5: Tile_Mountain,
            3: Tile_Dirt,
            2: Tile_Wall,
            1: Tile_Grass,
            0: Tile_Door
        }

        self.border_tile = []

        for i in range(len(self.tile_grid)):
            for j in range(len(self.tile_grid[i])):
                self.tile_grid[i][j] = map_dict[self.tile_grid[i][j]]()
                if isinstance(self.tile_grid[i][j], Tile_Highgrass):
                    self.border_tile.append(self.tile_grid[i][j])

        castle_home = []
        for i in range(5):
            for j in range(5):
                castle_home.append(self.tile_grid[i + 7][j + 10])

        self.spawn = Spawn(self, self.tile_grid[0][12])
        self.castle = Castle(castle_home)

        self.particle_holder = ParticleHolder()

        self.set_move_values()