feat: cells have weight, you can see it

This commit is contained in:
MlodyJacky 2024-05-05 12:39:12 +02:00
parent b7f186562b
commit 91a4e02c18
3 changed files with 25 additions and 5 deletions

15
app.py
View File

@ -19,7 +19,7 @@ def initBoard():
for i in range(prefs.GRID_SIZE): for i in range(prefs.GRID_SIZE):
row = [] row = []
for j in range(prefs.GRID_SIZE): for j in range(prefs.GRID_SIZE):
cell = Cell(i, j) cell = Cell(i, j, 1)
row.append(cell) row.append(cell)
cells.append(row) cells.append(row)
@ -39,12 +39,21 @@ def initBoard():
cells[6][2].interactableItem = Table(cells[6][2], "Table") cells[6][2].interactableItem = Table(cells[6][2], "Table")
cells[4][2].interactableItem = Table(cells[4][2], "Table") cells[4][2].interactableItem = Table(cells[4][2], "Table")
cells[9][9].waga = 2
cells[9][8].waga = 2
cells[9][7].waga = 2
cells[10][6].waga = 2
cells[7][7].waga = 2
def draw_grid(window, cells, agent): def draw_grid(window, cells, agent):
for i in range(prefs.GRID_SIZE): for i in range(prefs.GRID_SIZE):
for j in range(prefs.GRID_SIZE): for j in range(prefs.GRID_SIZE):
cells[i][j].update(window) cells[i][j].update(window)
if(cells[i][j].interactableItem): if(cells[i][j].interactableItem):
cells[i][j].interactableItem.update(window) cells[i][j].interactableItem.update(window)
cells[i][j].blit_text(cells[i][j].waga, i*50+6, j*52+6, 12,window)
font = pygame.font.SysFont('Comic Sans MS', 30) font = pygame.font.SysFont('Comic Sans MS', 30)
scoreText = font.render("Score: {}".format(str(round(agent.score,2))), 1, (0, 0, 0)) scoreText = font.render("Score: {}".format(str(round(agent.score,2))), 1, (0, 0, 0))
multiplierText = font.render("Multiplier: {}".format(str(round(agent.multiplier,2))), 1, (0, 0, 0)) multiplierText = font.render("Multiplier: {}".format(str(round(agent.multiplier,2))), 1, (0, 0, 0))
@ -81,9 +90,9 @@ agent = Agent(prefs.SPAWN_POINT[0], prefs.SPAWN_POINT[1], cells)
#target_x, target_y = 5,2 #target_x, target_y = 5,2
#target_x, target_y = 7,2 #target_x, target_y = 7,2
#target_x, target_y = 8,2 #target_x, target_y = 8,2
target_x, target_y = 4,8 #target_x, target_y = 4,8
#target_x, target_y = 0,9 #target_x, target_y = 0,9
#target_x, target_y = 9,11 target_x, target_y = 9,11
#target_x, target_y = 4,11 #target_x, target_y = 4,11
#target_x, target_y = 6,3 #target_x, target_y = 6,3
#target_x, target_y = 11,11 #target_x, target_y = 11,11

View File

@ -1,9 +1,11 @@
import pygame import pygame
import prefs import prefs
class Cell: class Cell:
def __init__(self, x, y, blocking_movement=False, interactableItem=False, texture=None): def __init__(self, x, y,waga, blocking_movement=False, interactableItem=False, texture=None):
self.X = x self.X = x
self.Y = y self.Y = y
self.waga = waga
self.rect = pygame.Rect(x * prefs.CELL_SIZE, y * prefs.CELL_SIZE, prefs.CELL_SIZE, prefs.CELL_SIZE) self.rect = pygame.Rect(x * prefs.CELL_SIZE, y * prefs.CELL_SIZE, prefs.CELL_SIZE, prefs.CELL_SIZE)
self.blocking_movement = blocking_movement self.blocking_movement = blocking_movement
self.interactableItem = interactableItem self.interactableItem = interactableItem
@ -11,6 +13,13 @@ class Cell:
self.prepareTexture(texture) self.prepareTexture(texture)
else: else:
self.texture = texture self.texture = texture
def blit_text(self,tekst, x, y, rozmiar_czcionki,window):
font = pygame.font.Font('freesansbold.ttf', rozmiar_czcionki)
text = font.render(str(tekst), True, (0, 255, 0), (0, 0, 128))
textRect = text.get_rect()
textRect.center = (x,y)
window.blit(text, textRect)
def prepareTexture(self, texture): def prepareTexture(self, texture):
preparedTexture = pygame.image.load(texture).convert_alpha() preparedTexture = pygame.image.load(texture).convert_alpha()

View File

@ -3,5 +3,7 @@ HEIGHT = WIDTH
GRID_SIZE = 12 GRID_SIZE = 12
CELL_SIZE = WIDTH // GRID_SIZE CELL_SIZE = WIDTH // GRID_SIZE
SPAWN_POINT = (5, 5) SPAWN_POINT = (5, 5)
COLORS = [(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 0), (255, 0, 255), (0, 255, 255), (128, 0, 128), (255, 165, 0), (0, 128, 128), (128, 128, 0)] COLORS = [(130, 200, 200)]