Color support
This commit is contained in:
parent
2dc22589df
commit
b3abceb273
22
tetris.py
22
tetris.py
@ -10,13 +10,13 @@ import pygame
|
||||
class Tetrad:
|
||||
block_rotations = 4
|
||||
block_configs = [
|
||||
[[[1, 0], [1, 1], [1, 2], [1, 3]], [[0, 1], [1, 1], [2, 1], [3, 1]], [[1, 0], [1, 1], [1, 2], [1, 3]], [[0, 1], [1, 1], [2, 1], [3, 1]]], # Shape_I
|
||||
[[[0, 1], [1, 1], [2, 1], [1, 2]], [[1, 0], [1, 1], [2, 1], [1, 2]], [[1, 0], [0, 1], [1, 1], [2, 1]], [[1, 0], [0, 1], [1, 1], [1, 2]]], # Shape T
|
||||
[[[0, 0], [0, 1], [1, 0], [1, 1]], [[0, 0], [0, 1], [1, 0], [1, 1]], [[0, 0], [0, 1], [1, 0], [1, 1]], [[0, 0], [0, 1], [1, 0], [1, 1]]], # Shape O
|
||||
[[[1, 0], [1, 1], [1, 2], [2, 2]], [[2, 0], [2, 1], [1, 1], [0, 1]], [[0, 0], [1, 0], [1, 1], [1, 2]], [[0, 1], [1, 1], [2, 1], [0, 2]]], # Shape L
|
||||
[[[1, 0], [1, 1], [1, 2], [0, 2]], [[2, 1], [2, 2], [1, 1], [0, 1]], [[1, 0], [2, 0], [1, 1], [1, 2]], [[0, 0], [1, 1], [2, 1], [0, 1]]], # Shape J
|
||||
[[[1, 1], [2, 1], [0, 2], [1, 2]], [[1, 0], [1, 1], [2, 1], [2, 2]], [[1, 1], [2, 1], [0, 2], [1, 2]], [[1, 0], [1, 1], [2, 1], [2, 2]]], # Shape S
|
||||
[[[0, 1], [1, 1], [1, 2], [2, 2]], [[1, 1], [1, 2], [2, 0], [2, 1]], [[0, 1], [1, 1], [1, 2], [2, 2]], [[1, 1], [1, 2], [2, 0], [2, 1]]] # Shape Z
|
||||
(1, [[[1, 0], [1, 1], [1, 2], [1, 3]], [[0, 1], [1, 1], [2, 1], [3, 1]], [[1, 0], [1, 1], [1, 2], [1, 3]], [[0, 1], [1, 1], [2, 1], [3, 1]]]), # Shape_I
|
||||
(2, [[[0, 1], [1, 1], [2, 1], [1, 2]], [[1, 0], [1, 1], [2, 1], [1, 2]], [[1, 0], [0, 1], [1, 1], [2, 1]], [[1, 0], [0, 1], [1, 1], [1, 2]]]), # Shape T
|
||||
(3, [[[0, 0], [0, 1], [1, 0], [1, 1]], [[0, 0], [0, 1], [1, 0], [1, 1]], [[0, 0], [0, 1], [1, 0], [1, 1]], [[0, 0], [0, 1], [1, 0], [1, 1]]]), # Shape O
|
||||
(4, [[[1, 0], [1, 1], [1, 2], [2, 2]], [[2, 0], [2, 1], [1, 1], [0, 1]], [[0, 0], [1, 0], [1, 1], [1, 2]], [[0, 1], [1, 1], [2, 1], [0, 2]]]), # Shape L
|
||||
(5, [[[1, 0], [1, 1], [1, 2], [0, 2]], [[2, 1], [2, 2], [1, 1], [0, 1]], [[1, 0], [2, 0], [1, 1], [1, 2]], [[0, 0], [1, 1], [2, 1], [0, 1]]]), # Shape J
|
||||
(6, [[[1, 1], [2, 1], [0, 2], [1, 2]], [[1, 0], [1, 1], [2, 1], [2, 2]], [[1, 1], [2, 1], [0, 2], [1, 2]], [[1, 0], [1, 1], [2, 1], [2, 2]]]), # Shape S
|
||||
(7, [[[0, 1], [1, 1], [1, 2], [2, 2]], [[1, 1], [1, 2], [2, 0], [2, 1]], [[0, 1], [1, 1], [1, 2], [2, 2]], [[1, 1], [1, 2], [2, 0], [2, 1]]]) # Shape Z
|
||||
]
|
||||
|
||||
|
||||
@ -26,8 +26,12 @@ class Tetrad:
|
||||
self.rotation = rotation
|
||||
|
||||
|
||||
def color(self):
|
||||
return self.block_configs[self.config][0]
|
||||
|
||||
|
||||
def layout(self):
|
||||
layout = self.block_configs[self.config][self.rotation]
|
||||
layout = self.block_configs[self.config][1][self.rotation]
|
||||
return map(lambda p: (self.position[0]+p[0], self.position[1]+p[1]), layout)
|
||||
|
||||
|
||||
@ -95,7 +99,7 @@ class Board:
|
||||
|
||||
def render_tetrad(self, surface, tetrad):
|
||||
for point in tetrad.layout():
|
||||
self.render_block(surface, 2, point)
|
||||
self.render_block(surface, tetrad.color(), point)
|
||||
|
||||
|
||||
def render_block(self, surface, color, position):
|
||||
|
Loading…
Reference in New Issue
Block a user