当前位置: 首页>>代码示例>>Python>>正文


Python Button.draw方法代码示例

本文整理汇总了Python中Button.Button.draw方法的典型用法代码示例。如果您正苦于以下问题:Python Button.draw方法的具体用法?Python Button.draw怎么用?Python Button.draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Button.Button的用法示例。


在下文中一共展示了Button.draw方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from Button import Button [as 别名]
# 或者: from Button.Button import draw [as 别名]
class WindowBar:
	def __init__(self, parent, absx, absy, title=None):
		self.x = 0
		self.y = 0
		self.absx = absx
		self.absy = absy
		self.parent = parent
		self.width = self.parent.get_width()
		self.height = 20
		self.surface = pygame.Surface((self.width, self.height))
		self.surface.fill((100,100,100))
		self.title = title
		if self.title != None:
			self.button = Button(0, 0, self.title, self.surface, (100,100,100))

	def is_clicked(self):
		# doesn't actually check if clicked, just mouse over
		mx, my = pygame.mouse.get_pos()
		if mx > self.absx and mx < self.absx + self.width and my > self.absy and my < self.absy + self.height:
			return True

	def draw(self):
		if self.title != None:
			self.button.draw(self.surface)
		self.parent.blit(self.surface, (self.x, self.y))
开发者ID:jackneedham,项目名称:Raspberry-Pi-Project,代码行数:27,代码来源:WindowBar.py

示例2: draw

# 需要导入模块: from Button import Button [as 别名]
# 或者: from Button.Button import draw [as 别名]
 def draw(self):
     if self.left + self.max_width <= self.parent.width - self.parent.bd_width - \
        2 * self.parent.h_margin:
         self.visible = True
     else:
         self.visible = False
     Button.draw(self)
开发者ID:adozenlines,项目名称:freevo1,代码行数:9,代码来源:LetterBoxGroup.py

示例3: __init__

# 需要导入模块: from Button import Button [as 别名]
# 或者: from Button.Button import draw [as 别名]
	def __init__(self, screen,text):
		pygame.mixer.music.stop()


	        # set up music
 	        pygame.mixer.music.load('error.mid')
	        pygame.mixer.music.play(-1, 0.0)

		pygame.font.init()
		fontobject = pygame.font.Font(None,18)
		
               	bckgd = pygame.image.load('Images/error.jpg')
               	screen.blit(bckgd,(0,0))
		pygame.draw.rect(screen, (75,0,0),((screen.get_width() / 2) - 100,100,200,20), 0)
		pygame.draw.rect(screen, (255,255,255),((screen.get_width() / 2) - 102,98,204,24), 1)
		if len(text) != 0:
			screen.blit(fontobject.render(text, 1, (255,255,255)),((screen.get_width() / 2) - 100, 100))
			pygame.display.flip()
			btnReplay = Button('Play Again ?')
			btnExit = Button('Exit')
			clock = pygame.time.Clock()
			
			run1= True;
			run2= False;
			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 btnReplay.obj.collidepoint(mouse2):
							print "restart"
							os.execl(sys.executable, sys.executable, *sys.argv)
						elif btnExit.obj.collidepoint(mouse2):
							print "exit"
							run1= False;
							run2 = True;
				btnReplay.draw(screen, mouse2, (100,(screen.get_height()-100),100,20), (100,(screen.get_height()-100)))
				btnExit.draw(screen, mouse2, (300,(screen.get_height()-100),100,20), (300,(screen.get_height()-100)))
				pygame.display.update()
				clock.tick(60)
			if run2 :
				sys.exit()
			else :
				print "some error"
				return
开发者ID:BlazingFire,项目名称:SimPhy,代码行数:48,代码来源:errorScreen.py

示例4: Scoreboard

# 需要导入模块: from Button import Button [as 别名]
# 或者: from Button.Button import draw [as 别名]
class Scoreboard(object):
	
	def __init__(self, main):
		self.main = main;
		self.highScores = [];
		self.highScoreDisplays = [];
		# populate the highscores and displays
		for i in range(0, 5):
			self.highScores.append(0);
			tScore = TextItem(400, 250 + i * 50, 400, 150, [str(i+1)+': ' + str(self.highScores[i])], showRect = False);
			self.highScoreDisplays.append(tScore);

		self.background_image = os.path.join('assets', 'startscreen', 'night_sunset_gradient.png');
		self.background = Background(self.background_image);
		self.menuBtn = Button(500, 600, 200, 75, 'Menu');
		self.playerScoreDisplay = TextItem(400, 100, 400, 150, [''], showRect = False, fontSize = 72);

	def listenForEvents(self):
		if 1 in pygame.mouse.get_pressed():
			if self.menuBtn.is_under(pygame.mouse.get_pos()):
				self.main.set_mode('menu');

	def renderScreen(self):
		self.background.draw(self.main.screen);
		self.menuBtn.draw(self.main.screen);
		self.playerScoreDisplay.draw(self.main.screen);
		for displays in self.highScoreDisplays:
			displays.draw(self.main.screen);

	def enter(self):
		print("entered Scoreboard");
		self.playerScoreDisplay.setText(['You did it! Score: ' + self.main.score]);
		# append the player score to highScores
		print self.highScores
		self.highScores.append(int(self.main.score));
		print self.highScores
		# sort highScore
		self.highScores.sort();
		print self.highScores
		# remove the minimum and display the rest in sorted order
		self.highScores.pop(0);
		print self.highScores
		for i in range(0, 5):
			self.highScoreDisplays[i].setText([str(i+1)+': ' + str(self.highScores[5 - 1 - i])])
开发者ID:Argzero,项目名称:Fractionauts,代码行数:46,代码来源:Scoreboard.py

示例5: Ask

# 需要导入模块: from Button import Button [as 别名]
# 或者: from Button.Button import draw [as 别名]
class Ask(Window):
    def __init__(self, question, parent, answer_var):
        self.width = 400
        self.height = 200
        self.parent = parent
        self.x = (parent.get_width() - self.width) / 2.0
        self.y = (parent.get_height() - self.height) / 2.0
        self.text = question
        answer_var = "LOL"
        Window.__init__(self, self.x, self.y, self.width, self.height, parent, "Ask", True)
        self.q_label = Button(20, 50, self.text, self.surface, (255, 255, 255), hpad=0)
        self.a_input = Input(20, 80, 360)

    def draw(self):
        self.q_label.draw(self.surface)
        self.a_input.draw(self.surface)
        Window.draw(self)

    def update(self, mouseclick, scrolldown=False, scrollup=False, keypressed=""):
        self.a_input.update(self.x + self.a_input.x, self.y + self.a_input.y, mouseclick, keypressed)
        Window.update(self, mouseclick, scrolldown=False, scrollup=False, keypressed="")
开发者ID:jackneedham,项目名称:Raspberry-Pi-Project,代码行数:23,代码来源:Ask.py

示例6: startGame2

# 需要导入模块: from Button import Button [as 别名]
# 或者: from Button.Button import draw [as 别名]
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)
开发者ID:BlazingFire,项目名称:SimPhy,代码行数:42,代码来源:game2.py

示例7: Welcome

# 需要导入模块: from Button import Button [as 别名]
# 或者: from Button.Button import draw [as 别名]
class Welcome():
	def __init__(self, game):

		self.game = game
		self.font = game.font
		self.one_player_button = Button([300, 350], [200, 30], "1P VS AI", self.font)
		self.one_player_button2 = Button([300, 400], [200, 30], "AI VS 1P", self.font)
		self.two_player_button = Button([300, 450], [200, 30], "1P VS 2P", self.font)

	def draw(self):
		game = self.game
		screen = game.screen
		self.one_player_button.draw(screen)
		self.one_player_button2.draw(screen)
		self.two_player_button.draw(screen)

	def handle_key_event(self, e):
		game = self.game
		pos = e.pos
		
		if self.one_player_button.check(pos):
			game.window = 1
			game.with_AI = True
			game.AI_first = True
 			

		elif self.one_player_button2.check(pos):
			game.window = 1
			game.with_AI = True
			game.AI_first = False
			
		elif self.two_player_button.check(pos):
			game.window = 1
			game.with_AI = False
开发者ID:one-atom,项目名称:Gomoku,代码行数:36,代码来源:Welcome.py

示例8: draw

# 需要导入模块: from Button import Button [as 别名]
# 或者: from Button.Button import draw [as 别名]
    def draw(self):
        if self.current_beatmap<len(self.beatmaps):
            currentb = self.beatmaps[self.current_beatmap]
        else:
            currentb = None
        h = variables.height
        w = variables.width
        b = h * 13 / 16
        p = classvar.player
        # background
        variables.screen.fill(variables.BLACK)

        # draw enemy first
        if self.state != "dance":
            self.enemy.animation.reset() # if not dancing, use first frame
            

        # draw enemy
        self.enemy.animation.draw_topright(variables.screen, enemypic_height())
            
        playerpicandrect = self.getplayerpicandrect()
        

        # draw the player
        if self.state == "dance":
            # draw the special animation behind the player
            self.drawspecialmove()
        variables.screen.blit(playerpicandrect[0], playerpicandrect[1])

        if currentb != None:
            # now draw the combo if necessary
            self.drawcombo()

        if self.enemy.animation.updatealwaysbattle:
            self.updatescreenforenemy()
        
        # draw beatmap
        if self.state == "dance":
            self.beatmaps[self.current_beatmap].draw()
        elif self.state == "attacking":
            self.beatmaps[self.current_beatmap].draw_pads()

        if self.state == "choose":
            # enemy name
            enemyname = variables.font.render("LV " + str(self.enemy.lv) + " " + self.enemy.name + " appears!", 0,
                                              variables.WHITE)
            enemynamescaled = sscale(enemyname)
            variables.screen.blit(enemynamescaled, [w / 2 - (enemynamescaled.get_width() / 2), h / 2])

            self.battlechoice.draw()
            
            # draw the wave above the battlechoice
            wavex = self.battlechoice.buttons[-2].x * variables.width
            # the height of the wave
            waveamp = (self.battlechoice.buttons[-2].height()*3/4) * 0.5
            
            wavelen = self.battlechoice.buttons[-2].width()*3/4
            wavey = self.battlechoice.buttons[-2].y*variables.height-waveamp
            loopbuffer = play_sound.all_tones[variables.settings.soundpack].loopbuffers[0]
            skiplen = (len(loopbuffer)/25)/wavelen
            drawwave(loopbuffer, skiplen, wavex, wavey, waveamp, wavelen, (255,255,255))

            # draw the scale above battlechoice
            firstscalex = self.battlechoice.buttons[-1].x * variables.width
            scalex = firstscalex
            scaley = self.battlechoice.buttons[-1].y*variables.height - self.battlechoice.buttons[-1].height()
            scaleintervals = play_sound.scales[self.getscalename()]
            for i in scaleintervals:
                tpic = getTextPic(str(i)+" ", variables.gettextsize(), variables.WHITE)
                variables.screen.blit(tpic, (scalex, scaley))
                scalex += tpic.get_width()
            variables.dirtyrects.append(Rect(firstscalex, scaley, scalex-firstscalex, self.battlechoice.buttons[-1].height()))

        elif self.state == "lose" or self.state == "win":

            # button
            if self.state == "win":
                conttext = "continue"
                # button coordinates are multipliers of screen width and height
                continuebutton = Button(1 / 2, b/h, conttext, variables.gettextsize()/h)
                continuebutton.iscentered = True
                continuebutton.draw(True)
            else:
                self.retrychoice.draw()

            # text
            text = None
            if self.state == "lose":
                text = variables.font.render("you lost...", 0, variables.WHITE)
            else:
                text = variables.font.render("you win!", 0, variables.WHITE)
            textscaled = sscale(text)
            variables.screen.blit(textscaled, [w / 2 - (textscaled.get_width() / 2), h / 2])
            self.drawscoretable()

        
        elif self.state == "exp" or self.state == "got exp":
            text = "continue"
            # continue button
            continuebutton = Button(1 / 2, b/h, text, variables.gettextsize()/h)
#.........这里部分代码省略.........
开发者ID:oflatt,项目名称:pythonRpgProject,代码行数:103,代码来源:Battle.py

示例9: compAbyNLM

# 需要导入模块: from Button import Button [as 别名]
# 或者: from Button.Button import draw [as 别名]

#.........这里部分代码省略.........
					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")
开发者ID:gopal10sep,项目名称:SimPhy-1,代码行数:104,代码来源:AbyNLM.py

示例10: compTbyNLM

# 需要导入模块: from Button import Button [as 别名]
# 或者: from Button.Button import draw [as 别名]

#.........这里部分代码省略.........
					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")
开发者ID:gopal10sep,项目名称:SimPhy-1,代码行数:104,代码来源:TbyNLM.py

示例11: str

# 需要导入模块: from Button import Button [as 别名]
# 或者: from Button.Button import draw [as 别名]
						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)
	except :
		print "error"
		errorScreen(DISPLAYSURF,"Something went wrong")
		os.execl(sys.executable, sys.executable, *sys.argv)
开发者ID:BlazingFire,项目名称:SimPhy,代码行数:32,代码来源:demo.py

示例12: run

# 需要导入模块: from Button import Button [as 别名]
# 或者: from Button.Button import draw [as 别名]
def run():

    pygame.init()
    start = 0
    #heigth
    h = 480
    #width
    w = 1000
    #control if the ball is on the screen
    f = 0
    #direction of the character
    v = 0

    color = (0, 255, 0)
    #load images
    fire = pygame.image.load("pySM/images/fire.bmp")
    img = pygame.image.load("pySM/images/spm.bmp")
    img2 = pygame.image.load("pySM/images/spm2.bmp")
    #load and play music
    pygame.mixer.init(44100, -16, 2, 2048)
    pygame.mixer.music.load("pySM/music/song.mp3")
    pygame.mixer.music.play(0, 0.0)
    
    man = Man(40, 358, 0, [img, img2, fire])
    screen = pygame.display.set_mode((w, h))
    
    running = 1
    
    button = Button(color, (w/2-50, h/2-25), (100, 50)) 
    rectMan = pygame.Rect(man.go-35, man.up-40, 95, 160)
    rectOst = pygame.Rect(500, 430, 50, 50)

    text = pygame.font.SysFont('arial.ttf', 30)
    startText = text.render("START", True, (0,0,0))

    while running:
        event = pygame.event.poll()
        if event.type == pygame.QUIT:
            running = 0
        
        screen.fill((0, 0, 0))  
        if(start == 0):
            button.draw(screen)
            screen.blit(startText, (465, 230))
            if(button.isClicked()):
                start = 1
        elif(start == 1):
            pygame.draw.rect(screen, color, rectMan)
            pygame.draw.rect(screen, color, rectOst)
            
            if(rectOst.colliderect(rectMan)):
                if(color == (0, 255, 0)):
                    color = (255, 0 ,0)
                else:
                    color = (0, 255, 0)
            key = pygame.key.get_pressed()
            if (key[pygame.K_a]):
                v = 1
            if (key[pygame.K_d]):
                v = 0
            
            #if the user press f key, initialize the variables
            #based on the position of the ball
            if(key[pygame.K_f]):
                man.fire(v)

            rectMan = man.move(key, rectMan, rectOst)
            rectMan = man.jump(key, rectMan, rectOst)
            #draw the character 
            man.draw(screen)

        pygame.display.flip()
        pygame.time.wait(5)
开发者ID:campo23,项目名称:pySM,代码行数:75,代码来源:__main__.py

示例13: App

# 需要导入模块: from Button import Button [as 别名]
# 或者: from Button.Button import draw [as 别名]
class App(object):
    
    def __init__(self):
        '''
        Returns an app object
        '''
        pygame.display.set_caption("SoundScape")
        self.screen = pygame.display.set_mode((800, 600),1)
        self.paintScreen = self.screen.subsurface(pygame.Rect(100, 0, 600, 500))
        self.paletteScreen = self.screen.subsurface(pygame.Rect(0, 0, 100, 300))
        self.screen.fill((183,183,183))
        self.paintScreen.fill((255,255,255))
        self.paletteScreen.blit(pygame.image.load("data/img/palette.png"), (0,0))
        self.paintRect = self.paintScreen.get_rect()
        self.paletteRect = self.paletteScreen.get_rect()
        self.brush = PaintBrush(self.paintScreen)
        self.painting = False
        self.undoCache = []
        pygame.mixer.init(buffer = 256)
        self.playButton = Button("data/img/play_button.png", (350, 500))
        self.playButton.draw(self.screen)
        self.stopButton = Button("data/img/stop_button.png", (460, 515))
        self.stopButton.draw(self.screen)
        self.chordButton = Button("data/img/chord_button.png", (265, 515))
        self.chordButton.draw(self.screen)
        self.demo1Button = Button("data/img/demo_1_button.png", (700, 0))
        self.demo1Button.draw(self.screen)
        self.demo2Button = Button("data/img/demo_2_button.png", (750, 0))
        self.demo2Button.draw(self.screen)
        self.demo3Button = Button("data/img/demo_3_button.png", (700, 50))
        self.demo3Button.draw(self.screen)
        self.demo1 = pygame.image.load('data/img/demo_1.png')
        self.demo2 = pygame.image.load('data/img/demo_2.png')
        self.demo3 = pygame.image.load('data/img/demo_3.png')
        self.help = pygame.image.load('data/img/help.png')
        self.scanGroup = pygame.sprite.Group()
        colorArray = [(254,0,0), (254,63,0), (254,127,0), (254, 214, 0),
                           (254,254,0), (127,254,0), (0,254,0), (13,152,185),
                           (0,0,254),(75,0,130), (143,0,254), (198, 21, 133)]
        # red, red-orange, orange, yellow-orange, yellow, yellow-green, green,
        # blue-green,blue, blue-violet, violet, red-violet
        noteArray = [pygame.mixer.Sound("data/C.ogg"),
                     pygame.mixer.Sound("data/C#.ogg"),
                     pygame.mixer.Sound("data/D.ogg"),
                     pygame.mixer.Sound("data/D#.ogg"),
                     pygame.mixer.Sound("data/E.ogg"),
                     pygame.mixer.Sound("data/F.ogg"),
                     pygame.mixer.Sound("data/F#.ogg"),
                     pygame.mixer.Sound("data/G.ogg"),
                     pygame.mixer.Sound("data/G#.ogg"),
                     pygame.mixer.Sound("data/A.ogg"),
                     pygame.mixer.Sound("data/A#.ogg"),
                     pygame.mixer.Sound("data/B.ogg")]
        #set the volumes at .3 to avoid gain
        for sound in noteArray:
            sound.set_volume(.3)
        #create a dict of notes with each notes corresponding color as its key
        self.noteDict = dict()
        for i in xrange(len(colorArray)):
            self.noteDict[colorArray[i]] = noteArray[i]
        self.playback = False
        self.canvasChordArray = []
        self.brush.set_brush(pygame.image.load("data/img/Brush.png"))
        self.brush.set_follow_angle(True)
        self.color = (254,0,0)
        self.brush.set_color(self.color)
        self.sound = self.noteDict[self.color]
        
    def save_paper(self):
        '''
        Make a copy of the screen and add it to the undoCache
        '''
        self.undoCache.append(self.paintScreen.copy())

    def undo_paper(self):
        '''
        Blits the previous saved state to the screen
        '''
        #Don't undo if there's nothing to undo
        if (len(self.undoCache) >= 1 and len(self.canvasChordArray) >= 1):
            p = self.undoCache.pop()
            self.canvasChordArray.pop()
            self.paintScreen.blit(p,(0,0))
            
    def paint_start(self):
        '''
        Initiates pinting and saves the state of the canvas before
        painting begins
        '''
        self.painting = True
        self.save_paper()
        
    def paint_stop(self):
        '''
        Ends the painting state
        '''
        self.painting = False
     
    def scan_col(self, surface,col):
        '''
#.........这里部分代码省略.........
开发者ID:amarsten,项目名称:SoundScape,代码行数:103,代码来源:App.py

示例14:

# 需要导入模块: from Button import Button [as 别名]
# 或者: from Button.Button import draw [as 别名]
	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")
开发者ID:BlazingFire,项目名称:SimPhy,代码行数:32,代码来源:demo.py

示例15: startGame1

# 需要导入模块: from Button import Button [as 别名]
# 或者: from Button.Button import draw [as 别名]
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)
开发者ID:BlazingFire,项目名称:SimPhy,代码行数:86,代码来源:game1.py


注:本文中的Button.Button.draw方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。