'Falling objects game in pygame
I'm currently trying to make a game where my shapes will fall from the top of the screen down repeatedly for a set amount of time, so far I have managed to get my shapes to be able to fall down the screen but the point I'm struggling with is getting then to show up at the top again and repeat.
This code shows how I have drawn the shapes onto the screen.
def draw_window_one(star, triangle,rectangle,square,hexagon,circle):
WIN.fill(WHITE)
WIN.blit(GOLD_STAR, (star.x, star.y))
WIN.blit(GREEN_TRIANGLE, (triangle.x, triangle.y))
WIN.blit(LIGHT_BLUE_RECTANGLE, (rectangle.x,rectangle.y))
WIN.blit(ORANGE_SQUARE, (square.x,square.y))
WIN.blit(PURPLE_HEXAGON, (hexagon.x,hexagon.y))
WIN.blit(RED_CIRCLE, (circle.x,circle.y))
pygame.display.update()
And then this is the logic for it where I have made them fall down on the screen.
def main():
star = pygame.Rect(75, 0, WIDTH, HEIGHT)
triangle = pygame.Rect(575, 0, WIDTH, HEIGHT)
rectangle = pygame.Rect(175, 0, WIDTH, HEIGHT)
square = pygame.Rect(275, 0, WIDTH, HEIGHT)
hexagon = pygame.Rect(375, 0, WIDTH, HEIGHT)
circle = pygame.Rect(475, 0, WIDTH, HEIGHT)
clock = pygame.time.Clock()
run = True
while run:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
star.y += 1
triangle.y += 1
rectangle.y += 1
square.y += 1
hexagon.y += 1
circle.y += 1
draw_window_one(star, triangle,rectangle,square,hexagon,circle)
pygame.quit()
if __name__ == "__main__":
main()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|