feat: add collision logic between entities
This commit is contained in:
18
Tetris.py
18
Tetris.py
@@ -28,7 +28,7 @@ class Tetris:
|
||||
self.tile_size = ConfigurationManager.configuration["engine"]["tile-size"]
|
||||
self.screen = pygame.display.set_mode((win_width, win_height))
|
||||
self.clock = pygame.time.Clock()
|
||||
self.well = Well((280, 80)) # TODO calculate position later
|
||||
self.well = Well((280, 80), ConfigurationManager.configuration["color"]["border"]) # TODO calculate position later and redo color config for well
|
||||
|
||||
loaded_icon = pygame.image.load(win_icon)
|
||||
pygame.display.set_caption(win_title)
|
||||
@@ -49,18 +49,26 @@ class Tetris:
|
||||
if self.current_piece:
|
||||
if event.key == pygame.K_SPACE:
|
||||
self.current_piece.rotate()
|
||||
if self.well and self.current_piece.collide(self.well):
|
||||
self.current_piece.revert()
|
||||
if event.key == pygame.K_LEFT:
|
||||
self.current_piece.move((-self.tile_size, 0))
|
||||
if self.well and self.current_piece.collide(self.well):
|
||||
self.current_piece.revert()
|
||||
if event.key == pygame.K_RIGHT:
|
||||
self.current_piece.move((self.tile_size, 0))
|
||||
if self.well and self.current_piece.collide(self.well):
|
||||
self.current_piece.revert()
|
||||
if event.key == pygame.K_UP:
|
||||
self.current_piece.move((0, -self.tile_size))
|
||||
if self.well and self.current_piece.collide(self.well):
|
||||
self.current_piece.revert()
|
||||
if event.key == pygame.K_DOWN:
|
||||
self.current_piece.move((0, self.tile_size))
|
||||
if self.well and self.current_piece.collide(self.well):
|
||||
self.current_piece.revert()
|
||||
if event.key == pygame.K_z:
|
||||
self.__generate_piece((300, 100))
|
||||
if event.key == pygame.K_x:
|
||||
self.current_piece.revert()
|
||||
|
||||
def draw(self) -> None:
|
||||
# TODO write not initialized exception
|
||||
@@ -71,9 +79,9 @@ class Tetris:
|
||||
|
||||
# draw all game objects
|
||||
if self.well:
|
||||
self.well.draw(self.screen)
|
||||
self.well.draw(self.screen, self.tile_size) # TODO Should it be doing taking in tile_size?
|
||||
if self.current_piece:
|
||||
self.current_piece.draw(self.screen)
|
||||
self.current_piece.draw(self.screen, self.tile_size)
|
||||
|
||||
# update display
|
||||
pygame.display.update()
|
||||
|
||||
Reference in New Issue
Block a user