feat: add next piece logic
This commit is contained in:
@@ -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