0
좋아요. 그래서 저는 14 살이라는 것을 모릅니다. 그래서 이것은 아마도 바보 같은 질문이 될 것이지만, 현재는 무작위로 움직이는 작은 블록을 가진 프로그램을 작성하려고합니다. 화면을 둘러 볼 때 나는 내가 한 일과 관련된 이슈를 보지 못한다.파이 게임에서 무작위로 이동
create_randomPATH(x, y)
을 그리고 그 기능에 당신은 예를 들어,의 지역 값을 변경 : 코드에서
import pygame,sys,random
from pygame.locals import *
#colours
red =(255,0,0)
white=(255,255,255)
#variables/objects
ship_width = 60
x = 400
y = 520
FPS = 60
clock =pygame.time.Clock()
screen = pygame.display.set_mode((800,600))
def move_rect(x,y):
ship = pygame.draw.rect(screen,red,(x,y,ship_width,ship_width))
def create_randomPATH(x,y):
random_gen = False
if random_gen == False:
randomX = random.randint(1,60)
randomY = random.randint(1,60)
random_gen = True
want_valX = x + randomX
want_valY = y + randomY
if want_valX != x:
x += 2
elif want-valY != y:
y += 2
print (x,y)
return x,y
while True:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
x -= 10
if event.key == pygame.K_RIGHT:
x += 10
if event.key == pygame.K_DOWN:
y += 10
if event.key == pygame.K_UP:
y -= 10
screen.fill(white)
create_randomPATH(x, y)
print (x,y)
move_rect(x, y)
pygame.display.update()
코드가 어떤 이상한 –
에 붙여 넣기 오류? – Octo
'가져 오기 무작위'수행해야합니다. – Octo