Skip to content

Creating Story

piitex edited this page Dec 28, 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."));
}

Modifying Variables

To change game/character variables and to display the changes you will have to refresh the story. You only need to refresh the story if the variable is displayed. This is because stories are initiated when they start and the dialogue is preset. To modify the dialogue you have to re-initiate the story which refresh() does. Below are examples on when to refresh and when to not. You do not have to refresh if the variable is displayed in a different story, only on the same story it is needed.

public void init() {
addScene(new ImageScene("1", character, "The potion is 10 gold."));
addScene(new ImageScene("2", mainCharacter, "That's expensive..."));
addScene(new ImageScene("3", character, "It's not getting any cheaper."));
addScene(new ImageScene("4", mainCharacter, "Fine I'll pay... Here's 10 gold.").onEnd(event -> {
// If the variable is not going to be displayed in text there is no need to refresh the story.
mainCharacter.setGold(mainCharacter.getGold() - 10);
}));
addScene(new ImageScene("5", character, "12 gold. It's 12 gold now."));
addScene(new ImageScene("6", mainCharacter, "What?"));
addScene(new ImageScene("7", character, "I said it's not getting any cheaper, 15 gold."));  
}
public void init() {
addScene(new ImageScene("1", character, "Did you just take 100 gold out of my pocket?").onEnd(event -> {
mainCharacter.setGold(mainCharacter.getGold() + 100);
            
// Since the 'getGold()' method is retrieved in the below texts we need to refresh it for it to be updated in the text.
this.refresh(); // Sometimes the compiler does not like 'refresh();' on it's own and needs to be called with 'this.refresh();
}));
addScene(new ImageScene("2", mainCharacter, "Nooo?? Why woul- You dare sully my name with thievery!"));
addScene(new ImageScene("3", character, "You know I have a spell that can see how much you have. You have " + mainCharacter.getGold() + " gold."));
}