【发布时间】:2020-12-20 16:18:11
【问题描述】:
我有一条正在画线的蛇,并且正在随机打孔,但是当蛇没有画线(打孔)时如何继续使用头部。这是我的代码:
import pygame
pygame.init()
import random
from random import randint
win = pygame.display.set_mode((1280,720))
background = pygame.Surface(win.get_size(), pygame.SRCALPHA)
background.fill((0, 0, 0, 1))
x = randint(150,1130)
y = randint(150,570)
vel = 0.6
direction = pygame.math.Vector2(vel, 0).rotate(random.randint(0, 360))
next_change_time = 0
draw_snake = False
clock = pygame.time.Clock()
run = True
while run:
clock.tick(150)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
current_time = pygame.time.get_ticks()
if current_time > next_change_time:
draw_snake = not draw_snake
if draw_snake:
next_change_time = current_time + random.randint(2000, 5000)
else:
next_change_time = current_time + random.randint(200, 500)
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
direction.rotate_ip(-0.8)
if keys[pygame.K_RIGHT]:
direction.rotate_ip(0.8)
x += direction.x
y += direction.y
if draw_snake:
pygame.draw.circle(win, (255,0,0), (round(x), round(y)), 4)
pygame.display.update()
pygame.quit()
当我在 while 循环中写 win.fill((0,0,0)) 时,只有头部在移动,但我想让那个头部只在孔中移动。
【问题讨论】:
标签: python pygame drawing head