Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame, sys
- max_tps = 20.0
- pygame.init()
- screen = pygame.display.set_mode((720,576))
- box = pygame.Rect(10,10,50,50)
- box2 = pygame.Rect(10,500,50,50)
- clock = pygame.time.Clock()
- delta = 0.0
- while True:
- for event in pygame.event.get():
- if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
- sys.exit(0)
- delta += clock.tick()/1000.0
- while delta > 1/max_tps:
- delta -= 1/max_tps
- keys = pygame.key.get_pressed()
- if keys[pygame.K_UP]:
- box.y -= 1
- if keys[pygame.K_DOWN]:
- box.y += 1
- if keys[pygame.K_LEFT]:
- box.x -= 1
- if keys[pygame.K_RIGHT]:
- box.x += 1
- if keys[pygame.K_w]:
- box2.y -= 1
- if keys[pygame.K_s]:
- box2.y += 1
- if keys[pygame.K_a]:
- box2.x -= 1
- if keys[pygame.K_d]:
- box2.x += 1
- screen.fill((0,0,0))
- pygame.draw.rect(screen, (52, 218, 206), box)
- pygame.draw.rect(screen, (52, 208, 200), box2)
- pygame.display.flip()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement