This project is read-only.

Hello World Example

Introduction
in this simple demonstration we are going to display "Hello World" on the screen

Code
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
    // - - Declarations - -
    /*
        * The Game Configuration to configure some basic settings like
        * Title: to set the title in the Titlebar
        * Width, Height: to set the size of the screen
        * UPS: Updates Per Second limit the amound of updates/renders
        * VSync: Vertical Sync (max fps is 60)
        */
    GameConfiguration gc = new GameConfiguration("Hello World!"); 
    /*
        * Creates a new instance of the game engine
        */
    GameEngine engine = new GameEngine();
    /*
        * The scene we are going to use to display the "Hello World" message
        */
    HelloWorldScene hwScene = new HelloWorldScene();
    /*
        * The HUD label we are going to use to display the text
        */
    HelloWorldLabel hwLabel = new HelloWorldLabel(gc.Width / 2, gc.Height / 2);
    /*
        * The HUD layer to place the HelloWorldLabel into
        */
    HudLayer hwSceneLayer = new HudLayer();

    // - - Methods - -
    /*
        * Lets first add the HelloWorldLabel to the HudLayer
        */
    hwSceneLayer.Labels.Add(hwLabel);
    /*
        * Now we can add the HudLayer to the HudLayers in the HelloWorldScene
        */
    hwScene.HudLayer.Add(hwSceneLayer);
    /*
        * Now lets add the HelloWorldScene to the Open Game Engine
        */
    engine.Scenes.Add(hwScene);
    /*
        * To display the scene we just need to switch to the scene we want
        */
    engine.SwitchScene("HelloWorldScene");

    // - - Run - -
    /*
        * Runs the game engine with the specified GameConfiguration
        */
    engine.Run(gc);
}

public class HelloWorldScene : GameScene
{
    public HelloWorldScene()
        : base("HelloWorldScene")
    {
    }
}

public class HelloWorldLabel : HudLabel
{
    public HelloWorldLabel(Int32 x, Int32 y)
        : base()
    {
        this.Font = new OpenGameEngine.Font("Comic Sans MS", 24f);
        this.Position = new OpenGameEngine.Vector2(x, y);
    }
}

Last edited Oct 4, 2013 at 4:29 PM by Matthiee, version 2

Comments

No comments yet.