Beispiel #1
0
class Asteroid():
    def __init__(self, stage, left, top, src, value):
        self.stage = stage
        image = assets.load_image(src)
        self.item = ItemImage(left, top, image)
        self.item.add_event_handler(ItemEvent.CLICK, self.handle_click)
        self.text = ItemText(left,
                             top,
                             stage.font,
                             0,
                             str(value),
                             width=self.item.get_width(),
                             height=self.item.get_height(),
                             h_align=2,
                             v_align=2)
        self.value = value

    def set_left(self, left):
        self.item.set_left(left)
        self.text.set_left(left)

    def set_top(self, top):
        self.item.set_top(top)
        self.text.set_top(top)

    def handle_click(self, item, args):
        self.stage.select(self)

    def exit(self):
        self.item.exit()
        self.item = None
        self.text.exit()
        self.text = None
Beispiel #2
0
 def __init__(self, stage, key, image, image_back):
     self.stage = stage
     self.key = key
     self.image = image
     self.image_back = image_back
     self.item = ItemImage(0, 0, image_back)
     self.item.add_event_handler(ItemEvent.CLICK, self.handle_click)
Beispiel #3
0
    def __init__(self, group, data):
        image = assets.load_image(data['src'])
        ItemImage.__init__(self, data.get('left', 0), data.get('top', 0),
                           image)
        self.image = image

        if 'rollover_src' in data:
            self.rollover_image = assets.load_image(data['rollover_src'])
            self.set_rollover_image(self.rollover_image)
        else:
            self.rollover_image = None

        if 'selected_src' in data:
            self.selected_image = assets.load_image(data['selected_src'])
        else:
            self.selected_image = None

        if 'value' in data:
            self.value = data['value']

        def handle_select(item, args):
            group.select(self)

        self.add_event_handler(ItemEvent.CLICK, handle_select)

        # Sounds
        if 'sound_click_handler' in data:
            self.add_event_handler(ItemEvent.CLICK,
                                   data['sound_click_handler'])

        if 'sound_mouse_enter_handler' in data:
            self.add_event_handler(ItemEvent.MOUSE_ENTER,
                                   data['sound_mouse_enter_handler'])
 def exit(self):
     ItemImage.exit(self)
     self.click_handler = None
     self.sound_click_handler = None
     self.sound_mouse_enter_handler = None
     self.presed_image = None
     self.rollover_image = None
     self.image = None
     self.disabled_image = None
Beispiel #5
0
 def __init__(self, stage, left, top, src, value):
     self.stage = stage
     image = assets.load_image(src)
     self.item = ItemImage(left, top, image)
     self.item.add_event_handler(ItemEvent.CLICK, self.handle_click)
     self.text = ItemText(left,
                          top,
                          stage.font,
                          0,
                          str(value),
                          width=self.item.get_width(),
                          height=self.item.get_height(),
                          h_align=2,
                          v_align=2)
     self.value = value
 def create_initial_dialog(self, data):
     data = DictClass(data)
     self.dialog_items = []
     self.dialog_animations = {}
     self.dialog_animation_items = []
     for (name, animation_data) in data["animations"].items():
         if "both" in animation_data:
             animation_data = animation_data["both"]
         else:
             animation_data = animation_data[
                 self.game.datastore.datamodel.character]
         self.dialog_animations[name] = animation = Animation(
             load_animation("", animation_data["animation"]))
         animation_item = ItemImage(animation_data["left"],
                                    animation_data["top"],
                                    animation.get_image())
         self.dialog_animation_items.append(animation_item)
         animation.item = animation_item
     for dialog_data in data["items"]:
         dialog = self.create_image(dialog_data["dialog"])[0]
         dialog.animation_name = dialog_data["animation"]
         self.dialog_items.append(dialog)
         self.dialog_animation_items.append(animation_item)
     self.dialog_mask = ItemMask(0, 0, (600, 450))
     self.dialog_mask.add_event_handler(ItemEvent.CLICK,
                                        lambda *args, **kwargs: None)
     self.dialog_mask.add_event_handler(ItemEvent.MOUSE_ENTER,
                                        lambda *args, **kwargs: None)
     self.current_dialog_frame = 0
     return self.dialog_items[:1] + [self.dialog_mask
                                     ] + self.dialog_animation_items
    def initialize(self):
        """
        Initialize the stage.

        Its preferred to add initialization code in the function instead of
        the constructor, because this function is invoked before show stage
        for first time and after release the memory of the previous stage.
        """
        self.set_closed_handler(self.exit)
        self.__mouser_cursor_item = ItemImage(0, 0, assets.load_image('cursor.png'))
        self.__mouse_pointer = (6, 0)
        self.reset_mouse_cursor()        
        
        stream = file('data/fonts.yaml', 'r')
        fonts = load(stream)
        self.named_items = {}
        self.named_fonts = {}
        
        for font in fonts:
            loaded_font = assets.load_font(fonts[font]['file_name'], fonts[font]['size'])
            setattr(self, font, loaded_font)
            self.named_fonts[font] = loaded_font
        
        # Load the sound
        self.click_sound = assets.load_sound('DGI_Click.ogg')
        self.mouse_enter_sound = assets.load_sound('DGI_Roll_Over.ogg')
        self.turn_page_sound = assets.load_sound('DGI_page_turn.ogg')
        
        self.data_sounds = {
                            'sound_click_handler': getattr(self, 'handle_sound_click'),
                            'sound_mouse_enter_handler': getattr(self, 'handle_sound_mouse_enter')
                            }
Beispiel #8
0
    def __init__(self,
                 left=0,
                 top=0,
                 base=None,
                 standing=None,
                 walking=None,
                 jumping=None):
        self.first_jumping = True
        self.first_walking = True

        # Load the sound
        self.footsteps_concrete_sound = assets.load_sound(
            'DGI_footsteps_concrete.ogg')
        self.jump_sound = assets.load_sound('DGI_jump.ogg')

        self.standing_still = assets.load_image(base + standing.src)
        if "wait" in standing:
            self.standing_wait = Animation(
                self.load_animation(base, [
                    DictClass({
                        'src': standing.src,
                        'duration': standing.duration
                    })
                ] + standing.wait))
        if jumping:
            self.jumping = assets.load_image(base + jumping.src)
        if walking:
            if "sideways" in walking:
                sideways = self.load_animation(base, walking.sideways)
                self.walking_sideways_left = Animation(sideways)
                self.walking_sideways_right = Animation([
                    self.Frame(frame.image.flip_h_copy(), frame.to)
                    for frame in sideways
                ])
            if "front" in walking:
                self.walking_front = Animation(
                    self.load_animation(base, walking.front))
            if "back" in walking:
                self.walking_back = Animation(
                    self.load_animation(base, walking.back))
        self.item = ItemImage(left, top, self.standing_still)
    def __init__(self, data):
        image = assets.load_image(data['src'])
        ItemImage.__init__(self, data.get('left', 0), data.get('top', 0),
                           image)
        self.image = image

        if 'rollover_src' in data:
            self.rollover_image = assets.load_image(data['rollover_src'])
        else:
            self.rollover_image = None

        if 'pressed_src' in data:
            self.pressed_image = assets.load_image(data['pressed_src'])
        else:
            self.pressed_image = None

        if 'click_handler' in data:
            self.click_handler = data['click_handler']
        else:
            self.click_handler = None

        # Sounds
        if 'sound_click_handler' in data:
            self.sound_click_handler = data['sound_click_handler']
        else:
            self.sound_click_handler = None

        if 'sound_mouse_enter_handler' in data:
            self.sound_mouse_enter_handler = data['sound_mouse_enter_handler']
        else:
            self.sound_mouse_enter_handler = None

        if 'disabled_src' in data:
            self.disabled_image = assets.load_image(data['disabled_src'])
            self.on = True
            self.turn_off()
        else:
            self.disabled_image = None
            self.on = False
            self.turn_on()
 def __init__(self, left, top, min, max, velocity, good, src, points,
              collision):
     self.left = left
     self.top = top
     self.min = min
     self.max = max
     self.velocity = velocity
     self.good = good
     image = assets.load_image(src)
     self.item = ItemImage(0, 0, image)
     self.points = points
     self.collision = collision
     if max:
         self.delta = random.choice([-1, 1])
         self.delta = random.choice([-1.5, -1, 1, 1.5])
     else:
         self.delta = 0
     if DEBUG:
         self.debug_item = ItemRect(self.get_left(),
                                    self.get_top(),
                                    self.get_width(),
                                    self.get_height(),
                                    border=(255, 255, 255))
 def create_image(self, data):
     if 'image' in data:
         image = data['image']
     else:
         image = assets.load_image(data['src'])
     item = ItemImage(data.get('left', 0), data.get('top', 0), image, hit_over_transparent = data.get("hit_over_transparent", False))
     if 'rollover_src' in data:
         item.rollover_image = assets.load_image(data['rollover_src'])
         item.set_rollover_image(item.rollover_image)
     else:
         item.rollover_image = None 
     return [item]
Beispiel #12
0
class Card():
    def __init__(self, stage, key, image, image_back):
        self.stage = stage
        self.key = key
        self.image = image
        self.image_back = image_back
        self.item = ItemImage(0, 0, image_back)
        self.item.add_event_handler(ItemEvent.CLICK, self.handle_click)

    def handle_click(self, item, args):
        self.stage.select(self)

    def select(self):
        self.item.set_image(self.image)

    def unselect(self):
        self.item.set_image(self.image_back)

    def exit(self):
        self.stage = None
        self.image = None
        self.image_back = None
        self.item.exit()
        self.item = None
    def __init__(self, stage):
        global DEFAULT_NAME, DEFAULT_ROOM

        self.go_to_last = False
        self.dialog = None
        self.paginator = None
        self.background = Layer()
        self.foreground = Layer()
        self.focus_group = FocusGroup()
        self.stage = stage
        self.current_callback = None
        self.current_id = None
        data = self.data = DictClass(load(file('data/common/activity.yaml')))
        self.clock_image = ItemImage(0, 0, assets.load_image(data.clock.src))
        layers = self.layers = DictClass()
        for k, i in data.layers.items():
            layers[k] = self.create_items(i)
        self.layers.main.name_input.set_focus_group(self.focus_group)
        self.layers.main.name_input.set_on_enter(self.handle_next)
        self.layers.main.name_input.set_text(DEFAULT_NAME)
        self.layers.main.room_input.set_focus_group(self.focus_group)
        self.layers.main.room_input.set_on_enter(self.handle_next)
        self.layers.main.room_input.set_text(DEFAULT_ROOM)
        self.current_layers = [layers.main.layer]
        text_box = self.layers.post.text_box = self.create_text_box(
            data.text_box)
        self.layers.post.layer.add(text_box)

        for item in self.stage.create_items_from_yaml(data["background"],
                                                      self):
            self.background.add(item)
        for item in self.stage.create_items_from_yaml(data["foreground"],
                                                      self):
            self.foreground.add(item)

        self.stage.start_timer('msgclock', 15000, self.update_messages_tick)
class Invader():
    def __init__(self, left, top, min, max, velocity, good, src, points,
                 collision):
        self.left = left
        self.top = top
        self.min = min
        self.max = max
        self.velocity = velocity
        self.good = good
        image = assets.load_image(src)
        self.item = ItemImage(0, 0, image)
        self.points = points
        self.collision = collision
        if max:
            self.delta = random.choice([-1, 1])
            self.delta = random.choice([-1.5, -1, 1, 1.5])
        else:
            self.delta = 0
        if DEBUG:
            self.debug_item = ItemRect(self.get_left(),
                                       self.get_top(),
                                       self.get_width(),
                                       self.get_height(),
                                       border=(255, 255, 255))

    def set_left(self, left):
        self.min -= left / 2
        self.max += left / 2
        self.item.set_left(left)
        if DEBUG:
            self.debug_item.set_left(left + self.collision.left)

    def exit(self):
        self.item.exit()
        self.item = None
        self.collision = None

    def get_left(self):
        return self.item.get_left() + self.collision.left

    def get_top(self):
        return self.item.get_top() + self.collision.top

    def get_width(self):
        return self.item.get_width(
        ) - self.collision.left - self.collision.right

    def get_height(self):
        return self.item.get_height(
        ) - self.collision.top - self.collision.bottom

    def move(self, time, velocity):
        if self.delta:
            left = self.item.get_left()
            if left + self.delta > self.max or left + self.delta + self.item.get_width(
            ) > SCREEN_WIDTH:
                self.delta = -1
                self.delta = random.choice([-1.5, -1])
            elif left + self.delta < self.min or left + self.delta < 0:
                self.delta = 1
                self.delta = random.choice([1, 1.5])
            left += self.delta * time * velocity * self.velocity
            self.item.set_left(left)
            if DEBUG:
                self.debug_item.set_left(left + self.collision.left)
        top = self.item.get_top() + time * velocity * self.velocity
        self.item.set_top(top)
        if DEBUG:
            self.debug_item.set_top(top + self.collision.top)
Beispiel #15
0
class Character():
    class Frame():
        def __init__(self, image, to):
            self.image = image
            self.to = to

        def exit(self):
            self.image = None

    def load_animation(self, base, animation):
        total_time = 0
        frames = []
        for frame in animation:
            total_time += frame.duration * 1000
            frames.append(
                self.Frame(assets.load_image(base + frame.src), total_time))
        return frames

    def __init__(self,
                 left=0,
                 top=0,
                 base=None,
                 standing=None,
                 walking=None,
                 jumping=None):
        self.first_jumping = True
        self.first_walking = True

        # Load the sound
        self.footsteps_concrete_sound = assets.load_sound(
            'DGI_footsteps_concrete.ogg')
        self.jump_sound = assets.load_sound('DGI_jump.ogg')

        self.standing_still = assets.load_image(base + standing.src)
        if "wait" in standing:
            self.standing_wait = Animation(
                self.load_animation(base, [
                    DictClass({
                        'src': standing.src,
                        'duration': standing.duration
                    })
                ] + standing.wait))
        if jumping:
            self.jumping = assets.load_image(base + jumping.src)
        if walking:
            if "sideways" in walking:
                sideways = self.load_animation(base, walking.sideways)
                self.walking_sideways_left = Animation(sideways)
                self.walking_sideways_right = Animation([
                    self.Frame(frame.image.flip_h_copy(), frame.to)
                    for frame in sideways
                ])
            if "front" in walking:
                self.walking_front = Animation(
                    self.load_animation(base, walking.front))
            if "back" in walking:
                self.walking_back = Animation(
                    self.load_animation(base, walking.back))
        self.item = ItemImage(left, top, self.standing_still)

    def exit(self):
        self.item.exit()
        self.standing_wait.exit()
        self.juming = None
        self.jump_sound = None
        self.footsteps_concrete_sound = None
        self.walking_sideways_left.exit()
        self.walking_sideways_left = None
        self.walking_sideways_right.exit()
        self.walking_sideways_right = None
        self.walking_front.exit()
        self.walking_front = None
        self.walking_back.exit()
        self.walking_back = None

    def update(self, delta_time, delta_left=0, delta_top=0, jumping=False):
        if delta_left == 0 and delta_top == 0:
            self.first_jumping = True
            self.first_walking = True

            self.footsteps_concrete_sound.stop()
            self.standing_wait.update(delta_time)
            self.item.set_image(self.standing_wait.get_image())
        else:
            self.standing_wait.reset()
            if jumping:
                self.first_walking = True
                if self.first_jumping:
                    self.footsteps_concrete_sound.stop()
                    self.jump_sound.play()
                    self.first_jumping = False
                self.item.set_image(self.jumping)
            else:
                self.first_jumping = True
                if self.first_walking:
                    self.footsteps_concrete_sound.play(-1)
                    self.first_walking = False
                if delta_left < 0:
                    self.walking_sideways_right.update(delta_time)
                    self.item.set_image(
                        self.walking_sideways_right.get_image())
                    return
                if delta_left > 0:
                    self.walking_sideways_left.update(delta_time)
                    self.item.set_image(self.walking_sideways_left.get_image())
                    return
                if delta_top < 0:
                    self.walking_back.update(delta_time)
                    self.item.set_image(self.walking_back.get_image())
                    return
                self.walking_front.update(delta_time)
                self.item.set_image(self.walking_front.get_image())
Beispiel #16
0
    def initialize(self):
        GameStage.initialize(self)
        stream = file('data/fonts.yaml', 'r')
        fonts = load(stream)
        for font in fonts:
            setattr(
                self, font,
                assets.load_font(fonts[font]['file_name'],
                                 fonts[font]['size']))

        self.data = DictClass(load(file('data/memory.yaml')))

        self.game_over_layer = Layer()
        image = assets.load_image(
            self.data.game_over[self.game.datastore.datamodel.character].src)
        item = ItemImage(self.data.game_over.left, self.data.game_over.top,
                         image)
        self.game_over_layer.add(item)

        self.main_layer = Layer()
        self.top_layer = Layer()

        self.time = self.data.time.max
        self.timer = DictClass({})
        image = assets.load_image(self.data.time.src)
        self.timer['skin'] = ItemImage(self.data.time.left, self.data.time.top,
                                       image)
        self.timer['value'] = ItemText(self.data.time.left,
                                       self.data.time.top,
                                       self.font,
                                       0,
                                       format_time(self.time),
                                       width=image.get_width(),
                                       height=image.get_height(),
                                       h_align=2,
                                       v_align=2)
        self.top_layer.add(self.timer.skin)
        self.top_layer.add(self.timer.value)

        self.score = 0
        self.score_board = DictClass({})
        image = assets.load_image(self.data.score.src)
        self.score_board['skin'] = ItemImage(self.data.score.left,
                                             self.data.score.top, image)
        self.score_board['value'] = ItemText(self.data.score.left,
                                             self.data.score.top,
                                             self.font,
                                             0,
                                             str(self.score),
                                             width=image.get_width(),
                                             height=image.get_height(),
                                             h_align=2,
                                             v_align=2)
        self.top_layer.add(self.score_board.skin)
        self.top_layer.add(self.score_board.value)

        self.deck = []
        image_back = assets.load_image(self.data.board.card_back)
        for k in range(0, len(self.data.board.cards)):
            image = assets.load_image(self.data.board.cards[k])
            self.deck.append([
                Card(self, k, image, image_back),
                Card(self, k, image, image_back)
            ])

        self.range = self.data.start
        self.cards = []
        self.deal()

        # Load the sound
        self.card_flip_sound = assets.load_sound('DGI_card_flip.ogg')
        self.item_found_sound = assets.load_sound('DGI_item_found.ogg')
        self.wrong_sound = assets.load_sound('DGI_wrong.ogg')
        self.lose_bell_sound = assets.load_sound('DGI_lose_bell.ogg')
        self.lose_music_sound = assets.load_sound('DGI_lose_music.ogg')
Beispiel #17
0
    def initialize(self):
        GameStage.initialize(self)
        stream = file('data/fonts.yaml', 'r')
        fonts = load(stream)
        for font in fonts:
            setattr(
                self, font,
                assets.load_font(fonts[font]['file_name'],
                                 fonts[font]['size']))

        self.data = DictClass(load(file('data/asteroids.yaml')))

        self.game_over_layer = Layer()
        image = assets.load_image(
            self.data.game_over[self.game.datastore.datamodel.character].src)
        item = ItemImage(self.data.game_over.left, self.data.game_over.top,
                         image)
        self.game_over_layer.add(item)

        self.main_layer = Layer()
        self.top_layer = Layer()

        self.time = self.data.time.max
        self.timer = DictClass({})
        image = assets.load_image(self.data.time.src)
        self.timer['skin'] = ItemImage(self.data.time.left, self.data.time.top,
                                       image)
        self.timer['value'] = ItemText(self.data.time.left,
                                       self.data.time.top,
                                       self.font,
                                       0,
                                       format_time(self.time),
                                       width=image.get_width(),
                                       height=image.get_height(),
                                       h_align=2,
                                       v_align=2)
        self.top_layer.add(self.timer.skin)
        self.top_layer.add(self.timer.value)

        self.score = 0
        self.score_board = DictClass({})
        image = assets.load_image(self.data.score.src)
        self.score_board['skin'] = ItemImage(self.data.score.left,
                                             self.data.score.top, image)
        self.score_board['value'] = ItemText(self.data.score.left,
                                             self.data.score.top,
                                             self.font,
                                             0,
                                             str(self.score),
                                             width=image.get_width(),
                                             height=image.get_height(),
                                             h_align=2,
                                             v_align=2)
        self.top_layer.add(self.score_board.skin)
        self.top_layer.add(self.score_board.value)

        self.level = self.data.start
        self.asteroids = []

        self.max_width = 0
        self.max_height = 0
        for a in self.data.asteroids:
            item = assets.load_image(a)
            if self.max_width < item.get_width():
                self.max_width = item.get_width()
            if self.max_height < item.get_height():
                self.max_height = item.get_height()
        self.max_col = int(SCREEN_WIDTH / self.max_width)
        self.max_row = int(SCREEN_HEIGHT / self.max_height)
        self.margin_left = (SCREEN_WIDTH % self.max_width) / 2
        self.margin_top = (SCREEN_HEIGHT % self.max_height) / 2

        # Load the sound
        self.click_sound = assets.load_sound('DGI_Click.ogg')
        self.item_found_sound = assets.load_sound('DGI_item_found.ogg')
        self.wrong_sound = assets.load_sound('DGI_wrong.ogg')
        self.lose_bell_sound = assets.load_sound('DGI_lose_bell.ogg')
        self.lose_music_sound = assets.load_sound('DGI_lose_music.ogg')
    def initialize(self):
        GameStage.initialize(self)
        stream = file('data/fonts.yaml', 'r')

        fonts = load(stream)
        for font in fonts:
            setattr(
                self, font,
                assets.load_font(fonts[font]['file_name'],
                                 fonts[font]['size']))

        self.data = DictClass(load(file('data/invaders.yaml')))

        self.good = self.data.start.good
        self.velocity = self.data.start.velocity
        self.interval = self.data.start.interval

        self.game_over_layer = Layer()
        image = assets.load_image(
            self.data.bad[self.game.datastore.datamodel.character].src)
        item = ItemImage(self.data.bad.left, self.data.bad.top, image)
        self.game_over_layer.add(item)
        image = assets.load_image(
            self.data.game_over[self.game.datastore.datamodel.character].src)
        item = ItemImage(self.data.game_over.left, self.data.game_over.top,
                         image)
        self.game_over_layer.add(item)

        image = assets.load_image(
            self.data.good[self.game.datastore.datamodel.character].src)
        self.good_indicator = ItemImage(self.data.good.left,
                                        self.data.good.top, image)

        self.text_indicators = []

        self.main_layer = Layer()
        self.top_layer = Layer()

        self.score = 0
        self.score_board = DictClass({})
        image = assets.load_image(self.data.score.src)
        self.score_board['skin'] = ItemImage(self.data.score.left,
                                             self.data.score.top, image)
        self.score_board['value'] = ItemText(self.data.score.left,
                                             self.data.score.top,
                                             self.font,
                                             0,
                                             str(self.score),
                                             width=image.get_width(),
                                             height=image.get_height(),
                                             h_align=2,
                                             v_align=2)
        self.top_layer.add(self.score_board.skin)
        self.top_layer.add(self.score_board.value)

        data = DictClass(load(file('data/map/common.yaml')))
        params = data.character[self.game.datastore.datamodel.character]
        params['base'] = data.character.base[
            self.game.datastore.datamodel.character].big
        self.character_animation = Character(**params)
        self.character = self.character_animation.item
        self.character.set_left(
            (SCREEN_WIDTH - self.character.get_width()) / 2)
        self.character.set_top(SCREEN_HEIGHT - self.character.get_height())
        left = self.character.get_left() + self.data.collision.left
        top = self.character.get_top() + self.data.collision.top
        width = self.character.get_width(
        ) - self.data.collision.left - self.data.collision.right
        height = self.character.get_height(
        ) - self.data.collision.top - self.data.collision.bottom
        if DEBUG:
            self.debug_character = ItemRect(left,
                                            top,
                                            width,
                                            height,
                                            border=(255, 255, 255))
        self.invaders = []

        # Load the sound
        self.item_found_sound = assets.load_sound('DGI_item_found.ogg')
        self.lose_hit_sound = assets.load_sound('DGI_lose_hit.ogg')
        self.lose_music_sound = assets.load_sound('DGI_lose_music.ogg')
Beispiel #19
0
 def exit(self):
     ItemImage.exit(self)
     self.selected_image = None
     self.rollover_image = None
     self.group = None
     self.rollover_image = None
class InvadersMinigame(GameStage):
    MOVE_INTERVAL = 30
    GOOD_INDICATOR_INTERVAL = 1000
    DIFFICULTY_INTERVAL = 10000
    GO_BACK_TIME = 3000

    def __init__(self, game):
        GameStage.__init__(self, game, Color('#333333'))

    def initialize(self):
        GameStage.initialize(self)
        stream = file('data/fonts.yaml', 'r')

        fonts = load(stream)
        for font in fonts:
            setattr(
                self, font,
                assets.load_font(fonts[font]['file_name'],
                                 fonts[font]['size']))

        self.data = DictClass(load(file('data/invaders.yaml')))

        self.good = self.data.start.good
        self.velocity = self.data.start.velocity
        self.interval = self.data.start.interval

        self.game_over_layer = Layer()
        image = assets.load_image(
            self.data.bad[self.game.datastore.datamodel.character].src)
        item = ItemImage(self.data.bad.left, self.data.bad.top, image)
        self.game_over_layer.add(item)
        image = assets.load_image(
            self.data.game_over[self.game.datastore.datamodel.character].src)
        item = ItemImage(self.data.game_over.left, self.data.game_over.top,
                         image)
        self.game_over_layer.add(item)

        image = assets.load_image(
            self.data.good[self.game.datastore.datamodel.character].src)
        self.good_indicator = ItemImage(self.data.good.left,
                                        self.data.good.top, image)

        self.text_indicators = []

        self.main_layer = Layer()
        self.top_layer = Layer()

        self.score = 0
        self.score_board = DictClass({})
        image = assets.load_image(self.data.score.src)
        self.score_board['skin'] = ItemImage(self.data.score.left,
                                             self.data.score.top, image)
        self.score_board['value'] = ItemText(self.data.score.left,
                                             self.data.score.top,
                                             self.font,
                                             0,
                                             str(self.score),
                                             width=image.get_width(),
                                             height=image.get_height(),
                                             h_align=2,
                                             v_align=2)
        self.top_layer.add(self.score_board.skin)
        self.top_layer.add(self.score_board.value)

        data = DictClass(load(file('data/map/common.yaml')))
        params = data.character[self.game.datastore.datamodel.character]
        params['base'] = data.character.base[
            self.game.datastore.datamodel.character].big
        self.character_animation = Character(**params)
        self.character = self.character_animation.item
        self.character.set_left(
            (SCREEN_WIDTH - self.character.get_width()) / 2)
        self.character.set_top(SCREEN_HEIGHT - self.character.get_height())
        left = self.character.get_left() + self.data.collision.left
        top = self.character.get_top() + self.data.collision.top
        width = self.character.get_width(
        ) - self.data.collision.left - self.data.collision.right
        height = self.character.get_height(
        ) - self.data.collision.top - self.data.collision.bottom
        if DEBUG:
            self.debug_character = ItemRect(left,
                                            top,
                                            width,
                                            height,
                                            border=(255, 255, 255))
        self.invaders = []

        # Load the sound
        self.item_found_sound = assets.load_sound('DGI_item_found.ogg')
        self.lose_hit_sound = assets.load_sound('DGI_lose_hit.ogg')
        self.lose_music_sound = assets.load_sound('DGI_lose_music.ogg')

    def increase_difficulty(self, key, data):
        if self.good + self.data.step.good >= self.data.min.good:
            self.good += self.data.step.good
        if self.velocity + self.data.step.velocity <= self.data.max.velocity:
            self.velocity += self.data.step.velocity
        if self.interval + self.data.step.interval >= self.data.min.interval:
            self.interval += self.data.step.interval
            self.stop_timer(1)
            self.start_timer(1, self.interval, self.create_invader)

    def create_invader(self, key, data):
        lst = [(True, self.good), (False, 1 - self.good)]
        good = w_choice(lst)
        if good:
            index = random.randint(0, len(self.data.invaders.good) - 1)
            invader = self.data.invaders.good[index]
        else:
            index = random.randint(0, len(self.data.invaders.bad) - 1)
            invader = self.data.invaders.bad[index]
        src = invader.src
        points = invader.points
        collision = invader.collision
        min = invader.min
        max = invader.max
        velocity = invader.velocity
        invader = Invader(0, 0, min, max, velocity, good, src, points,
                          collision)
        left = random.randint(
            0, SCREEN_WIDTH - invader.item.get_image().get_width())
        invader.set_left(left)
        top = -invader.item.get_image().get_height()
        invader.item.set_top(top)
        self.invaders.append(invader)

        self.main_layer.add(invader.item)
        if DEBUG:
            self.main_layer.add(invader.debug_item)

    def move_invaders(self, key, data):
        for item in self.text_indicators:
            item.set_top(item.get_top() - 2)

        for invader in self.invaders:
            invader.move(self.MOVE_INTERVAL, self.velocity)
            if (invader.item.get_top() > SCREEN_HEIGHT):
                self.remove_invader(invader)
            else:
                left = self.character.get_left() + self.data.collision.left
                top = self.character.get_top() + self.data.collision.top
                width = self.character.get_width(
                ) - self.data.collision.left - self.data.collision.right
                height = self.character.get_height(
                ) - self.data.collision.top - self.data.collision.bottom
                character = Rect(left, top, width, height)
                item = Rect(invader.get_left(), invader.get_top(),
                            invader.get_width(), invader.get_height())
                k = character.collidelist([item])
                if k != -1:
                    if invader.good:
                        self.character_animation.footsteps_concrete_sound.stop(
                        )
                        self.item_found_sound.play()
                        self.character_animation.first_walking = True

                        self.score += invader.points
                        self.score_board.value.set_text(str(self.score))
                        self.top_layer.add(self.good_indicator)
                        item = ItemText(invader.get_left(),
                                        invader.get_top(),
                                        self.font,
                                        0,
                                        "+" + str(invader.points),
                                        h_align=2,
                                        v_align=2)
                        self.text_indicators.append(item)
                        self.top_layer.add(item)
                        fade_out_item(item, True, self.GOOD_INDICATOR_INTERVAL)
                        self.start_timer(3, self.GOOD_INDICATOR_INTERVAL,
                                         self.remove_good_indicator)
                    else:
                        self.stop_timer(1)
                        self.stop_timer(2)
                        self.game_over()
                        return
                    self.remove_invader(invader)

    def remove_invader(self, invader):
        self.invaders.remove(invader)
        self.main_layer.remove(invader.item)
        invader.exit()
        if DEBUG:
            self.main_layer.remove(invader.debug_item)

    def remove_good_indicator(self, key, data):
        self.stop_timer(3)
        self.top_layer.remove(self.good_indicator)

    def prepare(self):
        self.show_board()
        self.key = None
        dialog = Intro(self, self.data.intro, self.start_game)
        dialog.start()

    def start_game(self):
        self.start_timer(1, self.interval, self.create_invader)
        self.start_timer(2, self.MOVE_INTERVAL, self.move_invaders)
        self.start_timer(4, self.DIFFICULTY_INTERVAL, self.increase_difficulty)
        self.start_timer(0, 30, self.manage_key)

    def show_board(self):
        self.main_layer.add(self.character)
        if DEBUG:
            self.main_layer.add(self.debug_character)
        self.add_layer(self.main_layer)
        self.add_layer(self.top_layer)

    def handle_event(self, e):
        if e.type == KEYDOWN:
            self.key = e.key
        if e.type == KEYUP:
            self.key = None

    def manage_key(self, key, data):
        delta = 0
        if self.key == K_LEFT:
            delta = -8
        if self.key == K_RIGHT:
            delta = 8
        left = self.character.get_left() + delta
        if 0 <= left and left <= SCREEN_WIDTH - self.character.get_width():
            self.character.set_left(left)
            if DEBUG:
                self.debug_character.set_left(left + self.data.collision.left)
            self.character_animation.update(self.MOVE_INTERVAL,
                                            delta_left=delta)

    def game_over(self):
        self.good_indicator.set_visible(False)
        self.character_animation.footsteps_concrete_sound.stop()
        self.lose_hit_sound.play()
        self.lose_music_sound.play()

        self.stop_timer(0)
        self.stop_timer(1)
        self.stop_timer(2)
        self.stop_timer(3)
        self.stop_timer(4)
        self.top_layer.remove(self.good_indicator)
        self.add_layer(self.game_over_layer)
        self.start_timer("go_back_timer", self.GO_BACK_TIME, self.go_back)

    def exit(self, other_stage):
        GameStage.exit(self, other_stage)
        self.good_indicator.exit()
        self.good_indicator = None
        self.character_animation.exit()
        self.character_animation = None
        for invader in self.invaders:
            invader.exit()
        self.invaders = None

    def go_back(self, *args, **kwargs):
        from game.stages.map import Map
        self.game.set_stage(Map(self.game))