Repository navigation
Characters
Characters are objects that resemble a character in your game. These objects can contain your own data and there is a lot of freedom you have with them. All characters have to be created before the story is created. I recommend creating the characters in the function createBaseData(), but before we do that we must create a character class. There are two types of character classes Character and MainCharacter. First let's create the main character of the story.
public class MyMainCharacter extends MainCharacter {
// You can add your own data here, more about this will be explained later but just to showcase lets add a money value
private int money;
public MyMainCharacter(String id, String name, Color color) {
super(id, name, color);
}
public int getMoney() {
return money;
}
}Okay let's process what we just did. We created a main character which requires three things; id, name, color. The id is used as a unique identifier for the character. The name is self explanatory and the color is the color display of the character. Let's create this character in our function.
@Override
public void createBaseData() {
new MyMainCharacter("mc", "mc", Color.RED);
}Once our character is created it is stored in the RenJava class. I recommend creating your own getInstance for your class but you can use the RenJava class if you want.
MyMainCharacter mc = (MyMainCharacter) RenJava.getInstance().getCharacter("mc); // You have to cast your own class to getCharacter()
// Now you can get data from the class
mc.getMoney();NPC (non playable characters) are characters in your game that are not the main character. Just like making a main character you have to create your own character class and extend Character.
public class MySideCharacter extends Character {
public MySideCharacter(String id, String name, Color color) {
super(id, name, color);
}
}Just like previously the parameters are the same and the class works in the same way. You can even store data just like you did before with money.
public class MySideCharacter extends Character {
private int relationship = 0;
public MySideCharacter(String id, String name, Color color) {
super("side character", "Side Character", Color.BLUE);
}
public boolean isFriend() {
return relationship > 20;
}
public void setRelationship(int amount) {
this.relationship = amount;
}
}I expanded this example a little more just to give you an idea on how you can effectively use these classes. Make sure you create the character in your RenJava class.
@Override
public void createBaseData() {
new MySideCharacter("sc", "Side Character", Color.RED);
}There will be a dedicated guide to persistent data but here I'm going to show you the process for characters. In short, persistent data is data that is stored in the save file. For example, this can be money, character relationships, and quest data. In order to save data the data must be in its own dedicated class and that class must implement PersistentData.
public class MyMainCharacter extends MainCharacter implements PersistentData {
// You can add your own data here, more about this will be explained later but just to showcase lets add a money value
private int money;
public MyMainCharacter(String id, String name, Color color) {
super(id, name, color);
}
public int getMoney() {
return money;
}
}In this example we want to save the characters money to the save file and in order to do this we must annotate the field with Data. Keep in mind, for any fields you want to save they must be generic and they cannot be final. These are the following generic fields; String, Boolean, Integer, Double, Float, Long.
public class MyMainCharacter extends MainCharacter implements PersistentData {
// You can add your own data here, more about this will be explained later but just to showcase lets add a money value
@Data
private int money;
public MyMainCharacter(String id, String name, Color color) {
super(id, name, color);
}
public int getMoney() {
return money;
}
}