Elysion library
by
, 11-11-2010 at 07:43 PM (43519 Views)
With all these new game libraries and engines popping up, I finally feel confident enough to promote my own game library with a little more effort. So here we go:
I will open a proper thread in a little while, right now I'm still finishing up a few things for its 3rd official release which will be some day this month. (The first two releases were back in 2005 and 2006 where it was called ElysionSDL. I doubt anyone remembers or used it back then as I never really advertised the library that much. Almost the complete code base has been rebuilt since then.)
A sample source code for a main menu would look like this:
This source code is taken from the current development version of my LD17 entry "A Practical Survival Guide for Robots".Code:unit uMainMenu; interface uses ElysionColors, ElysionTypes, ElysionStage, ElysionGraphics, ElysionTrueTypeFonts, ElysionApplication, ElysionGUI, ElysionInput; // and there are some other units which are not important right now type TMainMenu = class(TelStage) // TelStage might be renamed in the final version private fBackground: TelSprite; fMenu: TelMenu; fFont: TelTrueTypeFont; fLogo: TelSprite; fNewGameClick: Boolean; public constructor Create; Override; destructor Destroy; Override; procedure Render; Override; // To render any objects from this main menu procedure Update(dt: Double); Override; // dt = DeltaTime: Allows time-independent animation/movement procedure HandleEvents; Override; // To check for input events like key presses or mouse events published property Background: TelSprite read fBackground write fBackground; property Font: TelTrueTypeFont read fFont write fFont; property Logo: TelSprite read fLogo write fLogo; property Menu: TelMenu read fMenu write fMenu; property NewGameClick: Boolean read fNewGameClick write fNewGameClick; end; implementation constructor TMainMenu.Create; begin inherited; Background := TelSprite.Create; Background.LoadFromFile(GetResImgPath + 'background.jpg'); fFont := TelTrueTypeFont.Create; fFont.LoadFromFile(GetStdFont, 14); fFont.Color := Color.clWhite; fFont.RenderStyle := rtBlended; Logo := TelSprite.Create; Logo.LoadFromFile(GetResImgPath + 'logo.png'); Logo.Position.Make((ActiveWindow.Width - Logo.Width) div 2, 16, 0); Menu := TelMenu.Create; Menu.setButtons(GetResImgPath + 'button.png', GetStdFont, 15, ['New game', 'How to play', 'Credits', 'Settings', 'Quit']); Menu.Spacing := 16; Menu.Bounds.Make((ActiveWindow.Width - Menu.Width) div 2, Trunc(Logo.Position.Y + Logo.Height + 32)); Menu.HoverAnimation := true; end; destructor TMainMenu.Destroy; begin Menu.Destroy; inherited; end; procedure TMainMenu.Render; begin Background.Draw; Logo.Draw; GUI.Box(makeRect(Menu.Bounds.X - 8, Menu.Bounds.Y - 8, Menu.Width + 16, Menu.Height), makeCol(0, 0, 0, 128)); Menu.Draw; fFont.TextOut(makeV3f(8, ActiveWindow.Height - 50, 0), 'Some text \n With line break.'); end; procedure TMainMenu.Update(dt: Double); begin Menu.Update; end; procedure TMainMenu.HandleEvents; begin if Menu.OnButtonClick('New game') then begin GameState := gsGame; fNewGameClick := true; end; if Menu.OnButtonClick('How to play') then GameState := gsInstructions; if Menu.OnButtonClick('Credits') then GameState := gsCredits; if Menu.OnButtonClick('Settings') then GameState := gsSettings; if Menu.OnButtonClick('Quit') or Input.Keyboard.IsKeyHit(Key.Escape) then Application.Quit; end; end.
As you can see the whole library is designed to be as much object-oriented as possible. With the exception of assigning data types (like points, vertices and color) and collision detection pretty much everything is wrapped into classes.
For loading and displaying an image you need at least three lines, first to create an instance of a sprite class, then load an image from file through LoadFromFile(String) and finally call Draw(). The new version also features texture classes and a texture manager. So if load the same image twice, the texture manager thinks: "Oh, alright, so I see you are loading the same image a second time. Well, this would use up more memory if you do that, so I'm returning the instance of the first texture." (Although if you really want to load the same texture twice you are still able to do so.)
How would this main menu now be integrated into the game itself. The main source file (main.lpr or main.dpr) just contains the game loop and an instance of a game container class which itself has instances to different game states e.g. the main menu or the game itself.
What about 3D graphics?
Elysion is primarily designation for 2D application and games (because 2D games are my personal preference) but you are able to integrate Horde3D pretty easily. If you have done some work with Horde3D before you may have noticed that the lack in the 2D department. What Horde3D lacks, Elysion makes up for. Here is a screenshot of a sample application (The Horde3D Knight demo application mixed in with some of Elysion's functions such as sprite rotating, scaling, coloring, alpha, buttons and font rendering):
Some technical features
Graphical renderer: SDL + OpenGL
Image loading: Handled internally by Vampyre Imaging by default, can be switched to SDL_image
Audio: SDL_mixer
Font rendering: True type fonts with SDL_ttf or optionally bitmap fonts through SFont
Scripting: Thorium (I'm having a bit of trouble with this right now, so that will be disabled in the next official release)
I guess that's it for now. Thank for reading and let me know what you think even if you think there are already enough game engines out there.