refactor: move literals into constant variables
This commit is contained in:
28
main.py
28
main.py
@@ -1,20 +1,36 @@
|
||||
import pygame
|
||||
|
||||
WIN_WIDTH = 800
|
||||
WIN_HEIGHT = 600
|
||||
WIN_ICON = "img/tetris_icon.png"
|
||||
WIN_TITLE = "Tetris"
|
||||
WIN_BG_COLOR = (100, 149, 237) # cornflower blue, RGB
|
||||
|
||||
def draw(screen):
|
||||
# draw window bg
|
||||
screen.fill(WIN_BG_COLOR)
|
||||
|
||||
pygame.display.update()
|
||||
|
||||
def main():
|
||||
pygame.init()
|
||||
|
||||
screen = pygame.display.set_mode((800, 600))
|
||||
pygame.display.set_caption("Tetris")
|
||||
icon = pygame.image.load("img/tetris_icon.png")
|
||||
pygame.display.set_icon(icon)
|
||||
screen = pygame.display.set_mode((WIN_WIDTH, WIN_HEIGHT))
|
||||
loaded_icon = pygame.image.load(WIN_ICON)
|
||||
|
||||
pygame.display.set_caption(WIN_TITLE)
|
||||
pygame.display.set_icon(loaded_icon)
|
||||
|
||||
is_running = True
|
||||
while is_running:
|
||||
for event in pygame.event.get():
|
||||
|
||||
if event.type == pygame.QUIT:
|
||||
is_running = False
|
||||
|
||||
screen.fill((100, 149, 237))
|
||||
pygame.display.update()
|
||||
draw(screen)
|
||||
|
||||
pygame.quit()
|
||||
|
||||
# start main function
|
||||
main()
|
||||
Reference in New Issue
Block a user