Game
The King's Day

7 years ago

Entity Script System for Storytelling


For a long time, as a developer, I wanted to have a way to tell stories in my games using scripts similar to screenplays. I wanted to be able to change the script at anytime and make it reasonably flexible.

I started by opening my text editor and thinking of all the actions my sprites could perform. Actions like: walking, standing still, chasing, talking, etc. I also made a list of different game functions that might be useful in a script, like: camera controls, changing map tiles, creating or removing items, etc.

Then I stripped the list down to the bare minimum needed to make a story work in my game. The story can either be played out in sequence by itself or it will pause allowing the player to read the dialog before pressing enter to continue.

Here is an example of what the script looks like.

		
			script 1
moveto king 15 8
moveto queen 16 8
face queen west
talk queen "i want a new throne. this one is worn out."
wait 30
face king east
talk king "that will not be possible. i don't have the time to fix it right now.."
wait 30
face queen south
face king south
talk queen "I'm going to bed!"
wait 30
walkto queen 16 14
		
	

It uses a simple format of [ACTION] [ENTITY] [DATA] to determine what to do. The game loads the entire script into a list of strings. When I want to run a script, I change the state of the game to a script-mode and choose the script I want to execute. The engine then executes each list item one at a time until the script ends.

I decided that there were only a few commands that were needed in order to make the story work. MOVETO will transport an entity to a tile position; FACE will turn that entity to face that direction; TALK will display a text dialog box with the message between the quotes and a portrait of the entity talking; WAIT will cause the story to pause for [N] frames; WALKTO will cause that entity to walk toward that tile position the story continues once they reach that point. The game camera could also be made to move to a position but otherwise will just follow the King.

How it works in code is when each line of string is executed, the system determines the action being called and runs a function that controls that particular action. MOVETO will call a function within the script object that will take an Entity as a parameter and two integers for X and Y coordinates. The system will then put the appropriate Entity in the function and move it to the position specified.

		
			    String[] tokens = fileItems.getItem(currentAction).split(" ");

    if (tokens[0].equals("moveto"))
    {
        entityID = tokens[1];

        if (entityID.equals("king"))
        {
            xTarget = Integer.valueOf(tokens[2]) * Tile.SIZE;
            yTarget = Integer.valueOf(tokens[3]) * Tile.SIZE;
            Game.king.walking = false;
            if (moveTo(Game.king, xTarget, yTarget))
            {
                return true;
            } else
            {
                return false;
            }
        }
		
	

At first I gave each character object in my game their own dialog box that could appear when they talked. The problem I had was that sometimes a sprite would be drawn above a dialog box due to the order of rendering. My solution for this was to have the dialog box be its own object. I created a separate class which allowed me to customize the appearance of the dialog by adding a portrait box that I can change to show who is talking.

So at this point I’m just finished up the Intro and Outro sequences and the game will be released. It will still need a little bit of optimization but I’m happy with how it works at this point. If you have any questions about this, ask away!

Remelic



0 comments

Loading...

Next up

RELEASED - Will You Help the King?

The King's Day!

Sound Manager Working!

Working on a new project called Adventure Ops where you explore a world to discover secrets and solve a mystery. Game is coming along nicely.

So far the game only has one vehicle but more being planned. It's working; just has a few bugs to work out with collisions. The script I wrote can be applied to any vehicle in the game since the physics do not need to be too realistic.

Deleting Game Files

We are under attack!

We made a lot of improvements on the Freezing Plains visual. Things like pine trees, tiny bushes, some rocks, and others game props!

#IndieGame | #IndieDev | #GameDev | #PixelArt | #WaifuQuest | #WifeQuest | #screenshotsaturday

Finished a project I've been working on over the last few days!

Modeled and textured in Blender.

#3dart #lowpoly #npbr #fantasy #hut