TypePHP 编译器
https://swoole.com/aot/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.2 KiB
47 lines
1.2 KiB
# Example file showing a circle moving on screen
|
|
from lib2to3.fixer_util import is_tuple
|
|
|
|
import pygame
|
|
|
|
# pygame setup
|
|
pygame.init()
|
|
screen = pygame.display.set_mode((1280, 720))
|
|
clock = pygame.time.Clock()
|
|
running = True
|
|
dt = 0
|
|
|
|
player_pos = pygame.Vector2(screen.get_width() / 2, screen.get_height() / 2)
|
|
|
|
while running:
|
|
# poll for events
|
|
# pygame.QUIT event means the user clicked X to close your window
|
|
for event in pygame.event.get():
|
|
if event.type == pygame.QUIT:
|
|
running = False
|
|
|
|
# fill the screen with a color to wipe away anything from last frame
|
|
screen.fill("purple")
|
|
|
|
pygame.draw.circle(screen, "red", player_pos, 40)
|
|
|
|
keys = pygame.key.get_pressed()
|
|
|
|
if keys[pygame.K_w]:
|
|
player_pos.y -= 300 * dt
|
|
if keys[pygame.K_s]:
|
|
player_pos.y += 300 * dt
|
|
if keys[pygame.K_a]:
|
|
player_pos.x -= 300 * dt
|
|
if keys[pygame.K_d]:
|
|
player_pos.x += 300 * dt
|
|
|
|
# flip() the display to put your work on screen
|
|
pygame.display.flip()
|
|
|
|
# limits FPS to 60
|
|
# dt is delta time in seconds since last frame, used for framerate-
|
|
# independent physics.
|
|
dt = clock.tick(60) / 1000
|
|
|
|
pygame.quit()
|
|
|
|
|