diff --git a/bricks.py b/bricks.py index d4434ab..77e6487 100644 --- a/bricks.py +++ b/bricks.py @@ -28,6 +28,8 @@ class Brick: self.get_image() self.block_image = pygame.transform.scale(self.img, (48, 48)) if self.img else None self.draw_brick() + self.x, self.y = (3, 0) + self.location = list((self.x, self.y)) def get_image(self): match self.color: @@ -69,10 +71,12 @@ class Brick: print(f"State set to {self.state}") def move_right(self): - print("Moving right") + self.x += 1 + self.location = (self.x, self.y) def move_left(self): - print("Moving left") + self.x -= 1 + self.location = (self.x, self.y) def drop(self): print("Dropping") \ No newline at end of file diff --git a/dropzone.py b/dropzone.py index 6a2036b..cda799a 100644 --- a/dropzone.py +++ b/dropzone.py @@ -1,12 +1,18 @@ import pygame class DropZone(): - def __init__(self, width, height): - self.dropzone = pygame.Surface((width, height)) + def __init__(self, tile_size, width, height): + self.dropzone = pygame.Surface((width * tile_size, height * tile_size)) self.width = width self.height = height + self.tile_size = tile_size self.dropzone.fill((0, 0, 0)) # Fill with black + self.grid_row = [" "] * self.width + self.grid = [self.grid_row] * self.height - def draw(self, screen, tile_size): - screen.blit(self.dropzone, (tile_size * 4, tile_size * 1)) + def draw(self, screen): + screen.blit(self.dropzone, (self.tile_size * 4, self.tile_size * 1)) + + def draw_brick(self, brick, location): + self.dropzone.blit(brick, (location[0] * self.tile_size, location[1] * self.tile_size)) \ No newline at end of file diff --git a/tetris.py b/tetris.py index 77ded75..bc88bbb 100644 --- a/tetris.py +++ b/tetris.py @@ -7,7 +7,7 @@ from dropzone import DropZone from dropnext import DropNext from hud import Hud -__version__ = "0.0.1" +__version__ = "0.0.2" # Constants HAT_REPEAT_DELAY = 0 # milliseconds before first repeat @@ -43,7 +43,7 @@ class Tetris: print(self.next.color) self.hud = Hud(self.screen_width, self.screen_height, TILE_SIZE) - self.dropzone = DropZone(width = TILE_SIZE * 10, height = TILE_SIZE * 18) + self.dropzone = DropZone(TILE_SIZE, width = 10, height = 18) self.dropnext = DropNext(width = TILE_SIZE * 4, height = TILE_SIZE * 4) self.clock = pygame.time.Clock() @@ -57,7 +57,8 @@ class Tetris: self.screen.fill(enums.BrickColor.Cyan.value) self.hud.draw(self.screen) - self.dropzone.draw(self.screen, TILE_SIZE) + self.dropzone.draw(self.screen) + self.dropzone.draw_brick(self.current.brick, self.current.location) self.dropnext.draw(self.screen, TILE_SIZE) self.dropnext.draw_block(self.next.brick) @@ -97,11 +98,13 @@ class Tetris: break self.current.direction = enums.BrickDirection.Right self.current.move_right() + self.dropzone.draw_brick(self.current.brick, self.current.location) case pygame.K_LEFT: if self.current.direction == enums.BrickDirection.Dropped: break self.current.direction = enums.BrickDirection.Left self.current.move_left() + self.dropzone.draw_brick(self.current.brick, self.current.location) case pygame.K_UP: if self.current.direction == enums.BrickDirection.Dropped: break