-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgame3.py
63 lines (54 loc) · 1.94 KB
/
game3.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
import pygame
import inputbox
from pygame.locals import *
from animation3 import animation3
import errorScreen
from Button import Button
from constants import *
from const_colors import *
def startGame3(DISPLAYSURF):
fpsClock = pygame.time.Clock()
SCREEN_WIDTH = 600
#DISPLAYSURF = pygame.display.set_mode((SCREEN_WIDTH,400), 0, 32)
pygame.display.set_caption('Animation')
#btn = Button('Input the values')
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
pygame.quit()
sys.exit()
#elif event.type == pygame.MOUSEBUTTONDOWN:
# if btn.obj.collidepoint(mouse):
countInputs=1;
m1 = inputbox.ask(DISPLAYSURF, "Mass of object1, m1",countInputs)
m1_ = float (m1)
countInputs=countInputs+5;
u1 = inputbox.ask(DISPLAYSURF, "InitialVelocity of 1,u1",countInputs)
u1_ = float (u1)
countInputs=countInputs+5;
m2 = inputbox.ask(DISPLAYSURF, "Mass of object2, m2",countInputs)
m2_ = float (m2)
countInputs=countInputs+5;
u2 = inputbox.ask(DISPLAYSURF, "InitialVelocity of 2,u2",countInputs)
u2_ = float (u2)
if(m1_<=0 or m2_<=0):
errorScreen.errorScreen(DISPLAYSURF,"Invalid Mass entered")
v1 = (((m1_ - m2_)*u1_) + (2*m2_*u2_))/(m1_+m2_)
v1_ = round (v1,2)
v2 = ((2*m1_*u1_) - (( m1_ - m2_)* u2_))/(m1_+m2_)
v2_ = round (v2,2)
background = pygame.image.load('Images/game3/background.png')
DISPLAYSURF.blit(background,(0,0))
font = pygame.font.Font(None, 20)
text = font.render("Final Velocity of object A ="+str(v1_)+"metre/sec and Final Velocity of object B ="+str(v2_)+"metre/sec", 1, (10, 10, 10))
animation3(DISPLAYSURF,'right',text,u1_,u2_,v1_,v2_)
run = False
#btn.draw(DISPLAYSURF, mouse, (185,80,200,20), (225,83))
pygame.display.update()
clock.tick(60)