Total Overscript
Total Overscript is a simple one level RPG game showing many aspects of SC. Its code is simplified and the program
should be treated as a demo not a real game. Look into the code - it is strongly commented, main concepts are introduced
below.
The game uses WinApi and GDI so should work on most PC.
Your hero (you can fully configure him - though, from a script only) has some parameters like:
health, armor, strength, intelligence, agility. The game is pretty short, only one map
availble. You can fight against enemies, talk to NPC that give you tasks, use various items.
During the play you gain experience , and you can earn (or lost) gold.
The purpose of the game is to show some way of using SC in a larger program. You can freely
edit scripts, use data provided with that to see how it works. A whole level is loaded
from a text file - see it in data/levels directory - it can also be easily edited.
In data/img directory there are images used in the program, data/scripts contains all the scripts.
Steering is based on a keybord only, the view is isometric.
Steering:
- arrows - movement
- space - pick item, talk to NPC
- d - drop item
- enter - use inventory item
- number keys [1-9] - choose corresponding dialog answer
- F1 - enables/disables some debug information
Structure
Below a description of main classes of the game. More detailed info in the code.
- Game - The main class. There is only one object of it, it contains game systems (e.g. Renderer). This code
is inserted in a typical WinApi application structure (in the message loop).
- Renderer - It is responsible for drawing, displaying images
- Input - This class simplifies keyboard input handling, allows for not event-based key state queries.
- ScriptMngr - It manages scripts, loads SC environment, registers types, wraps script loading.
You may find some useful examples here.
- ImgMngr - Manages images - only one copy of the image from the particular path is in memory at given moment.
- DlgBox - It is responsible for displaying a dialog box. The dialog box contains some text (e.g. a character question)
and some user answers that may be chosen with number keys. The game contains two dialog boxes: one displayed at the bottom of the screen, one
fullscreen.
- Level - Represents the world. There is a single object at the given time, contains all entities, a path net, backgroud.
- Entity - Base (abstract) class for entities that appears in a level.
- Character - Represents characters - entities that can move such as enemies, NPC
- Player - Derived from Character - represents the hero steered by the user.
- StaticEntity - Entity that cannot move (e.g. a tree).
- Item - It represents an item - entity that can be carried in the inventory.
- PathNet - A whole level is covered by a uniform rectangular grid of nodes. Used by the path searcher
to find a path between given start and destination points.
- PathNode - A single element of a path or path net.
- Path - Represents a path - a set of connected nodes. AI-driven characters can move only on pathes.
- PathSearcher - Used to find a path with A* algorithm.
Execution
When the program starts a Game class object is initialized. It initalizes all the systems. Then, there is loaded a level
from the file. The level loads tile sets, entity templates and entities. When an entity is loaded, its initialization
script is executed (if specified).
Game logic is run with some frequency (frame by frame). First there is called NextFrame method
of the game object , next NextFrame of the level and NextFrame of all visible entities. After the logic of single frame is
executed the content of the window is redrawn.
SC usage
SC scripts are used at many points of the program. There are listed classes that uses scripts below. The name of the script is the name
of the member.
- Level
- initScript - called once after the level is loaded. Currently not implemented.
- nextFrameScript - called every time in NextFrame method. Currently checks a victory condition (player experience)
- Entity
- initScript - called once after the level is loaded.
- nextFrameScript - called every time in NextFrame method.
- collisionScript - called when the player bounding rectangle ovelaps the rectangle of the entity.
- pickScript - called when the player presses an interaction key nearby the entity (e.g. item standard behaviour is to add itself to the inventory.
- Character
- hitScript - defines a hit callback - SC function called when the entity is hit .
At loading time there is obtained a function from the hit script - void HitCallback(Character *entity, Int power). This function
is kept in SC function pointer hitCallback. When Hit method of the entity is called (usually from the script of some weapon) hitCallback
is called.
- deadScript - called once, when the health of the entity reaches 0.
- Item
- useScript - called when the player presses a use key and the item is selected in the inventory.
- dropScript - called when the item is dropped from the inventory.
What pay attention to?
There are listed the most important aspect, that you should pay attention to.
- See how the code is organised. It is just an example of a game structure, but look at the the points where scripts
are used
- Handling scripts, when they are loaded, destroyed ,called (e.g. Entity class).
- ScriptMngr class. It contains examples of data exporting.
- Using Sleep() method.
- Browse data/scripts directory. It contains all the scripts.
- See the level file (data/levels directory). You can add, change entities.
- Error reporting in ScriptMngr
- DlgBox class and dialog scripts. It is an example of a function pointer usage.
- One of more complex scripts is enemy_logic.sc