Commit 2d7e464c authored by Dimitris Strovolidis's avatar Dimitris Strovolidis

Optimizations

Add fps counter
parent 8fb99d7b
......@@ -29,9 +29,8 @@ class GameArea:
# rows x columns grid
self.grid = [[-1 for i in range(self.columns)] for j in range(self.rows)]
self.background = pygame.image.load(os.path.join('sprites', 'grid_background.png'))
self.background = pygame.transform.scale(self.background,
(self.area_width, self.area_height))
self.background = pygame.image.load(os.path.join('sprites', 'grid_background.png')).convert()
self.background = pygame.transform.scale(self.background, (self.area_width, self.area_height))
def collides(self, tetromino_coords):
......
......@@ -31,26 +31,26 @@ def main():
screen = pygame.display.set_mode(screen_res)
# load background
background = pygame.image.load(os.path.join('sprites', 'background.png'))
background = pygame.image.load(os.path.join('sprites', 'background.png')).convert()
background = pygame.transform.scale(background, screen.get_size())
# load font
font = pygame.font.Font(os.path.join('fonts', 'prstartk.ttf'), 18)
# load and scale all blocks (each tetromino has its own block color)
red_block = pygame.image.load(os.path.join('sprites', 'red_block.png'))
red_block = pygame.image.load(os.path.join('sprites', 'red_block.png')).convert()
red_block = pygame.transform.scale(red_block, (block_width, block_height))
lightblue_block = pygame.image.load(os.path.join('sprites', 'lightblue_block.png'))
lightblue_block = pygame.image.load(os.path.join('sprites', 'lightblue_block.png')).convert()
lightblue_block = pygame.transform.scale(lightblue_block, (block_width, block_height))
blue_block = pygame.image.load(os.path.join('sprites', 'blue_block.png'))
blue_block = pygame.image.load(os.path.join('sprites', 'blue_block.png')).convert()
blue_block = pygame.transform.scale(blue_block, (block_width, block_height))
yellow_block = pygame.image.load(os.path.join('sprites', 'yellow_block.png'))
yellow_block = pygame.image.load(os.path.join('sprites', 'yellow_block.png')).convert()
yellow_block = pygame.transform.scale(yellow_block, (block_width, block_height))
green_block = pygame.image.load(os.path.join('sprites', 'green_block.png'))
green_block = pygame.image.load(os.path.join('sprites', 'green_block.png')).convert()
green_block = pygame.transform.scale(green_block, (block_width, block_height))
orange_block = pygame.image.load(os.path.join('sprites', 'orange_block.png'))
orange_block = pygame.image.load(os.path.join('sprites', 'orange_block.png')).convert()
orange_block = pygame.transform.scale(orange_block, (block_width, block_height))
purple_block = pygame.image.load(os.path.join('sprites', 'purple_block.png'))
purple_block = pygame.image.load(os.path.join('sprites', '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,
......@@ -109,13 +109,17 @@ def main():
time_string = "Time " + '{0:02d}'.format(int(total_time // 60))\
+ ":" + '{0:02d}'.format(int(total_time % 60))
score_string = "Score: " + str(game_area.get_score())
score_string = "Score:" + str(game_area.get_score())
fps_string = "FPS:" + str(int(clock.get_fps()))
score_surface = write(font, score_string, text_color)
time_surface = write(font, time_string, text_color)
fps_surface = write(font, fps_string, text_color)
screen.blit(background, min_screen_coord)
screen.blit(score_surface, (15, 100))
screen.blit(time_surface, (15, 150))
screen.blit(score_surface, (15, 80))
screen.blit(time_surface, (15, 130))
screen.blit(fps_surface, (15, 180))
game_area.show(screen, color_blocks)
random_tetromino.show(screen)
pygame.display.flip()
......
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