Merge pull request 'Moving. /JL' (#2) from 0.0.2 into main

Reviewed-on: #2
This commit is contained in:
2025-04-21 21:34:06 +02:00
3 changed files with 22 additions and 9 deletions

View File

@@ -28,6 +28,8 @@ class Brick:
self.get_image() self.get_image()
self.block_image = pygame.transform.scale(self.img, (48, 48)) if self.img else None self.block_image = pygame.transform.scale(self.img, (48, 48)) if self.img else None
self.draw_brick() self.draw_brick()
self.x, self.y = (3, 0)
self.location = list((self.x, self.y))
def get_image(self): def get_image(self):
match self.color: match self.color:
@@ -69,10 +71,12 @@ class Brick:
print(f"State set to {self.state}") print(f"State set to {self.state}")
def move_right(self): def move_right(self):
print("Moving right") self.x += 1
self.location = (self.x, self.y)
def move_left(self): def move_left(self):
print("Moving left") self.x -= 1
self.location = (self.x, self.y)
def drop(self): def drop(self):
print("Dropping") print("Dropping")

View File

@@ -1,12 +1,18 @@
import pygame import pygame
class DropZone(): class DropZone():
def __init__(self, width, height): def __init__(self, tile_size, width, height):
self.dropzone = pygame.Surface((width, height)) self.dropzone = pygame.Surface((width * tile_size, height * tile_size))
self.width = width self.width = width
self.height = height self.height = height
self.tile_size = tile_size
self.dropzone.fill((0, 0, 0)) # Fill with black 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): def draw(self, screen):
screen.blit(self.dropzone, (tile_size * 4, tile_size * 1)) 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))

View File

@@ -7,7 +7,7 @@ from dropzone import DropZone
from dropnext import DropNext from dropnext import DropNext
from hud import Hud from hud import Hud
__version__ = "0.0.1" __version__ = "0.0.2"
# Constants # Constants
HAT_REPEAT_DELAY = 0 # milliseconds before first repeat HAT_REPEAT_DELAY = 0 # milliseconds before first repeat
@@ -43,7 +43,7 @@ class Tetris:
print(self.next.color) print(self.next.color)
self.hud = Hud(self.screen_width, self.screen_height, TILE_SIZE) 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.dropnext = DropNext(width = TILE_SIZE * 4, height = TILE_SIZE * 4)
self.clock = pygame.time.Clock() self.clock = pygame.time.Clock()
@@ -57,7 +57,8 @@ class Tetris:
self.screen.fill(enums.BrickColor.Cyan.value) self.screen.fill(enums.BrickColor.Cyan.value)
self.hud.draw(self.screen) 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(self.screen, TILE_SIZE)
self.dropnext.draw_block(self.next.brick) self.dropnext.draw_block(self.next.brick)
@@ -97,11 +98,13 @@ class Tetris:
break break
self.current.direction = enums.BrickDirection.Right self.current.direction = enums.BrickDirection.Right
self.current.move_right() self.current.move_right()
self.dropzone.draw_brick(self.current.brick, self.current.location)
case pygame.K_LEFT: case pygame.K_LEFT:
if self.current.direction == enums.BrickDirection.Dropped: if self.current.direction == enums.BrickDirection.Dropped:
break break
self.current.direction = enums.BrickDirection.Left self.current.direction = enums.BrickDirection.Left
self.current.move_left() self.current.move_left()
self.dropzone.draw_brick(self.current.brick, self.current.location)
case pygame.K_UP: case pygame.K_UP:
if self.current.direction == enums.BrickDirection.Dropped: if self.current.direction == enums.BrickDirection.Dropped:
break break