feat: add next piece logic
This commit is contained in:
@@ -147,12 +147,13 @@ class Piece(Entity):
|
||||
self.gravity_time = gravity_time - (game.get_level() * gravity_increase)
|
||||
self.set_time = set_time
|
||||
|
||||
def draw(self, surface: pygame.Surface, well: Well, stack: "Stack") -> None:
|
||||
def draw(self, surface: pygame.Surface, well: Well = None, stack: "Stack" = None) -> None:
|
||||
tile_size = ConfigurationManager.get("engine", "tile-size")
|
||||
|
||||
# ghost piece
|
||||
for square in self._get_ghost_piece_points(well, stack):
|
||||
pygame.draw.polygon(surface, pygame.Color("#FFFFFF"), square, max(tile_size // 6, 1)) # TODO add white to the yaml
|
||||
if well and stack:
|
||||
for square in self._get_ghost_piece_points(well, stack):
|
||||
pygame.draw.polygon(surface, pygame.Color("#FFFFFF"), square, max(tile_size // 6, 1)) # TODO add white to the yaml
|
||||
|
||||
super().draw(surface)
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import sys
|
||||
from typing import Text
|
||||
import pygame
|
||||
from pygame import mixer
|
||||
from tetris.util import ConfigurationManager
|
||||
from tetris.util import TextGenerator
|
||||
from tetris.util import Controller
|
||||
from tetris.entity import PieceGenerator
|
||||
from tetris.entity import Well
|
||||
from tetris.entity import Stack
|
||||
@@ -19,6 +17,7 @@ class Game:
|
||||
self.clock = None
|
||||
self.main_music = None
|
||||
self.current_piece = None
|
||||
self.next_piece = None
|
||||
self.well = None
|
||||
self.stack = None
|
||||
|
||||
@@ -53,10 +52,15 @@ class Game:
|
||||
# TODO write not initialized exception
|
||||
elapsed_time = self.clock.tick(self.fps)
|
||||
|
||||
if not self.next_piece:
|
||||
self.next_piece = PieceGenerator.get_piece((620, 160))
|
||||
|
||||
if self.current_piece:
|
||||
self.current_piece.update(elapsed_time, self)
|
||||
else:
|
||||
self.current_piece = PieceGenerator.get_piece((360, 100)) # TODO calculate spawn position
|
||||
self.current_piece = self.next_piece
|
||||
self.current_piece.move((360 - 620, 100 - 160)) # TODO calculate spawn position correctly
|
||||
self.next_piece = PieceGenerator.get_piece((620, 160)) # (360, 100)
|
||||
if self.stack and self.current_piece.collide(self.stack): # TODO game over redo
|
||||
pygame.quit()
|
||||
sys.exit()
|
||||
@@ -77,6 +81,8 @@ class Game:
|
||||
self.screen.fill(bg_color)
|
||||
|
||||
# draw all game objects
|
||||
if self.next_piece:
|
||||
self.next_piece.draw(self.screen)
|
||||
if self.well:
|
||||
self.well.draw(self.screen)
|
||||
if self.stack:
|
||||
|
||||
Reference in New Issue
Block a user