Skip to content

Commit

Permalink
Basic rows
Browse files Browse the repository at this point in the history
  • Loading branch information
jinglemansweep committed Nov 14, 2023
1 parent ae33fd4 commit 2c15477
Showing 1 changed file with 74 additions and 29 deletions.
103 changes: 74 additions & 29 deletions testing/sprites/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,63 @@ def update(self):
cy += sprite.rect.height


class CellContent(BaseSprite):
class CellRow(BaseSprite):
def __init__(self, x: int, y: int, width: int, height: int, cells: [BaseSprite]):
super().__init__()
self.x = x
self.y = y
self.width = width
self.height = height
self.cells = cells
self.image = pygame.Surface((self.width, self.height))
self.rect = self.image.get_rect()
self.render()

def update(self):
self.render()

def render(self):
surface = pygame.Surface((self.width, self.height))
cx = 0
for cell in self.cells:
cell.update()
cell.render()
surface.blit(cell.image, (cx, 0))
cx += cell.rect.width
self.image = pygame.Surface((cx, self.height))
self.image.blit(surface, (0, 0))
self.rect = self.image.get_rect()


class CellColumn(BaseSprite):
def __init__(self, x: int, y: int, width: int, height: int, cells: [BaseSprite]):
super().__init__()
self.x = x
self.y = y
self.width = width
self.height = height
self.cells = cells
self.image = pygame.Surface((self.width, self.height))
self.rect = self.image.get_rect()
self.render()

def update(self):
self.render()

def render(self):
surface = pygame.Surface((self.width, self.height))
cy = 0
for cell in self.cells:
cell.update()
cell.render()
surface.blit(cell.image, (0, cy))
cy += cell.rect.height
self.image = pygame.Surface((self.width, cy))
self.image.blit(surface, (0, 0))
self.rect = self.image.get_rect()


class Cell(BaseSprite):
def __init__(
self,
width: int,
Expand Down Expand Up @@ -87,7 +143,7 @@ def evaluate(self):
return current_second % self.seed == 0


class Cell(BaseSprite):
class Collapsible(BaseSprite):
def __init__(
self,
x: int,
Expand Down Expand Up @@ -196,28 +252,6 @@ def evaluate(self):
CELL_WIDTH = 100
CELL_HEIGHT = 50

content_r = CellContent(
CELL_WIDTH,
CELL_HEIGHT,
"RED",
color_bg=pygame.Color(128, 0, 0, 255),
seed=random.randint(5, 10),
)
content_g = CellContent(
CELL_WIDTH,
CELL_HEIGHT,
"GREEN",
color_bg=pygame.Color(0, 128, 0, 255),
seed=random.randint(5, 10),
)
content_b = CellContent(
CELL_WIDTH,
CELL_HEIGHT,
"BLUE",
color_bg=pygame.Color(0, 0, 128, 255),
seed=random.randint(5, 10),
)

colors = [
pygame.Color(128, 0, 0, 255),
pygame.Color(0, 128, 0, 255),
Expand All @@ -231,7 +265,7 @@ def evaluate(self):
contents = []

for i in range(9):
content = CellContent(
content = Cell(
CELL_WIDTH,
CELL_HEIGHT,
f"Content {i}",
Expand All @@ -243,8 +277,8 @@ def evaluate(self):

sprites = []

for i in range(9):
sprite = Cell(
for i in range(10):
sprite = Collapsible(
0 * CELL_WIDTH,
0,
CELL_WIDTH,
Expand All @@ -255,8 +289,19 @@ def evaluate(self):
)
sprites.append(sprite)

for sprite in sprites:
cell_group.add(sprite)
column1_sprites = sprites[0:5]
column2_sprites = sprites[5:10]

column1 = CellColumn(
0, 0, CELL_WIDTH, CELL_HEIGHT * len(column1_sprites), column1_sprites
)
column2 = CellColumn(
0, 0, CELL_WIDTH, CELL_HEIGHT * len(column2_sprites), column2_sprites
)

row = CellRow(0, 0, CELL_WIDTH * 2, 256, [column1, column2])

cell_group.add(row)

running = True
while running:
Expand Down

0 comments on commit 2c15477

Please sign in to comment.