Commit 16/04-24

This commit is contained in:
Hannah-Dagemark 2024-04-16 19:46:37 +02:00
commit 5d14ce22bf
7 changed files with 76 additions and 13 deletions

38
Main.py
View file

@ -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

View file

@ -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))

View file

@ -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]

0
Script/ScriptUtils.py Normal file
View file

Binary file not shown.