-
Notifications
You must be signed in to change notification settings - Fork 0
/
game1.py
93 lines (92 loc) · 3.34 KB
/
game1.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
import pygame
import os
import sys
import inputbox
from Button import Button
from animation import animation
from errorScreen import errorScreen
from pygame.locals import *
def startGame1(DISPLAYSURF):
btn = Button('Final Vel,v')
btn2 = Button('Time, t')
btn3 = Button('In. Vel, u')
btn4 = Button('Accn., a')
btn5 = Button('Displacement, s')
clock = pygame.time.Clock()
background=pygame.image.load('Images/game1.jpg')
run = True
while run:
DISPLAYSURF.blit(background,(0,0))
mouse = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
elif event.type == pygame.MOUSEBUTTONDOWN:
if btn.obj.collidepoint(mouse):
countInputs=1;
u1 = inputbox.ask(DISPLAYSURF, "Initial velocity, u",countInputs)
u2 = float (u1)
countInputs=countInputs+5;
a1 = inputbox.ask(DISPLAYSURF, "Acceleration, a",countInputs)
a2 = float (a1)
countInputs=countInputs+5;
t1 = inputbox.ask(DISPLAYSURF, "Time, t",countInputs)
t2 = float (t1)
v1 = u2 + a2 * t2
v2 = str (v1)
font = pygame.font.Font(None, 36)
text = font.render("The Final Velocity hence calculated is "+v2+"metre/sec", 1, (10, 10, 10))
animation(DISPLAYSURF,'right',text)
elif btn2.obj.collidepoint(mouse):
countInputs=1;
u1 = inputbox.ask(DISPLAYSURF, "Initial Velocity, u",countInputs)
u2 = float (u1)
countInputs=countInputs+5;
a1 = inputbox.ask(DISPLAYSURF, "Acceleration, a",countInputs)
a2 = float (a1)
countInputs=countInputs+5;
v1 = inputbox.ask(DISPLAYSURF, "Final Velocity, t",countInputs)
v2 = float (v1)
t1 = (v2-u2)/a2
t2 = str (t1)
if(t1<0):
errorScreen(DISPLAYSURF,"Invalid datas entered")
font = pygame.font.Font(None, 36)
text = font.render("The Time hence calculated is "+t2+"seconds", 1, (10, 10, 10))
animation(DISPLAYSURF,'right',text)
elif btn3.obj.collidepoint(mouse):
countInputs=1;
v1 = inputbox.ask(DISPLAYSURF, "Final velocity, v",countInputs)
v2 = float (v1)
countInputs=countInputs+5;
a1 = inputbox.ask(DISPLAYSURF, "Acceleration, a",countInputs)
a2 = float (a1)
countInputs=countInputs+5;
t1 = inputbox.ask(DISPLAYSURF, "Time, t",countInputs)
t2 = float (t1)
u1 = v2 - (a2 * t2)
u2 = str (u1)
font = pygame.font.Font(None, 36)
text = font.render("The Initial Velocity hence calculated is "+u2+"metre/sec", 1, (10, 10, 10))
animation(DISPLAYSURF,'right',text)
elif btn4.obj.collidepoint(mouse):
countInputs=1;
u1 = inputbox.ask(DISPLAYSURF, "Initial velocity, u",countInputs)
u2 = float (u1)
countInputs=countInputs+5;
v1 = inputbox.ask(DISPLAYSURF, "Final velocity, v",countInputs)
v2 = float (v1)
countInputs=countInputs+5;
t1 = inputbox.ask(DISPLAYSURF, "Time, t",countInputs)
t2 = float (t1)
a1 = (v2 - u2)/t2
a2 = str (v1)
font = pygame.font.Font(None, 36)
text = font.render("The Acceleration hence calculated is "+a2+"metre/sec^2", 1, (10, 10, 10))
animation(DISPLAYSURF,'right',text)
btn.draw(DISPLAYSURF, mouse, (100,100,100,20), (125,103))
btn2.draw(DISPLAYSURF, mouse, (100,130,100,20), (125,133))
btn3.draw(DISPLAYSURF, mouse, (100,160,100,20), (125,163))
btn4.draw(DISPLAYSURF, mouse, (100,190,100,20), (125,193))
pygame.display.update()
clock.tick(60)