Skip to content

VikramSGIT/MarsEngine

Repository files navigation

Welcome to MarsEngine

MarsEngine is Real-Time 3D Creative Engine. MarsEngine focuses over High Stablity and Portablility. Also MarsEngine targets toward very Low Memory usage. For now MarsEngine is a early build, only libraries are available.

Making a Game within A Minute

MarsEngine has well built libraries capable of building a Game in minutes.

Prerequisite

Step 1:

  • Make a directory where game needs to be build.
  • Clone/download MarsEngine easy_game branch.
  • Extract this zip file into the directory.

Step 2:

  • Open Application.cpp file in Visual Studios ( or using any other code editor?).
  • Paste this code into Paste Code Here!! inside Application.cpp.
  Ref<ME::Mesh> Logo = ME::GenRect("Vikram", glm::vec2(590.0f, 310.0f), glm::vec2(690.0f, 410.0f));
  Logo->Scale( {3.4f, 2.0f, 1.0f} );
  Logo->SetReset(Logo->GetVertices());
  ME::MeshQueue Queue;
  Queue.PushMesh(Logo);

  Ref<ME::Renderer::Shader> shader = CreateRef<ME::Renderer::OpenGL::OpenGLShader>("MarsEngine\\MarsEngine\\res\\shaders\\Basic.shader");
  glm::mat4 MVP = glm::ortho(0.0f, 1280.0f, 0.0f, 720.0f);
  shader->SetUniformsMat4f("u_MVP", MVP);

  Ref<ME::Renderer::OpenGL::OpenGLTexture> texture = CreateRef<ME::Renderer::OpenGL::OpenGLTexture>("MarsEngine\\Branding\\MarsEngine\\MarsEngine.png");
  renderer->AddRenderSubmition(Queue, [&texture, &shader]()
  {
  	texture->Bind();
  	shader->SetUniforms1i("u_Texture", texture->GetSlot());
  });

  /// Editable///
  glm::vec3 gravity(0.0f, -9.8f, 0.0f);
  glm::vec3 forceX(5.0f, 0.0f, 0.0f);
  glm::vec3 forceY(0.0, 20.0f, 0.0f);
  float e = 0.8;
  ///
  glm::vec3 speed(0.0f, 0.0f, 0.0f);

  ME::Utils::Time::timer timer;
  while(Running)
  {
  	if(timer.TimeElapsed()[0] > ME::Utils::Time::milliseconds(10))
  	{
  		speed += gravity;
  		if(window->IsKeyPressed(Event::Key::W))
  			speed += forceY;
  		if(window->IsKeyPressed(Event::Key::A))
  			speed -= forceX;
  		if(window->IsKeyPressed(Event::Key::S))
  			speed -= forceY;
  		if(window->IsKeyPressed(Event::Key::D))
  			speed += forceX;
  		
  		Logo->Translate(speed / glm::vec3(10.0f, 10.0f, 1.0f));
  		timer.Reset();
  	}

  	for(ME::VERTEX vertex : Logo->GetVertices())
  	{
  		if(vertex.vertices[0] <= 0.0f)
  		{
  			speed.x = std::abs(speed.x) * e;
  			Logo->Translate({-vertex.vertices[0], 0.0f, 0.0f});
  		}
  		else if(vertex.vertices[0] >= 1280.0f)
  		{
  			speed.x = -std::abs(speed.x) * e;
  			Logo->Translate({1280.0f -vertex.vertices[0], 0.0f, 0.0f});
  		}
  		if(vertex.vertices[1] <= 0.0f)
  		{
  			speed.y = std::abs(speed.y) * e;
  			Logo->Translate({0.0f, -vertex.vertices[1], 0.0f});
  		}
  		else if(vertex.vertices[1] >= 720.0f)
  		{
  			speed.y = -std::abs(speed.y) * e;
  			Logo->Translate({0.0f, 720.0f -vertex.vertices[1], 0.0f});
  		}
  	}
  	if (glfwWindowShouldClose(window->GetNativeWindow()))
  		Running = false;

  	renderer->Draw(shader);
  	renderer->OnUpdate();
  	window->OnUpdate();
  }
  • Now run TheGame.bat on your working directory.
  • Feel the Magic!!

This guide will soon be updated with the things you can play within to make the game much cooler.