Skip to content

GameDevRichtofen-G/GameEngine-ConsoleCS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C# Console Game Engine

About

This is a simple game engine created in one day using C#. It leverages console applications to provide a basic framework for game development.

Getting Started

GameEngine-C#RAW

This is the core engine where you can create your own games. To run it, simply either play in debug mode or run the application directly.

GameEngine-CarGame

This is a game template created using the engine. To run it, either play in debug mode or launch the application.

Example Image

Main_class

Main_class is a type of class that can be used during gameplay.
You can place it, render it, handle collisions, update it, or destroy it.

Create Child Classes

To create an instance of Main_Class, go to Solution ExplorerRight-click on ProjectNameAddNew Item.
Make sure to update the reference like this:

internal class [ClassName] : Main_class

Variables :

float : x : x coordinates y : y coordinates z : z coordinates

w : width of Main_class

h : height of Main_class

.

bool Check_for_collision : Can we check for collision or not

bool Can_render : A variable that determines whether that render engine can render Main_class or not

bool spawn : if false, this class will be destroyed. bool Physics : Defines whether class needs physic or not

float Gravity : Force of the gravity float Velocity : The speed and direction of an object as it falls under the influence of gravity .

List of String List shape : Defines the structure of a class and how the rendering engine processes it for rendering visuals. Example :

shape = [["####"]].

to render more layers, add more element like this :

shape = [["####"],["####"],"####"];
/*OUTPUT : #####
           #####
           #####*/

ConsoleColor color : Determine how render engine render the color of Main_class a.k.a material

Functions :

To use functions in Main_class instances make sure to override them.

public override void BeginPlay()
{
    //will get called on the first frame
}
public override void BeginPlay_Respawn()
{
    // A function that is called when the class has been spawned.
}
public override void Update(float deltaTime)
{
    //will get called on everyFrame
}
public override void InputRecieve(Input_system CatchInput)
{
    //will get called on everyFrame
}
public override void SpawnClass(Main_class SpawnClass,float x, float y,bool Can_render)
{
        //spawn a class

        //setting up coordinates
        SpawnClass.x = x;
        SpawnClass.y = y;
        SpawnClass.z = 0;


        //setting up some other settings
        SpawnClass.Can_render = true;
        SpawnClass.BeginPlay_Respawn();

    //check to see if this class's Public_classes is available
    if (variables != null)
    {
         variables.Classes.Add(SpawnClass); //Spawn the class by adding it to Public_class's Classes
    }

    
}
public override void Check_collision(Main_class other)
{
    //check for collision function
    if (other is [TargetClass])
    {
        if (x < other.x + other.w && x + w > other.x && y < other.y + other.h && y + h > other.y)
        {
            
        }
    }
}

BeginPlay function

A function present in every instance of the Main_Class. It is called only during the first frame and can be useful for initializing variables.

Example

public override void BeginPlay()
{
    spawn = true;
    Can_render = true;
    shape = "[[]]"; 
    color = ConsoleColor.Red;
    w = 8;
    h = 1;
    Check_for_collision = true;
}


Update function

A function present in every instance of the Main_Class. It is called every frame and can be useful for updating the class.

Parameters

deltaTime : the time interval in seconds it took from the last frame to the current frame

Example

public override void Update(float deltaTime)
{
    //if bullet's x coordinates was bigger than 5,minus x from speed, else destroy bullet
    if(x > 5)
    {
        x = x - (speed * deltaTime);
    }
    else
    {
        spawn = false;
    }
}

Input System

How to Use

To handle inputs in your Main_class, you need to override the InputRecieve method like this:

public override void InputRecieve(Input_system CatchInput)
{
    // Handle input logic here
}

Example

Here’s an example of using inputs to move forward when the W key is pressed:

public override void InputRecieve(Input_system CatchInput)
{
    if ((GetAsyncKeyState(VK_W) & 0x8000) != 0)
    {
        // Move forward when W key is pressed
    }
}

Supported Inputs

Here’s a list of all the inputs you can use in your game:

Movement Keys

  • VK_W = 0x57W Key
  • VK_A = 0x41A Key
  • VK_S = 0x53S Key
  • VK_D = 0x44D Key

Arrow Keys

  • VK_UP = 0x26Up Arrow
  • VK_DOWN = 0x28Down Arrow
  • VK_LEFT = 0x25Left Arrow
  • VK_RIGHT = 0x27Right Arrow

Action Keys

  • VK_SPACE = 0x20Space Bar
  • VK_ENTER = 0x0DEnter Key
  • VK_ESCAPE = 0x1BEscape Key
  • VK_TAB = 0x09Tab Key

Modifier Keys

  • VK_SHIFT = 0x10Shift Key
  • VK_CTRL = 0x11Control Key
  • VK_ALT = 0x12Alt Key

Function Keys

  • VK_F1 = 0x70F1 Key
  • VK_F2 = 0x71F2 Key
  • VK_F3 = 0x72F3 Key
  • VK_F4 = 0x73F4 Key
  • VK_F5 = 0x74F5 Key
  • VK_F6 = 0x75F6 Key
  • VK_F7 = 0x76F7 Key
  • VK_F8 = 0x77F8 Key
  • VK_F9 = 0x78F9 Key
  • VK_F10 = 0x79F10 Key
  • VK_F11 = 0x7AF11 Key
  • VK_F12 = 0x7BF12 Key

Other Keys

  • VK_CAPITAL = 0x14Caps Lock
  • VK_BACKSPACE = 0x08Backspace Key
  • VK_DELETE = 0x2EDelete Key
  • VK_HOME = 0x24Home Key
  • VK_END = 0x23End Key
  • VK_PAGEUP = 0x21Page Up
  • VK_PAGEDOWN = 0x22Page Down

Numpad Keys

  • VK_NUMPAD0 = 0x60Numpad 0
  • VK_NUMPAD1 = 0x61Numpad 1
  • VK_NUMPAD2 = 0x62Numpad 2
  • VK_NUMPAD3 = 0x63Numpad 3
  • VK_NUMPAD4 = 0x64Numpad 4
  • VK_NUMPAD5 = 0x65Numpad 5
  • VK_NUMPAD6 = 0x66Numpad 6
  • VK_NUMPAD7 = 0x67Numpad 7
  • VK_NUMPAD8 = 0x68Numpad 8
  • VK_NUMPAD9 = 0x69Numpad 9
  • VK_NUMLOCK = 0x90Num Lock
  • VK_SCROLL = 0x91Scroll Lock

SpawnClass function

A function that can be use for spawning a new Main_class instance.

Parameters

Main_class as SpawnClass .

x : x coordinates

y : y coordinates .

Can_render : Determine if class is visible or not

Example:

TankClass :

public override void Update(float deltaTime)
{

    
    //if random time was 0 or less, we will create a bullet class
    if(Random_Time <= 0)
    {
        //create and spawn a bullet class
        Bullet bullet = new Bullet();
        SpawnClass(bullet, x, y, true);
       
        //reseting the random_Time to pick number between 1,7
        Random_Time = random.Next(1, 7);
        
        

    }

Check_collision function

A function that checks whether Main_class instance hit another Main_class instance.

Parameters

Main_class as other

Example

if (other is Bullet)
{
    /*                             How collision works?
                   first we check if other class is a bullet class
                if yes then we use this formula to check for collision

     𝑥 < 𝑜𝑡ℎ𝑒𝑟.𝑥 + 𝑜𝑡ℎ𝑒𝑟.𝑤 && 𝑥 + 𝑤 > 𝑜𝑡ℎ𝑒𝑟.𝑥 && 𝑦 < 𝑜𝑡ℎ𝑒𝑟.𝑦 + 𝑜𝑡ℎ𝑒𝑟.ℎ && 𝑦 + ℎ > 𝑜𝑡ℎ𝑒𝑟.𝑦

                       if true then we destroy this car class


 */

if (other is Bullet)
{
    if (x < other.x + other.w && x + w > other.x && y < other.y + other.h && y + h > other.y)
    {
        variables.Player1_statue = false;
        other.spawn = false;
        spawn = false;
    }
}
}

NOTE

you need to set up this function manually

Destroy class

to destroy a Main_class instance you need to make spawn variable false. like this :

public void Example_Function()
{
    spawn = false;
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages