Skip to content

Creating Story

piitex edited this page Nov 27, 2024 · 8 revisions

Construction

THIS PAGE IS UNDER CONSTRUCTION!

Before You Begin

You must have completed the previous steps which include installing the framework and creating the main menu.

Stories

Stories is the foundation of the novel. It is responsible for mapping and managing the scenes. Scenes are the frames within the game. You can view more about scenes here.

Creating a Story

To create a story we need to make a new class. I will call this IntroStory for example.

import me.piitex.renjava.api.stories.Story;
public class IntroStory extends Story {

  public IntroStory(String id) {
      super(id);
  }

  @Override
  public void init() {

  }
}

Adding Scenes

The 'init' function is used to add the scenes to the Story by using the addScene() function. Note, you will not be able to call this function if the class does not extends Story.

@Override
public void init() {
  // As of right now there is no Nar character. This will be created later down the road.
  addScene(new ImageScene("1", nar, "It's time to wake up again.", new ImageOverlay("stories/intro/introbg.png")));
}

Let's break down the ImageScene. The first parameter is the ID. Every scene needs a unique ID. The second parameter is the character. As of right now we do not have a character called nar. You can pass null to the character but this will make the scene not render a text-box. The third parameter is the dialogue of what the character said. If you passed null for character it is pointless to add dialogue. The last parameter is the ImageOverlay. This is used as the background image. If you wish to render a black screen you can pass null.

Mapping the Story

Every story needs to be mapped for the engine to play them in correct order. You can map stories within your main class inside the createStory() function.

public class HeroAdventure extends RenJava {
...
  public void createStory() {
    // To map stores we need to create the objects.
    new IntroStory("id"); // The ID should be changed to intro.
  }
}

Story pathing

You can instruct the story to display scenes in a specific order using events. The following is a choice scene where the player can choose their route.

@Override
public void init() {
ChoiceScene choiceScene = new ChoiceScene("5");
choiceScene.addChoice(new Choice("no", "Lay in bed all day."));
choiceScene.addChoice(new Choice("yes", "Get up."));
choiceScene.onChoice(event -> {
  if (event.getChoice().getId().equalsIgnoreCase("yes")) {
    // Instead of calling addScene(); We have to use the displayScene function first.
    displayScene("6");
  }
  if (event.getChoice().getId().equalsIgnoreCase("no")) {
    displayScene("8");
  }
  });
}

It doesn't just have to be choice scenes either. You can path the story by choices the player had made along the way and achieve unique dialogue.

@Override
public void init() {
ImageScene imageScene = new ImageScene("12", character, "I bet you went out there without a potion... Idiot.");
imageScene.onEnd(event -> {
  event.setAutoPlayNextScene(false); // Very important! Prevents the engine from auto-playing next scene.
  if (mainCharacter.collectPotion()) {
    displayScene("13");  
  } else {
    displayScene("15");
  }
});
addScene(new ImageScene("13", mainCharacter, "I actually did collect one for once. So, ha."));
addScene(new ImageScene("14", character, "What? You want a cookie for doing one thing right?").onEnd(event -> {
  event.setAutoPlayNextScene(false);
  displayScene("17");
));
addScene(new ImageScene("15", mainCharacter, "Uhhh... No, I grabbed one..."));
addScene(new ImageScene("16", character, "uhuh. I'm sure."));
}