feat: limit frames per second to 60
This commit is contained in:
7
main.py
7
main.py
@@ -1,11 +1,15 @@
|
|||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
|
# window properties
|
||||||
WIN_WIDTH = 800
|
WIN_WIDTH = 800
|
||||||
WIN_HEIGHT = 600
|
WIN_HEIGHT = 600
|
||||||
WIN_ICON = "img/tetris_icon.png"
|
WIN_ICON = "img/tetris_icon.png"
|
||||||
WIN_TITLE = "Tetris"
|
WIN_TITLE = "Tetris"
|
||||||
WIN_BG_COLOR = (100, 149, 237) # cornflower blue, RGB
|
WIN_BG_COLOR = (100, 149, 237) # cornflower blue, RGB
|
||||||
|
|
||||||
|
# engine properties
|
||||||
|
FPS = 60
|
||||||
|
|
||||||
def draw(screen):
|
def draw(screen):
|
||||||
# draw window bg
|
# draw window bg
|
||||||
screen.fill(WIN_BG_COLOR)
|
screen.fill(WIN_BG_COLOR)
|
||||||
@@ -16,6 +20,7 @@ def main():
|
|||||||
pygame.init()
|
pygame.init()
|
||||||
|
|
||||||
screen = pygame.display.set_mode((WIN_WIDTH, WIN_HEIGHT))
|
screen = pygame.display.set_mode((WIN_WIDTH, WIN_HEIGHT))
|
||||||
|
clock = pygame.time.Clock()
|
||||||
loaded_icon = pygame.image.load(WIN_ICON)
|
loaded_icon = pygame.image.load(WIN_ICON)
|
||||||
|
|
||||||
pygame.display.set_caption(WIN_TITLE)
|
pygame.display.set_caption(WIN_TITLE)
|
||||||
@@ -23,6 +28,8 @@ def main():
|
|||||||
|
|
||||||
is_running = True
|
is_running = True
|
||||||
while is_running:
|
while is_running:
|
||||||
|
clock.tick(FPS)
|
||||||
|
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
|
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
|
|||||||
Reference in New Issue
Block a user