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:
|
class Tetrad:
|
||||||
block_rotations = 4
|
block_rotations = 4
|
||||||
block_configs = [
|
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
|
(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
|
||||||
[[[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
|
(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
|
||||||
[[[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
|
(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
|
||||||
[[[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
|
(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
|
||||||
[[[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
|
(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
|
||||||
[[[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
|
(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
|
||||||
[[[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
|
(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
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -25,9 +25,13 @@ class Tetrad:
|
|||||||
self.position = position
|
self.position = position
|
||||||
self.rotation = rotation
|
self.rotation = rotation
|
||||||
|
|
||||||
|
|
||||||
|
def color(self):
|
||||||
|
return self.block_configs[self.config][0]
|
||||||
|
|
||||||
|
|
||||||
def layout(self):
|
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)
|
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):
|
def render_tetrad(self, surface, tetrad):
|
||||||
for point in tetrad.layout():
|
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):
|
def render_block(self, surface, color, position):
|
||||||
|
Loading…
Reference in New Issue
Block a user