Move block working. /JL
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import pygame
|
||||
from enums import BrickColor
|
||||
|
||||
class DropNext():
|
||||
def __init__(self, width, height):
|
||||
@@ -11,5 +12,6 @@ class DropNext():
|
||||
screen.blit(self.dropnext, (tile_size * 15, tile_size * 2))
|
||||
|
||||
def draw_block(self, brick):
|
||||
self.dropnext.fill(BrickColor.Black.value)
|
||||
self.dropnext.blit(brick, ((self.width - brick.get_width()) / 2, (self.height - brick.get_height()) / 2))
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import pygame
|
||||
from enums import BrickColor
|
||||
|
||||
class DropZone():
|
||||
def __init__(self, tile_size, width, height):
|
||||
@@ -6,7 +7,6 @@ class DropZone():
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.tile_size = tile_size
|
||||
self.dropzone.fill((0, 0, 0)) # Fill with black
|
||||
self.grid_row = [" "] * self.width
|
||||
self.grid = [self.grid_row] * self.height
|
||||
|
||||
@@ -14,5 +14,5 @@ class DropZone():
|
||||
screen.blit(self.dropzone, (self.tile_size * 4, self.tile_size * 1))
|
||||
|
||||
def draw_brick(self, brick, location):
|
||||
self.dropzone.fill(BrickColor.Black.value)
|
||||
self.dropzone.blit(brick, (location[0] * self.tile_size, location[1] * self.tile_size))
|
||||
|
1
enums.py
1
enums.py
@@ -8,6 +8,7 @@ class BrickColor(Enum):
|
||||
Magenta = (255, 0, 255)
|
||||
Yellow = (255, 255, 0)
|
||||
Cyan = (0, 255, 255)
|
||||
Black = (0, 0, 0)
|
||||
|
||||
class BrickState(Enum):
|
||||
Current = 0
|
||||
|
22
tetris.py
22
tetris.py
@@ -7,7 +7,7 @@ from dropzone import DropZone
|
||||
from dropnext import DropNext
|
||||
from hud import Hud
|
||||
|
||||
__version__ = "0.0.2"
|
||||
__version__ = "0.0.3"
|
||||
|
||||
# Constants
|
||||
HAT_REPEAT_DELAY = 0 # milliseconds before first repeat
|
||||
@@ -21,6 +21,9 @@ class Tetris:
|
||||
|
||||
while self.running:
|
||||
self.main_loop()
|
||||
|
||||
if self.joysticks:
|
||||
self.joysticks[self.joy.get_instance_id()].controllers[0].close()
|
||||
|
||||
pygame.quit()
|
||||
|
||||
@@ -105,14 +108,15 @@ class Tetris:
|
||||
self.current.direction = enums.BrickDirection.Left
|
||||
self.current.move_left()
|
||||
self.dropzone.draw_brick(self.current.brick, self.current.location)
|
||||
case pygame.K_UP:
|
||||
case pygame.K_SPACE:
|
||||
if self.current.direction == enums.BrickDirection.Dropped:
|
||||
break
|
||||
self.current.rotate()
|
||||
case pygame.K_DOWN:
|
||||
case pygame.K_RETURN:
|
||||
if self.current.direction == enums.BrickDirection.Dropped:
|
||||
break
|
||||
self.current.drop()
|
||||
|
||||
case pygame.JOYHATMOTION:
|
||||
self.hat_direction = event.value
|
||||
self.hat_x, self.hat_y = self.hat_direction
|
||||
@@ -129,11 +133,13 @@ class Tetris:
|
||||
break
|
||||
self.current.direction = enums.BrickDirection.Left
|
||||
self.current.move_left()
|
||||
elif self.hat_y == 1:
|
||||
if self.current.direction == enums.BrickDirection.Dropped:
|
||||
break
|
||||
self.current.rotate()
|
||||
elif self.hat_y == -1:
|
||||
|
||||
case pygame.JOYBUTTONDOWN:
|
||||
if event.button == 2:
|
||||
if self.current.direction == enums.BrickDirection.Dropped:
|
||||
break
|
||||
self.current.rotate()
|
||||
elif event.button == 0:
|
||||
if self.current.direction == enums.BrickDirection.Dropped:
|
||||
break
|
||||
self.current.drop()
|
||||
|
Reference in New Issue
Block a user