diff --git a/NS.py b/NS.py index b7702eb..f3b1ac6 100644 --- a/NS.py +++ b/NS.py @@ -64,6 +64,7 @@ class NS(Game, Animation): self.introduction = Introduction(self) self.wipe = Wipe(self) self.platform = Platform(self) + self.dialogue = Dialogue(self) self.chemtrails = Chemtrails(self) self.boss = Boss(self) self.last_press = get_ticks() @@ -80,6 +81,14 @@ class NS(Game, Animation): self.boss.reset() self.chemtrails.reset() self.platform.reset() + self.dialogue.reset() + + def suppress_input(self): + self.suppressing_input = True + self.platform.unpress() + + def unsuppress_input(self): + self.suppressing_input = False def respond(self, event): if not self.suppressing_input and event.type in (KEYDOWN, KEYUP): @@ -219,14 +228,42 @@ class Title(GameChild): self.text.update() -class Introduction(Animation): +class Dialogue(Animation): + + BACKGROUND = 255, 255, 255 + BORDER = 0, 0, 0 + TEXT_COLOR = 0, 0, 0 + FONT_PATH = "rounded-mplus-1m-bold.ttf" + FONT_SIZE = 18 def __init__(self, parent): - Animation.__init__(self, parent) - self.tony = load(self.get_resource("Big_Tony.png")) + Animation.__init__(self, parent, interval=70) + ds = self.get_display_surface() + dsr = ds.get_rect() + frame = Surface((640, 72)) + frame.fill(self.BORDER) + frame.fill(self.BACKGROUND, (1, 1, frame.get_width() - 2, frame.get_height() - 2)) + self.text_box = Sprite(self) + self.text_box.add_frame(frame) + self.text_box.location.bottomleft = dsr.bottomleft + frame = Surface((66, 66)) + frame.fill(self.BORDER) + frame.fill(self.BACKGROUND, (1, 1, frame.get_width() - 2, frame.get_height() - 2)) + self.avatar_box = Sprite(self) + self.avatar_box.add_frame(frame) + self.avatar_box.location.bottomleft = self.text_box.location.topleft + frame = Surface((128, 24)) + frame.fill(self.BORDER) + frame.fill(self.BACKGROUND, (1, 1, frame.get_width() - 2, frame.get_height() - 2)) + self.name_box = Sprite(self) + self.name_box.add_frame(frame) + self.name_box.location.bottomleft = self.avatar_box.location.bottomright def reset(self): + self.halt() self.deactivate() + self.first_pressed = False + self.first_press_elapsed = 0 def deactivate(self): self.active = False @@ -234,10 +271,130 @@ class Introduction(Animation): def activate(self): self.active = True + def set_avatar(self, image): + self.avatar = Sprite(self) + self.avatar.add_frame(image) + self.avatar.location.center = self.avatar_box.location.center + + def set_name(self, text): + font = Font(self.get_resource(self.FONT_PATH), self.FONT_SIZE) + self.name = Sprite(self) + self.name.add_frame(font.render(text, True, self.TEXT_COLOR)) + self.name.location.midleft = self.name_box.location.left + 5, self.name_box.location.centery + + def show_text(self, text): + self.full_text = text + self.text_index = 0 + self.play() + + def build_frame(self): + self.text_index += 1 + if self.text_index == len(self.full_text): + self.halt() + + def show_all(self): + self.text_index = len(self.full_text) + self.halt() + def update(self): if self.active: Animation.update(self) + self.avatar_box.update() + self.avatar.update() + self.name_box.update() + self.name.update() + self.text_box.update() + font = Font(self.get_resource(self.FONT_PATH), self.FONT_SIZE) + message = Sprite(self) + lines = self.full_text[:self.text_index].split("\n") + frame = Surface((self.text_box.location.w - 10, 30 * len(lines)), SRCALPHA) + for ii, line in enumerate(lines): + surface = font.render(line, True, self.TEXT_COLOR) + frame.blit(surface, (0, 30 * ii)) + message.add_frame(frame) + message.location.topleft = self.text_box.location.left + 9, self.text_box.location.top + 8 + message.update() + + +class Introduction(Animation): + + TEXT = "Hey, you lizard slime bag. It's me Giant Tony. " + \ + "Do you think you\ncan skate like me? Prove it!", \ + "I'll even give you my board for this adventure. And ink my name\n" + \ + "on it. Now the power of Giant Tony pulses through you." + + def __init__(self, parent): + Animation.__init__(self, parent) + self.tony = load(self.get_resource("Big_Tony.png")).convert() + self.skateboard = Sprite(self) + self.skateboard.load_from_path(self.get_resource("Introduction_skateboard.png"), True) + self.skateboard.hide() + self.slime_bag = Sprite(self) + self.slime_bag.load_from_path(self.get_resource("Introduction_slime_bag.png"), True) + self.slime_bag.location.center = self.get_display_surface().get_rect().center + self.tony_avatar = load(self.get_resource("Introduction_tony_avatar.png")).convert() + self.advance_prompt = Sprite(self) + self.advance_prompt.load_from_path(self.get_resource("Dialogue_buttons_full.png"), True, + False, (255, 255, 255)) + self.advance_prompt.load_from_path(self.get_resource("Dialogue_buttons_half.png"), True, + False, (255, 255, 255)) + self.advance_prompt.add_frameset([0], name="full", switch=True) + self.advance_prompt.add_frameset([1], name="half") + dsr = self.get_display_surface().get_rect() + self.advance_prompt.location.bottomright = dsr.right - 3, dsr.bottom - 3 + self.register(self.start) + + def reset(self): + self.deactivate() + self.cancel_first_press() + + def deactivate(self): + self.active = False + + def activate(self): + self.active = True + self.play(self.start, delay=3000, play_once=True) + + def start(self): + self.cancel_first_press() + dialogue = self.get_game().dialogue + dialogue.activate() + dialogue.set_avatar(self.tony_avatar) + dialogue.set_name("???") + dialogue.show_text(self.TEXT[0]) + self.text_index = 0 + + def cancel_first_press(self): + self.first_pressed = False + self.first_pressed_elapsed = 0 + self.advance_prompt.set_frameset("full") + + def update(self): + if self.active: + Animation.update(self) + dialogue = self.get_game().dialogue + if not self.first_pressed and self.get_game().platform.get_edge_pressed() == NS.N: + self.first_pressed = True + self.advance_prompt.set_frameset("half") + elif self.first_pressed and self.get_game().platform.get_edge_pressed() == NS.NW: + if dialogue.is_playing(): + dialogue.show_all() + else: + self.text_index += 1 + if self.text_index == 1: + dialogue.set_name("Tony") + dialogue.show_text(self.TEXT[self.text_index]) + self.get_game().platform.unpress() + self.cancel_first_press() + elif self.first_pressed: + self.first_pressed_elapsed += self.get_game().time_filter.get_last_frame_duration() + if self.first_pressed_elapsed > 4000: + self.cancel_first_press() self.get_display_surface().blit(self.tony, (0, 0)) + self.slime_bag.update() + self.get_game().dialogue.update() + if not self.is_playing(self.start) and not dialogue.is_playing(): + self.advance_prompt.update() class Wipe(Animation): @@ -264,7 +421,7 @@ class Wipe(Animation): def start(self, callback): self.activate() self.up = True - self.get_game().suppressing_input = True + self.get_game().suppress_input() self.blind_height = self.get_display_surface().get_height() / self.BLIND_COUNT self.callback = callback self.play() @@ -280,7 +437,7 @@ class Wipe(Animation): if self.blind_height >= self.get_display_surface().get_height() / self.BLIND_COUNT: self.halt() self.deactivate() - self.get_game().suppressing_input = False + self.get_game().unsuppress_input() def update(self): if self.active: @@ -319,6 +476,10 @@ class Platform(GameChild): def activate(self): self.active = True + def unpress(self): + for light in self.lights: + light.pressed = False + def get_pressed(self): return [light.position for light in self.lights if light.pressed] diff --git a/resource/Dialogue_buttons_full.png b/resource/Dialogue_buttons_full.png new file mode 100644 index 0000000..1e131ba Binary files /dev/null and b/resource/Dialogue_buttons_full.png differ diff --git a/resource/Dialogue_buttons_half.png b/resource/Dialogue_buttons_half.png new file mode 100644 index 0000000..0a81a86 Binary files /dev/null and b/resource/Dialogue_buttons_half.png differ diff --git a/resource/Introduction_skateboard.png b/resource/Introduction_skateboard.png new file mode 100644 index 0000000..e5b31e3 Binary files /dev/null and b/resource/Introduction_skateboard.png differ diff --git a/resource/Introduction_slime_bag.png b/resource/Introduction_slime_bag.png new file mode 100644 index 0000000..28867e0 Binary files /dev/null and b/resource/Introduction_slime_bag.png differ diff --git a/resource/Introduction_tony_avatar.png b/resource/Introduction_tony_avatar.png new file mode 100644 index 0000000..53998ab Binary files /dev/null and b/resource/Introduction_tony_avatar.png differ