From 5d14ce22bf7515e88b8b3a11cad8a24679c92d10 Mon Sep 17 00:00:00 2001 From: Hannah-Dagemark Date: Tue, 16 Apr 2024 19:46:37 +0200 Subject: [PATCH] Commit 16/04-24 --- Main.py | 38 ++++++++++++++++++ Map/MapManager.py | 33 +++++++++++++-- Map/TileTypes.py | 18 ++++----- Map/__pycache__/MapManager.cpython-312.pyc | Bin 9108 -> 10555 bytes Map/__pycache__/TileTypes.cpython-312.pyc | Bin 5344 -> 4628 bytes Script/ScriptUtils.py | 0 .../__pycache__/ScriptUtils.cpython-312.pyc | Bin 0 -> 164 bytes 7 files changed, 76 insertions(+), 13 deletions(-) create mode 100644 Script/ScriptUtils.py create mode 100644 Script/__pycache__/ScriptUtils.cpython-312.pyc diff --git a/Main.py b/Main.py index 57f6123..437d4e4 100644 --- a/Main.py +++ b/Main.py @@ -3,12 +3,15 @@ import sys from threading import Thread sys.path.append('./Map') +sys.path.append('./Script') +import ScriptUtils import MapManager # pygame setup pygame.init() screen = pygame.display.set_mode((1280, 720)) +pygame.display.set_caption('CountDuchKing') clock = pygame.time.Clock() running = True @@ -84,6 +87,17 @@ while bY < mapHeight: bY += 10 y = bY +class uText: + + def __init__(self): + self.font = pygame.font.SysFont('Comic Sans MS', 30) + + def write(self, text): + text = self.font.render(text, antialias=True, color=(255,255,255)) + return text + +uTexter = uText() + pygame.image.save(map, "./Map/Images/blackstripes.png") GameMap = MapManager.MapManager() @@ -101,16 +115,40 @@ pygame.image.save(map, "./Map/Images/sampledone.png") timeX = pygame.time.get_ticks() +print("Entering Running Stage") + +tile_pressed = None + 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 + if event.type == pygame.MOUSEBUTTONDOWN: + if pygame.mouse.get_pressed()[0] == True: + print(f"MB1 is true") + pos = pygame.mouse.get_pos() + tile_pressed = GameMap.findTileAt(pos) # fill the screen with a color to wipe away anything from last frame screen.fill("black") + font = pygame.font.Font(pygame.font.get_default_font(), 36) + + if tile_pressed != None: + tile_pressed = str(tile_pressed) + tilePrint = font.render(tile_pressed, True, (255, 255, 255)) + tilePrintRect = tilePrint.get_rect() + tilePrintRect = tilePrintRect.move(1000,50) + screen.blit(tilePrint, tilePrintRect) + + textPrint = font.render('State', True, (255, 255, 255)) + textPrintRect = textPrint.get_rect() + textPrintRect = textPrintRect.move(1000,0) + + screen.blit(textPrint, textPrintRect) + screen.blit(map, maprect) # RENDER YOUR GAME HERE diff --git a/Map/MapManager.py b/Map/MapManager.py index 85e240e..0345c64 100644 --- a/Map/MapManager.py +++ b/Map/MapManager.py @@ -84,7 +84,7 @@ class MapManager: if (y-1) % 5 == 0: currentVertical += 1 currentHorizontal = 0 - print(f"Current Vertical:{currentVertical}") + #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): @@ -93,7 +93,7 @@ class MapManager: for pixel in goodtiles: self.tiles[f"{currentTile}"].add_pixel(pixel) if tileprint < 20: - print(f"Added tiles: {goodtiles}") + #print(f"Added tiles: {goodtiles}") tileprint += 1 colour1 = 0 colour2 = 255 @@ -115,7 +115,7 @@ class MapManager: types = self.TileWorker.get_terrain("types") for tile in self.tiles.keys(): position = self.tiles[f"{tile}"].Position - print(f"{position}") + #print(f"{position}") if position[1] == 0: choice = random.randrange(1,7) if choice != 6 and position[0] != 0: @@ -145,7 +145,7 @@ class MapManager: 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}") + #print(f"{tilesMapped}") mappedColours = self.TileWorker.get_terrain("colours") for x in self.tiles.keys(): tile = self.tiles[f"{x}"] @@ -154,6 +154,24 @@ class MapManager: colour1, colour2, colour3 = colour[0], colour[1], colour[2] tile.paint_pixels(mapObject, int(colour1),int(colour2),int(colour3)) + def findTileAt(self, pos): + for x in self.tiles.keys(): + tile = self.tiles[f"{x}"] + if any(x == pos for x in tile.getPixels()): + if int(x) == int(tile.getId()): + return x + else: + print(f"Missmatching ID for found tile: {x} / {tile.getId()}") + return (x,tile.getId()) + + print(f"Could not find tile at position: {pos[0]},{pos[1]}") + return None + + def getTileInfo(self, id): + info = {} + info["id"] = id + info["pixels"] = self.tiles[f"{id}"].getPixels() + class Tile: @@ -162,13 +180,20 @@ class Tile: self.Position = Pos self.pixels = [] self.colour = (random.randint(0,255),random.randint(0,255),random.randint(0,255)) + self.terrain = "" def getId(self): return self.Id + + def getPixels(self): + return self.pixels def add_pixel(self,pixel): self.pixels.append(pixel) + def add_terrain(self, terrain): + self.terrain = terrain + 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/Map/TileTypes.py b/Map/TileTypes.py index e997471..b8955b1 100644 --- a/Map/TileTypes.py +++ b/Map/TileTypes.py @@ -31,7 +31,7 @@ class TerrainWorker: dictionary = {} for terrain in self.terrains: dictionary[terrain.name] = terrain.colour - print(f"{dictionary}") + #print(f"{dictionary}") return dictionary def biomebalance(self, biome): @@ -57,26 +57,26 @@ class TerrainWorker: if pos[1] == 0: available_terrains = self.terrainNames else: - print(f"Testing: {dict[pos[0]][pos[1]-1]}") + #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]}") + #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]}") + #print(f"Found proxy terrain: {dict[pos[0]+1][pos[1]-1]}") if proximity_terrains == []: - print("Fixing null proxy error") + #print("Fixing null proxy error") available_terrains = self.terrainNames for terrain in proximity_terrains: - print(f"Terrain using:{terrain}") + #print(f"Terrain using:{terrain}") for matchterrain in self.terrains: if matchterrain.name == terrain: - print(f"Matched with Terrain successfully") + #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}") + #print(f"Found available terrain:{proxy}") tTypeNum = random.randrange(0, len(available_terrains)) return available_terrains[tTypeNum] diff --git a/Map/__pycache__/MapManager.cpython-312.pyc b/Map/__pycache__/MapManager.cpython-312.pyc index dc234d94443700844f89d4a9cd96a2ba0e3a4800..a483555ffe90e229b3e736894b2d2c23d944825b 100644 GIT binary patch delta 2186 zcmZuyeQZ-z6u;+v^n2~rc8r#FdmC(0nRSX5Rwo9xI2PStfP#d9Wv?3@vzzyI;%b+o zlGvGn8&{o*;EXYd1cNRnGeT61QR5$M47FDOAkp}d_y-gdP-FDm*HvfYP2TUFbMHOp zp8LD!-1|(+dmHVa7Zq6uw##W>_f=)w{xDq6-mIvxsPcZY%{XN68{c~UfUMln6xx2T z7NOeq-Qid)yuG=U? zWOmZ>j?b`1AcV?EK@}54gbWL+Fl<$g!#4aEv2zwLd&fFh^O;0O|CC5lPLiEg9vN?{ z2{l_@<{Im;Z2>boZu42F0lR;8BTVINEdVdFkbN!WSkhht-?J(EQMky$j!wAD-gj(* z(^IbEgJ2Hg@`fbob+XGA7dunpW4V%X=wZ8E8-&p@_N8+izD8vei0rgWgWFlXy92t} z@tEN4ecuXC7^Ce^xUIU$-bCX71Js6!G)8>FeViyjtX6`S@PgNswW z-ZO&X(w#s&KDNr2sb6gPaE*Dr%XZc%uU~99=i=Cf?EKSAD2e!8IS7P23CvJc$0mzS zwr0{f#;L>D36I?;93~!|H!Q~Gf^izUL52OMq{z;h%U3s(6Z0b{&=+qSj0WT8yi7<^ zDD*Gr6ML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wKV2(MsM!`CW% zY3bF{{sk>rt^CsPy%6~8MIatuDPGbS+)dS30zXMqqdSxzcY6+P*M4%zhju8xZRhMa z6ttT=cFz$SXPVLm4(SQFVb?KyNNUnvkR!DNLX+IGya(FlEUca2G37!%q{xByvrL{_Jjq7;Cx8ev$~_Fq}e`?~-D diff --git a/Map/__pycache__/TileTypes.cpython-312.pyc b/Map/__pycache__/TileTypes.cpython-312.pyc index 842453d1aafa9fbb8029bd4dbc3c9a6fb9cd6f9e..b0bab43bf18d784819f0a64853b08a87c8843806 100644 GIT binary patch delta 553 zcmaE$IYou{G%qg~0}u$e$)+ve$lK1UVCQTV6Iz^FR2-9$n3tCrjQew0Sk_8AisQ$rbDdjCzw-vPbCGFalV4g?tjSU& z2{gM%3`pE!g9sK$Pxj@AV+@_VhQpin0~>>g+-4TeDn_PdOp_b9%o#-{_i-z5q%dcj z1NE7JIFkc-*jW{7ShAQW3o;2$&gbEr{D(`7b2TH#*$fPflXH30VH&I^=kch4H7Fx# z&}XS(NoSbc$SxyL%Ur|a!VsIvz);It!;r-?c_X_hX9$qTR>PLX2C{&cHCuy$p_s8p z7%0L4k{2}w%CnbnL+oQO-q3YCMXazXj18_Ewzqk?A zniwxcG2;Q^S4m84y+_MXyw*wZ~e5);JOc%MHK5yrhjY%(6bvh+sz4#F4cHq`;U(Q9hV z9M{N3d8CNP;1%48A=0QD_9(^O_*XRHX-zc|4M!8A*dXsTqAvA0coxm6kF#GH!|a*a zfg;mXsZ>d=HNL4;@W%Yuym$6foQiasWK-8gj zM&qr*s4Jy#%H};*%yNVQZVaH}YJFoDg+b5D7dbHN!$I9*kV<=GH*c=!+&I0q%+z zy?%p>3!>-`M!LDA*%!QyQ@BVX9R4R_Eh;9p!&^CAA|@k}{GdNRaY+bp*Mjj&Tv?1I zCMJYf>;iV*NY?wf%^Loz{$SXDJ}hk4X`#2CVniL$Bv}qiway~bS<=-ZhxYWzb-hulZ_Na9j@;CuGaJr3@>9#s6@J-O zX!A;~J(9^+)c3AeBQyMhYd(@Wl`~{VbMEX|VXsrNbV{|ZBGV;fA8Li^o!C6T=*mX& zr&bKhqbu&^u|k_qYVDOweMNnLNyn#8e$d%uhpD}&?+lyP<9;e}$)&rx2gF}3 C?k*ev diff --git a/Script/ScriptUtils.py b/Script/ScriptUtils.py new file mode 100644 index 0000000..e69de29 diff --git a/Script/__pycache__/ScriptUtils.cpython-312.pyc b/Script/__pycache__/ScriptUtils.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..24c6d33af90715deb6a6753240486312865f4482 GIT binary patch literal 164 zcmX@j%ge<81g1r@X(0MBh(HIQS%4zb87dhx8U0o=6fpsLpFwJVIXhd$gche36~|;G z=H(^Exa237=BDPA6vwz{mUxsV#W?4e=9RdVCTDnO=B393Cl_TFlt8J_lFXc9y@JYL g95%W6DWy57c15f}GZ}%n7{vI<%*e=C#0+Es0O%DdT>t<8 literal 0 HcmV?d00001