Привет! Я просмотрел несколько сообщений и не вижу ответа. Я строю простую игру со змеями, и когда я с oop по draw.rect
она не работает вместе с surface.fill.
Кажется, что не имеет значения, куда я положил команду flip()
/ update()
, пожалуйста, помогите!
import pygame
from pygame import Color
surface = pygame.display.set_mode((400, 400))
gs = 20
tail = 5
trail = []
pygame.time.set_timer(pygame.USEREVENT, 250)
sx = sy = 15
vx = vy = 0
block = pygame.Rect(100, 100, 20, 20)
while True:
for e in pygame.event.get():
if e.type == pygame.USEREVENT:
trail.append({"x": sx, "y": sy})
print(trail)
while len(trail) > tail:
trail.pop(0)
surface.fill(Color("black"))
for t in trail:
print(t)
pygame.draw.rect(
surface, Color("green"), (sx * gs, sy * gs, gs - 1, gs - 1)
)
pygame.display.update()
sx += vx
sy += vy
if sx > gs - 1:
sx = 0
if sx < 0:
sx = gs - 1
if sy > gs - 1:
sy = 0
if sy < 0:
sy = gs - 1
if e.type == pygame.KEYDOWN:
if e.key == 273 and vy != 1:
vx, vy = 0, -1
if e.key == 274 and vy != -1:
vx, vy = 0, 1
if e.key == 275 and vx != -1:
vx, vy = 1, 0
if e.key == 276 and vx != 1:
vx, vy = -1, 0