-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
61 lines (52 loc) · 1.5 KB
/
Copy pathmain.py
File metadata and controls
61 lines (52 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import sys
import pygame
from random import randint
#define variables
width=600
height=400
delta=int(width/10)
xpos_bird=width-delta
ypos_bird=delta
xpos_tree=100
ypos_tree=100
speed_bird=1
framerate=120
pygame.init()
#set screen
screen=pygame.display.set_mode((width,height))
# init clock from time
clock=pygame.time.Clock()
# init load images
bg=pygame.image.load("resources/green2.jpg")
tree=pygame.image.load("resources/tree2.png")
aim=pygame.image.load("resources/crosshair.png")
# load list of birds
birds=[]
for birdno in range(10):
#tmpBird={"img":bird, "name":(f'Bird_{birdno}'), "counter":0, "xpos":randint((width-delta),width})}
tmpxpos=randint((width-delta),width)
tmpypos=randint((delta),4*delta)
tmpspeed=randint(1,3)
tmplink = pygame.image.load("resources/bird.png")
tmpBird={"link":tmplink,"name":"Bird_"+str(birdno), "count":0,"xpos":tmpxpos,"ypos":tmpypos, "speed":tmpspeed}
birds.append(tmpBird)
#start the loop
while True:
# check events with for-loop
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
#put background on screen
screen.blit(bg,(0,0))
# modify moving objects
for bird in birds:
bird['xpos']-=bird['speed']
screen.blit(bird['link'], (bird['xpos'],bird['ypos']))
#put paint stuff on screen
screen.blit(tree,(100,100))
screen.blit(aim,((pygame.mouse.get_pos())))
#update screen
pygame.display.update()
#tick the clock
clock.tick(60)