📜 ⬆️ ⬇️

Kolobok on a visit at Windows 8: development diaries (part 1)

A couple of weeks ago we published our first material, " Kolobok Visiting Windows 8: Development Diaries (Introduction) ", today we continue this topic and tell in more detail the structure of the abstract level of our architecture, as we have organized it for today.

First sketches


Recently we received the first pictures from the artist. Here is the concept at the moment:



BaseGame abstract class


This class assumes responsibility for managing the main life cycle of the game, and also includes the logic and physics of the game.
')
public abstract class BaseGame: DisposeSupport
/// <summary> /// Describes an abstract game /// </summary> public abstract class BaseGame:DisposeSupport { /// <summary> /// The game Logic /// </summary> protected abstract ILogic Logic { get; } /// <summary> /// The game Physics /// </summary> protected abstract IPhysics Physics { get; } /// <summary> /// Initialize the game /// </summary> public void Initialize(){} /// <summary> /// Start the new game /// </summary> public void StartNewGame(){} /// <summary> /// Activate the game /// </summary> public void ActivateGame(){} /// <summary> /// Pause on game /// </summary> public void Pause(){} /// <summary> /// Restart the game /// </summary> public void Restart(){} /// <summary> /// Resume the game /// </summary> public void Resume(){} /// <summary> /// Exit the game /// </summary> public void Exit(){} public event Action Win; public event Action GameOver; public event Action Lose; } 


The life cycle can be represented as follows:


Visualization


Visualization at the top level is not tied to the game. Communication with rendering occurs only in a specific implementation of the game.
The visualization is the responsibility of the IRenderer interface, which provides the implementation of three methods:

public interface IRenderer <TInit, TRender>: IDisposable
 /// <summary> /// Describes a renderer class /// </summary> /// <typeparam name="TInit">Type that used for method Initialize parameter</typeparam> /// <typeparam name="TRender">Type that used for methods Render and ScreenSizeChanged parameters</typeparam> public interface IRenderer<TInit, TRender>: IDisposable { /// <summary> /// On initialize a device /// </summary> /// <param name="initParameter">Initialize parameter</param> void Initialize(TInit initParameter); /// <summary> /// On render per frame /// </summary> /// <param name="renderParameter">Render parameter</param> void Render(TRender renderParameter); /// <summary> /// On screen size changed /// </summary> /// <param name="renderParameter">Render parameter</param> void ScreenSizeChanged(TRender renderParameter); } 


Visualization cycle:

IRenderer also inherits the IDisposable interface, which provides the implementation of a set of methods for deterministic destruction of objects. In our implementation, drawing objects are also inherited from the Component class from the SharpDX library, where you can use the methods associated with putting resources into the delete list that an object passes before destroying it, and we get a ready-made implementation of IDisposable.

Logics


In our game is represented by the interface ILogic

public interface ILogic
 /// <summary> /// Describes a game logic /// </summary> public interface ILogic { /// <summary> /// Start game /// </summary> void StartGame(); /// <summary> /// Stop game /// </summary> void StopGame(); /// <summary> /// Pause game /// </summary> void PauseGame(); /// <summary> /// Resume game /// </summary> void ResumeGame(); /// <summary> /// Fire game event /// </summary> void FireEvent(IGameEvent @event); /// <summary> /// Win game event /// </summary> event Action Win; /// <summary> /// Lose game event /// </summary> event Action Lose; /// <summary> /// Delete game object event /// </summary> event Action<string> ObjectDeleted; /// <summary> ///Character moved event /// </summary> event Action<string,float,float,float> CharacterMoved; /// <summary> ///Character moved by path event /// </summary> event Action<string, IList<PathData>> CharacterMovedPath; /// <summary> ///Character patrol by path event /// </summary> event Action<string, IList<PathData>> CharacterPatrolPath; /// <summary> ///Character patrol event /// </summary> event Action<string, float, float, float> CharacterPatrol; /// <summary> ///Character moved to object event /// </summary> event Action<string, string, float> CharacterMovedToObject; /// <summary> ///Character in chase for object event /// </summary> event Action<string, string, float> CharacterChase; /// <summary> /// watch if the one object look at another; /// </summary> event Action<string, string> WatchedLook; /// <summary> /// watch the distance between two objects; /// </summary> event Action<string, string, float> WatchedDistance; /// <summary> /// character stop; /// </summary> event Action<string> ActionStopped; /// <summary> ///The rules factory /// </summary> IRuleFactory RuleFactory { get; } } 

When a game event occurs, the logic processes the set of rules, checks the conditions and the possibility of their execution, and then initiates Win, Lose or Game Over events that are passed to the game.

Duty cycle of game logic:


Physics



public interface IPhysics
 public interface IPhysics { /// <summary> /// add object to simulation /// </summary> /// <param name="obj">object</param> void AddObject(IObject obj); /// <summary> /// remove object from simulation /// </summary> /// <param name="obj">object</param> void RemoveObject(IObject obj); /// <summary> /// simulate world on specified time after start /// </summary> /// <param name="time">seconds</param> void Simulate(float time); /// <summary> /// signal that initialization starts /// </summary> void BeginInitialization(); /// <summary> /// signal that initialization included adding of objects is finished /// </summary> void EndInitialization(); /// <summary> /// getting movement observer for observing different events related to movement of objects /// </summary> /// <returns>moevement observer</returns> IMovementObserver GetMovementObserver(); /// <summary> /// get object factory /// </summary> /// <returns>getting object factory</returns> IObjectFactory GetObjectFactory(); } 


The interface for physics provides methods for adding, deleting physical objects,
simulations of the world for a certain time, getting a factory of objects and an event listener
movement of objects. The physical object interface is shown below.

public interface IObject
 public interface IObject { /// <summary> /// getting transformation matrix of object /// </summary> /// <returns>matrix</returns> Matrix GetTransform(); float X { get; set; } float Y { get; set; } float Z { get; set; } } 


With this interface you can set and get the initial coordinates of the object, as well as
transformation matrix as a result of the simulation of the world.

Findings:


We want to say that acquaintance with DirectX and the game development itself is a very interesting and new area for us.

According to C # 5.0 and development for Windows Store, we want to highlight the following features:

Source: https://habr.com/ru/post/169981/


All Articles