-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
94 lines (68 loc) · 2.1 KB
/
main.py
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
import asyncio
import pygame
from ProjectConstants import *
import sys
from ExtraPages.Menu import draw_menu
from ExtraPages.LearnMore import draw_learn_more
from UIElements.Button import Button
from PhysicsModules.Kinematics import Kinematics
from PhysicsModules.CircularMotion import CircularMotion
import time
def update_game_state(new_state):
global gameState
gameState = new_state
def all_pages():
screen.fill(backgroundColor)
global gameState
#return to menu button
if gameState != "menu":
menuButton = Button(centerX=SCREEN_WIDTH - 75, centerY=50, width=100, height=50, textSize=30, borderSize=10, text="Menu")
if menuButton.draw_and_check_click(screen):
gameState = "menu"
#game states: menu, kinematics, circularMotion, learnMore
gameState = "menu"
#objects
kinematicsObj = Kinematics(100, 500, 50, 0)
circularMotionObj = CircularMotion(SCREEN_WIDTH / 2 - 250, CircularMotion.groundHeight / 2, 10)
async def main():
#game start
#game variables
GAME_OVER = False
all_pages()
draw_menu(screen, update_game_state)
pygame.display.update()
frame_count = 0
frame_rate = 0
start_time = time.time()
while not GAME_OVER:
#startTime = time.time()
all_pages()
if gameState == "menu":
pygame.display.set_caption("Main Menu")
draw_menu(screen, update_game_state)
if gameState == "kinematics":
pygame.display.set_caption("Kinematics")
kinematicsObj.draw_static(screen)
if gameState == "circularMotion":
pygame.display.set_caption("Circular Motion")
circularMotionObj.draw_static(screen, 0.1) #1 pixel is 0.1m
if gameState == "learnMore":
pygame.display.set_caption("Learn More")
draw_learn_more(screen)
for event in pygame.event.get():
if event.type == pygame.QUIT:
GAME_OVER = True
frame_count += 1
if time.time() - start_time > 1:
frame_rate = frame_count
frame_count = 0
start_time = time.time()
draw_text_left(screen, 5, 10, 10, "FPS: " + str(frame_rate))
pygame.display.update()
clock.tick(FPS)
await asyncio.sleep(0)
#endTime = time.time()
#print(round(1 / (endTime - startTime), 3))
pygame.quit()
sys.exit()
asyncio.run(main())