Untitled
unknown
python
2 years ago
2.1 kB
3
Indexable
Never
# import import pygame, sys, random pygame.init() # initializing screen = pygame.display.set_mode((800, 600)) # display surface clock = pygame.time.Clock() # determine speed / frame rate of the game bg = pygame.image.load('wood_bg.png') # same folder land_bg = pygame.image.load('land_bg.png') # land image water = pygame.image.load('water_bg.png') # water image cloud_1 = pygame.image.load('cloud1.png') # cloud img 1 cloud_2 = pygame.image.load('cloud2.png') # cloud img 2 crosshair = pygame.image.load('crosshair.png') duck_surface = pygame.image.load('duck.png') duck_list = [] # empty list for duck in range(10): # for loop to show 10 ducks duck_position_x = random.randrange(50,750) duck_position_y = random.randrange(100,550) duck_rect = duck_surface.get_rect(center=(duck_position_x, duck_position_y)) duck_list.append(duck_rect) land_pos_y = 500 land_speed = 1 water_pos_y = 550 water_speed = 1.5 while True: # game loop for event in pygame.event.get(): # when the while loop starts # pygame starts looking for all the events if event.type == pygame.QUIT: # closing pygame.quit() # close pygame sys.exit() # close all the program if event.type == pygame.MOUSEMOTION: pygame.mouse.get_pos() cross_rect = crosshair.get_rect(center=pygame.mouse.get_pos()) screen.blit(bg, (0, 0)) land_pos_y = land_pos_y + land_speed if land_pos_y <= 500 or land_pos_y >= 550: land_speed *= -1 screen.blit(land_bg, (0, land_pos_y)) water_pos_y += water_speed if water_pos_y <= 510 or water_pos_y >= 560: water_speed *= -1 screen.blit(water, (0, water_pos_y)) for duck_rect in duck_list: # display screen.blit(duck_surface, duck_rect) screen.blit(crosshair, cross_rect) screen.blit(cloud_1, (30, 30)) screen.blit(cloud_2, (150, 70)) screen.blit(cloud_1, (350, 40)) screen.blit(cloud_2, (550, 65)) screen.blit(cloud_1, (700, 50)) pygame.display.update() clock.tick(60) # frame rate