forked from sd18spring/InteractiveProgramming
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.py
More file actions
Latest commit
117 lines (96 loc) · 2.87 KB
/
Copy pathinterface.py
File metadata and controls
117 lines (96 loc) · 2.87 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
"""
Asteroids via Pygame
@authors coreyacl & nathanestill
"""
importpygame
frommathimportcos,sin,sqrt,radians,atan,pi
fromclassesimport*
importtime
importrandom
""" initiate pygame """
pygame.init()
""" initiate screen """
display_width=1600
display_height=1200
imgScale=.13
gameDisplay=pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption("Asteroids")
black= (0,0,0)
white= (255,255,255)
""" some other important things """
clock=pygame.time.Clock()
running=True
""" initiate ship object """
shipImg=pygame.image.load('spa1.png')
shipX= (display_width*.5)
shipY= (display_height*.5)
w,h=shipImg.get_size()
shipImg=pygame.transform.scale(shipImg,(int(w*imgScale),int(h*imgScale)))
ship=Ship(shipX,shipY,270,shipImg,gameDisplay)
""" initiate asteroids and UFOs """
numberOfAsteroids=4
AllThings=listOfObjects(gameDisplay,ship)
AllThings.Asteroids.spawnAsteroids(numberOfAsteroids)
AllThings.UFOs.spawnBigUFO()
AllThings.update() # testing the many asteroids spawn in the right spot
""" initiate GUI """
gui=GUI(gameDisplay)
""" initialize the ship to be able to shoot"""
canShoot=True
shoot_count=20
whilerunning:
""" listens to events and does stuff """
foreventinpygame.event.get():
ifevent.type==pygame.QUIT:
running=False
# print(event)
ifevent.type==pygame.KEYUP:
ifevent.key==pygame.K_q:
running=False
ifevent.key==pygame.K_t:
ship.lives+=1
ifevent.key==pygame.K_r:
ifshoot_count==20:
shoot_count=2
elifshoot_count==2:
shoot_count=20
""" player interface """
keys_pressed=pygame.key.get_pressed()
ifkeys_pressed[pygame.K_UP]:
ship.move()
else:
ship.drift=True
ifkeys_pressed[pygame.K_LEFT]:
ship.rotate(1)
ifkeys_pressed[pygame.K_RIGHT]:
ship.rotate(-1)
if(canShoot):
counter=0
else:
counter+=1
if(counter>=shoot_count):
canShoot=True
ifkeys_pressed[pygame.K_SPACE]:
if(canShoot):
ship.shoot(AllThings)
canShoot=False
counter=0
""" UFO spawning """
randomInt=random.randint(1,1000)
if(randomInt==1andlen(AllThings.UFOs.listOfUFOs) ==0):
AllThings.UFOs.spawnBigUFO()
""" spawns new level """
if(len(AllThings.Asteroids.listOfAsteroids) ==0andlen(AllThings.UFOs.listOfUFOs) ==0):
numberOfAsteroids+=1
AllThings.Asteroids.spawnAsteroids(numberOfAsteroids)
gameDisplay.fill(black)
gui.update(ship)
ifship.lives>0:
ship.update()
AllThings.update()
ifship.lives==0:
gui.gameOver(ship)
pygame.display.update()
clock.tick(60)
pygame.quit()
quit()