Documentation/Programming Tutorials/Creation of a new Game Type

From NeoAxis 3D Engine Wiki

Jump to: navigation, search
Go to higher level



In this tutorial you will learn how to create a new Game Type. This tutorial consists of two parts

  • Adding a new type to the list of game objects to make it accessible from the list of game objects,
  • Creating a new game window.

In this tutorial you will create a simple game type. You will create a game window class with a UI for it as well.

Adding a new type to the list

To add a new game type to the map’s game type list you have to edit the GameMap.cs file of the GameEntities project.

The list of the available game classes is given in the GameTypes part of the code.

public enum GameTypes
	//Put here your game type.

Add a new game type after the "Put here your game type." comment.

Now, compile the project and start the map editor. The new type will be in the list.
Game type1.jpg

Creating new game window

Creating a simple game window

To start new window creation make a blank class. All game window classes in NeoAxis Engine are derived from the GameWindow class.

Open the Game project and add a new NewGameTypeWindow.cs file to it. Paste the following code in this file:

using System;
using System.Collections.Generic;
using System.Text;
using Engine;
using Engine.UISystem;
using Engine.MathEx;
using Engine.EntitySystem;
using Engine.MapSystem;
namespace Game
    class NewGameTypeWindow : GameWindow

To complete the creation of this simplest game window class you have to add the implementation of the OnGetCameraTransform method to it. This method reports the camera position to the engine. Thus, the data for the last camera position in Map Editor will be transmitted to the engine.

protected override void OnGetCameraTransform(out Vec3 position, out Vec3 forward,
    out Vec3 up, ref Degree cameraFov)
    //camera position
    position = Map.Instance.EditorCameraPosition;
    //Camera direction
    forward = Map.Instance.EditorCameraDirection.GetVector();
    //Camera angle
    cameraFov = Map.Instance.Fov;
    //Vertical DIRECTION
    up = Vec3.ZAxis;

You have created a simplest class. Now, you have to make the engine use your new game window class.

Open the GameEngineApp.cs file of Game project. Find the CreateGameWindowByGameType method. You can see that it is used for creating game windows of the standard game types of NeoAxis Engine.

GameWindow CreateGameWindowByGameType( GameMap.GameTypes gameType )
    switch( gameType )
    case GameMap.GameTypes.Action:
    case GameMap.GameTypes.TPSArcade:
        return new ActionGameWindow();
    case GameMap.GameTypes.RTS:
        return new RTSGameWindow();
    case GameMap.GameTypes.TurretDemo:
        return new TurretDemoGameWindow();
    case GameMap.GameTypes.JigsawPuzzleGame:
        return new JigsawPuzzleGameWindow();
    //Here it is necessary to add a your specific game mode.
    case GameMap.GameTypes.NewGameType:
        return new NewGameTypeWindow();
    return null;

Add new game type processing after the "Here it is necessary to add a your specific game mode." comment.

Compile your project.

Now proceed to the testing of a new game type. For the demonstration you will need a map (for example In map properties set the GameType parameter value (in the GameMap scrollbar of the map settings) to NewGameType.

Adjusting the map for the new game type

Now, start the map in the simulation mode

The new game type in action

As you can see, the game class you have created is black (no GUI and any interactivity). In the next part of the tutorial you will learn how to make it more interactive.

Game window class expansion

Let us start with getting some information about There are a number of cameras on this map that you can use to take a look at the game world.

You will have to change the code of the OnGetCameraTransform method. You will access the camera through its name, thereby acquiring information on its world position. In case your game type is used on another map which does not have a camera of the specified name, you can get the information on position from the saved position of the editor camera.

protected override void OnGetCameraTransform(out Vec3 position, out Vec3 forward,
    out Vec3 up, ref Degree cameraFov)
    //You gain access to the camera
    MapCamera mapCamera = Entities.Instance.GetByName("MapCamera_0") as MapCamera;
    //If the camera is found
    if (mapCamera != null)
        position = mapCamera.Position;
        forward = mapCamera.Rotation * new Vec3(1, 0, 0);
        cameraFov = mapCamera.Fov;
        position = Map.Instance.EditorCameraPosition;
        forward = Map.Instance.EditorCameraDirection.GetVector();
        cameraFov = Map.Instance.Fov;
    //Vertical direction
    up = Vec3.ZAxis;

Now, proceed to the interactivity. Add a menu to your game type consisting of a single Create Box button. Pressing it will make a box fall on the map.

First, you will need a user interface (GUI). To make the things simpler it will consist of a single Create Box button.

Graphical interface of the game type window

There are two things you have to do now:

  • To link the game window with the UI,
  • To write a method that will add a box to the map when the button is pressed.

First, determine a variable to implement access to the user interface. Secondly, add the OnAttach method implementation. This is the method to be called when the game window is created. In this method you will create (load from a file) the UI and link it to the window. You also have to make the CreateBox button respond for the click. That is how the code should look like:

//A variable used for accessing game window UI
Control hudControl;
protected override void OnAttach()
    //Call parent method
    //UI load
    hudControl = ControlDeclarationManager.Instance.CreateControl("Gui\\NewGameTypeHUD.gui");
    //Add gui to the window
    //Adding button click response
    ((Button)hudControl.Controls["CreateBox"]).Click += CreateBoxButton_Click;

The only thing you need now is a function to add a box to the map. Here is the code for this function:

void CreateBoxButton_Click( Button sender )
    //If there is an access to the map
    if (Map.Instance != null)
        //The creating of a new game object (box)
        MapObject box = (MapObject)Entities.Instance.Create("Box", Map.Instance);
        //Setting the position of the box
        box.Position = new Vec3(1.6f, 18.0f, 10.0f);
        //Finish creation

The game window class is now complete and everything you need now is to compile the project.

To see the game class in action start map in simulation mode (the GameType parameter should be set to NewGameType).

To test the new game type user interface, press the Create Box button to make a box fall on the map.

New game type in action


In this tutorial you have learned how to add new game types to the game engine and to create game window classes. For better understanding of game window work principles you can examine the following classes of the Game project:

  • ActionGameWindow – a game window used for implementation of games as well as other projects with first- or third-person character control.
  • TurretDemoGameWindow – A subclass for the ActionGameWindow class used in the TurretDemo map.
  • RTSGameWindow – An example of an RTS game created using the engine (see the RTSDemo map).
  • JigsawPuzzleGameWindow – An example of a puzzle game with multiplayer.