import pygame, random
import structures, entities

all = pygame.sprite.Group()
walls = pygame.sprite.Group()
floors = pygame.sprite.Group()
dumpsters = pygame.sprite.Group()
junk = pygame.sprite.Group()

def createWall(pos, image):
    global all, walls
    new = structures.wall(pos, image)

    all.add(new)
    walls.add(new)

def createFloor(pos):
    global all, floors
    new = structures.floor(pos)

    all.add(new)
    floors.add(new)

def createJunk(pos):
    global all, junk
    new = entities.junk(pos)

    all.add(new)
    junk.add(new)

def createDumpster(pos):
    global all, dumpsters
    new = structures.dumpster(pos)

    all.add(new)
    dumpsters.add(new)

def generateMap(number):
    global all, walls, floors, dumpsters, junk

    if number == 1:
        for i in range(27):
            createWall([0, i * -80], None)
            createWall([80 * 34, i * -80], None)

        for i in range(12):
            createWall([80 + (i * 80), -80 * 0], None)
            createWall([80 + (i * 80), -80 * 15], None)
            createWall([80 + (i * 80), -80 * 26], None)

            createWall([(80 * 22) + (i * 80), -80 * 0], None)
            createWall([(80 * 22) + (i * 80), -80 * 15], None)
            createWall([(80 * 22) + (i * 80), -80 * 26], None)

        for i in range(-2, 30):
            if (not i > 1 or not i < 7) and (not i > 15 or not i < 21):
                createWall([80 * 13, -80 * i], None)
                createWall([80 * 21, -80 * i], None)

        for i in range(14, 21):
            if not i > 15 or not i < 21:
                createWall([80 * i, 80 * 2], None)
                createWall([80 * i, -80 * 13], None)
            createWall([80 * i, -80 * 29], None)

        for i in range(2, 13):
            createWall([80 * i, 80 * 1], "wall")
            createWall([80 * i, 80 * 2], "wall")

        for i in range(15, 22):
            if not i > 15 or not i < 21:
                createWall([80 * i, 80 * 3], "wall")
                createWall([80 * i, 80 * 4], "wall")

        for i in range(24, 35):
            createWall([80 * i, 80 * 1], "wall")
            createWall([80 * i, 80 * 2], "wall")

        for i in range(0, 25):
            createWall([80 * 35, -80 * i], "wallup")
            createWall([80 * 36, -80 * i], "wallup")

        for i in range(16, 26):
            if not i > 15 or not i < 21:
                createWall([80 * 28, -80 * i], None)

        createWall([0, 80], "wallsplitup")
        createWall([80, 80], "wall")
        createWall([80, 160], "wallsplitup")

        createWall([80 * 13, 240], "wallsplitup")
        createWall([80 * 14, 240], "wall")
        createWall([80 * 14, 320], "wallsplitup")

        createWall([80 * 22, 80], "wallsplit2")
        createWall([80 * 23, 160], "wallsplit2")

        createWall([80 * 22, 160], "wallup")
        createWall([80 * 23, 80], "wall")

        createWall([80 * 22, 320], "wall")
        createWall([80 * 23, 240], "wallup")

        createWall([80 * 22, 240], "wallsplit")
        createWall([80 * 23, 320], "wallsplit")

        createWall([80 * 35, 160], "wall")
        createWall([80 * 36, 80], "wallup")

        createWall([80 * 35, 80], "wallsplit")
        createWall([80 * 36, 160], "wallsplit")

        createWall([80 * 35, -80 * 25], "wallup")

        createWall([80 * 35, -80 * 26], "wallsplitdown")
        createWall([80 * 36, -80 * 25], "wallsplitdown")

        createWall([80 * 22, -80 * 28], "wallup")

        createWall([80 * 23, -80 * 28], "wallsplitdown")
        createWall([80 * 22, -80 * 29], "wallsplitdown")

        createWall([80 * 22, -80 * 27], "wallup")
        createWall([80 * 23, -80 * 27], "wallup")

        for x in range(3, 13):
            for y in range(1, 13):
                createFloor([x * 80, y * -80])

        for x in range(3, 13):
            for y in range(16, 24):
                createFloor([x * 80, y * -80])

        for x in range(16, 22):
            for y in range(14, 27):
                createFloor([x * 80, y * -80])

        for x in range(16, 22):
            for y in range(-1, 11):
                createFloor([x * 80, y * -80])

        for x in range(24, 34):
            for y in range(1, 24):
                createFloor([x * 80, y * -80])

        for i in range(1, 13):
            createWall([2 * 80, i * -80], "interiorup")
            createWall([1 * 80, i * -80], "interiorfull")

        for i in range(16, 24):
            createWall([2 * 80, i * -80], "interiorup")
            createWall([1 * 80, i * -80], "interiorfull")

            if not i > 15 or not i < 21:
                createWall([23 * 80, i * -80], "interiorup")
                createWall([22 * 80, i * -80], "interiorfull")

                createWall([30 * 80, i * -80], "interiorup")
                createWall([29 * 80, i * -80], "interiorfull")

        createWall([80 * 2, -80 * 13], "interiorsplit")
        createWall([80, -80 * 14], "interiorsplitall")

        createWall([80, 13 * -80], "interiorfull")
        createWall([2 * 80, 14 * -80], "interiorfull")

        for i in range(3, 13):
            createWall([i * 80, 13 * -80], "interior")
            createWall([i * 80, 14 * -80], "interiorfull")
            createWall([i * 80, 24 * -80], "interior")
            createWall([i * 80, 25 * -80], "interiorfull")

        createWall([80 * 2, -80 * 24], "interiorsplit")
        createWall([80, -80 * 25], "interiorsplitall")

        createWall([80, 24 * -80], "interiorfull")
        createWall([2 * 80, 25 * -80], "interiorfull")

        for i in range(1, 13):
            if not i > 1 or not i < 7:
                createWall([23 * 80, i * -80], "interiorup")
                createWall([22 * 80, i * -80], "interiorfull")

            if i < 11:
                if not i > 1 or not i < 7:
                    createWall([15 * 80, i * -80], "interiorup")
                    createWall([14 * 80, i * -80], "interiorfull")

        createWall([15 * 80, 0 * -80], "interiorup")
        createWall([14 * 80, 0 * -80], "interiorfull")
        createWall([15 * 80, -1 * -80], "interiorup")
        createWall([14 * 80, -1 * -80], "interiorfull")

        createWall([80 * 15, -80 * 11], "interiorsplit")
        createWall([80 * 14, -80 * 12], "interiorsplitall")

        createWall([14 * 80, 11 * -80], "interiorfull")
        createWall([15 * 80, 12 * -80], "interiorfull")

        for i in range(24, 34):
            createWall([i * 80, 13 * -80], "interior")
            createWall([i * 80, 14 * -80], "interiorfull")

        createWall([80 * 22, -80 * 14], "interiorsplitall")
        createWall([80 * 23, -80 * 13], "interiorsplit")

        createWall([22 * 80, 13 * -80], "interiorfull")
        createWall([23 * 80, 14 * -80], "interiorfull")


        createWall([80 * 23, -80 * 24], "interiorsplit")
        createWall([80 * 22, -80 * 25], "interiorsplitall")

        createWall([22 * 80, 24 * -80], "interiorfull")
        createWall([23 * 80, 25 * -80], "interiorfull")

        createWall([80 * 30, -80 * 24], "interiorsplit")
        createWall([80 * 29, -80 * 25], "interiorsplitall")

        createWall([29 * 80, 24 * -80], "interiorfull")
        createWall([30 * 80, 25 * -80], "interiorfull")

        for i in range(24, 28):
            createWall([i * 80, 24 * -80], "interior")
            createWall([i * 80, 25 * -80], "interiorfull")

        for i in range(31, 34):
            createWall([i * 80, 24 * -80], "interior")
            createWall([i * 80, 25 * -80], "interiorfull")

        for i in range(16, 21):
                createWall([i * 80, 27 * -80], "interior")
                createWall([i * 80, 28 * -80], "interiorfull")

        for i in range(14, 27):
            if not i > 15 or not i < 21:
                createWall([15 * 80, i * -80], "interiorup")
                createWall([14 * 80, i * -80], "interiorfull")

        createWall([80 * 15, -80 * 27], "interiorsplit")
        createWall([80 * 14, -80 * 28], "interiorsplitall")

        createWall([14 * 80, 27 * -80], "interiorfull")
        createWall([15 * 80, 28 * -80], "interiorfull")

        for x in range(13, 16):
            for y in range(2, 7):
                createFloor([x * 80, y * -80])

            for y in range(16, 21):
                createFloor([x * 80, y * -80])

        for x in range(21, 24):
            for y in range(16, 21):
                createFloor([x * 80, y * -80])

            for y in range(1, 7):
                createFloor([x * 80, y * -80])

        for x in range(16, 21):
            for y in range(2, 5):
                createFloor([x * 80, y * 80])

            for y in range(11, 14):
                createFloor([x * 80, y * -80])

        createWall([16 * 80, 3 * 80], "wallsplitdown2")
        createWall([17 * 80, 4 * 80], "wallsplitdown2")
        createWall([16 * 80, 4 * 80], "wall")

        createWall([19 * 80, 3 * 80], "wallsplitup")
        createWall([20 * 80, 3 * 80], "wall")
        createWall([20 * 80, 4 * 80], "wallsplitup")

        createWall([19 * 80, 2 * 80], None)
        createWall([20 * 80, 2 * 80], None)

        createWall([17 * 80, 11 * -80], "interiorsplitdown")
        createWall([16 * 80, 12 * -80], "interiorsplitdown2")
        createWall([16 * 80, 11 * -80], "interior")

        createWall([19 * 80, 12 * -80], "interiorsplitup2")
        createWall([20 * 80, 12 * -80], "interiorfull")
        createWall([20 * 80, 11 * -80], "interiorsplitup")

        createWall([19 * 80, 13 * -80], None)
        createWall([20 * 80, 13 * -80], None)

        createWall([17 * 80, 11 * -80], "interiorsplitdown3")
        createWall([16 * 80, 12 * -80], "interiorsplitdown2")
        createWall([16 * 80, 11 * -80], "interior")

        createWall([19 * 80, 12 * -80], "interiorsplitup2")
        createWall([20 * 80, 12 * -80], "interiorfull")
        createWall([20 * 80, 11 * -80], "interiorsplitup")

        createWall([19 * 80, 13 * -80], None)
        createWall([20 * 80, 13 * -80], None)

        createWall([14 * 80, 6 * -80], "interiorsplitup2")
        createWall([15 * 80, 5 * -80], "interiorsplitup3")
        createWall([15 * 80, 6 * -80], "interiorup")

        createWall([14 * 80, 3 * -80], "interiorsplitdown2")
        createWall([14 * 80, 2 * -80], "interiorfull")
        createWall([15 * 80, 2 * -80], "interiorsplitdown")

        createWall([13 * 80, 2 * -80], None)
        createWall([13 * 80, 3 * -80], None)

        ###

        createWall([22 * 80, 6 * -80], "interiorsplitup2")
        createWall([23 * 80, 5 * -80], "interiorsplitup3")
        createWall([23 * 80, 6 * -80], "interiorup")

        createWall([22 * 80, 3 * -80], "interiorsplitdown2")
        createWall([22 * 80, 2 * -80], "interiorfull")
        createWall([23 * 80, 2 * -80], "interiorsplitdown")

        createWall([21 * 80, 2 * -80], None)
        createWall([21 * 80, 3 * -80], None)

        for i in range(12):
            createJunk([random.randint(16, 20) * 80, random.randint(-1, 10) * -80])

        for i in range(10):
            createJunk([random.randint(16, 20) * 80, random.randint(14, 24) * -80])

        for i in range(20):
            createJunk([random.randint(3, 12) * 80, random.randint(1, 12) * -80])

        for i in range(20):
            createJunk([random.randint(25, 33) * 80, random.randint(1, 12) * -80])

        for i in range(12):
            createJunk([random.randint(3, 12) * 80, random.randint(16, 21) * -80])

        for i in range(5):
            createJunk([random.randint(25, 27) * 80, random.randint(16, 21) * -80])

        for i in range(5):
            createJunk([random.randint(31, 33) * 80, random.randint(16, 21) * -80])

        createDumpster([3 * 80, 3 * 80])
        createDumpster([9 * 80, 3 * 80])
        createDumpster([3 * 80, 27 * -80])
        createDumpster([9 * 80, 27 * -80])

    return all, walls, floors, dumpsters, junk

