Block falling working. /JL

This commit is contained in:
2025-04-22 20:59:52 +02:00
parent 2e3460dca5
commit 9696719067
3 changed files with 20 additions and 7 deletions

View File

@@ -61,7 +61,8 @@ class Brick:
return True if self.state == enums.BrickState.Current else False
def update(self):
pass
self.y += 1
self.location = (self.x, self.y)
def rotate(self):
print("Rotating")

11
hud.py
View File

@@ -4,9 +4,6 @@ from enums import BrickColor
class Hud:
def __init__(self, screen_width, screen_height, tile_size, font_size=36, highscore_file="highscore.txt"):
self.score = 0
self.lines = 0
self.level = 0
self.highscore_file = highscore_file
self.highscore = self.load_highscore()
@@ -15,6 +12,8 @@ class Hud:
self.screen_width = screen_width
self.screen_height = screen_height
self.tile_size = tile_size
self.reset()
def load_highscore(self):
if os.path.exists(self.highscore_file):
@@ -45,9 +44,13 @@ class Hud:
def level_up(self):
self.level += 1
def reset(self, reset_score=True):
def reset(self, reset_score=True, reset_lines=True, reset_level=True):
if reset_score:
self.score = 0
if reset_lines:
self.lines = 0
if reset_level:
self.level = 1
def draw(self, screen):
# Score (top-left)

View File

@@ -7,7 +7,7 @@ from dropzone import DropZone
from dropnext import DropNext
from hud import Hud
__version__ = "0.0.3"
__version__ = "0.0.4"
# Constants
HAT_REPEAT_DELAY = 0 # milliseconds before first repeat
@@ -51,7 +51,13 @@ class Tetris:
self.clock = pygame.time.Clock()
self.rumble_timer = pygame.time.get_ticks()
self.fall_speed = 1000 # in milliseconds
self.fall_timer = pygame.USEREVENT + 1
pygame.time.set_timer(self.fall_timer, self.get_fall_speed(self.hud.level))
def get_fall_speed(self, level):
return max(100, 1000 - (level - 1) * 100)
def main_loop(self):
if self.joysticks:
if pygame.time.get_ticks() - self.rumble_timer > RUMBLE_TIMEOUT:
@@ -166,6 +172,9 @@ class Tetris:
break
self.current.drop()
case self.fall_timer:
self.current.update()
# Handle hotplugging
case pygame.JOYDEVICEADDED:
# This event will be generated when the program starts for every