Skip to content
/ Zote Public

Zote is a 2D Game Engine developed for my final university assignment.

Notifications You must be signed in to change notification settings

asu4net/Zote

Repository files navigation

drawing

Zote Engine

Zote is a 2D Game Engine developed for my final university assignment.

Features

  • Scene
  • Camera (Orthographic and Perspective)
  • Entities and Components
  • 2D Rendering
  • 2D Physics
  • Scripting System
  • Build System
  • Input System

Build

  • Ensure you are using Windows 64-bit
  • Ensure you have Visual Studio 2022 installed
  • Clone this project
  • Open the project's root folder
  • Run GenerateProjects.bat
  • Open Zote.sln
  • Build the Game project
  • Hit the play button and ✨Enjoy✨

Hello Zote

Window setup

Zote doesn't have an Editor yet. So if you want to create a brand new game some basic setup is required. In order to start writing code go to the Game project and open Game.cpp. Then, inside the Run method, create your first Window and call his Init() and StartLoop() methods.

Ref<Window> myWindow = MakeRef<Window>();
myWindow->Init();

//Your scene setup code goes HERE.

myWindow->StartLoop();

The window must be constructed as a reference. The Ref syntax is just a normal shared pointer. The StartLoop() method initialises the window loop. So if you write code after that function it won't execute until the Zote Window get's closed.

Running the application now should open an empty grey window.

First entity

In order to create entites a Scene instance is required. At this point you can't create multiple scenes. After the scene initialisation you can call the scene CreateEntity() method and start adding components to it.

Scene myScene(myWindow);
Entity zote = myScene.CreateEntity();
zote.AddComponent<SpriteComponent>("Textures/alex.png");

At this point by running the application you should be experiencing the pleasure of being in the presence of Alex, the creator of this high tech engine.

Script System

The script system is quite similar to the Unity Monobehiavours. Behind the scenes works with the ECS pattern but the usage is more simple. To start using scripts you must to add the ScriptComponent to your entity.

Then, you can create your script in new .h and .cpp separated files. The next example will show how to create a script that changes between two sprites:

SwitchBetweenSprites.h

#pragma once
#include <ZoteCommon.h>

using namespace Zote;

class SwitchBetweenSprites : public Script
{
public:
	cstr pathA = "Textures/csharp.png";
	cstr pathB = "Textures/cpp.png";
	float timeToSwitch = 1;

	void Start() override;
	void Update(float deltaTime) override;

private:
	
	Entity thisEntity;
	bool change = false;
	float currentTime = 0;

};

SwitchBetweenSprites.cpp

#include "SwitchBetweenSprites.h"

void SwitchBetweenSprites::Start()
{
	LOG("Script SwitchBetweenSprites started");
	thisEntity = GetEntity();
}

void SwitchBetweenSprites::Update(float deltaTime)
{
	auto& spriteComponent = thisEntity.GetComponent<SpriteComponent>();
	
	currentTime += deltaTime;

	if (currentTime < timeToSwitch)
		return;

	currentTime = 0;

	cstr path = change ? pathA : pathB;
	spriteComponent.AddTexture(path);
	change = !change;

	LOG("Sprite texture updated to: " << path);
}

When the script is ready go back to Game.cpp and don't forget to write the preprocessor statement, for this example: #include "Scripts/SwitchBetweenSprites.h". By using the AddScript() method you can attach the script to the script component. It is possible to call this function with multiple scripts to attach them to a single Entity. It's mandatory to create the script instance as a pointer. This is the final code inside the Run() method.

Ref<Window> window = MakeRef<Window>();
window->Init();

Scene scene(window);

Entity myEntity = scene.CreateEntity();
myEntity.AddComponent<SpriteComponent>();

auto& myEntity_Scripts = myEntity.AddComponent<ScriptComponent>();
myEntity_Scripts.AddScript(new SwitchBetweenSprites());

window->StartLoop();

By hitting the run button you should see, in first place a blank quad, and then the csharp and cpp textures switching in the screen.

About

Zote is a 2D Game Engine developed for my final university assignment.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published