Skip to content

Latest commit

 

History

History
410 lines (329 loc) · 11.5 KB

Documentation.md

File metadata and controls

410 lines (329 loc) · 11.5 KB

Documentation

This is the documentation for Marcel Engine.

Table of Contents

Getting Started

To get started on a new Game in Marcel Engine please download the latest empty Build from here.

Then you can unzip the File and Open it in Visual Studio.

Your Code will go into the Your Code.cs file.

There the engine is set up already.

The Engine

Here are the main parts of the engine

Main Engine

This is the main part of the engine.

Initialisation

You can initialise the engine in two ways:

MainEngine engine = new MainEngine((SIZE_X, SIZE_Y, FONT_SIZE), SHOULD_WINDOW_MAXIMISE);
//OR
MainEngine engine = new MainEngine((SIZE_X, SIZE_Y, FONT_SIZE), SHOULD_WINDOW_MAXIMISE, FONT_NAME);

Rendering

The engine renders a Frame with the RenderFrame() Method. It takes a number as an input and tries to draw at that framerate. If you use -1 as the input, it will draw as fast as it can.

RenderFrame(double prefferedFps);

You can also change the backround colour with the SetNewBackroundColour() Method. Its takes an int between 0 and 15 as input.

SetNewBackroundColour(int colour);

Collision

You can check the collision between two objects by using the CheckObjectCollision() Method. It takes two Objects as input and returns true, if they are colliding.

CheckObjectCollision(Object a, Object b);

Main Scene

The engine has an active scene by default.

You can change it with the ChangeActiveScene() Method. It takes a scene object as input and replaces the active scene with that one.

ChangeActiveScene(Scene new_scene)

You can add and Remove Objects with the AddObjectToScene/RemoveObjectFromScene Method. They take an Object as an input.

AddObjectToScene(Object obj);
RemoveObjectFromScene(Object obj);

Camera

The engine also has a Camera. (It IS NOT connected to the local scene!!!)

You can move it around with the following Methods:

MoveCameraPosition((int x, int y) position);
MoveXCameraPosition(int x);
MoveYCameraPosition(int y);

Outdated Input

There's still outdated Input with the GetKey() and GetKeyChar() Method

Objects

This is the Object class. All of the objects in the whole engine and your game will use it.

Each Object has a Player and a Text Object, an Active Position type, a layer its on, a boolean showing if its shown, a Position, an Offset Position.

Creating a new Object

you can make a new Object with the standard constructor.

Object Test = new Object();

You will then need to set its active object type.

Test.ActiveObjectType = 1;
// 0 for none
// 1 for Player
// 2 for Text

Each object also has an Update Method which updates its Position and other stuff to the screen.

Test.Update();

Movement

You can move an Object with the following Methods:

Move((int x, int y) pos);
MoveX(int amount);
MoveY(int amount);

Cloning

You can clone any Object with the Clone() Command. This will return an exact copy of the first object, but not linked to it.

Clone();

Player Object

The Player SubObject doesnt need any initialisation. Its ActiveObjectTypeNumber is 1. You can access the Player SubObject like this:

Test.Player

The Player Object has the following things: an Active Sprite, an Active Animation Sprite, a Sprite Library, its Parent Object, Its Rotation and scale, a bool saying if the sprite is animated, the current animation sprite library, an animation library, the frame the animation is on and the animation speed.

You can Turn the Player Object by either changing its rotation or by using the TurnTo command.

Test.Player.Rotation = 90; // Sets the rotation to 90°
Test.Player.TurnTo(Object obj); // Turns to an Object
Test.Player.TurnTo((int x, int y) pos); // Turns to some location

You can also change its scale:

Test.Player.Scale = 2; // Makes the Object twice the original size.

If you change the scale or rotation by changing the variables you will have to update its Sprite:

Test.Player.UpdateSprite();

And of course you also have to update the Object.

You can change its Animation by changing the Current animation library and changing the IsSpriteAnimated to true.

And you can interact with the other libaries in it and also dont need to initialise them.

You can also just clone the Player Object:

Object.Player clone = Test.Player.Clone();

Text Object

The Text Object is for Displaying Text. Its ActiveObjectTypeNumber is 2.

It has a Parent Object, the actual Text, the Text colour, the charpixeldata (don't worry about that) and a bool saying if the text has a transparent backround. The Text Object also doesn't need any initialisation.

You can update its text by changing the Text variable:

Object.Text.Text = "Hello, World!";

You will need to update the Text if you change the text:

Object.Text.UpdateText();

And of course you also have to update the Object.

You can also clone the Text Object:

Object.Text clone = Test.Text.Clone();

Scene Object

The scene is a sepperate object in its own class. It can be initialised with a name or without a name:

Scene testscene = new Scene();
Scene testscene = new Scene(string _name);

It has a List of Objects that you can add and remove Objects to/from. You can switch The active Scenes with this Class.

Graphics

The main graphics core.

Sprite

A Sprite contains a few things: a boolean saying if it has an image, the image data, the source image data, its border, if its centered, its rotation and its scale.

You can initialise a Sprite with nothing or a path with a filename. (they are relative to the exe and you should put sprites into the engine folder or another folder)

Graphics.Sprite test = new Sprite();
Graphics.Sprite test = new Sprite(string Filename, bool _centered);

You can also set an Image with the SetImage Method:

SetImageFromFile(string filename, bool _centered);

And if you do any changes to a sprite, you should use the UpdateImage Method to update the image data!

UpdateImage();

You can also clone a Sprite

Graphics.Sprite testclone = test.Clone();

SpriteLib

This is a Library with Sprites.

You need to initialise it without anything.

Graphics.Sprite_Lib lib = new Graphics.Sprite_Lib(); // sets up a new Sprite Library.
lib.Sprites.Add("Test", test); // the Sprites List is actually a Dictionary!

Input

Here you can get the Inputs.

You can easily initialise it by making a new instance of it. (Its actually included in the empty project!)

Input inp = new Input();

You can get the information on if a key is pressed like this:

inp.KeyPressed(Input.Key.(Enter key here)));

For example checking if the A key is pressed:

if (inp.KeyPressed(Input.Key.A))
{
   /*Do some stuff*/
}

Sound

Sound manager for the engine.

Sounds are pretty simple to use.

You initialise a Sound Object with a Filename:

Sound Testsound = new Sound("test.mp3");

Supported Filetypes I think: http://support.microsoft.com/kb/316992

Then you can either Play the sound (or add it to a queue if a sound is playing)

Testsound.Play(bool _loop); // you can decide if the sound should loop

or stop all playing things:

Testsound.Stop();

or stop all playing things and use a new file:

Testsound.New_File("test2.mp3");

And you can also change its Volume:

Testsound.Volume = 95; // 95%

Networking

Networking core for the engine. You can setup Networking pretty easily:

Networking testnetwork = new Networking();

then you can start either a client or a server (or both) with a given IP:

testnetwork.Client_.Start("localhost");
testnetwork.Server_.Start("localhost");

Server

When you start a server you will interact with the received and reply variable:

while (true)
{
    if (testnetwork.Server_.Received != "")
    {
        /*Do stuff...*/
        testnetwork.Server_.Reply = "Something";
        testnetwork.Server_.Received = "";
    }
}

Receive is what the server received and reply is what it will reply with.

Client

When you start a server you will interact with the tosend and received variable:

testnetwork.Client_.ToSend = "TestMessage123";
testnetwork.Client_.Received = "";
while (testnetwork.Client_.Received == "")
{
}
/*Do stuff... with the received variable*/
testnetwork.Client_.Received = "";

ToSend is what the client will send and received is what it got as a reply from the Server.

Screen

Internal stuff you dont need to care about.

Internals

Internal stuff of the engine.

Debug Logger

You can set up a Debug Logger. It will open up a second window and log stuff on it there.

Internals.Debug_Logger logger = new Internals.Debug_Logger();

You can log any String like this:

logger.Log("This is a test");

You can also change its title with the Set_title Method:

logger.Set_title("Test Title!");

Boot

You can enable fastboot manually in the engine. (It will basically skip the smal little splashscreen.)

You will have to go to the MainEngine.cs File and locate the initialise() Method. There you have to add internal.FastBoot = true; after internal = new Internals();

It should look like this before:

            Console.CursorVisible = false;
            Display = new Screen(size, maximize, console_font);
            _frames = 0;
            _lastTimeBeforeXFrames = DateTime.Now;
            ActiveScene = new Scene("Main");
            _internal = new Internals();
            //internal_.fastboot = true; // Delete this and just add _internal.FastBoot = true; right here
            if (!_internal.FastBoot)
            {
                AddObjectToScene(_internal.SplashscreenObject);
                RenderFrame(0.5);
                RemoveObjectFromScene(_internal.SplashscreenObject);
                RenderFrame(1);
            }

And now like this

            Console.CursorVisible = false;
            Display = new Screen(size, maximize, console_font);
            _frames = 0;
            _lastTimeBeforeXFrames = DateTime.Now;
            ActiveScene = new Scene("Main");
            _internal = new Internals();
            _internal.FastBoot = true;
            if (!_internal.FastBoot)
            {
                AddObjectToScene(_internal.SplashscreenObject);
                RenderFrame(0.5);
                RemoveObjectFromScene(_internal.SplashscreenObject);
                RenderFrame(1);
            }