diff --git a/Archive/V1/GFX/sample.txt b/Archive/V1/GFX/sample.txt new file mode 100644 index 0000000..e69de29 diff --git a/Archive/V1/Main.py b/Archive/V1/Main.py new file mode 100644 index 0000000..57f6123 --- /dev/null +++ b/Archive/V1/Main.py @@ -0,0 +1,126 @@ +import pygame +import sys +from threading import Thread + +sys.path.append('./Map') + +import MapManager + +# pygame setup +pygame.init() +screen = pygame.display.set_mode((1280, 720)) +clock = pygame.time.Clock() +running = True + +map = pygame.image.load( "./Map/Images/sample.jpg") +maprect = map.get_rect() + +mapWidth = int(map.get_width()) +mapHeight = int(map.get_height()) + +y = 0 +bY = 5 +bX = 4 + +time1 = pygame.time.get_ticks() + +while bX < mapWidth: + for x in range(bX, mapWidth): + if y < mapHeight: + map.set_at((x, y), (0,0,0,255)) + y += 1 + if y % 5 == 0: + map.set_at((x, y), (0,0,0,255)) + y += 1 + screen.blit(map, maprect) + pygame.display.flip() + bX += 8 + y = 0 + +y = bY + +while bY < mapHeight: + for x in range(0, mapWidth): + if y < mapHeight: + map.set_at((x, y), (0,0,0,255)) + y += 1 + if y % 5 == 0: + map.set_at((x, y), (0,0,0,255)) + y += 1 + screen.blit(map, maprect) + pygame.display.flip() + bY += 10 + y = bY + +bX = 4 +y = 0 + +while bX < mapWidth: + for x in range(bX, -1, -1): + if y < mapHeight: + map.set_at((x, y), (0,0,0,255)) + y += 1 + if y % 5 == 0: + map.set_at((x, y), (0,0,0,255)) + y += 1 + screen.blit(map, maprect) + pygame.display.flip() + bX += 8 + y = 0 + +bY = 2 +y = bY + +while bY < mapHeight: + for x in range(mapWidth, 0, -1): + if y < mapHeight: + map.set_at((x, y), (0,0,0,255)) + y += 1 + if y % 5 == 0: + map.set_at((x, y), (0,0,0,255)) + y += 1 + screen.blit(map, maprect) + pygame.display.flip() + bY += 10 + y = bY + +pygame.image.save(map, "./Map/Images/blackstripes.png") + +GameMap = MapManager.MapManager() + +GameMap.load(map) + +t = Thread(target=GameMap.populate, args=(map,)) +t.start() + +time2 = pygame.time.get_ticks() + +print(str(time2 - time1)) + +pygame.image.save(map, "./Map/Images/sampledone.png") + +timeX = pygame.time.get_ticks() + +while running: + # poll for events + # pygame.QUIT event means the user clicked X to close your window + for event in pygame.event.get(): + if event.type == pygame.QUIT: + running = False + + # fill the screen with a color to wipe away anything from last frame + screen.fill("black") + + screen.blit(map, maprect) + + # RENDER YOUR GAME HERE + + # flip() the display to put your work on screen + pygame.display.flip() + + clock.tick(120) # limits FPS to 120 + timeY = pygame.time.get_ticks() + if timeY % 1000 == 0: + print(f"{timeY-timeX}ms per tick\n{1000/(timeY-timeX)} Ticks per second") + timeX = pygame.time.get_ticks() +pygame.quit() \ No newline at end of file diff --git a/Archive/V1/Map/Images/blackstripes.png b/Archive/V1/Map/Images/blackstripes.png new file mode 100644 index 0000000..02c772a Binary files /dev/null and b/Archive/V1/Map/Images/blackstripes.png differ diff --git a/Archive/V1/Map/Images/sample.jpg b/Archive/V1/Map/Images/sample.jpg new file mode 100644 index 0000000..6cd3941 Binary files /dev/null and b/Archive/V1/Map/Images/sample.jpg differ diff --git a/Archive/V1/Map/Images/sample.png b/Archive/V1/Map/Images/sample.png new file mode 100644 index 0000000..042bc81 Binary files /dev/null and b/Archive/V1/Map/Images/sample.png differ diff --git a/Archive/V1/Map/Images/sampledone.png b/Archive/V1/Map/Images/sampledone.png new file mode 100644 index 0000000..9ad694f Binary files /dev/null and b/Archive/V1/Map/Images/sampledone.png differ diff --git a/Archive/V1/Map/MapManager.py b/Archive/V1/Map/MapManager.py new file mode 100644 index 0000000..85e240e --- /dev/null +++ b/Archive/V1/Map/MapManager.py @@ -0,0 +1,175 @@ +import random +import TileTypes + +class MapManager: + + def tileChecker(self, x, y, map): + list = [] + CurY = y + CurX = x + RelX = 0 + RelY = 0 + floor = False + contact = False + while not floor: + if map.get_at((CurX, CurY)) == (255,255,255,255) and y != 0: + list.append((CurX,CurY)) + while not contact: + if CurX+RelX-1 >= 0: + RelX -= 1 + else: + contact = True + if map.get_at((CurX+RelX, CurY)) == (0,0,0,255): + contact = True + if map.get_at((CurX+RelX, CurY)) == (255,255,255,255): + list.append((CurX+RelX,CurY)) + contact = False + RelX = 0 + while not contact: + if CurX+RelX+1 < map.get_width(): + RelX += 1 + else: + contact = True + if map.get_at((CurX+RelX, CurY)) == (0,0,0,255): + contact = True + if map.get_at((CurX+RelX, CurY)) == (255,255,255,255): + list.append((CurX+RelX,CurY)) + if CurY+1 < map.get_height(): + CurY += 1 + else: + floor = True + contact = False + RelX = 0 + elif map.get_at((CurX, CurY)) == (255,255,255,255) and y == 0: + list.append((CurX,CurY)) + contact = False + contactB = False + RelX = 0 + RelY = 0 + while not contact: + if map.get_at((CurX+RelX, CurY)) == (0,0,0,255): + contact = True + if map.get_at((CurX+RelX, CurY)) == (255,255,255,255): + list.append((CurX+RelX,CurY)) + while not contactB: + if CurY+RelY+1 < map.get_height(): + RelY += 1 + else: + contactB = True + if map.get_at((CurX+RelX, CurY+RelY)) == (255,255,255,255): + list.append((CurX+RelX,CurY+RelY)) + else: + contactB = True + if CurX+RelX+1 < map.get_width(): + RelX += 1 + else: + contact = True + contactB = False + RelY = 0 + contact = False + floor = True + RelX = 0 + else: + floor = True + return list + + def load(self,mapObject): + print("Loading map") + self.tiles = {} + tileprint = 0 + currentVertical = 0 + currentHorizontal = 0 + currentTile = 0 + for y in range(0, mapObject.get_height()-1): + if (y-1) % 5 == 0: + currentVertical += 1 + currentHorizontal = 0 + print(f"Current Vertical:{currentVertical}") + for x in range(0, mapObject.get_width()-1): + CurCol = mapObject.get_at((x, y)) + if CurCol == (255,255,255,255): + self.tiles[f"{currentTile}"] = Tile(currentTile,(currentHorizontal,currentVertical)) + goodtiles = self.tileChecker(x, y, mapObject) + for pixel in goodtiles: + self.tiles[f"{currentTile}"].add_pixel(pixel) + if tileprint < 20: + print(f"Added tiles: {goodtiles}") + tileprint += 1 + colour1 = 0 + colour2 = 255 + colour3 = 0 + self.tiles[f"{currentTile}"].paint_pixels(mapObject, int(colour1),int(colour2),int(colour3)) + currentTile += 1 + currentHorizontal += 1 + self.amountOfTiles = currentTile + self.Verticals = 200 + self.Horizontals = 200 + print(f"{self.tiles.keys()}") + + def populate(self, mapObject): + print("Populating map") + print("Loading terrains...") + self.TileWorker = TileTypes.TerrainWorker() + self.TileWorker.generateTerrain() + tilesMapped = [["" for i in range(self.Verticals)] for j in range(self.Horizontals)] + types = self.TileWorker.get_terrain("types") + for tile in self.tiles.keys(): + position = self.tiles[f"{tile}"].Position + print(f"{position}") + if position[1] == 0: + choice = random.randrange(1,7) + if choice != 6 and position[0] != 0: + tilesMapped[position[0]][position[1]] = tilesMapped[position[0]-1][position[1]] + else: + tilesMapped[position[0]][position[1]] = self.TileWorker.get_rand_tType(tilesMapped, position) + elif position [0] == 0: + choice = random.randrange(1,7) + if choice != 6 and position[1] != 0: + tilesMapped[position[0]][position[1]] = tilesMapped[position[0]][position[1]-1] + else: + tilesMapped[position[0]][position[1]] = self.TileWorker.get_rand_tType(tilesMapped, position) + else: + choice = random.randrange(1,21) + if choice <= 6: + tilesMapped[position[0]][position[1]] = tilesMapped[position[0]][position[1]-1] + elif choice >= 7 and choice <= 14: + tilesMapped[position[0]][position[1]] = tilesMapped[position[0]-1][position[1]] + elif choice != 20: + choice2 = random.randrange(1,3) + if choice2 == 1: + tilesMapped[position[0]][position[1]] = tilesMapped[position[0]][position[1]-1] + else: + if position[0] != int(mapObject.get_width()): + tilesMapped[position[0]][position[1]] = tilesMapped[position[0]+1][position[1]-1] + else: + tilesMapped[position[0]][position[1]] = tilesMapped[position[0]-1][position[1]-1] + elif choice == 20: + tilesMapped[position[0]][position[1]] = self.TileWorker.get_rand_tType(tilesMapped, position) + print(f"{tilesMapped}") + mappedColours = self.TileWorker.get_terrain("colours") + for x in self.tiles.keys(): + tile = self.tiles[f"{x}"] + if tilesMapped[tile.Position[0]][tile.Position[1]] != "": + colour = mappedColours[f"{tilesMapped[tile.Position[0]][tile.Position[1]]}"] + colour1, colour2, colour3 = colour[0], colour[1], colour[2] + tile.paint_pixels(mapObject, int(colour1),int(colour2),int(colour3)) + + +class Tile: + + def __init__(self, Id, Pos): + self.Id = Id + self.Position = Pos + self.pixels = [] + self.colour = (random.randint(0,255),random.randint(0,255),random.randint(0,255)) + + def getId(self): + return self.Id + + def add_pixel(self,pixel): + self.pixels.append(pixel) + + def paint_pixels(self, map, r,g,b): + for pixel in self.pixels: + map.set_at((pixel[0],pixel[1]), (r,g,b,255)) + diff --git a/Archive/V1/Map/TileTypes.py b/Archive/V1/Map/TileTypes.py new file mode 100644 index 0000000..2f0a068 --- /dev/null +++ b/Archive/V1/Map/TileTypes.py @@ -0,0 +1,73 @@ +import random + +class TerrainWorker: + + def generateTerrain(self): + self.terrains = [] + ocean = Terrain("ocean", (0, 102, 255), 2, True, ("plains", "forest", "hills")) + self.terrains.append(ocean) + lake = Terrain("lake", (0, 204, 255), 1, True, ("plains", "forest", "hills")) + self.terrains.append(lake) + plains = Terrain("plains", (0, 200, 0), 1, False, ("ocean", "lake", "forest", "hills", "desert")) + self.terrains.append(plains) + forest = Terrain("forest", (0, 100, 0), 2, False, ("ocean", "lake", "plains", "hills")) + self.terrains.append(forest) + hills = Terrain("hills", (102, 102, 153), 2, False, ("ocean", "lake", "plains", "forest")) + self.terrains.append(hills) + desert = Terrain("desert", (230, 230, 0), 1, False, ("plains", "dune")) + self.terrains.append(desert) + dune = Terrain("dune", (153, 153, 0), 2, False, ("desert",)) + self.terrains.append(dune) + self.terrainNames = [] + for terrain in self.terrains: + self.terrainNames.append(str(terrain.name)) + print(f"Added {self.terrainNames}") + + + def get_terrain(self, action): + if action == "types": + return self.terrainNames + if action == "colours": + dictionary = {} + for terrain in self.terrains: + dictionary[terrain.name] = terrain.colour + print(f"{dictionary}") + return dictionary + + def get_rand_tType(self,dict,pos): + available_terrains = [] + proximity_terrains = [] + if pos[1] == 0: + available_terrains = self.terrainNames + else: + print(f"Testing: {dict[pos[0]][pos[1]-1]}") + if dict[pos[0]][pos[1]-1] != "" and dict[pos[0]][pos[1]-1] != None: + proximity_terrains.append(dict[pos[0]][pos[1]-1]) + print(f"Found proxy terrain: {dict[pos[0]][pos[1]-1]}") + print(f"Testing: {dict[pos[0]+1][pos[1]-1]}") + if dict[pos[0]+1][pos[1]-1] != "" and dict[pos[0]+1][pos[1]-1] != None: + proximity_terrains.append(dict[pos[0]+1][pos[1]-1]) + print(f"Found proxy terrain: {dict[pos[0]+1][pos[1]-1]}") + if proximity_terrains == []: + print("Fixing null proxy error") + available_terrains = self.terrainNames + for terrain in proximity_terrains: + print(f"Terrain using:{terrain}") + for matchterrain in self.terrains: + if matchterrain.name == terrain: + print(f"Matched with Terrain successfully") + for proxy in matchterrain.proxys: + available_terrains.append(proxy) + print(f"Found available terrain:{proxy}") + + tTypeNum = random.randrange(0, len(available_terrains)) + return available_terrains[tTypeNum] + +class Terrain: + + def __init__(self, name, colour, moveC, water, proxys): + self.name = name + self.colour = colour + self.moveCost = moveC + self.isWater = water + self.proxys = proxys \ No newline at end of file diff --git a/Archive/V1/Map/__pycache__/MapManager.cpython-312.pyc b/Archive/V1/Map/__pycache__/MapManager.cpython-312.pyc new file mode 100644 index 0000000..73bc139 Binary files /dev/null and b/Archive/V1/Map/__pycache__/MapManager.cpython-312.pyc differ diff --git a/Archive/V1/Map/__pycache__/TileTypes.cpython-312.pyc b/Archive/V1/Map/__pycache__/TileTypes.cpython-312.pyc new file mode 100644 index 0000000..cd2d494 Binary files /dev/null and b/Archive/V1/Map/__pycache__/TileTypes.cpython-312.pyc differ diff --git a/Archive/V1/Realms/RealmManager.py b/Archive/V1/Realms/RealmManager.py new file mode 100644 index 0000000..e69de29 diff --git a/Archive/V1/Realms/template.realm b/Archive/V1/Realms/template.realm new file mode 100644 index 0000000..e69de29 diff --git a/Archive/V1/SFX/sample.txt b/Archive/V1/SFX/sample.txt new file mode 100644 index 0000000..e69de29 diff --git a/Main.py b/Main.py index 6a51e0d..57f6123 100644 --- a/Main.py +++ b/Main.py @@ -1,5 +1,6 @@ import pygame import sys +from threading import Thread sys.path.append('./Map') @@ -89,10 +90,8 @@ GameMap = MapManager.MapManager() GameMap.load(map) -screen.blit(map, maprect) -pygame.display.flip() - -GameMap.populate(map) +t = Thread(target=GameMap.populate, args=(map,)) +t.start() time2 = pygame.time.get_ticks() diff --git a/Map/Images/sampledone.png b/Map/Images/sampledone.png index 1ba680c..9ad694f 100644 Binary files a/Map/Images/sampledone.png and b/Map/Images/sampledone.png differ diff --git a/Map/MapManager.py b/Map/MapManager.py index 24f9be8..85e240e 100644 --- a/Map/MapManager.py +++ b/Map/MapManager.py @@ -81,9 +81,10 @@ class MapManager: currentHorizontal = 0 currentTile = 0 for y in range(0, mapObject.get_height()-1): - if (y-1) % 10 == 0: + if (y-1) % 5 == 0: currentVertical += 1 currentHorizontal = 0 + print(f"Current Vertical:{currentVertical}") for x in range(0, mapObject.get_width()-1): CurCol = mapObject.get_at((x, y)) if CurCol == (255,255,255,255): @@ -94,15 +95,15 @@ class MapManager: if tileprint < 20: print(f"Added tiles: {goodtiles}") tileprint += 1 - colour1 = 255 - colour2 = 0 + colour1 = 0 + colour2 = 255 colour3 = 0 self.tiles[f"{currentTile}"].paint_pixels(mapObject, int(colour1),int(colour2),int(colour3)) currentTile += 1 currentHorizontal += 1 self.amountOfTiles = currentTile - self.Verticals = 59 - self.Horizontals = 207 + self.Verticals = 200 + self.Horizontals = 200 print(f"{self.tiles.keys()}") def populate(self, mapObject): @@ -120,22 +121,36 @@ class MapManager: if choice != 6 and position[0] != 0: tilesMapped[position[0]][position[1]] = tilesMapped[position[0]-1][position[1]] else: - tilesMapped[position[0]][position[1]] = self.TileWorker.get_rand_tType() - else: - choice = random.randrange(1,12) - if choice <= 5: + tilesMapped[position[0]][position[1]] = self.TileWorker.get_rand_tType(tilesMapped, position) + elif position [0] == 0: + choice = random.randrange(1,7) + if choice != 6 and position[1] != 0: tilesMapped[position[0]][position[1]] = tilesMapped[position[0]][position[1]-1] - elif choice != 11: + else: + tilesMapped[position[0]][position[1]] = self.TileWorker.get_rand_tType(tilesMapped, position) + else: + choice = random.randrange(1,21) + if choice <= 6: + tilesMapped[position[0]][position[1]] = tilesMapped[position[0]][position[1]-1] + elif choice >= 7 and choice <= 14: tilesMapped[position[0]][position[1]] = tilesMapped[position[0]-1][position[1]] - elif choice == 11: - tilesMapped[position[0]][position[1]] = self.TileWorker.get_rand_tType() + elif choice != 20: + choice2 = random.randrange(1,3) + if choice2 == 1: + tilesMapped[position[0]][position[1]] = tilesMapped[position[0]][position[1]-1] + else: + if position[0] != int(mapObject.get_width()): + tilesMapped[position[0]][position[1]] = tilesMapped[position[0]+1][position[1]-1] + else: + tilesMapped[position[0]][position[1]] = tilesMapped[position[0]-1][position[1]-1] + elif choice == 20: + tilesMapped[position[0]][position[1]] = self.TileWorker.get_rand_tType(tilesMapped, position) print(f"{tilesMapped}") mappedColours = self.TileWorker.get_terrain("colours") for x in self.tiles.keys(): tile = self.tiles[f"{x}"] if tilesMapped[tile.Position[0]][tile.Position[1]] != "": colour = mappedColours[f"{tilesMapped[tile.Position[0]][tile.Position[1]]}"] - print(f"{colour}") colour1, colour2, colour3 = colour[0], colour[1], colour[2] tile.paint_pixels(mapObject, int(colour1),int(colour2),int(colour3)) @@ -145,7 +160,6 @@ class Tile: def __init__(self, Id, Pos): self.Id = Id self.Position = Pos - print(f"{Pos[0]},{Pos[1]}") self.pixels = [] self.colour = (random.randint(0,255),random.randint(0,255),random.randint(0,255)) diff --git a/Map/TileTypes.py b/Map/TileTypes.py index ff193b7..e997471 100644 --- a/Map/TileTypes.py +++ b/Map/TileTypes.py @@ -4,19 +4,19 @@ class TerrainWorker: def generateTerrain(self): self.terrains = [] - ocean = Terrain("ocean", (0, 102, 255), 2, True) + ocean = Terrain("ocean", (0, 102, 255), 2, True, ("plains", "forest", "hills")) self.terrains.append(ocean) - lake = Terrain("lake", (0, 204, 255), 1, True) + lake = Terrain("lake", (0, 204, 255), 1, True, ("plains", "forest", "hills")) self.terrains.append(lake) - plains = Terrain("plains", (0, 200, 0), 1, False) + plains = Terrain("plains", (0, 200, 0), 1, False, ("ocean", "lake", "forest", "hills", "desert")) self.terrains.append(plains) - forest = Terrain("forest", (0, 100, 0), 2, False) + forest = Terrain("forest", (0, 100, 0), 2, False, ("ocean", "lake", "plains", "hills")) self.terrains.append(forest) - hills = Terrain("hills", (102, 102, 153), 2, False) + hills = Terrain("hills", (102, 102, 153), 2, False, ("ocean", "lake", "plains", "forest")) self.terrains.append(hills) - desert = Terrain("desert", (230, 230, 0), 1, False) + desert = Terrain("desert", (230, 230, 0), 1, False, ("plains", "dune")) self.terrains.append(desert) - dune = Terrain("dune", (153, 153, 0), 2, False) + dune = Terrain("dune", (153, 153, 0), 2, False, ("desert",)) self.terrains.append(dune) self.terrainNames = [] for terrain in self.terrains: @@ -31,16 +31,61 @@ class TerrainWorker: dictionary = {} for terrain in self.terrains: dictionary[terrain.name] = terrain.colour + print(f"{dictionary}") return dictionary + + def biomebalance(self, biome): + if biome == "ocean": + return 2 + if biome == "lake": + return 3 + if biome == "plains": + return 5 + if biome == "forest": + return 4 + if biome == "hills": + return 3 + if biome == "desert": + return 2 + if biome == "dune": + return 1 - def get_rand_tType(self): - tTypeNum = random.randrange(0, len(self.terrains)) - return self.terrainNames[tTypeNum] + + def get_rand_tType(self,dict,pos): + available_terrains = [] + proximity_terrains = [] + if pos[1] == 0: + available_terrains = self.terrainNames + else: + print(f"Testing: {dict[pos[0]][pos[1]-1]}") + if dict[pos[0]][pos[1]-1] != "" and dict[pos[0]][pos[1]-1] != None: + proximity_terrains.append(dict[pos[0]][pos[1]-1]) + print(f"Found proxy terrain: {dict[pos[0]][pos[1]-1]}") + print(f"Testing: {dict[pos[0]+1][pos[1]-1]}") + if dict[pos[0]+1][pos[1]-1] != "" and dict[pos[0]+1][pos[1]-1] != None: + proximity_terrains.append(dict[pos[0]+1][pos[1]-1]) + print(f"Found proxy terrain: {dict[pos[0]+1][pos[1]-1]}") + if proximity_terrains == []: + print("Fixing null proxy error") + available_terrains = self.terrainNames + for terrain in proximity_terrains: + print(f"Terrain using:{terrain}") + for matchterrain in self.terrains: + if matchterrain.name == terrain: + print(f"Matched with Terrain successfully") + for proxy in matchterrain.proxys: + for x in range(0, self.biomebalance(proxy)): + available_terrains.append(proxy) + print(f"Found available terrain:{proxy}") + + tTypeNum = random.randrange(0, len(available_terrains)) + return available_terrains[tTypeNum] class Terrain: - def __init__(self, name, colour, moveC, water): + def __init__(self, name, colour, moveC, water, proxys): self.name = name self.colour = colour self.moveCost = moveC - self.isWater = water \ No newline at end of file + self.isWater = water + self.proxys = proxys \ No newline at end of file diff --git a/Map/__pycache__/MapManager.cpython-312.pyc b/Map/__pycache__/MapManager.cpython-312.pyc index 58d32f5..dc234d9 100644 Binary files a/Map/__pycache__/MapManager.cpython-312.pyc and b/Map/__pycache__/MapManager.cpython-312.pyc differ diff --git a/Map/__pycache__/TileTypes.cpython-312.pyc b/Map/__pycache__/TileTypes.cpython-312.pyc index 1c41081..842453d 100644 Binary files a/Map/__pycache__/TileTypes.cpython-312.pyc and b/Map/__pycache__/TileTypes.cpython-312.pyc differ