Пример #1
0
	def on_key_press(symbol, modifiers):
		current_scene = scene.get()
		game_state=game.state()
		corps = game.GET_CORPS()

		# Escape pressed
		if symbol == key.ESCAPE:
			# Game back action
			if current_scene is 'game':
				if game.pause() is True:
					cursor.set('default')
					background.scene_speed('pause')
				
				else:
					cursor.disable()
					background.scene_speed('game')
			
			# Levels back action
			elif current_scene is 'levels':
				menu.init()
			
			# Help back action
			elif current_scene is 'help':
				scene.set('levels')
				help.slide(1)
			
			# Menu back action
			elif current_scene is 'menu':
				pyglet.app.exit()
		
		# Arrow pressed
		elif current_scene is 'game':	
			if 'Phagocyte' in corps.keys():	
				if symbol == key.UP:
					corps['Phagocyte']['pushUp'] = 1
				if symbol == key.DOWN:
					corps['Phagocyte']['pushDown'] = 1
				if symbol == key.RIGHT:
					corps['Phagocyte']['pushRight'] = 1
				if symbol == key.LEFT:
					corps['Phagocyte']['pushLeft'] = 1
		
		return True
Пример #2
0
	def on_mouse_press(x, y, button, modifiers):
		current_scene = scene.get()
		
		# Left click
		if button == mouse.LEFT:
			# Menu clicks
			if current_scene is 'menu':
				# Music button
				if (x >= 40 and x <= 86 and y >= 13 and y <= 59) or (x >= 116 and x <= 294 and y >= 21 and y <= 50):
					sound.play('02')
					settings.toggleMusic()
				
				# Sound button
				if (x >= 404 and x <= 450 and y >= 13 and y <= 59) or (x >= 480 and x <= 790 and y >= 21 and y <= 50):
					sound.play('02')
					settings.toggleSound()
				
				# About button
				if x >= 932 and x <= 978 and y >= 13 and y <= 59 or menu.hasAbout() == True:
					sound.play('03')
					menu.toggleAbout()
				
				# Play button
				if x >= 40 and x <= 310 and y >= 497 and y <= 572:
					sound.play('01')
					levels.init()
			
			# Levels clicks
			elif current_scene is 'levels':
				# Back button
				if x >= 20 and x <= 204 and y >= 15 and y <= 57:
					sound.play('01')
					menu.init()
				
				# Fight (bacteria) button
				if x >= 142 and x <= 392 and y >= 199 and y <= 244:
					sound.play('04')
					
					game.init('bacteria')
				
				# Fight (virus) button
				if x >= 632 and x <= 882 and y >= 199 and y <= 244:
					sound.play('04')
					game.init('virus')
				
				# Help (bacteria) button
				if x >= 142 and x <= 392 and y >= 164 and y <= 198:
					sound.play('03')
					help.init('bacteria')
				
				# Help (virus) button
				if x >= 632 and x <= 882 and y >= 164 and y <= 198:
					sound.play('03')
					help.init('virus')
				
				# Difficulty (easy) button
				if x >= 452 and x <= 482 and y >= 15 and y <= 57:
					sound.play('02')
					settings.toggleDifficulty(1)
				
				# Difficulty (medium) button
				if x >= 497 and x <= 528 and y >= 15 and y <= 57:
					sound.play('02')
					settings.toggleDifficulty(2)
				
				# Difficulty (hard) button
				if x >= 542 and x <= 573 and y >= 15 and y <= 57:
					sound.play('02')
					settings.toggleDifficulty(3)
			
			# Help clicks
			elif current_scene is 'help':
				scene.set('levels')
				help.slide(1)
			
			# Game clicks
			elif current_scene is 'game':
				# End of game motion
				if game.state() is 'win' or game.state() is 'loose':
					# Quit button
					if x >= 260 and x <= 304 and y >= 124 and y <= 172:
						pyglet.app.exit()
					
					# Menu button
					elif x >= 324 and x <= 372 and y >= 124 and y <= 166:
						menu.init()
					
					# Retry button
					elif x >= 694 and x <= 742 and y >= 124 and y <= 172:
						game.init(mode.get())
				
				# Paused game clicks
				elif game.paused() is True:
					# Quit button
					if x >= 341 and x <= 386 and y >= 227 and y <= 270:
						pyglet.app.exit()
					
					# Menu button
					elif x >= 405 and x <= 453 and y >= 227 and y <= 270:
						if game.pause() is False:
							menu.init()
					
					# Resume button
					elif x >= 647 and x <= 683 and y >= 227 and y <= 270:
						if game.pause() is False:
							cursor.disable()
							background.scene_speed('game')
		
		return True