-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectConstants.py
More file actions
252 lines (193 loc) · 6.08 KB
/
ProjectConstants.py
File metadata and controls
252 lines (193 loc) · 6.08 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
import pygame
import math
pygame.init()
#Project Constants
#game window
SCREEN_WIDTH = 1000
SCREEN_HEIGHT = SCREEN_WIDTH * 0.7
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Main Menu")
#game variables
clock = pygame.time.Clock()
FPS = 60
#colors
WHITE = pygame.Color("#FFFFFF")
BLACK = pygame.Color("#000000")
LIGHT_GREY = pygame.Color("#D3D3D3")
RED = pygame.Color("#FF0000")
backgroundColor = WHITE
textColor = BLACK
hoverColor = LIGHT_GREY
sliderBarColor = BLACK
sliderBarHandleColor = RED
objectsColor = BLACK
#Game Logo
logo = pygame.image.load('images/PhysiFun Logo 800x600.svg').convert_alpha()
scaled_logo = pygame.transform.scale(logo, (600, 450)).convert_alpha()
#physical constants
GRAVITY = 9.8
#Project Methods
#clicking mechanism
ifMouseDownEarlier = False
def ifClicked():
global ifMouseDownEarlier
if pygame.mouse.get_pressed()[0] == 1:
if not ifMouseDownEarlier:
ifMouseDownEarlier = True
#print("Yes")
return True
else:
ifMouseDownEarlier = False
return False
def rotate_surface(surface, angle, x, y):
#rotate surface around pivot point
rotated_surface = pygame.transform.rotate(surface, angle)
#make pivot point center
pivotX = x
pivotY = y
rect = rotated_surface.get_rect()
rect.center = pivotX, pivotY
return rotated_surface, rect
#10, 20, 25, 30, 70
font10 = pygame.font.Font("fonts/Jost-700-Bold.otf", 10)
font20 = pygame.font.Font("fonts/Jost-700-Bold.otf", 20)
font25 = pygame.font.Font("fonts/Jost-700-Bold.otf", 25)
font30 = pygame.font.Font("fonts/Jost-700-Bold.otf", 30)
font70 = pygame.font.Font("fonts/Jost-700-Bold.otf", 70)
def draw_text_center(screen, centerX, centerY, textSize, text):
if textSize == 10:
font = font10
elif textSize == 20:
font = font20
elif textSize == 25:
font = font25
elif textSize == 30:
font = font30
elif textSize == 70:
font = font70
else:
font = pygame.font.Font("fonts/Jost-700-Bold.otf", textSize)
text = font.render(text, True, textColor)
text_rect = text.get_rect(center=(centerX, centerY))
screen.blit(text, text_rect)
return (textSize, text_rect.right, centerY)
def draw_text_left(screen, leftX, centerY, textSize, text):
if textSize == 10:
font = font10
elif textSize == 20:
font = font20
elif textSize == 25:
font = font25
elif textSize == 30:
font = font30
elif textSize == 70:
font = font70
else:
font = pygame.font.Font("fonts/Jost-700-Bold.otf", textSize)
text = font.render(text, True, textColor)
text_rect = text.get_rect(left=leftX, centery=centerY)
screen.blit(text, text_rect)
return (textSize, text_rect.right, centerY)
def draw_text_right(screen, rightX, centerY, textSize, text):
if textSize == 10:
font = font10
elif textSize == 20:
font = font20
elif textSize == 25:
font = font25
elif textSize == 30:
font = font30
elif textSize == 70:
font = font70
else:
font = pygame.font.Font("fonts/Jost-700-Bold.otf", textSize)
text = font.render(text, True, textColor)
text_rect = text.get_rect(right=rightX, centery=centerY)
screen.blit(text, text_rect)
return (textSize, text_rect.right, centerY)
def draw_text_top_left(screen, leftX, topY, textSize, text):
if textSize == 10:
font = font10
elif textSize == 20:
font = font20
elif textSize == 25:
font = font25
elif textSize == 30:
font = font30
elif textSize == 70:
font = font70
else:
font = pygame.font.Font("fonts/Jost-700-Bold.otf", textSize)
text = font.render(text, True, textColor)
screen.blit(text, (leftX, topY))
def draw_superscript(screen, positionTuple, text):
text = font10.render(text, True, textColor)
text_rect = text.get_rect(left=positionTuple[1], top=positionTuple[2] - positionTuple[0] * 3 / 5)
screen.blit(text, text_rect)
return text_rect.right
def draw_left_with_superscript(screen, leftX, centerY, textSize, text):
split_text = text.split('^')
cleaned_text = [sub_text for sub_text in split_text if sub_text]
lastRightCoordinate = leftX
for n in range(len(cleaned_text)):
if n % 2 == 0:
if textSize == 10:
font = font10
elif textSize == 20:
font = font20
elif textSize == 25:
font = font25
elif textSize == 30:
font = font30
elif textSize == 70:
font = font70
else:
font = pygame.font.Font("fonts/Jost-700-Bold.otf", textSize)
text = font.render(cleaned_text[n], True, textColor)
text_rect = text.get_rect(left=lastRightCoordinate, centery=centerY)
screen.blit(text, text_rect)
lastRightCoordinate = text_rect.right
if n % 2 == 1:
text = font10.render(cleaned_text[n], True, textColor)
text_rect = text.get_rect(left=lastRightCoordinate, top=centerY - textSize * 3 / 5)
screen.blit(text, text_rect)
lastRightCoordinate = text_rect.right
def draw_left_with_subscript(screen, leftX, centerY, textSize, text):
split_text = text.split('_')
cleaned_text = [sub_text for sub_text in split_text if sub_text]
lastRightCoordinate = leftX
for n in range(len(cleaned_text)):
if n % 2 == 0:
if textSize == 10:
font = font10
elif textSize == 20:
font = font20
elif textSize == 25:
font = font25
elif textSize == 30:
font = font30
elif textSize == 70:
font = font70
else:
font = pygame.font.Font("fonts/Jost-700-Bold.otf", textSize)
text = font.render(cleaned_text[n], True, textColor)
text_rect = text.get_rect(left=lastRightCoordinate, centery=centerY)
screen.blit(text, text_rect)
lastRightCoordinate = text_rect.right
if n % 2 == 1:
text = font10.render(cleaned_text[n], True, textColor)
text_rect = text.get_rect(left=lastRightCoordinate, top=centerY + textSize * 1 / 10)
screen.blit(text, text_rect)
lastRightCoordinate = text_rect.right
def degrees_to_mouse(centerX, centerY):
# Get the mouse position
mouse_x, mouse_y = pygame.mouse.get_pos()
# Calculate the angle between the arrow and the mouse position
dx = mouse_x - centerX
dy = mouse_y - centerY
return math.degrees(math.atan2(-dy, dx))
def blit_center(screen, image, coordinates):
image_rect = image.get_rect()
blit_x = coordinates[0] - (image_rect.width // 2)
blit_y = coordinates[1] - (image_rect.height // 2)
screen.blit(image, (blit_x, blit_y))