Exemplo n.º 1
0
def main():
	
	# create AI decision tree
	learner1 = Learner(1)
	learner2 = Learner(2)
	learner2.display_tree()
	learner2.cross_validation()
	
	# initialize joysticks
	# because this line is only called once, all usuable joysticks must be plugged in at program start
	pygame.joystick.init()
	joysticks = [pygame.joystick.Joystick(x) for x in range(pygame.joystick.get_count())]
	for i in range(len(joysticks)):
		joysticks[i].init()
	
	joystick1 = ''
	joystick2 = ''
	if len(joysticks) > 0:
		joystick1 = GameJoystick("xbox", joysticks[0])
	else:
		joystick1 = GameJoystick("keyboard")

	if len(joysticks) > 1:
		joystick2 = GameJoystick("xbox", joysticks[1])
	else:
		joystick2 = GameJoystick("keyobard")

	# set screen size
	screen = pygame.display.set_mode((screenX, screenY))

	pygame.display.set_caption('Falcon Poncho')
	fontObj = pygame.font.Font('freesansbold.ttf', 32)

	player1 = Player(1, 75, 100, joystick1)
	player2 = Player(2, 590, 100, joystick2)
	player2.myDirection = direction['left']
	world = GameWorld()
	recorder = Recorder()

	# timer used for falcon punch timing
	currentTime = 0
	menuTimer = 0

	# load music and play indefinitely
	menuMusic = pygame.mixer.Sound("lib/Menu_Music.wav")
	menuMusic.play()

	inMenu = True
	canPressStart = False
	menuBackground = pygame.image.load("lib/main_menu.png")
	startButton = pygame.image.load("lib/press_start.png")
	
	while True:
		
		# Repetition
		# check for quit event
		for event in pygame.event.get():
			if event.type == QUIT:
				pygame.quit()
				sys.exit()
	
		if inMenu:
			screen.blit(pygame.transform.scale(menuBackground, (screenX, screenY)), (0, 0))
			
			if menuTimer < 750:
				screen.blit(startButton, (300, 500))
			else:
				canPressStart = True
			if not joystick1 == '':
				if joystick1.checkAction('start') and canPressStart:
					inMenu = False
					menuMusic.stop()
					gameMusic.play(-1)
					canPressStart = False
				if joystick1.checkAction('select') and canPressStart:
					player2.isAI = True
					player2.learner = learner2
					inMenu = False
					menuMusic.stop()
					gameMusic.play(-1)
					canPressStart = False
				if joystick1.checkAction('home') and canPressStart:
					player1.isAI = True
					player1.learner = learner1
					player2.isAI = True
					player2.learner = learner2
					inMenu = False
					menuMusic.stop()
					gameMusic.play(-1)
					canPressStart = False

			menuTimer = menuTimer%1500 + fpsClock.get_time()

		else:
			# check time passed
			currentTime += fpsClock.get_time()
			GameDriver(player1, player2, world, currentTime, joystick1, joystick2, screen, fontObj, recorder)

		# Essential lines of code. Game will run turble if these are not here
		pygame.display.update()
		fpsClock.tick(60) # 60 fps??? Can't really tell