Commit bdc63828 authored by Dimitris Strovolidis's avatar Dimitris Strovolidis

Code Improvements

Merge block sprites
Change blocks loading
parent 332833b4
......@@ -47,7 +47,7 @@ def main():
screen = pygame.display.set_mode(screen_res)
pygame.key.set_repeat(100, 100)
blocks_path = os.path.join('sprites', 'blocks')
blocks_path = os.path.join('sprites', 'blocks.png')
game_background_path = os.path.join('sprites', 'background.png')
menu_background_path = os.path.join('sprites', 'menu_background.png')
grid_background_path = os.path.join('sprites', 'grid_background.png')
......@@ -60,22 +60,12 @@ def main():
font = pygame.font.Font(os.path.join('fonts', font_file), 18)
# load and scale all blocks (each tetromino has its own block color)
red_block = pygame.image.load(os.path.join(blocks_path, 'red_block.png')).convert()
red_block = pygame.transform.scale(red_block, (block_width, block_height))
lightblue_block = pygame.image.load(os.path.join(blocks_path, 'lightblue_block.png')).convert()
lightblue_block = pygame.transform.scale(lightblue_block, (block_width, block_height))
blue_block = pygame.image.load(os.path.join(blocks_path, 'blue_block.png')).convert()
blue_block = pygame.transform.scale(blue_block, (block_width, block_height))
yellow_block = pygame.image.load(os.path.join(blocks_path, 'yellow_block.png')).convert()
yellow_block = pygame.transform.scale(yellow_block, (block_width, block_height))
green_block = pygame.image.load(os.path.join(blocks_path, 'green_block.png')).convert()
green_block = pygame.transform.scale(green_block, (block_width, block_height))
orange_block = pygame.image.load(os.path.join(blocks_path, 'orange_block.png')).convert()
orange_block = pygame.transform.scale(orange_block, (block_width, block_height))
purple_block = pygame.image.load(os.path.join(blocks_path, 'purple_block.png')).convert()
purple_block = pygame.transform.scale(purple_block, (block_width, block_height))
color_blocks = (lightblue_block, yellow_block, purple_block, blue_block, orange_block, green_block, red_block)
color_blocks = []
blocks = pygame.image.load(blocks_path).convert()
blocks = pygame.transform.scale(blocks, (block_width * 7, block_height))
for i in range(7):
block_surface = blocks.subsurface(i * block_width, 0, block_width, block_height)
color_blocks.append(block_surface)
next_surface = write(font, "NEXT", text_color)
......
......@@ -5,136 +5,136 @@ from random import randint
class Tetromino:
# I tetromino
i_tetromino_angle_0 = [[".#.."],
[".#.."],
[".#.."],
[".#.."]]
i_tetromino_angle_0 = [".#..",
".#..",
".#..",
".#.."]
# rotate 90 degrees cw (clockwise)
i_tetromino_angle_90 = [["...."],
["####"],
["...."],
["...."]]
i_tetromino_angle_90 = ["....",
"####",
"....",
"...."]
i_tetromino = (i_tetromino_angle_0, i_tetromino_angle_90,
i_tetromino_angle_0, i_tetromino_angle_90)
# O tetromino
o_tetromino_angle_0 = [["...."],
[".##."],
[".##."],
["...."]]
o_tetromino_angle_0 = ["....",
".##.",
".##.",
"...."]
o_tetromino = (o_tetromino_angle_0, o_tetromino_angle_0,
o_tetromino_angle_0, o_tetromino_angle_0)
# T tetromino
t_tetromino_angle_0 = [["...."],
["###."],
[".#.."],
["...."]]
t_tetromino_angle_0 = ["....",
"###.",
".#..",
"...."]
# rotate 90 degrees cw
t_tetromino_angle_90 = [[".#.."],
["##.."],
[".#.."],
["...."]]
t_tetromino_angle_90 = [".#..",
"##..",
".#..",
"...."]
# rotate 180 degrees cw
t_tetromino_angle_180 = [[".#.."],
["###."],
["...."],
["...."]]
t_tetromino_angle_180 = [".#..",
"###.",
"....",
"...."]
# rotate 270 degrees cw
t_tetromino_angle_270 = [[".#.."],
[".##."],
[".#.."],
["...."]]
t_tetromino_angle_270 = [".#..",
".##.",
".#..",
"...."]
t_tetromino = (t_tetromino_angle_0, t_tetromino_angle_90,
t_tetromino_angle_180, t_tetromino_angle_270)
# J tetromino
j_tetromino_angle_0 = [["...."],
["###."],
["..#."],
["...."]]
j_tetromino_angle_0 = ["....",
"###.",
"..#.",
"...."]
# rotate 90 degrees cw
j_tetromino_angle_90 = [[".#.."],
[".#.."],
["##.."],
["...."]]
j_tetromino_angle_90 = [".#..",
".#..",
"##..",
"...."]
# rotate 180 degrees cw
j_tetromino_angle_180 = [["#..."],
["###."],
["...."],
["...."]]
j_tetromino_angle_180 = ["#...",
"###.",
"....",
"...."]
# rotate 270 degrees cw
j_tetromino_angle_270 = [[".##."],
[".#.."],
[".#.."],
["...."]]
j_tetromino_angle_270 = [".##.",
".#..",
".#..",
"...."]
j_tetromino = (j_tetromino_angle_0, j_tetromino_angle_90,
j_tetromino_angle_180, j_tetromino_angle_270)
# L tetromino cw
l_tetromino_angle_0 = [["...."],
["###."],
["#..."],
["...."]]
l_tetromino_angle_0 = ["....",
"###.",
"#...",
"...."]
# rotate 90 degrees cw
l_tetromino_angle_90 = [["##.."],
[".#.."],
[".#.."],
["...."]]
l_tetromino_angle_90 = ["##..",
".#..",
".#..",
"...."]
# rotate 180 degrees cw
l_tetromino_angle_180 = [["..#."],
["###."],
["...."],
["...."]]
l_tetromino_angle_180 = ["..#.",
"###.",
"....",
"...."]
# rotate 270 degrees cw
l_tetromino_angle_270 = [[".#.."],
[".#.."],
[".##."],
["...."]]
l_tetromino_angle_270 = [".#..",
".#..",
".##.",
"...."]
l_tetromino = (l_tetromino_angle_0, l_tetromino_angle_90,
l_tetromino_angle_180, l_tetromino_angle_270)
# S tetromino
s_tetromino_angle_0 = [[".##."],
["##.."],
["...."],
["...."]]
s_tetromino_angle_0 = [".##.",
"##..",
"....",
"...."]
# rotate 90 degrees cw
s_tetromino_angle_90 = [[".#.."],
[".##."],
["..#."],
["...."]]
s_tetromino_angle_90 = [".#..",
".##.",
"..#.",
"...."]
s_tetromino = (s_tetromino_angle_0, s_tetromino_angle_90,
s_tetromino_angle_0, s_tetromino_angle_90)
# Z tetromino
z_tetromino_angle_0 = [["##.."],
[".##."],
["...."],
["...."]]
z_tetromino_angle_0 = ["##..",
".##.",
"....",
"...."]
# rotate 90 degrees cw
z_tetromino_angle_90 = [["..#."],
[".##."],
[".#.."],
["...."]]
z_tetromino_angle_90 = ["..#.",
".##.",
".#..",
"...."]
z_tetromino = (z_tetromino_angle_0, z_tetromino_angle_90,
z_tetromino_angle_0, z_tetromino_angle_90)
......@@ -184,7 +184,7 @@ class Tetromino:
tetromino_coord = []
for i in range(len(self.current_frame)):
for char in self.current_frame[i][0]:
for char in self.current_frame[i]:
if char == '#':
if self.min_coord[0] <= x <= self.max_coord[0]:
tetromino_coord.append([x, y])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment