import sys

import pygame
from pygame import mouse, display, key
from pygame.locals import *

from GameChild import *
from Animation import *
from Audio import *
from Display import *
from Configuration import *
from EventDelegate import *
from Input import *
from ScreenGrabber import *
from Timer import *
from PauseScreen import *
from introduction.Introduction import *
from overworld.Overworld import *
from levels.LevelFactory import *
from ending.Ending import *
from scoreboard.HighScores import *
from scoreboard.GlyphPalette import *

class Game(GameChild, Animation):

    def __init__(self):
        GameChild.__init__(self)
        self.configuration = Configuration()
        Animation.__init__(self, self.configuration["display-frame-duration"])
        pygame.init()
        mouse.set_visible(False)
        self.add_children()
        self.subscribe_to_events()
        self.introduction.activate()
        self.clear_queue()
        self.delegate.enable()

    def add_children(self):
        self.delegate = EventDelegate(self)
        self.display = Display(self)
        self.input = Input(self)
        self.audio = Audio(self)
        self.screen_grabber = ScreenGrabber(self)
        self.timer = Timer(self)
        self.pause_screen = PauseScreen(self)
        self.introduction = Introduction(self)
        self.overworld = Overworld(self)
        self.level_factory = LevelFactory(self)
        self.glyph_palette = GlyphPalette(self)
        self.ending = Ending(self)
        self.high_scores = HighScores(self)

    def subscribe_to_events(self):
        self.subscribe_to(QUIT, self.end)
        self.subscribe_to(Input.command_event, self.end)

    def get_configuration(self):
        return self.configuration

    def get_input(self):
        return self.input

    def sequence(self):
        self.delegate.dispatch_events()
        self.introduction.update()
        self.overworld.update()
        self.level_factory.update()
        display.update()

    def end(self, evt):
        if evt.type == QUIT or evt.command == "quit":
            sys.exit()
        elif evt.command == "skip" and key.get_mods() & KMOD_LSHIFT:
            self.skip_to_ending()

    def skip_to_ending(self):
        self.timer.conceal()
        self.introduction.deactivate()
        self.ending.display()
from pygame import Color

from esp_hadouken.GameChild import *
from esp_hadouken.Font import *

class InputMessage(GameChild):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.render()
        self.set_rect()

    def render(self):
        config = self.get_configuration()
        size = config["ending-input-message-size"]
        text = config["ending-input-message"]
        color = Color(config["ending-input-message-color"])
        background = Color(config["ending-input-message-bg"])
        self.message = Font(self, size).render(text, True, color, background)

    def set_rect(self):
        relative = self.parent.get_rect()
        rect = self.message.get_rect()
        rect.centerx = relative.centerx
        rect.top = self.get_configuration()["ending-input-message-y"]
        self.rect = rect

    def activate(self):
        self.active = True

    def deactivate(self):
        self.active = False

    def update(self):
        if self.active:
            self.draw()

    def draw(self):
        self.parent.blit(self.message, self.rect)
from pygame import Surface, image

from esp_hadouken.GameChild import *
from esp_hadouken.Input import *
from esp_hadouken.Toy import *
from Score import *
from name_prompt.NamePrompt import *
from InputMessage import *
from esp_hadouken.scoreboard.Scoreboard import *

class Ending(GameChild, Surface):

    def __init__(self, game):
        GameChild.__init__(self, game)
        self.display_surface = self.get_screen()
        Surface.__init__(self, self.display_surface.get_size())
        self.add_children()
        self.subscribe_to_events()
        self.set_background()
        self.deactivate()

    def add_children(self):
        self.score = Score(self)
        self.name_prompt = NamePrompt(self)
        self.input_message = InputMessage(self)
        self.scoreboard = Scoreboard(self)

    def subscribe_to_events(self):
        self.subscribe_to(USEREVENT, self.display)
        self.subscribe_to(Input.command_event, self.run_command)

    def display(self, evt=None):
        if not evt or evt.name == "toy-collected":
            self.deactivate()
            self.activate()
            self.activate_initial_widgets()
            self.update()

    def activate(self):
        self.active = True
        self.start_music()

    def activate_initial_widgets(self):
        self.input_message.activate()
        self.name_prompt.activate()
        self.score.activate()

    def deactivate(self):
        self.active = False
        self.deactivate_initial_widgets()
        self.scoreboard.deactivate()

    def deactivate_initial_widgets(self):
        self.input_message.deactivate()
        self.name_prompt.deactivate()
        self.score.deactivate()

    def run_command(self, evt):
        if evt.command == "reset":
            self.deactivate()
        if self.active and evt.command == "advance":
            if self.name_prompt.active:
                self.deactivate_initial_widgets()
                self.update()
                self.get_high_scores().add(self.name_prompt.get_initials())
                self.scoreboard.activate()
            else:
                self.get_input().post_command("reset")

    def set_background(self):
        path = self.get_resource("ending-bg-path")
        background = image.load(path).convert()
        self.background = background

    def set_toy(self):
        toy = Toy(self)
        config = self.get_configuration()
        toy.resize(config["ending-toy-size"])
        toy.place(config["ending-toy-position"])
        toy.show()
        self.toy = toy

    def start_music(self):
        path = self.get_resource("ending-audio-path")
        self.get_audio().play_bgm(path)

    def update(self):
        self.clear()
        self.score.update()
        self.name_prompt.update()
        self.scoreboard.update()
        self.draw()

    def clear(self):
        self.blit(self.background, (0, 0))

    def draw(self):
        self.display_surface.blit(self, (0, 0))
35.172.233.2
35.172.233.2
35.172.233.2
 
January 28, 2014


E F F L U E N C E