diff --git a/Main.py b/Main.py index baa3f3a..894b353 100644 --- a/Main.py +++ b/Main.py @@ -26,67 +26,98 @@ mapHeight = int(map.get_height()) time1 = pygame.time.get_ticks() def initMapGen(): y = 0 - bY = 5 - bX = 4 + bY = 10 + cY = 0 + bX = 6 + i = 0 + 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 + cY += 1 + if cY % 7 == 0: + while i != 4: + map.set_at((x, y), (0,0,0,255)) + y += 1 + i += 1 + i = 0 + cY += 1 screen.blit(map, maprect) pygame.display.flip() - bX += 8 + bX += 12 y = 0 + cY = 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 + bX = 6 y = 0 + cY = y + i = 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 + cY += 1 + if cY % 7 == 0: + while i != 4: + map.set_at((x, y), (0,0,0,255)) + y += 1 + i += 1 + i = 0 + cY += 1 screen.blit(map, maprect) pygame.display.flip() - bX += 8 + bX += 12 y = 0 + cY = y - bY = 2 y = bY + cY = 0 + + while bY < mapHeight: + for x in range(0, mapWidth): + if y < mapHeight: + map.set_at((x, y), (0,0,0,255)) + y += 1 + cY += 1 + if cY % 7 == 0: + while i != 4: + map.set_at((x, y), (0,0,0,255)) + y += 1 + i += 1 + i = 0 + cY += 1 + screen.blit(map, maprect) + pygame.display.flip() + bY += 20 + y = bY + cY = 0 + + bY = 12 + y = bY + cY = 2 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 + cY += 1 + if cY % 7 == 0: + while i != 4: + map.set_at((x, y), (0,0,0,255)) + y += 1 + i += 1 + i = 0 + cY += 1 screen.blit(map, maprect) pygame.display.flip() - bY += 10 + bY += 20 y = bY + cY = 2 initMapGen() class uText: @@ -94,14 +125,23 @@ class uText: def __init__(self): self.font = pygame.font.Font(pygame.font.get_default_font(), 36) self.texts = [] + self.takenPos = [] + self.texts_to_remove = [] def write(self, text, position): - self.texts.append((text,position)) + if not (text,position) in self.texts: + for textTest in self.texts: + if textTest[0] != text and textTest[1] == position: + self.texts.remove(textTest) + self.texts.append((text,position)) + print(self.texts) - def delete(self, text): + def delete(self, parameter, info): text2 = [] for place in self.texts: - if place[0] != text: + if place[0] != info and parameter == "name": + text2.append(place) + elif place[1] != info and parameter == "pos": text2.append(place) self.texts = text2 @@ -113,16 +153,86 @@ class uText: screen.blit(textPrint, textPrintRect) def runTextTile(self, tile_pressed): + i=0 info = GameMap.getTileInfo(tile_pressed) + self.write(info["terrain"],(1000,50)) + + for bit in info["gameplay"]: + if True: #type(bit) == " button["xPos"] and pos[0] < button["xPos"] + button["width"]: + if pos[1] > button["yPos"] and pos[1] < button["yPos"] + button["height"]: + button["isHover"] = True + elif button["isHover"] == True: + button["isHover"] = False + + def drawButtons(self): + for button in self.buttons: + buttonRect = pygame.Rect(button["xPos"],button["yPos"],button["width"],button["height"]) + if button["isHover"] == False: + pygame.draw.rect(screen,(button["colour_standby"]),buttonRect) + else: + pygame.draw.rect(screen,(button["colour_hover"]),buttonRect) + +uButtoner = uButtons() uTexter = uText() -uTexter.write("State",(1000,0)) +def prerenderGraphics(): + uTexter.write("State",(1000,0)) + uButtoner.addButton("Claim",850,600,110,40,"darkgray","gray") +prerenderGraphics() + + pygame.image.save(map, "./Map/Images/blackstripes.png") @@ -156,6 +266,8 @@ while running: print(f"MB1 is true") pos = pygame.mouse.get_pos() tile_pressed = GameMap.findTileAt(pos) + if tile_pressed != None: + GameMap.paintTileBorder(tile_pressed, map) # fill the screen with a color to wipe away anything from last frame screen.fill("black") @@ -163,10 +275,12 @@ while running: if tile_pressed != None: uTexter.runTextTile(tile_pressed) + uButtoner.updateHover() + uButtoner.drawButtons() uTexter.runText() - + screen.blit(map, maprect) - + # RENDER YOUR GAME HERE # flip() the display to put your work on screen diff --git a/Map/Images/blackstripes.png b/Map/Images/blackstripes.png index 02c772a..d7e3a5d 100644 Binary files a/Map/Images/blackstripes.png and b/Map/Images/blackstripes.png differ diff --git a/Map/Images/sampledone.png b/Map/Images/sampledone.png index 9ad694f..37d7091 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 ea8241e..9da9ce5 100644 --- a/Map/MapManager.py +++ b/Map/MapManager.py @@ -76,12 +76,13 @@ class MapManager: def load(self,mapObject): print("Loading map") self.tiles = {} + self.paintedTile = None tileprint = 0 currentVertical = 0 currentHorizontal = 0 currentTile = 0 for y in range(0, mapObject.get_height()-1): - if (y-1) % 5 == 0: + if (y-1) % 10 == 0: currentVertical += 1 currentHorizontal = 0 #print(f"Current Vertical:{currentVertical}") @@ -102,8 +103,8 @@ class MapManager: currentTile += 1 currentHorizontal += 1 self.amountOfTiles = currentTile - self.Verticals = 200 - self.Horizontals = 200 + self.Verticals = 120 + self.Horizontals = 80 print(f"{self.tiles.keys()}") def populate(self, mapObject): @@ -152,8 +153,9 @@ class MapManager: 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)) tile.add_terrain(f"{tilesMapped[tile.Position[0]][tile.Position[1]]}") + tile.paint_pixels(mapObject, int(colour1),int(colour2),int(colour3)) + tile.findBorder(mapObject) def findTileAt(self, pos): for x in self.tiles.keys(): @@ -170,9 +172,26 @@ class MapManager: def getTileInfo(self, id): info = {} + thistile = self.tiles[f"{id}"] info["id"] = id - info["pixels"] = self.tiles[f"{id}"].getPixels() - info["terrain"] = self.tiles[f"{id}"].getTerrain() + info["pixels"] = thistile.getPixels() + info["terrain"] = thistile.getTerrain() + info["border"] = thistile.getBorderPixels() + info["gameplay"] = thistile.getGameplayInfo() + return info + + def paintTileBorder(self, id, mapObject): + if self.paintedTile != None: + self.clearPaintedTile(mapObject) + print("Clearing previous tile") + tile = self.tiles[f"{id}"] + tile.paint_border_pixels(mapObject) + self.paintedTile = tile + + def clearPaintedTile(self, mapObject): + self.paintedTile.paint_border_pixels(mapObject) + self.paintedTile = None + print("Cleared previous tile") class Tile: @@ -183,6 +202,13 @@ class Tile: self.pixels = [] self.colour = (random.randint(0,255),random.randint(0,255),random.randint(0,255)) self.terrain = "" + self.resources = {} + self.buildings = [] + self.units = {} + self.owner = "Unclaimed" + self.pop = 0 + self.borderPixels = [] + self.borderPainted = False def getId(self): return self.Id @@ -192,14 +218,53 @@ class Tile: def getTerrain(self): return self.terrain + + def getBorderPixels(self): + return self.borderPixels + + def getGameplayInfo(self): + infoToSend = (("resources", self.resources), ("buildings", self.buildings), ("units", self.units), ("owner", self.owner), ("population", self.pop)) + return infoToSend def add_pixel(self,pixel): self.pixels.append(pixel) def add_terrain(self, terrain): self.terrain = terrain + #print(f"Added terrain for tile {self.Id}, it is now a {self.terrain} / {terrain} biome") def paint_pixels(self, map, r,g,b): for pixel in self.pixels: map.set_at((pixel[0],pixel[1]), (r,g,b,255)) + + def paint_border_pixels(self, map): + if self.borderPainted == False: + print(f"Painting border for tile {self.Id}") + for pixel in self.borderPixels: + map.set_at((pixel[0],pixel[1]), (255,255,255,255)) + self.borderPainted = True + else: + print(f"Clearing border for tile {self.Id}") + for pixel in self.borderPixels: + map.set_at((pixel[0],pixel[1]), (0,0,0,255)) + + def findBorder(self, map): + for pixel in self.pixels: + #check above + if pixel[1] != 0: + if map.get_at((pixel[0],pixel[1]-1)) == ((0,0,0,255)): + self.borderPixels.append((pixel[0],pixel[1]-1)) + #check right + if pixel[0] < map.get_width()-1: + if map.get_at((pixel[0]+1,pixel[1])) == ((0,0,0,255)): + self.borderPixels.append((pixel[0]+1,pixel[1])) + #check below + if pixel[1] < map.get_height()-1: + if map.get_at((pixel[0],pixel[1]+1)) == ((0,0,0,255)): + self.borderPixels.append((pixel[0],pixel[1]+1)) + #check left + if pixel[0] != 0: + if map.get_at((pixel[0]-1,pixel[1])) == ((0,0,0,255)): + self.borderPixels.append((pixel[0]-1,pixel[1])) + diff --git a/Map/__pycache__/MapManager.cpython-312.pyc b/Map/__pycache__/MapManager.cpython-312.pyc index 66151b7..d751afa 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 5303f28..b0bab43 100644 Binary files a/Map/__pycache__/TileTypes.cpython-312.pyc and b/Map/__pycache__/TileTypes.cpython-312.pyc differ diff --git a/Script/__pycache__/ScriptUtils.cpython-312.pyc b/Script/__pycache__/ScriptUtils.cpython-312.pyc index 69d7e6b..24c6d33 100644 Binary files a/Script/__pycache__/ScriptUtils.cpython-312.pyc and b/Script/__pycache__/ScriptUtils.cpython-312.pyc differ diff --git a/cache.py b/cache.py new file mode 100644 index 0000000..4565da3 --- /dev/null +++ b/cache.py @@ -0,0 +1,63 @@ +def initMapGen(): + y = 0 + bY = 5 + bX = 4 + 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 % set_at((x, y), (0,0,0,255)) + y5 == 0: + map. += 1 + screen.blit(map, maprect) + pygame.display.flip() + bY += 10 + y = bY \ No newline at end of file