Code structure
This document describes how the files intereact and what purpose they have. Additionally, it is described what is going to change about it.
General changes
Aims:- Levelfiles should contain their own scripts, models, textures, particlescripts
- Gameplay items (weapons, enemy vessels) should be freely configurable from the levelfiles
- saving gamestates
- Campaigns should be possible
- Levels should be directories that can contain multiple level files
- scripts in leveldirectories are used for loading
- level directories are used for resources
- weaponary and enemy behavior must be defined in leveldirectories
- save specific parameters between different levels
- level.lua - must read and support directory structure
- game.lua - must use script files do define weapon and gameplay behavior
Configuration and information files:
- config.cfg: Saves settings for postFX / options
- Automaticly generated by options.lua
- highscores.cfg: saves the highscores
- Automaticly generatedby demohighscores.lua
- .projectinfo.lua: Display information for the projectmanager
File: main.lua
Provides functions to start
- Menu
- Mapeditor
- Gameplay
- F5: start menu
- Deletes GUI childs on the rootcontainer
- sets game,level and menu to nil
- executes scripts/menu.lua
- F8: starts Mapeditor
- sets game,level and menu to nil
- Deletes GUI childs on the rootcontainer
- executes scripts/level.lua
- Note: Reloading the mapeditor while it is already loaded will break the code due to a currently unknown bug - if reloading is required, switch to menu and switch to the mapeditor
- F9: load the default map and play it
- Deletes GUI childs on the rootcontainer
- Note: won't show up highscore nor does the level end, this works only if started from the menu
File: scripts/res.lua
Resource management. Stores models, sounds and textures in global tables.
- mdl: model files
- snd: sound files
- tex: texture files
Future changes:
- adding particle scripts
- automatic loading of files
- Namings are not dependent on file names, namings might be changed
File: scripts/options.lua
Creates class named "Options" and instantiates a global value named "gameoptions".
- gameoptions.cfg contains configuration settings
- gameoptions:set(key,value) can set a generic key value which will be saved in the cfg table. Also saves the change in the config.cfg file
File: scripts/demohighscores.lua
Creates class named "Highscores" and instantiates a global value named "highscores".
- highscores.scores is a table that contains sorted list of highscore holdes, where
- .name: callsign (usually three letters)
- .points: achieved points
- .date: dd.mm.yyyy string
- Must be rewritten so it can store scores for different map files
- Anticheating is a waste of time on such a project - but this would be the first place to make it more safe
File: scripts/posteffects.lua
Handles the postprocessing effects like blur and distortions. Creates a global table named "postfx". Contains further functions that allow modification of effects.
- postfx.glow: Glow effect handle
- postfx.glow.strength(number): strength of glow
- postfx.glow.eff:thres(number): how bright must the color be in order to be used for the glow effect
- postfx.distort: Distortion effect handle
- postfx.distort.scale(x,y): ?
- postfx.distort.noise(x,y): ?
- postfx.distort.offset(0,0): ?
File: scripts/menu.lua
Manages the mainmenu gui. Creates a global named "menu".
Loads "level0.lua" as game. Deletes all enemy nodes from the game, disables the think of the player's ship and calls the think method. Steers the player's ship to follow and shoot the mouse cursor. Moves the camera of the game object slowly up. No idea how long this will take to move the entire level, but the level (a testlevel) is really pretty long.
Functions:
- menu:showMenu(component,title = "Sparc")
- Shows a component in the box. The size of the component is used to change the menu container's size. All menupages are using this function to create their GUI.
- local functions: addlabel, addrect, addbutton - helpers to add greenish components to a container
- Allow starting different levels
- Show information on levels
- Show level dependent highscores
- Think about a system how to save / load play states, must be implemented in game.lua
- shooting the mouse is boring. Clicking somewhere should spawn an extra which the ship trys to collect.
File:scripts/entity.lua
Creates class EditEntity?. EditEntity? is used by level.lua. Implements functions to work with property tables.
The purpose of the editentity is to create an object that has parameters that can be displayed in a GUI and be edited directly.
Future changes:
- likely alot
File: scripts/level.lua
Provides several classes that handles GUI editing of entities.
Most important:
- saving: type in console (press F1):
saveworld("filename.lua")to save the world to "filename.lua" - loading: type in console:
loadworld("filename.lua")to load map from "filename.lua"
- Likely to change alot.
- see General Changes
- L3D? Layers for rendered objects:
- layer 0-3: for objects that are drawn before player/enemy ships are drawn
- layer 4-5: reserved for objects created by the game
- layer 6-9: usable for objects to be drawn after the game objects
- layer 10-15: reserved for postfx
File: scripts/game.lua
Creates class Game, Player, Projectile.
- new(Game,Levelfile): loads the level by its file and creates all ships / enemies
- game.cam: actornode that binds the camera
- game.sun: actornode that binds global light to a position kept relative to the cam
- game:showMenu(comp,onok): shows a GUI component and pauses the gameplay. If a function as onok is passed, this function is called if the user pressed OK.
- game:showMessage(tx,onok): creates a text GUI element that is shown using showMenu
- game:think(donthidemouse) manages the gameplay.
- game.player: player ship
- see General Changes