Today, I watched this video, and made a object avoidance game. You control a rectangle, and you have to avoid projectiles that fall from the sky.
def draw(player, elapsed_time, stars):
WIN.blit(BG, (0, 0))
time_text = FONT.render(f"Time: {round(elapsed_time)}s", 1, "white")
WIN.blit(time_text, (10, 10))
pygame.draw.rect(WIN, "red", player)
for star in stars:
pygame.draw.rect(WIN, "white", star)
pygame.display.update()
^This function handles all the visual aspects of the game. It renders the background image, the player character, the falling stars, and the time counter.
def main():
run = True
player = pygame.Rect(200, HEIGHT - PLAYER_HEIGHT,
PLAYER_WIDTH, PLAYER_HEIGHT)
clock = pygame.time.Clock()
start_time = time.time()
elapsed_time = 0
star_add_increment = 2000
star_count = 0
stars = []
hit = False
^This function contains the primary game loop. It manages the game logic, like player movement, star spawning, collision detection, and handling the “game over”.

Leave a Reply