0
我正在製作一個遊戲,玩家控制一個捕捉落下食物的精靈。以前的精靈在改變y_positions時要留下來移動
但是,我遇到了食物下降的問題。
import pygame
import random
import time
d_w = 800
d_h = 600
fall_speed = 5
screen = pygame.display.set_mode((d_w, d_h))
clock = pygame.time.Clock()
BGCOLOR = (0, 155, 0)
goodFood = pygame.image.load('burg.png')
def randFoodGen():
x_food = d_w/2
y_food = 0
return x_food,y_food
def BurgGen():
x_food, y_food = randFoodGen()
screen.fill(BGCOLOR)
while True:
y_food = y_food + fall_speed
if y_food > d_w:
x_food = (random.randrange(0, d_w))
y_food = -30
screen.blit(goodFood, [x_food, y_food])
pygame.display.update()
clock.tick(30)
BurgGen()
它結束了維持落下的食物精靈的前一個位置,就像這樣: Anger