Я пытаюсь оживить восход солнца. Стартовая позиция солнца будет чуть ниже правого нижнего края экрана, и на каждой петле она будет двигаться на 10 пунктов к верхнему левому углу. Я поместил этот код в цикл while, чтобы солнце перестало двигаться после достижения определенной точки.
Однако, когда я запускаю программу, я не вижу ожидаемого эффекта восходящего солнца. Вместо этого солнце просто вспыхнуло по двум координатам x, y, которые я поместил в качестве точек остановки. Я думал, что это потому, что моя программа была слишком быстрой, поэтому я попытался уменьшить clock.tick
до разных секунд, но все, что он делает, это увеличивает разницу во времени между началом программы и бликами солнца в конечных точках.
Пока это мой код. Есть некоторые другие вещи, которые я оживляю на случай, если код выглядит запутанным:
import pygame
import random
import time
# Define some colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
GREY = (169,169,169)
ORANGE = (255,140,0)
YELLOW = (255,255,0)
pygame.init()
# Set the width and height of the screen [width, height]
size = (700, 500)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("First animation")
# Loop until the user clicks the close button.
done = False
# Used to manage how fast the screen updates
clock = pygame.time.Clock()
colour_list = []
default_colours = [BLACK,BLACK,BLACK]
one_colour = RED
two_colour = ORANGE
three_colour = GREEN
colour_list = [one_colour,two_colour,three_colour]
#starting position of the sun
circle_x = 750
circle_y = 550
#speed and direction of circle
circle_change_x = -5
circle_change_y = -5
# -------- Main Program Loop -----------
while not done:
# --- Main event loop
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
screen.fill(WHITE)
# animates the rising of the sun
pygame.draw.circle(screen,YELLOW,[circle_x,circle_y],50)
#moves the sun's starting point
while circle_x >=50 and circle_y >=50:
circle_x += circle_change_x
circle_y += circle_change_y
#draws the road
pygame.draw.rect(screen,BLACK,[0,400,700,100],0)
pygame.draw.rect(screen,WHITE,[100,430,100,25],0)
pygame.draw.rect(screen,WHITE,[300,430,100,25],0)
pygame.draw.rect(screen,WHITE,[500,430,100,25],0)
#draws the street light
x_position = 345
y_position = 225
pygame.draw.rect(screen,GREY,[350,300,15,100],0)
pygame.draw.rect(screen,BLACK,[x_position,y_position,25,75],0)
circle_list = []
for i in range(3):
y_position += 20
circle = pygame.draw.circle(screen,default_colours[i],[358,y_position],7)
circle_list.append(circle)
# --- Go ahead and update the screen with what we've drawn.
pygame.display.flip()
# --- Limit to 60 frames per second
clock.tick(60)
# Close the window and quit.
pygame.quit()