#!/usr/bin/env python3 # -*- coding: utf-8 -*- from libstormgames import * # Initial variable settings mode = "menu" sounds = initialize_gui("Monkey Spank") pygame.event.set_allowed(pygame.KEYDOWN) pygame.mixer.set_reserved(1) pygame.mixer.set_reserved(2) def butthead_taunt(sounds): global bonus global bonusTime play_random(sounds, "butt-head") bonus = True bonusTime = time.time() def monkey_taunt(): t = pygame.mixer.Channel(1) left = 1.0 right = 1.0 taunt = random.randrange(1, 4) if taunt == 1: right = 0.0 if taunt == 3: left = 0.0 t.play(sounds['monkey-taunt']) t.set_volume(left, right) return taunt def player_action(monkey, reaction): if monkey != reaction: return True global spanks left = 0.7 right = 0.7 if reaction == 1: right = 0.0 if reaction == 3: left = 0.0 p = pygame.mixer.Channel(2) p.play(sounds['spank-hit']) p.set_volume(left, right) score.Increase_Score(10) spanks += 1 return False def game(mode): pygame.mixer.music.pause() global bonus global bonusTime bonusTime = int(time.time()) encourage = int(time.time()) lose = False cut_scene(sounds, 'start-game') startTime = time.time() totalTime = startTime global spanks taunt = monkey_taunt() timeOut = time.time() while lose == False: if spanks <= 10 and time.time() - timeOut > 3: lose = True continue elif spanks > 10 and spanks <= 20 and time.time() - timeOut > 2: lose = True continue elif spanks > 20 and time.time() - timeOut > 1: lose = True continue event = pygame.event.poll() if event.type == pygame.KEYDOWN: # Escape is the back/exit key, close the game if not playing, or return to menu if playing. if event.key == pygame.K_ESCAPE: if mode != "menu": mode = "menu" return mode elif mode == "menu": exit_game() elif event.key == pygame.K_LEFT: lose = player_action(taunt, 1) if lose == True: continue taunt = monkey_taunt() timeOut = time.time() elif event.key == pygame.K_DOWN: lose = player_action(taunt, 2) if lose == True: continue taunt = monkey_taunt() timeOut = time.time() elif event.key == pygame.K_UP: lose = player_action(taunt, 2) if lose == True: continue taunt = monkey_taunt() timeOut = time.time() elif event.key == pygame.K_RIGHT: lose = player_action(taunt, 3) if lose == True: continue taunt = monkey_taunt() timeOut = time.time() elif event.key == pygame.K_SPACE and bonus == True: bonus = False score.Increase_Score(100) k = pygame.mixer.Channel(0) k.play(sounds['kick-hit']) pygame.event.clear() if time.time() - bonusTime > 0.83: bonus = False totalTime = time.time() if int(time.time()) - encourage == 8: if random.randrange(0, 5) < 2: play_random(sounds, "encourage") else: butthead_taunt(sounds) encourage = int(time.time()) pygame.event.pump() time.sleep(0.001) pygame.mixer.stop() time.sleep(0.1) pygame.event.clear() play_random(sounds, "lose", interrupt = True) message = ["You spanked the monkey " + str(spanks) + " "] if spanks == 1: message[0] += "time." if spanks != 1: message[0] += "times." if score.New_High_Score() != None: message.append("Congratulations! you beat the score at position " + str(score.New_High_Score()) + ".") message.append("Your total time was " + str(round(totalTime - startTime, 2)) + " seconds.") try: message.append("You averaged " + str(round(spanks / (totalTime - startTime), 2)) + " monkey spanks per second.") except: message.append("You averaged 0.00 monkey spanks per second.") message.append("You scored " + str(score.Get_Score()) + " points.") time.sleep(0.1) display_text(message) return "menu" # Game starts at main menu mode = game_menu(sounds, "start game", "instructions", "donate", "credits", "learn sounds", "exit_game") while mode != "exit_game": bonus = False bonusTime = time.time() score = scoreboard() spanks = 0 if mode == "menu": mode = game_menu(sounds, "start game", "instructions", "donate", "credits", "learn sounds", "exit_game") if mode == "start game": mode = game(mode) if mode == "learn sounds": mode = learn_sounds(sounds) time.sleep(0.001)