Code Monkey home page Code Monkey logo

easy2d's Introduction

Contributors Forks Stargazers Issues MIT License LinkedIn


Logo

Easy 2D

A simple but robust 2D game engine/API aimed to create simple 2D games.
Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgements

About The Project

This engine was initially oriented on a simple game that me and my father decided to make: Tank Wars. Frankly, I wanted to create a more of like an engine that simplifies the process of creating various types games, instead of focusing on a single game. That's why I have started the Easy 2D project - in which I improve my C and OpenGL knowledge with creating a useful software that creates things I love. Also note that this Engine (though as of now it really is an API/Wrapper of OpenGL) is only focused on 2D rendering, however after this project I may implement Easy3D which focuses on 3D rendering.

Also, you may find the code obscure/not professional - since I develop the library as I learn (on the fly). If you do, please send me an email ([email protected]) and I would be happy to alter the code according to your observation.

A note: Since the engine is currently under development, the codebase lacks quality at some parts, however I aim to refactor this whole engine once I get things up going on and working.

Built With

Getting Started

To get this engine locally, there are 2 options for you: 1) build & install from the source (recommended), 2) download the prebuilt binaries for your platform (as of now the engine supports UNIX machines). All the dependencies of the engine are already in the repo, so no need to download any external library locally (although cmake must be installed if you are planning to build from the source). Here are some simple steps to get this engine up and running locally on your system.

Prerequisites

  • CMake (If you are planning to build from the source)

Installation

Building & Installing from source

  1. Clone the repo
    git clone https://github.com/ehurturk/Easy2D.git
  2. Create the build directory
    mkdir -p ./build
  3. Generate the build files
    cd build && cmake ..
  4. Compile the project
    make # if a problem happens, try adding sudo (ex: sudo make)
  5. Install the library to your system
    sudo make install # you can change where to install the library by editing the Makefile

Downloading the prebuilt binaries for your platform

Here is the download link to download the correct binaries without building from the source code. To be able to successfully install Easy2D to your system, just move the downloaded library file (libEasy2D.dylib for mac) to /usr/local/lib, and the whole include folder to /usr/local/include.

Usage

Including the library into your project

Although the library is made using the C programming language, it can be used within C++ projects as well. After you have completed the installation process, the necessary dynamic library would be placed under /usr/local/lib directory, whereas the necessary include files would be placed under /usr/local/include directory.

  • Using a package manager like CMake:

    I recommend using cmake as the build file generator which simplifies the entire process. For projects using CMake, here is a simple CMakeLists.txt file to get you started with Easy2D:

    # CMakeListst.txt, placed inside the root directory of the project.
    cmake_minimum_required(VERSION 3.19)
    project(PROJECT_NAME)
    
    set(CMAKE_CXX_STANDARD 17) # for C++17 standard
    set(CMAKE_C_STANDARD 99) # for C99 standard
    
    find_library(Easy2DLIB libEasy2D.1.0.dylib) # locate the dynamic library file inside /usr/local/lib/
    message(STATUS ${EASY2D_LIB}) # output the path of the lib to see if cmake found the file or not
    
    include_directories(/usr/local/include) # since the Easy2D include files are placed under /usr/local/include, you need to include this inside cmake to be able to access the header files
    add_executable(PROJECT_NAME main.cpp)
    target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC ${Easy2DLIB})
  • Using a simple Makefile:

    LIB=-L/usr/local/lib # the lib location
    INC=-I/usr/local/include # the include direction
    CC = g++ # the g++ compiler
    CFLAGS = -Wall # enable all warnings
    
    default:    main
    
    main: 
        $(CC) $(CFLAGS) $(INC) main.cpp -o main
    
    clean:
        rm -r test.o make.out

Example demonstrating a simple sprite being rendered

Here is a boilerplate code that makes use of Easy2D which renders a white rectangle in the middle of the screen:

#include <Easy2D/easy2d.h> /* the public header file (note: use angled brackets (<>) */

#define EZ_DEBUG_ENABLED

void init();
void update();
void destroy();

EZApplication *app; /* the main application */
EZScene *scene; /* the scene containing all gameobjects, camera, etc. */

int main() {
    app = ezCreateApplication();
    /* After creating the application, you need to register it to Easy2D */
    ezRegisterAsApplication(app);
    /* Then bind the functions */
    ezBindAppInitCallback(init);
    ezBindAppUpdateCallback(update);
    ezBindAppDestroyCallback(destroy);
    
    ezStart(); /* start Easy2D application */

    return 0;
}


void init() {
    app->window   = ezCreateWindow("Easy2DSandbox", 800, 600);
    scene         = ezCreateScene();
    EZCamera *cam = ezCreateCamera(EZ_ORTHOGRAPHIC);
    ezAddToScene(scene, (void *)cam, EZ_CAMERA);

    /* Create a sprite with default shader which implements proj and model matrices by default */
    EZSprite *sprite = ezSquareSprite();

    // Alternatively, you can bind your own shaders / textures the sprite using:

    // EZShader *shader      = ezDirectShaderPipeline(2, 
    //                                (EZShaderInfo){.type = EZ_VERTEX_SHADER, .src = "../res/simple.vs"},
    //                                (EZShaderInfo{.type = EZ_FRAGMENT_SHADER, .src = "../res/simple.fs"}));
    // ezSetSpriteShader(sprite, shader);

    // EZTexture *tex1 = ezLoadTexture("../res/barack.jpeg");
    // ezSetSpriteTexture(sprite, tex1); */

    /* Add the sprite to the scene */
    ezAddToScene(scene, (void *)sprite, EZ_GAMEOBJECT);
}

void update() {
    /* The main loop */
    while (!ezIsWindowOpen(app->window)) {
        /* Renderer stuff */
        ezSetBackgroundColor(0.0f, 0.0f, 0.0f, 1.0f);
        ezClearFrame();
        
        /* Render the current scene */
        ezRenderScene(scene);
        ezUpdateWindow(app->window);
    }
}

void destroy() { 
    /* The cleanup method basically */
    ezFreeApp(app); /* deallocate the app */
    ezDestroyScene(scene); /* deallocate all the objects the scene includes, and their dependent objects */
}

For more examples, please refer to the Documentation or the Sandbox Repository.

Supported Platforms

The engine currently supports UNIX machines since it uses dll

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Emir Hurturk - [email protected]

Project Link: https://github.com/ehurturk/Easy2D

easy2d's People

Contributors

ehurturk avatar

Stargazers

mohamad hani janaty avatar  avatar YENLING LIN avatar  avatar  avatar  avatar Cem Hurturk avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.