demonstration of the fps clock

Home   »   demonstration of the fps clock

import pygame
from pygame.locals import *

pygame.init()

# CREATE THE WINDOW SURFACE
resolution = (800,600) # (Width, Height)
screen = pygame.display.set_mode(resolution)
red = pygame.surface.Surface((30,30))
red.fill('red')
x,y = 0,0
fps = pygame.time.Clock()
running = True
speed = 5
while running:
    for event in pygame.event.get():
        if event.type == QUIT:
            running = False
    k = pygame.key.get_pressed()
    if k[K_LEFT]:
        x -= speed
    if k[K_RIGHT]:
        x += speed
    if k[K_UP]:
        y -= speed
    if k[K_DOWN]:
        y += speed
    screen.fill('black')
    screen.blit(red,(x,y))
    pygame.display.update()
    # IGNORE EVERYTHING ABOVE
    fps.tick(60)

Leave a Reply

Your email address will not be published. Required fields are marked *