Commit 27/04-24
Woot Woot
This commit is contained in:
parent
5d14ce22bf
commit
db36a4cd7a
5 changed files with 90 additions and 69 deletions
54
Main.py
54
Main.py
|
|
@ -21,12 +21,13 @@ maprect = map.get_rect()
|
||||||
mapWidth = int(map.get_width())
|
mapWidth = int(map.get_width())
|
||||||
mapHeight = int(map.get_height())
|
mapHeight = int(map.get_height())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
time1 = pygame.time.get_ticks()
|
||||||
|
def initMapGen():
|
||||||
y = 0
|
y = 0
|
||||||
bY = 5
|
bY = 5
|
||||||
bX = 4
|
bX = 4
|
||||||
|
|
||||||
time1 = pygame.time.get_ticks()
|
|
||||||
|
|
||||||
while bX < mapWidth:
|
while bX < mapWidth:
|
||||||
for x in range(bX, mapWidth):
|
for x in range(bX, mapWidth):
|
||||||
if y < mapHeight:
|
if y < mapHeight:
|
||||||
|
|
@ -87,17 +88,42 @@ while bY < mapHeight:
|
||||||
bY += 10
|
bY += 10
|
||||||
y = bY
|
y = bY
|
||||||
|
|
||||||
|
initMapGen()
|
||||||
class uText:
|
class uText:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.font = pygame.font.SysFont('Comic Sans MS', 30)
|
self.font = pygame.font.Font(pygame.font.get_default_font(), 36)
|
||||||
|
self.texts = []
|
||||||
|
|
||||||
def write(self, text):
|
def write(self, text, position):
|
||||||
text = self.font.render(text, antialias=True, color=(255,255,255))
|
self.texts.append((text,position))
|
||||||
return text
|
|
||||||
|
def delete(self, text):
|
||||||
|
text2 = []
|
||||||
|
for place in self.texts:
|
||||||
|
if place[0] != text:
|
||||||
|
text2.append(place)
|
||||||
|
self.texts = text2
|
||||||
|
|
||||||
|
def runText(self):
|
||||||
|
for text in self.texts:
|
||||||
|
textPrint = self.font.render(str(text[0]), True, (255, 255, 255))
|
||||||
|
textPrintRect = textPrint.get_rect()
|
||||||
|
textPrintRect = textPrintRect.move(int(text[1][0]),int(text[1][1]))
|
||||||
|
screen.blit(textPrint, textPrintRect)
|
||||||
|
|
||||||
|
def runTextTile(self, tile_pressed):
|
||||||
|
info = GameMap.getTileInfo(tile_pressed)
|
||||||
|
tile_pressed = str(tile_pressed)
|
||||||
|
tilePrint = self.font.render(tile_pressed, True, (255, 255, 255))
|
||||||
|
tilePrintRect = tilePrint.get_rect()
|
||||||
|
tilePrintRect = tilePrintRect.move(1000,50)
|
||||||
|
screen.blit(tilePrint, tilePrintRect)
|
||||||
|
|
||||||
uTexter = uText()
|
uTexter = uText()
|
||||||
|
|
||||||
|
uTexter.write("State",(1000,0))
|
||||||
|
|
||||||
pygame.image.save(map, "./Map/Images/blackstripes.png")
|
pygame.image.save(map, "./Map/Images/blackstripes.png")
|
||||||
|
|
||||||
GameMap = MapManager.MapManager()
|
GameMap = MapManager.MapManager()
|
||||||
|
|
@ -134,20 +160,10 @@ while running:
|
||||||
# fill the screen with a color to wipe away anything from last frame
|
# fill the screen with a color to wipe away anything from last frame
|
||||||
screen.fill("black")
|
screen.fill("black")
|
||||||
|
|
||||||
font = pygame.font.Font(pygame.font.get_default_font(), 36)
|
|
||||||
|
|
||||||
if tile_pressed != None:
|
if tile_pressed != None:
|
||||||
tile_pressed = str(tile_pressed)
|
uTexter.runTextTile(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))
|
uTexter.runText()
|
||||||
textPrintRect = textPrint.get_rect()
|
|
||||||
textPrintRect = textPrintRect.move(1000,0)
|
|
||||||
|
|
||||||
screen.blit(textPrint, textPrintRect)
|
|
||||||
|
|
||||||
screen.blit(map, maprect)
|
screen.blit(map, maprect)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,7 @@ class MapManager:
|
||||||
colour = mappedColours[f"{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]
|
colour1, colour2, colour3 = colour[0], colour[1], colour[2]
|
||||||
tile.paint_pixels(mapObject, int(colour1),int(colour2),int(colour3))
|
tile.paint_pixels(mapObject, int(colour1),int(colour2),int(colour3))
|
||||||
|
tile.add_terrain(f"{tilesMapped[tile.Position[0]][tile.Position[1]]}")
|
||||||
|
|
||||||
def findTileAt(self, pos):
|
def findTileAt(self, pos):
|
||||||
for x in self.tiles.keys():
|
for x in self.tiles.keys():
|
||||||
|
|
@ -161,7 +162,7 @@ class MapManager:
|
||||||
if int(x) == int(tile.getId()):
|
if int(x) == int(tile.getId()):
|
||||||
return x
|
return x
|
||||||
else:
|
else:
|
||||||
print(f"Missmatching ID for found tile: {x} / {tile.getId()}")
|
print(f"Mismatching ID for found tile: {x} / {tile.getId()}")
|
||||||
return (x,tile.getId())
|
return (x,tile.getId())
|
||||||
|
|
||||||
print(f"Could not find tile at position: {pos[0]},{pos[1]}")
|
print(f"Could not find tile at position: {pos[0]},{pos[1]}")
|
||||||
|
|
@ -171,6 +172,7 @@ class MapManager:
|
||||||
info = {}
|
info = {}
|
||||||
info["id"] = id
|
info["id"] = id
|
||||||
info["pixels"] = self.tiles[f"{id}"].getPixels()
|
info["pixels"] = self.tiles[f"{id}"].getPixels()
|
||||||
|
info["terrain"] = self.tiles[f"{id}"].getTerrain()
|
||||||
|
|
||||||
|
|
||||||
class Tile:
|
class Tile:
|
||||||
|
|
@ -188,6 +190,9 @@ class Tile:
|
||||||
def getPixels(self):
|
def getPixels(self):
|
||||||
return self.pixels
|
return self.pixels
|
||||||
|
|
||||||
|
def getTerrain(self):
|
||||||
|
return self.terrain
|
||||||
|
|
||||||
def add_pixel(self,pixel):
|
def add_pixel(self,pixel):
|
||||||
self.pixels.append(pixel)
|
self.pixels.append(pixel)
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue