This is a simple game engine created in one day using C#. It leverages console applications to provide a basic framework for game development.
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.
This is a game template created using the engine. To run it, either play in debug mode or launch the application.
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.
To create an instance of Main_Class, go to Solution Explorer → Right-click on ProjectName → Add → New Item.
Make sure to update the reference like this:
internal class [ClassName] : Main_classfloat : 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
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)
{
}
}
}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.
public override void BeginPlay()
{
spawn = true;
Can_render = true;
shape = "[[]]";
color = ConsoleColor.Red;
w = 8;
h = 1;
Check_for_collision = true;
}
A function present in every instance of the Main_Class. It is called every frame and can be useful for updating the class.
deltaTime : the time interval in seconds it took from the last frame to the current frame
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;
}
}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
}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
}
}Here’s a list of all the inputs you can use in your game:
VK_W = 0x57→ W KeyVK_A = 0x41→ A KeyVK_S = 0x53→ S KeyVK_D = 0x44→ D Key
VK_UP = 0x26→ Up ArrowVK_DOWN = 0x28→ Down ArrowVK_LEFT = 0x25→ Left ArrowVK_RIGHT = 0x27→ Right Arrow
VK_SPACE = 0x20→ Space BarVK_ENTER = 0x0D→ Enter KeyVK_ESCAPE = 0x1B→ Escape KeyVK_TAB = 0x09→ Tab Key
VK_SHIFT = 0x10→ Shift KeyVK_CTRL = 0x11→ Control KeyVK_ALT = 0x12→ Alt Key
VK_F1 = 0x70→ F1 KeyVK_F2 = 0x71→ F2 KeyVK_F3 = 0x72→ F3 KeyVK_F4 = 0x73→ F4 KeyVK_F5 = 0x74→ F5 KeyVK_F6 = 0x75→ F6 KeyVK_F7 = 0x76→ F7 KeyVK_F8 = 0x77→ F8 KeyVK_F9 = 0x78→ F9 KeyVK_F10 = 0x79→ F10 KeyVK_F11 = 0x7A→ F11 KeyVK_F12 = 0x7B→ F12 Key
VK_CAPITAL = 0x14→ Caps LockVK_BACKSPACE = 0x08→ Backspace KeyVK_DELETE = 0x2E→ Delete KeyVK_HOME = 0x24→ Home KeyVK_END = 0x23→ End KeyVK_PAGEUP = 0x21→ Page UpVK_PAGEDOWN = 0x22→ Page Down
VK_NUMPAD0 = 0x60→ Numpad 0VK_NUMPAD1 = 0x61→ Numpad 1VK_NUMPAD2 = 0x62→ Numpad 2VK_NUMPAD3 = 0x63→ Numpad 3VK_NUMPAD4 = 0x64→ Numpad 4VK_NUMPAD5 = 0x65→ Numpad 5VK_NUMPAD6 = 0x66→ Numpad 6VK_NUMPAD7 = 0x67→ Numpad 7VK_NUMPAD8 = 0x68→ Numpad 8VK_NUMPAD9 = 0x69→ Numpad 9VK_NUMLOCK = 0x90→ Num LockVK_SCROLL = 0x91→ Scroll Lock
A function that can be use for spawning a new Main_class instance.
Main_class as SpawnClass
.
x : x coordinates
y : y coordinates
.
Can_render : Determine if class is visible or not
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);
}A function that checks whether Main_class instance hit another Main_class instance.
Main_class as other
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;
}
}
}you need to set up this function manually
to destroy a Main_class instance you need to make spawn variable false. like this :
public void Example_Function()
{
spawn = false;
}