Example #1
0
	def __init__(self,screen,direction,text):
		FPS = 30
		fpsClock = pygame.time.Clock()
		screen = pygame.display.set_mode((600,400), 0, 32)
		pygame.display.set_caption('Animation')
		WHITE = (255, 255, 255)
		catImg = pygame.image.load('cat2.png')
		tree = pygame.image.load('tree.png')
		background = pygame.image.load('background.png')
		screen.blit(background,(0,0))
		treex=370
		treey = 0
		catx = 0
		caty = 240
		textpos = text.get_rect()
		textpos.centerx = background.get_rect().centerx
		textpos.y = 350
		background.blit(text, textpos)
		while True :			#main game loop
			screen.blit(background,(0,0))
			if direction == 'right':
				catx += 5
		        	treex -= 5
			if catx>600 :
				errorScreen(screen,"Oops.. Block went to Infinity")
			screen.blit(catImg, (catx,caty))
			screen.blit(tree, (treex,treey))
			for event in pygame.event.get():
				if event.type == QUIT:
					pygame.quit()
					sys.exit()
			pygame.display.update()
			fpsClock.tick(FPS)
Example #2
0
	def __init__(self,screen,direction,text):
		FPS = 30
		fpsClock = pygame.time.Clock()
		screen = pygame.display.set_mode((600,400), 0, 32)
		pygame.display.set_caption('Animation')
		WHITE = (255, 255, 255)
		block = pygame.image.load('Images/3.png')
	
		background = pygame.image.load('Images/4.png')
		screen.blit(background,(0,0))
		
		blockx = 267
		blocky = 0
		textpos = text.get_rect()
		textpos.x = 0
		textpos.y = 350
		background.blit(text, textpos)
		while True :			#main game loop
			screen.blit(background,(0,0))
			if direction == 'down':
				blocky += 5
		        	

				
			if blocky>450 :
				errorScreen(screen,"Oops.. The block fell down !")
				#screen.blit(infinity,(400,200))
			screen.blit(block, (blockx,blocky))
			
			for event in pygame.event.get():
				if event.type == QUIT:
					pygame.quit()
					sys.exit()
			pygame.display.update()
			fpsClock.tick(FPS)
Example #3
0
def ask(DISPLAY_SURF, question,countIn):
	print ("inside inputbox")
	try:
		"ask(DISPLAY_SURF, question) -> answer"
		pygame.font.init()
		current_string = []
		display_box(DISPLAY_SURF,countIn, question + ": " + "".join(current_string))
		#print "now enter"
		while True:
			mouse = pygame.mouse.get_pos()
			#	keeping pygame.QUIT part here is useless, because just in the first interation the control enters in get_key
			#	function and stays there till a key is pressed, so it doesnt check for pygame.QUIT part
			for event in pygame.event.get():
				if event.type == pygame.QUIT:
					pygame.quit()
					sys.exit()
			inkey = get_key()
			if inkey == K_BACKSPACE:
				current_string = current_string[0:-1]
			elif inkey == K_RETURN:
				break
			elif inkey == K_MINUS:
				if len(current_string) == 0:
					current_string.append("-")
			elif inkey <= 127:
				current_string.append(chr(inkey))
			display_box(DISPLAY_SURF, countIn,question + ": " + "".join(current_string))
		return "".join(current_string)
	except :
		print ("error in getting input")
		errorScreen.errorScreen(DISPLAY_SURF,"Error in getting "+question)
		return
Example #4
0
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)
Example #5
0
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)
Example #6
0
def startGame(DISPLAY_SURF):
	background=pygame.image.load('Images/simphy.jpg')
	DISPLAY_SURF.blit(background,SCREEN_TOPLEFT)
	pygame.mixer.music.load('Sound/bill1.ogg')
	pygame.mixer.music.play(-1, 0.0)
	try:
		btn_linear_motion = pygame.image.load('Images/buttons/linear_motion_button.png')
		btn_vertical_motion = pygame.image.load('Images/buttons/vertical_motion_button.png')
		btn_momentum = pygame.image.load('Images/buttons/momentum_button.png')
		clock = pygame.time.Clock()
		run1= True;
		while run1:
			DISPLAY_SURF.blit(background,SCREEN_TOPLEFT)
			mouse = pygame.mouse.get_pos()
			for event in pygame.event.get():
				if event.type == pygame.QUIT:
					if pygame.mixer.music.get_busy():
						pygame.mixer.music.stop()
					run1 = False
					pygame.quit()
					sys.exit()
				elif event.type == pygame.MOUSEBUTTONDOWN:
					if rect_linear_motion.collidepoint(mouse):
						game1.startGame1(DISPLAY_SURF)
					elif rect_vertical_motiond.collidepoint(mouse):
						game2.startGame2(DISPLAY_SURF)
					elif rect_momentum.collidepoint(mouse):
						print ("game 3")
						game3.startGame3(DISPLAY_SURF)
						
			rect_linear_motion = DISPLAY_SURF.blit(btn_linear_motion ,(100,210))
			rect_vertical_motiond = DISPLAY_SURF.blit(btn_vertical_motion,(300,210))
			rect_momentum= DISPLAY_SURF.blit(btn_momentum,(200,310))

			pygame.display.update()
			clock.tick(60)
	except Exception:							# except is the python equivalent of catch block
		print ("error in demo")
		errorScreen.errorScreen(DISPLAY_SURF,"Something went wrong")
	else:
		print ("all good")
Example #7
0
def startGame2(DISPLAYSURF):
	btn = Button('Start')

	clock = pygame.time.Clock()
	background=pygame.image.load('Images/1.png')
	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;
											
					m1 = inputbox.ask(DISPLAYSURF, "Mass, M",countInputs)
					m2 = float (m1)
					countInputs=countInputs+5;
					u1 = inputbox.ask(DISPLAYSURF, "Coefficient of Friction, u",countInputs)
					u2 = float (u1)
					countInputs=countInputs+5;
					f1 = inputbox.ask(DISPLAYSURF, "Force, F",countInputs)
					f2 = float (f1)
					v1 = u2 * f2
					W = m2 * 9.8
						
					if ( W > v1):
						font = pygame.font.Font(None, 36)
						text = font.render("The block will fall down.", 1, (10, 10, 10))
						animation2(DISPLAYSURF,'down',text)
					else:
						res=pygame.image.load('Images/5.png')
   						DISPLAYSURF.blit(res,(0,0))
						errorScreen(DISPLAYSURF,"The block wont show any motion!")
					
		btn.draw(DISPLAYSURF, mouse, (200,300,100,20), (225,303))

		pygame.display.update()
		clock.tick(60)
Example #8
0
def ask(screen, question,countIn):
	try:
		"ask(screen, question) -> answer"
		pygame.font.init()
		current_string = []
		display_box(screen,countIn, question + ": " + string.join(current_string,""))
		#print "now enter"
		while 1:
			inkey = get_key()
			if inkey == K_BACKSPACE:
				current_string = current_string[0:-1]
			elif inkey == K_RETURN:
				break
			elif inkey == K_MINUS:
				if len(current_string) == 0:
					current_string.append("-")
			elif inkey <= 127:
				current_string.append(chr(inkey))
			display_box(screen, countIn,question + ": " + string.join(current_string,""))
		return string.join(current_string,"")
	except :
		print "error in getting input"
		errorScreen(screen,"Error in getting "+question)
		return
Example #9
0
def startGame2(DISPLAY_SURF):
    print("INSIDE GAME2.py")
    btn_start = pygame.image.load('Images/buttons/start.png')

    clock = pygame.time.Clock()
    background = pygame.image.load('Images/game2/1.png')
    run = True
    while run:
        DISPLAY_SURF.blit(background, SCREEN_TOPLEFT)
        mouse = pygame.mouse.get_pos()
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                run = False
            elif event.type == pygame.MOUSEBUTTONDOWN:
                if rect_start.collidepoint(mouse):
                    countInputs = 1

                    mass = inputbox.ask(DISPLAY_SURF, "Mass, M", countInputs)
                    mass = float(mass)
                    if mass <= 0:
                        errorScreen.errorScreen(DISPLAY_SURF,
                                                "Mass must be Positve")
                    countInputs = countInputs + 5
                    initial_velocity = inputbox.ask(DISPLAY_SURF,
                                                    "Coeff. of Friction, u",
                                                    countInputs)
                    initial_velocity = float(initial_velocity)
                    if initial_velocity > 1:
                        errorScreen.errorScreen(DISPLAY_SURF,
                                                "Invalid coeff. of friction")
                    if initial_velocity < 0:
                        errorScreen.errorScreen(DISPLAY_SURF,
                                                "Invalid coeff. of friction")
                    countInputs = countInputs + 5
                    force = inputbox.ask(DISPLAY_SURF, "Force, F", countInputs)
                    force = float(force)
                    final_velocity = initial_velocity * force
                    weight = mass * 9.8

                    if (weight > final_velocity):
                        font = pygame.font.Font(None, 36)
                        text = font.render("The block will fall down.", 1,
                                           (10, 10, 10))
                        animation2(DISPLAY_SURF, 'down', text)
                    else:
                        res = pygame.image.load('Images/game2/5.png')
                        DISPLAY_SURF.blit(res, SCREEN_TOPLEFT)
                        endScreen(DISPLAY_SURF, ":)")

        rect_start = DISPLAY_SURF.blit(btn_start, (220, 303))

        pygame.display.update()
        clock.tick(60)
Example #10
0
def startGame2(DISPLAY_SURF):
	print ("INSIDE GAME2.py")
	btn_start = pygame.image.load('Images/buttons/start.png')

	clock = pygame.time.Clock()
	background=pygame.image.load('Images/game2/1.png')
	run = True
	while run:
		DISPLAY_SURF.blit(background,SCREEN_TOPLEFT)
		mouse = pygame.mouse.get_pos()
		for event in pygame.event.get():
			if event.type == pygame.QUIT:
				run = False
			elif event.type == pygame.MOUSEBUTTONDOWN:
				if rect_start.collidepoint(mouse):
					countInputs = 1;
											
					mass = inputbox.ask(DISPLAY_SURF, "Mass, M",countInputs)
					mass = float (mass)
					if mass <= 0 :
						errorScreen.errorScreen(DISPLAY_SURF,"Mass must be Positve")
					countInputs = countInputs + 5;
					initial_velocity = inputbox.ask(DISPLAY_SURF, "Coeff. of Friction, u",countInputs)
					initial_velocity = float (initial_velocity)
					if initial_velocity > 1 :
						errorScreen.errorScreen(DISPLAY_SURF,"Invalid coeff. of friction")
					if initial_velocity < 0 :
						errorScreen.errorScreen(DISPLAY_SURF,"Invalid coeff. of friction")
					countInputs = countInputs + 5;
					force = inputbox.ask(DISPLAY_SURF, "Force, F",countInputs)
					force = float (force)
					final_velocity = initial_velocity * force
					weight = mass * 9.8
						
					if ( weight > final_velocity):
						font = pygame.font.Font(None, 36)
						text = font.render("The block will fall down.", 1, (10, 10, 10))
						animation2(DISPLAY_SURF,'down',text)
					else:
						res = pygame.image.load('Images/game2/5.png')
						DISPLAY_SURF.blit(res,SCREEN_TOPLEFT)
						endScreen(DISPLAY_SURF,":)")
					
		rect_start = DISPLAY_SURF.blit(btn_start ,(220,303))

		

		pygame.display.update()
		clock.tick(60)
Example #11
0
def compSbyNLM(DISPLAY_SURF):
    print("INSIDE SbyNLM.py")

    btn_s1 = pygame.image.load('Images/buttons/parameters/s1.png')
    btn_s2 = pygame.image.load('Images/buttons/parameters/s2.png')
    btn_s3 = pygame.image.load('Images/buttons/parameters/s3.png')
    btn_s4 = pygame.image.load('Images/buttons/parameters/s4.png')

    btn_back = Button('Back')
    btn_back.setColor(RED)
    btn_back.setHoverColor(LIME)
    btn_back.setFontColor(BLUE)
    clock = pygame.time.Clock()
    background = pygame.image.load('Images/game1/input_values.png')

    run = True

    while run:
        DISPLAY_SURF.blit(background, SCREEN_TOPLEFT)
        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 rect_s1.collidepoint(mouse):
                    countInputs = 1
                    # countInputs is related to the y coordinate of the input text boxes
                    initial_velocity = inputbox.ask(DISPLAY_SURF,
                                                    "Initial velocity, u",
                                                    countInputs)
                    initial_velocity = float(initial_velocity)
                    countInputs = countInputs + 5
                    acceleration = inputbox.ask(DISPLAY_SURF,
                                                "Acceleration, a", countInputs)
                    acceleration = float(acceleration)
                    countInputs = countInputs + 5
                    time = inputbox.ask(DISPLAY_SURF, "Time, t", countInputs)
                    time = float(time)
                    if (time < 0):
                        errorScreen.errorScreen(DISPLAY_SURF,
                                                "Negative time entered")
                        run = False
                    displacement = initial_velocity * time + acceleration * time * time / 2
                    final_velocity = initial_velocity + acceleration * time

                    font = pygame.font.Font(None, 36)
                    text = font.render(
                        "The Displacement hence calculated is " +
                        str(displacement) + "metre", 1, WHITE)
                    path = "Images/game1/Explanation/Calculate_S/G1/"
                    anim1(DISPLAY_SURF, text, final_velocity, initial_velocity,
                          acceleration, time, displacement, path)
                    run = False
                elif rect_s2.collidepoint(mouse):
                    countInputs = 1
                    # countInputs is related to the y coordinate of the input text boxes
                    final_velocity = inputbox.ask(DISPLAY_SURF,
                                                  "Final velocity, v",
                                                  countInputs)
                    final_velocity = float(final_velocity)
                    countInputs = countInputs + 5
                    acceleration = inputbox.ask(DISPLAY_SURF,
                                                "Acceleration, a", countInputs)
                    acceleration = float(acceleration)
                    countInputs = countInputs + 5
                    time = inputbox.ask(DISPLAY_SURF, "Time, t", countInputs)
                    time = float(time)
                    if (time < 0):
                        errorScreen.errorScreen(DISPLAY_SURF,
                                                "Negative time entered")
                        run = False
                    displacement = final_velocity * time - acceleration * time * time / 2
                    initial_velocity = final_velocity - acceleration * time

                    font = pygame.font.Font(None, 36)
                    text = font.render(
                        "The Displacement hence calculated is " +
                        str(displacement) + "metre", 1, WHITE)
                    path = "Images/game1/Explanation/Calculate_S/G2/"
                    anim1(DISPLAY_SURF, text, final_velocity, initial_velocity,
                          acceleration, time, displacement, path)
                    run = False
                elif rect_s3.collidepoint(mouse):
                    countInputs = 1
                    # countInputs is related to the y coordinate of the input text boxes
                    initial_velocity = inputbox.ask(DISPLAY_SURF,
                                                    "Initial velocity, u",
                                                    countInputs)
                    initial_velocity = float(initial_velocity)
                    countInputs = countInputs + 5
                    final_velocity = inputbox.ask(DISPLAY_SURF,
                                                  "Final velocity, v",
                                                  countInputs)
                    final_velocity = float(final_velocity)
                    countInputs = countInputs + 5
                    time = inputbox.ask(DISPLAY_SURF, "Time, t", countInputs)
                    time = float(time)
                    if (time < 0):
                        errorScreen.errorScreen(DISPLAY_SURF,
                                                "Negative time entered")
                        run = False
                    if (time == 0):
                        displacement = 0
                        acceleration = 0
                    else:
                        acceleration = (final_velocity -
                                        initial_velocity) / time
                        if (acceleration == 0):
                            displacement = initial_velocity * time
                        else:
                            displacement = (final_velocity * final_velocity -
                                            initial_velocity * initial_velocity
                                            ) / 2 / acceleration

                    font = pygame.font.Font(None, 36)
                    text = font.render(
                        "The Displacement hence calculated is " +
                        str(displacement) + "metre", 1, WHITE)
                    path = "Images/game1/Explanation/Calculate_S/G3/"
                    anim1(DISPLAY_SURF, text, final_velocity, initial_velocity,
                          acceleration, time, displacement, path)
                    run = False
                elif rect_s4.collidepoint(mouse):
                    countInputs = 1
                    # countInputs is related to the y coordinate of the input text boxes
                    initial_velocity = inputbox.ask(DISPLAY_SURF,
                                                    "Initial velocity, u",
                                                    countInputs)
                    initial_velocity = float(initial_velocity)
                    countInputs = countInputs + 5
                    final_velocity = inputbox.ask(DISPLAY_SURF,
                                                  "Final Velocity, v",
                                                  countInputs)
                    final_velocity = float(final_velocity)
                    countInputs = countInputs + 5
                    acceleration = inputbox.ask(DISPLAY_SURF,
                                                "Acceleration, a", countInputs)
                    acceleration = float(acceleration)
                    if (acceleration == 0):
                        displacement = 0
                        time = 0
                    else:
                        displacement = (final_velocity * final_velocity -
                                        initial_velocity *
                                        initial_velocity) / 2 / acceleration
                        time = (final_velocity -
                                initial_velocity) / acceleration
                        if (time < 0):
                            errorScreen.errorScreen(
                                DISPLAY_SURF,
                                "Inconsistent data entered.(results to Negative time)"
                            )
                            run = False

                    font = pygame.font.Font(None, 36)
                    text = font.render(
                        "The Displacement hence calculated is " +
                        str(displacement) + "metre", 1, WHITE)
                    path = "Images/game1/Explanation/Calculate_S/G4/"
                    anim1(DISPLAY_SURF, text, final_velocity, initial_velocity,
                          acceleration, time, displacement, path)
                    run = False
                elif btn_back.obj.collidepoint(mouse):
                    run = False
        rect_s1 = DISPLAY_SURF.blit(btn_s1, (125, 103))
        rect_s2 = DISPLAY_SURF.blit(btn_s2, (125, 153))
        rect_s3 = DISPLAY_SURF.blit(btn_s3, (125, 203))
        rect_s4 = DISPLAY_SURF.blit(btn_s4, (125, 253))

        btn_back.draw(DISPLAY_SURF, mouse, (550, 10, 45, 20), (560, 13))
        pygame.display.update()
        clock.tick(60)
    print("Exit from SbyNLM")
Example #12
0
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)
Example #13
0
def compAbyNLM(DISPLAY_SURF):
	print ("INSIDE AbyNLM.py")

	btn_a1 = pygame.image.load('Images/buttons/parameters/a1.png') 	
	btn_a2 = pygame.image.load('Images/buttons/parameters/a2.png') 
	btn_a3 = pygame.image.load('Images/buttons/parameters/a3.png') 
	btn_a4 = pygame.image.load('Images/buttons/parameters/a4.png') 

	btn_back = Button('Back')
	btn_back.setColor(RED)
	btn_back.setHoverColor(LIME)
	btn_back.setFontColor(BLUE)
	clock = pygame.time.Clock()
	background=pygame.image.load('Images/game1/input_values.png')	
	run = True
	while run:
		DISPLAY_SURF.blit(background,SCREEN_TOPLEFT)
		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 rect_a1.collidepoint(mouse):
					countInputs = 1;	# countInputs is related to the y coordinate of the input text boxes
					initial_velocity = inputbox.ask(DISPLAY_SURF, "Initial velocity, u",countInputs)
					initial_velocity = float (initial_velocity)
					countInputs = countInputs + 5;
					final_velocity = inputbox.ask(DISPLAY_SURF, "Final Velocity, v",countInputs)
					final_velocity = float (final_velocity)
					countInputs = countInputs + 5;
					time = inputbox.ask(DISPLAY_SURF, "Time, t",countInputs)
					time = float (time)
					if(time < 0):
						errorScreen.errorScreen(DISPLAY_SURF,"Negative time entered")
						run = False
					if(time == 0):
						errorScreen.errorScreen(DISPLAY_SURF,"Time cannot be zero in this case")
						run = False
					acceleration = (final_velocity - initial_velocity)/time
					displacement = initial_velocity*time+ acceleration*time*time/2
					
					font = pygame.font.Font(None, 36)
					text = font.render("Acceleration hence calculated is "+ str(acceleration) +"meter/sec/sec", 1, WHITE)
					path = "Images/game1/Explanation/Calculate_A/G1/"
					anim1(DISPLAY_SURF,text,final_velocity,initial_velocity,acceleration,time,displacement,path)
					run = False
				elif rect_a2.collidepoint(mouse):
					countInputs = 1;	# countInputs is related to the y coordinate of the input text boxes
					displacement = inputbox.ask(DISPLAY_SURF, "Displacement, s",countInputs)
					displacement = float (displacement)
					countInputs = countInputs + 5;
					final_velocity = inputbox.ask(DISPLAY_SURF, "Final Velocity, v",countInputs)
					final_velocity = float (final_velocity)
					countInputs = countInputs + 5;
					time = inputbox.ask(DISPLAY_SURF, "Time, t",countInputs)
					time = float (time)
					if(time < 0):
						errorScreen.errorScreen(DISPLAY_SURF,"Negative time entered")
						run = False
					if(time == 0):
						errorScreen.errorScreen(DISPLAY_SURF,"Time cannot be zero in this case")
						run = False
					acceleration = (final_velocity*time - displacement)*2/time/time
					
					initial_velocity = final_velocity - acceleration*time
					font = pygame.font.Font(None, 36)
					text = font.render("Acceleration hence calculated is "+ str(acceleration) +"meter/sec/sec", 1, WHITE)
					path = "Images/game1/Explanation/Calculate_A/G2/"
					anim1(DISPLAY_SURF,text,final_velocity,initial_velocity,acceleration,time,displacement,path)
					run = False
				elif rect_a3.collidepoint(mouse):
					countInputs = 1;	# countInputs is related to the y coordinate of the input text boxes
					initial_velocity = inputbox.ask(DISPLAY_SURF, "Initial velocity, u",countInputs)
					initial_velocity = float (initial_velocity)
					countInputs = countInputs + 5;
					displacement = inputbox.ask(DISPLAY_SURF, "Displacement, s",countInputs)
					displacement = float (displacement)
					countInputs = countInputs + 5;
					time = inputbox.ask(DISPLAY_SURF, "Time, t",countInputs)
					time = float (time)
					if(time < 0):
						errorScreen.errorScreen(DISPLAY_SURF,"Negative time entered")
						run = False
					if(time == 0):
						errorScreen.errorScreen(DISPLAY_SURF,"Time cannot be zero in this case")
						run = False
					acceleration = ((displacement-initial_velocity*time)/time/time)*2
					
					final_velocity = initial_velocity + acceleration*time
					font = pygame.font.Font(None, 36)
					text = font.render("Acceleration hence calculated is "+ str(acceleration) +"meter/sec/sec", 1, WHITE)
					path = "Images/game1/Explanation/Calculate_A/G3/"
					anim1(DISPLAY_SURF,text,final_velocity,initial_velocity,acceleration,time,displacement,path)
					run = False
				elif rect_a4.collidepoint(mouse):
					countInputs = 1;	# countInputs is related to the y coordinate of the input text boxes
					initial_velocity = inputbox.ask(DISPLAY_SURF, "Initial velocity, u",countInputs)
					initial_velocity = float (initial_velocity)
					countInputs = countInputs + 5;
					displacement = inputbox.ask(DISPLAY_SURF, "Displacement, s",countInputs)
					displacement = float (displacement)
					countInputs = countInputs + 5;
					final_velocity = inputbox.ask(DISPLAY_SURF, "Final Velocity, v",countInputs)
					final_velocity = float (final_velocity)
					if(displacement==0):
						errorScreen.errorScreen(DISPLAY_SURF,"Displacement cannot be zero in this case")
						run = False
					acceleration = (final_velocity*final_velocity - initial_velocity*initial_velocity )/2/displacement
					if (acceleration == 0):
						time =0
					else :
						time = (final_velocity - initial_velocity)/acceleration
					if(time < 0):
						errorScreen.errorScreen(DISPLAY_SURF,"Inconsistent data entered.(results to Negative time)")
						run = False
					
					font = pygame.font.Font(None, 36)
					text = font.render("Acceleration hence calculated is "+ str(acceleration) +"meter/sec/sec", 1, WHITE)
					path = "Images/game1/Explanation/Calculate_A/G4/"
					anim1(DISPLAY_SURF,text,final_velocity,initial_velocity,acceleration,time,displacement,path)
					run = False
				elif btn_back.obj.collidepoint(mouse):
					run = False
		rect_a1 = DISPLAY_SURF.blit(btn_a1,(125, 103))
		rect_a2 = DISPLAY_SURF.blit(btn_a2,(125, 153))
		rect_a3 = DISPLAY_SURF.blit(btn_a3,(125, 203))
		rect_a4 = DISPLAY_SURF.blit(btn_a4,(125, 253))

		btn_back.draw(DISPLAY_SURF,mouse,(550,10,45,20),(560,13))
		pygame.display.update()
		clock.tick(60)
	print ("exit from AbyNLM")
Example #14
0
    def __init__(self, DISPLAY_SURF, direction, text):
        FPS = 30
        fpsClock = pygame.time.Clock()
        SCREEN_WIDTH = 600
        DISPLAY_SURF = pygame.display.set_mode((SCREEN_WIDTH, 400), 0, 32)
        pygame.display.set_caption('Animation')
        WHITE = WHITE
        RED = RED
        catImg = pygame.image.load('Images/game4/block.png')
        cloud = pygame.image.load('Images/game4/cloudf.png')
        tree = pygame.image.load('Images/game4/tree.png')
        background = pygame.image.load('Images/game4/background.png')
        DISPLAY_SURF.blit(background, SCREEN_TOPLEFT)
        treex = 370
        treey = 0
        catx = 0
        caty = 240
        textpos = text.get_rect()
        textpos.centerx = background.get_rect().centerx
        textpos.y = 350
        countTrees = 0
        background.blit(text, textpos)

        cloudx = SCREEN_WIDTH + 5
        cloudy = 60
        centerx = SCREEN_WIDTH
        fontObj = pygame.font.Font(None, 16)
        textSurfaceObj = fontObj.render('Block is going to infinity!!', True,
                                        RED)
        textRectObj = textSurfaceObj.get_rect()
        textRectObj.center = (centerx, 50)

        while True:  #main game loop
            DISPLAY_SURF.blit(background, SCREEN_TOPLEFT)
            textRectObj.center = (centerx, cloudy)

            if direction == 'right':
                if catx < SCREEN_WIDTH / 2:
                    catx += 5
                else:
                    treex -= 5

                if countTrees > 1:
                    cloudx -= 5
                    centerx -= 5
                    textRectObj.center = (centerx, 50)
                    DISPLAY_SURF.blit(textSurfaceObj, textRectObj)
                    DISPLAY_SURF.blit(cloud, (cloudx, cloudy))
                    catx += 5
                    treex += 5
                    if catx > 580:
                        errorScreen.errorScreen(DISPLAY_SURF,
                                                "Block went to Infinity")
                DISPLAY_SURF.blit(catImg, (catx, caty))
                DISPLAY_SURF.blit(tree, (treex, treey))
                if treex < -tree.get_width() - 10:
                    treex = SCREEN_WIDTH + 20
                    countTrees += 1
            if direction == 'left':
                catx += 5
                if catx > 500:
                    catx = 0
                    pygame.time.wait(700)  # pause for 700 mili seconds
                    errorScreen.errorScreen(DISPLAY_SURF,
                                            "Block went to -ve infinfity")
                DISPLAY_SURF.blit(catImg, (catx, caty))
                DISPLAY_SURF.blit(tree, (treex, treey))
            for event in pygame.event.get():
                if event.type == QUIT:
                    pygame.quit()
                    sys.exit()

            pygame.display.update()
            fpsClock.tick(FPS)
Example #15
0
def compTbyNLM(DISPLAY_SURF):

	btn_t1 = pygame.image.load('Images/buttons/parameters/t1.png') 	
	btn_t2 = pygame.image.load('Images/buttons/parameters/t2.png') 
	btn_t3 = pygame.image.load('Images/buttons/parameters/t3.png') 
	btn_t4 = pygame.image.load('Images/buttons/parameters/t4.png') 

	btn_back = Button('Back')
	btn_back.setColor(RED)
	btn_back.setHoverColor(LIME)
	btn_back.setFontColor(BLUE)
	clock = pygame.time.Clock()
	background=pygame.image.load('Images/game1/input_values.png')
	
	run = True
	
	while run:
		DISPLAY_SURF.blit(background,SCREEN_TOPLEFT)
		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 rect_t1.collidepoint(mouse):
					countInputs = 1;	# countInputs is related to the y coordinate of the input text boxes
					final_velocity = inputbox.ask(DISPLAY_SURF, "Final Velocity, v",countInputs)
					final_velocity = float (final_velocity)
					countInputs = countInputs + 5;
					acceleration = inputbox.ask(DISPLAY_SURF, "Acceleration, a",countInputs)
					acceleration = float (acceleration)
					countInputs = countInputs + 5;
					initial_velocity = inputbox.ask(DISPLAY_SURF, "Initial Velocity, u",countInputs)			
					initial_velocity = float (initial_velocity)
					if(acceleration==0):
						errorScreen.errorScreen(DISPLAY_SURF,"Acceleration cannot be zero in this case")
						run = False
					time = (final_velocity -initial_velocity)/acceleration
					if(time < 0):
						errorScreen.errorScreen(DISPLAY_SURF,"Inconsistent data entered.(results to Negative time)")
						run = False
					displacement = initial_velocity*time + acceleration*time*time/2
					
					font = pygame.font.Font(None, 36)
					text = font.render("The Time hence calculated is "+ str(time) +" sec", 1, WHITE)
					path = "Images/game1/Explanation/Calculate_T/G1/"
					anim1(DISPLAY_SURF,text,final_velocity,initial_velocity,acceleration,time,displacement,path)
					run = False
				elif rect_t2.collidepoint(mouse):
					countInputs = 1;	# countInputs is related to the y coordinate of the input text boxes
					initial_velocity = inputbox.ask(DISPLAY_SURF, "Initial Velocity, u",countInputs)
					initial_velocity = float (initial_velocity)
					countInputs = countInputs + 5;
					displacement = inputbox.ask(DISPLAY_SURF, "Displacement, s",countInputs)
					displacement = float (displacement)
					countInputs = countInputs + 5;
					acceleration = inputbox.ask(DISPLAY_SURF, "Acceleration, a",countInputs)
					acceleration = float (acceleration)
					try :
						final_velocity = math.sqrt(initial_velocity*initial_velocity + 2*acceleration*displacement)
					except :
						errorScreen.errorScreen(DISPLAY_SURF,"Inconsistent data")
					if(acceleration==0):
						if (initial_velocity == 0):
							errorScreen.errorScreen(DISPLAY_SURF,"Inconsistent data")
							run = False
						else :
							time = displacement/initial_velocity
					else :
						time = (final_velocity - initial_velocity)/acceleration
					if(time < 0):
						errorScreen.errorScreen(DISPLAY_SURF,"Inconsistent data entered.(results to Negative time)")
						run = False
					
					font = pygame.font.Font(None, 36)
					text = font.render("The Time hence calculated is "+ str(time) +" sec", 1, WHITE)
					path = "Images/game1/Explanation/Calculate_T/G2/"
					anim1(DISPLAY_SURF,text,final_velocity,initial_velocity,acceleration,time,displacement,path)
					run = False
				elif rect_t3.collidepoint(mouse):
					countInputs = 1;	# countInputs is related to the y coordinate of the input text boxes
					initial_velocity = inputbox.ask(DISPLAY_SURF, "Initiual Velocity, u",countInputs)
					initial_velocity = float (initial_velocity)
					countInputs = countInputs + 5;
					displacement = inputbox.ask(DISPLAY_SURF, "Displacement, s",countInputs)
					displacement = float (displacement)
					countInputs = countInputs + 5;
					final_velocity = inputbox.ask(DISPLAY_SURF, "Final Velocity, v",countInputs)
					final_velocity = float (final_velocity)
					if(displacement==0):
						acceleration = 0
						time = 0
					else :
						acceleration = (final_velocity*final_velocity - initial_velocity*initial_velocity)/2/displacement
						if(acceleration==0):
							errorScreen.errorScreen(DISPLAY_SURF,"Inconsistent data entered.(results to zero acceleration)")
							run = False
						time = (final_velocity - initial_velocity)/acceleration
						if(time < 0):
							errorScreen.errorScreen(DISPLAY_SURF,"Inconsistent data entered.(results to Negative time)")
							run = False
					
					font = pygame.font.Font(None, 36)
					text = font.render("The Time hence calculated is "+ str(time) +" sec", 1, WHITE)
					path = "Images/game1/Explanation/Calculate_T/G3/"
					anim1(DISPLAY_SURF,text,final_velocity,initial_velocity,acceleration,time,displacement,path)
					run = False
				elif rect_t4.collidepoint(mouse):
					countInputs = 1;	# countInputs is related to the y coordinate of the input text boxes
					final_velocity = inputbox.ask(DISPLAY_SURF, "Final Velocity, v",countInputs)
					final_velocity = float (final_velocity)
					countInputs = countInputs + 5;
					displacement = inputbox.ask(DISPLAY_SURF, "Displacement, s",countInputs)
					displacement = float (displacement)
					countInputs = countInputs + 5;
					acceleration = inputbox.ask(DISPLAY_SURF, "Acceleration, a",countInputs)
					acceleration = float (acceleration)
					initial_velocity = math.sqrt(final_velocity*final_velocity - 2*acceleration*displacement)
					if(acceleration==0):
						if (final_velocity == 0):
							errorScreen.errorScreen(DISPLAY_SURF,"Inconsistent data")
							run = False
						else :
							time = displacement/final_velocity
					else :
						time = (final_velocity - initial_velocity)/acceleration
					if(time < 0):
						errorScreen.errorScreen(DISPLAY_SURF,"Inconsistent data entered.(results to Negative time)")
						run = False
					
					font = pygame.font.Font(None, 36)
					text = font.render("The Time hence calculated is "+ str(time) +" sec", 1, WHITE)
					path = "Images/game1/Explanation/Calculate_T/G4/"
					anim1(DISPLAY_SURF,text,final_velocity,initial_velocity,acceleration,time,displacement,path)
					run = False
				elif btn_back.obj.collidepoint(mouse):
					run = False

		rect_t1 = DISPLAY_SURF.blit(btn_t1,(125, 103))
		rect_t2 = DISPLAY_SURF.blit(btn_t2,(125, 153))
		rect_t3 = DISPLAY_SURF.blit(btn_t3,(125, 203))
		rect_t4 = DISPLAY_SURF.blit(btn_t4,(125, 253))
		btn_back.draw(DISPLAY_SURF,mouse,(550,10,45,20),(560,13))
		pygame.display.update()
		clock.tick(60)
	print ("Exit from TbyNLM")
Example #16
0
						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)
Example #17
0
	pygame.mixer.music.play(-1, 0.0)
	musicPlaying = True
	
	try:
		btngame1=Button('Linear Motion')
		btngame2=Button('Vertical Motion')	
		clock = pygame.time.Clock()
		run1= True;
		while run1:
			mouse2 = pygame.mouse.get_pos()
			for event in pygame.event.get():
				if event.type == pygame.QUIT:
					sys.exit()
				elif event.type == pygame.MOUSEBUTTONDOWN:
					if btngame1.obj.collidepoint(mouse2):
						game1.startGame1(DISPLAYSURF)
					elif btngame2.obj.collidepoint(mouse2):
						game2.startGame2(DISPLAYSURF)
			btngame1.draw(DISPLAYSURF, mouse2, (100,210,150,20), (100,210))
			btngame2.draw(DISPLAYSURF, mouse2, (300,210,150,20), (300,210))
			pygame.display.update()
			clock.tick(60)


	except :
		if musicPlaying:
			pygame.mixer.music.stop()
		else:
			pygame.mixer.music.play(-1, 0.0)
		errorScreen(DISPLAYSURF,"Something went wrong")
Example #18
0
def compVbyNLM(DISPLAY_SURF):
    btn_v1 = pygame.image.load('Images/buttons/parameters/v1.png')
    btn_v2 = pygame.image.load('Images/buttons/parameters/v2.png')
    btn_v3 = pygame.image.load('Images/buttons/parameters/v3.png')
    btn_v4 = pygame.image.load('Images/buttons/parameters/v4.png')

    btn_back = Button('Back')
    btn_back.setColor(RED)
    btn_back.setHoverColor(LIME)
    btn_back.setFontColor(BLUE)
    clock = pygame.time.Clock()
    background = pygame.image.load('Images/game1/input_values.png')

    run = True
    Zero = 0
    while run:
        DISPLAY_SURF.blit(background, SCREEN_TOPLEFT)
        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 rect_v1.collidepoint(mouse):
                    countInputs = 1
                    # countInputs is related to the y coordinate of the input text boxes
                    initial_velocity = inputbox.ask(DISPLAY_SURF,
                                                    "Initial velocity, u",
                                                    countInputs)
                    initial_velocity = float(initial_velocity)
                    countInputs = countInputs + 5
                    acceleration = inputbox.ask(DISPLAY_SURF,
                                                "Acceleration, a", countInputs)
                    acceleration = float(acceleration)
                    countInputs = countInputs + 5
                    time = inputbox.ask(DISPLAY_SURF, "Time, t", countInputs)
                    time = float(time)
                    if (time < 0):
                        errorScreen.errorScreen(DISPLAY_SURF,
                                                "Negative time entered")
                        run = False
                    final_velocity = initial_velocity + acceleration * time
                    displacement = initial_velocity * time + acceleration * time * time / 2
                    final_velocity = str(final_velocity)
                    font = pygame.font.Font(None, 36)
                    text = font.render(
                        "The Final Velocity hence calculated is " +
                        str(final_velocity) + " metre/sec", 1, WHITE)
                    path = "Images/game1/Explanation/Calculate_V/G1/"
                    anim1(DISPLAY_SURF, text, final_velocity, initial_velocity,
                          acceleration, time, displacement, path)
                    run = False

                elif rect_v2.collidepoint(mouse):
                    countInputs = 1
                    # countInputs is related to the y coordinate of the input text boxes
                    displacement = inputbox.ask(DISPLAY_SURF,
                                                "Displacement, s", countInputs)
                    displacement = float(displacement)
                    countInputs = countInputs + 5
                    acceleration = inputbox.ask(DISPLAY_SURF,
                                                "Acceleration, a", countInputs)
                    acceleration = float(acceleration)
                    countInputs = countInputs + 5
                    time = inputbox.ask(DISPLAY_SURF, "Time, t", countInputs)
                    time = float(time)
                    if (time < 0):
                        errorScreen.errorScreen(DISPLAY_SURF,
                                                "Negative time entered")
                        run = False
                    if (time == 0):
                        errorScreen.errorScreen(
                            DISPLAY_SURF, "Time cannot be zero in this case")
                        run = False
                    initial_velocity = (displacement -
                                        acceleration * time * time / 2) / time
                    final_velocity = initial_velocity + acceleration * time
                    final_velocity = str(final_velocity)
                    font = pygame.font.Font(None, 36)
                    text = font.render(
                        "The Final Velocity hence calculated is " +
                        str(final_velocity) + " metre/sec", 1, WHITE)
                    path = "Images/game1/Explanation/Calculate_V/G2/"
                    anim1(DISPLAY_SURF, text, final_velocity, initial_velocity,
                          acceleration, time, displacement, path)
                    run = False
                elif rect_v3.collidepoint(mouse):
                    countInputs = 1
                    # countInputs is related to the y coordinate of the input text boxes
                    initial_velocity = inputbox.ask(DISPLAY_SURF,
                                                    "Initial velocity, u",
                                                    countInputs)
                    initial_velocity = float(initial_velocity)
                    countInputs = countInputs + 5
                    displacement = inputbox.ask(DISPLAY_SURF,
                                                "Displacement, s", countInputs)
                    displacement = float(displacement)
                    countInputs = countInputs + 5
                    time = inputbox.ask(DISPLAY_SURF, "Time, t", countInputs)
                    time = float(time)
                    print("abcddfghj")
                    if (time < 0):
                        errorScreen.errorScreen(DISPLAY_SURF,
                                                "Negative time entered")
                        run = False
                    if (time == 0):
                        errorScreen.errorScreen(
                            DISPLAY_SURF, "Time cannot be zero in this case")
                        run = False
                    acceleration = ((displacement - initial_velocity * time) /
                                    time / time) * 2
                    print("abcddfasdfghghj")
                    final_velocity = initial_velocity + acceleration * time
                    final_velocity = str(final_velocity)
                    font = pygame.font.Font(None, 36)
                    text = font.render(
                        "The Final Velocity hence calculated is " +
                        str(final_velocity) + " metre/sec", 1, WHITE)
                    print("abcddfghsdfghjdfghjkdfghjkj")
                    path = "Images/game1/Explanation/Calculate_V/G3/"
                    anim1(DISPLAY_SURF, text, final_velocity, initial_velocity,
                          acceleration, time, displacement, path)
                    run = False
                elif rect_v4.collidepoint(mouse):
                    countInputs = 1
                    # countInputs is related to the y coordinate of the input text boxes
                    initial_velocity = inputbox.ask(DISPLAY_SURF,
                                                    "Initial velocity, u",
                                                    countInputs)
                    initial_velocity = float(initial_velocity)
                    countInputs = countInputs + 5
                    displacement = inputbox.ask(DISPLAY_SURF,
                                                "Displacement, s", countInputs)
                    displacement = float(displacement)
                    countInputs = countInputs + 5
                    acceleration = inputbox.ask(DISPLAY_SURF,
                                                "Acceleration, a", countInputs)
                    acceleration = float(acceleration)
                    final_velocity = math.sqrt(initial_velocity *
                                               initial_velocity +
                                               2 * acceleration * displacement)
                    final_velocity = str(final_velocity)
                    if (acceleration == 0):
                        time = 0
                    else:
                        time = (final_velocity -
                                initial_velocity) / acceleration
                    if (time < 0):
                        errorScreen.errorScreen(
                            DISPLAY_SURF,
                            "Inconsistent data entered.(results to Negative time)"
                        )
                        run = False
                    font = pygame.font.Font(None, 36)
                    text = font.render(
                        "The Final Velocity hence calculated is " +
                        str(final_velocity) + " metre/sec", 1, WHITE)
                    path = "Images/game1/Explanation/Calculate_V/G4/"
                    anim1(DISPLAY_SURF, text, final_velocity, initial_velocity,
                          acceleration, time, displacement, path)
                    run = False
                elif btn_back.obj.collidepoint(mouse):
                    run = False

        rect_v1 = DISPLAY_SURF.blit(btn_v1, (125, 103))
        rect_v2 = DISPLAY_SURF.blit(btn_v2, (125, 153))
        rect_v3 = DISPLAY_SURF.blit(btn_v3, (125, 203))
        rect_v4 = DISPLAY_SURF.blit(btn_v4, (125, 253))

        btn_back.draw(DISPLAY_SURF, mouse, (550, 10, 45, 20), (560, 13))
        pygame.display.update()
        clock.tick(60)
    print("exit from VbyNLM")
Example #19
0
def compTbyNLM(DISPLAY_SURF):

    btn_t1 = pygame.image.load('Images/buttons/parameters/t1.png')
    btn_t2 = pygame.image.load('Images/buttons/parameters/t2.png')
    btn_t3 = pygame.image.load('Images/buttons/parameters/t3.png')
    btn_t4 = pygame.image.load('Images/buttons/parameters/t4.png')

    btn_back = Button('Back')
    btn_back.setColor(RED)
    btn_back.setHoverColor(LIME)
    btn_back.setFontColor(BLUE)
    clock = pygame.time.Clock()
    background = pygame.image.load('Images/game1/input_values.png')

    run = True

    while run:
        DISPLAY_SURF.blit(background, SCREEN_TOPLEFT)
        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 rect_t1.collidepoint(mouse):
                    countInputs = 1
                    # countInputs is related to the y coordinate of the input text boxes
                    final_velocity = inputbox.ask(DISPLAY_SURF,
                                                  "Final Velocity, v",
                                                  countInputs)
                    final_velocity = float(final_velocity)
                    countInputs = countInputs + 5
                    acceleration = inputbox.ask(DISPLAY_SURF,
                                                "Acceleration, a", countInputs)
                    acceleration = float(acceleration)
                    countInputs = countInputs + 5
                    initial_velocity = inputbox.ask(DISPLAY_SURF,
                                                    "Initial Velocity, u",
                                                    countInputs)
                    initial_velocity = float(initial_velocity)
                    if (acceleration == 0):
                        errorScreen.errorScreen(
                            DISPLAY_SURF,
                            "Acceleration cannot be zero in this case")
                        run = False
                    time = (final_velocity - initial_velocity) / acceleration
                    if (time < 0):
                        errorScreen.errorScreen(
                            DISPLAY_SURF,
                            "Inconsistent data entered.(results to Negative time)"
                        )
                        run = False
                    displacement = initial_velocity * time + acceleration * time * time / 2

                    font = pygame.font.Font(None, 36)
                    text = font.render(
                        "The Time hence calculated is " + str(time) + " sec",
                        1, WHITE)
                    path = "Images/game1/Explanation/Calculate_T/G1/"
                    anim1(DISPLAY_SURF, text, final_velocity, initial_velocity,
                          acceleration, time, displacement, path)
                    run = False
                elif rect_t2.collidepoint(mouse):
                    countInputs = 1
                    # countInputs is related to the y coordinate of the input text boxes
                    initial_velocity = inputbox.ask(DISPLAY_SURF,
                                                    "Initial Velocity, u",
                                                    countInputs)
                    initial_velocity = float(initial_velocity)
                    countInputs = countInputs + 5
                    displacement = inputbox.ask(DISPLAY_SURF,
                                                "Displacement, s", countInputs)
                    displacement = float(displacement)
                    countInputs = countInputs + 5
                    acceleration = inputbox.ask(DISPLAY_SURF,
                                                "Acceleration, a", countInputs)
                    acceleration = float(acceleration)
                    try:
                        final_velocity = math.sqrt(
                            initial_velocity * initial_velocity +
                            2 * acceleration * displacement)
                    except:
                        errorScreen.errorScreen(DISPLAY_SURF,
                                                "Inconsistent data")
                    if (acceleration == 0):
                        if (initial_velocity == 0):
                            errorScreen.errorScreen(DISPLAY_SURF,
                                                    "Inconsistent data")
                            run = False
                        else:
                            time = displacement / initial_velocity
                    else:
                        time = (final_velocity -
                                initial_velocity) / acceleration
                    if (time < 0):
                        errorScreen.errorScreen(
                            DISPLAY_SURF,
                            "Inconsistent data entered.(results to Negative time)"
                        )
                        run = False

                    font = pygame.font.Font(None, 36)
                    text = font.render(
                        "The Time hence calculated is " + str(time) + " sec",
                        1, WHITE)
                    path = "Images/game1/Explanation/Calculate_T/G2/"
                    anim1(DISPLAY_SURF, text, final_velocity, initial_velocity,
                          acceleration, time, displacement, path)
                    run = False
                elif rect_t3.collidepoint(mouse):
                    countInputs = 1
                    # countInputs is related to the y coordinate of the input text boxes
                    initial_velocity = inputbox.ask(DISPLAY_SURF,
                                                    "Initiual Velocity, u",
                                                    countInputs)
                    initial_velocity = float(initial_velocity)
                    countInputs = countInputs + 5
                    displacement = inputbox.ask(DISPLAY_SURF,
                                                "Displacement, s", countInputs)
                    displacement = float(displacement)
                    countInputs = countInputs + 5
                    final_velocity = inputbox.ask(DISPLAY_SURF,
                                                  "Final Velocity, v",
                                                  countInputs)
                    final_velocity = float(final_velocity)
                    if (displacement == 0):
                        acceleration = 0
                        time = 0
                    else:
                        acceleration = (final_velocity * final_velocity -
                                        initial_velocity *
                                        initial_velocity) / 2 / displacement
                        if (acceleration == 0):
                            errorScreen.errorScreen(
                                DISPLAY_SURF,
                                "Inconsistent data entered.(results to zero acceleration)"
                            )
                            run = False
                        time = (final_velocity -
                                initial_velocity) / acceleration
                        if (time < 0):
                            errorScreen.errorScreen(
                                DISPLAY_SURF,
                                "Inconsistent data entered.(results to Negative time)"
                            )
                            run = False

                    font = pygame.font.Font(None, 36)
                    text = font.render(
                        "The Time hence calculated is " + str(time) + " sec",
                        1, WHITE)
                    path = "Images/game1/Explanation/Calculate_T/G3/"
                    anim1(DISPLAY_SURF, text, final_velocity, initial_velocity,
                          acceleration, time, displacement, path)
                    run = False
                elif rect_t4.collidepoint(mouse):
                    countInputs = 1
                    # countInputs is related to the y coordinate of the input text boxes
                    final_velocity = inputbox.ask(DISPLAY_SURF,
                                                  "Final Velocity, v",
                                                  countInputs)
                    final_velocity = float(final_velocity)
                    countInputs = countInputs + 5
                    displacement = inputbox.ask(DISPLAY_SURF,
                                                "Displacement, s", countInputs)
                    displacement = float(displacement)
                    countInputs = countInputs + 5
                    acceleration = inputbox.ask(DISPLAY_SURF,
                                                "Acceleration, a", countInputs)
                    acceleration = float(acceleration)
                    initial_velocity = math.sqrt(
                        final_velocity * final_velocity -
                        2 * acceleration * displacement)
                    if (acceleration == 0):
                        if (final_velocity == 0):
                            errorScreen.errorScreen(DISPLAY_SURF,
                                                    "Inconsistent data")
                            run = False
                        else:
                            time = displacement / final_velocity
                    else:
                        time = (final_velocity -
                                initial_velocity) / acceleration
                    if (time < 0):
                        errorScreen.errorScreen(
                            DISPLAY_SURF,
                            "Inconsistent data entered.(results to Negative time)"
                        )
                        run = False

                    font = pygame.font.Font(None, 36)
                    text = font.render(
                        "The Time hence calculated is " + str(time) + " sec",
                        1, WHITE)
                    path = "Images/game1/Explanation/Calculate_T/G4/"
                    anim1(DISPLAY_SURF, text, final_velocity, initial_velocity,
                          acceleration, time, displacement, path)
                    run = False
                elif btn_back.obj.collidepoint(mouse):
                    run = False

        rect_t1 = DISPLAY_SURF.blit(btn_t1, (125, 103))
        rect_t2 = DISPLAY_SURF.blit(btn_t2, (125, 153))
        rect_t3 = DISPLAY_SURF.blit(btn_t3, (125, 203))
        rect_t4 = DISPLAY_SURF.blit(btn_t4, (125, 253))
        btn_back.draw(DISPLAY_SURF, mouse, (550, 10, 45, 20), (560, 13))
        pygame.display.update()
        clock.tick(60)
    print("Exit from TbyNLM")