-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
195 lines (182 loc) · 6.8 KB
/
Copy pathmain.py
File metadata and controls
195 lines (182 loc) · 6.8 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import pygame,os,time,random
from particle import *
from utility import *
from root import *
from fountainBase import *
from spinner import *
from button import *
pygame.init()
class Main:
''' main class that controls the entire programm '''
def __init__(self):
self.WIDTH = 600
self.HEIGHT = 750
self.TITLE = "Fireworks!!"
#height of canvas for fireworks
self.canvasHeight = 600
self.FPS = 30
self.screen = pygame.display.set_mode((self.WIDTH,self.HEIGHT))
pygame.display.set_caption(self.TITLE)
self.clock = pygame.time.Clock()
self.isRunning = True
self.otp = False
self.play = False
#clickstate is index of current firework
self.clickState = 1
self.run()
def run(self):
self.isPlaying = True
# these groups will hold add objects
self.TempContainer = []
self.ParticleContainer = []
self.ThrustContainer = []
self.SubNodeContainer = []
self.FountainParticles = []
self.SpinnerParticles = []
self.Btns = []
while self.isPlaying:
self.clock.tick(self.FPS)
self.dt = self.clock.tick(self.FPS)/1000
self.ready()
self.createButtons()
self.Btn1.clicked = True
self.events()
self.update()
self.draw()
def ready(self):
if self.play and not self.otp:
count = 1
self.spwan(count)
self.play = False
def spwan(self,count):
# spwan count number of rocket root nodes (TEST)
for i in range(count):
self.randt = random.randint(-250,250)
self.randt2 = random.randint(-50,20)
self.randv = random.randint(-50,50)
self.randvy = random.randint(-50,60)
temp = random.choice([4,6])
EXPLOSION_SOUNDS[temp].play()
t = Root(self,self.WIDTH/2 + self.randt,self.canvasHeight+self.randt2,random.randint(100,500),"N")
self.TempContainer.append(t)
def spwanXY(self,count,x,y,d,t):
#spawn method
for i in range(count):
temp = random.choice([4,6])
EXPLOSION_SOUNDS[temp].play()
t = Root(self,x,y,d,t)
self.TempContainer.append(t)
def checkBtnState(self):
# checks btn state
if self.clickState==1:
self.Btn1.clicked = True
if self.clickState==2:
self.Btn2.clicked = True
if self.clickState==3:
self.Btn3.clicked = True
if self.clickState==4:
self.Btn4.clicked = True
if self.clickState==5:
self.Btn5.clicked = True
def resetClick(self):
#resets click
self.Btn1.clicked = False
self.Btn2.clicked = False
self.Btn3.clicked = False
self.Btn4.clicked = False
self.Btn5.clicked = False
def createButtons(self):
self.Btn1 = Button(self,self.screen,5,600,114,100,RED,"Rocket 1")
self.Btn2 = Button(self,self.screen,124,600,114,100,ORANGECORAL,"Rocket 2")
self.Btn3 = Button(self,self.screen,243,600,114,100,YELLOW,"Rocket 3")
self.Btn4 = Button(self,self.screen,362,600,114,100,GREEN,"Fountain")
self.Btn5 = Button(self,self.screen,481,600,114,100,BLUE," Spinner")
def events(self):
for event in pygame.event.get():
if event.type == pygame.QUIT:
if self.isPlaying:
self.isPlaying = False
self.isRunning = False
if event.type == pygame.KEYDOWN:
self.play = True
#mouse click event
if event.type == pygame.MOUSEBUTTONDOWN and event.button== 1:
mouse_x, mouse_y = event.pos
#handling click for btns
if mouse_y>600 and mouse_y<700:
if mouse_x>5 and mouse_x<119:
self.clickState =1
if mouse_x>124 and mouse_x<238:
self.clickState =2
if mouse_x>243 and mouse_x<357:
self.clickState =3
if mouse_x>362 and mouse_x<476:
self.clickState =4
if mouse_x>481 and mouse_x<595:
self.clickState =5
#handling click for crackers
if mouse_y < 600:
if self.clickState == 1:
self.spwanXY(1,mouse_x,self.WIDTH+100,self.canvasHeight-mouse_y,"N")
if self.clickState == 2:
self.spwanXY(1,mouse_x,self.WIDTH+100,self.canvasHeight-mouse_y,"S")
if self.clickState ==3:
self.spwanXY(1,mouse_x,self.WIDTH+100,self.canvasHeight-mouse_y,"B")
if self.clickState == 4:
t = FountainBase(self,mouse_x)
self.FountainParticles.append(t)
if self.clickState == 5:
t = Spinner(self,mouse_x,mouse_y)
self.SpinnerParticles.append(t)
def update(self):
#resetclick
self.resetClick()
#check for btn state
self.checkBtnState()
#update each group
for i in self.TempContainer:
i.update()
for i in self.ParticleContainer:
i.update()
for i in self.ThrustContainer:
i.update()
for i in self.SubNodeContainer:
i.update()
for i in self.FountainParticles:
i.update()
for i in self.SpinnerParticles:
i.update()
# update each btn
self.Btn1.update()
self.Btn2.update()
self.Btn3.update()
self.Btn4.update()
self.Btn5.update()
def draw(self):
self.screen.fill(BACKGROUND)
#draw each groups
for i in self.TempContainer:
i.draw()
for i in self.ParticleContainer:
i.draw()
for i in self.ThrustContainer:
i.draw()
for i in self.SubNodeContainer:
i.draw()
for i in self.FountainParticles:
i.draw()
for i in self.SpinnerParticles:
i.draw()
#draw background for bts
pygame.draw.rect(self.screen,(25,25,25),(0,600,600,100))
# draw each btns
self.Btn1.draw()
self.Btn2.draw()
self.Btn3.draw()
self.Btn4.draw()
self.Btn5.draw()
pygame.display.update()
if __name__ == "__main__":
temp = Main()
pygame.quit()
pygame.display.quit()