Giter Site home page Giter Site logo

ChEngine

Quick-start Java application skeleton for simulation and gaming. ChEngine is driven by a runtime loop, making use of one method for behind-the-scenes program logic and another for rendering images to the screen.

Get the latest build here.

Usage

The core of ChEngine is ChApplication, an abstract class that can be extended directly or indirectly via ChApplicationAdapter. The adapter class is a child of ChApplication and implements all the required methods with an empty definiton, acknowledging that not all of the capabilities offered by ChEngine are practical in every program solution.

The current abstract methods in ChApplication are init, update, render, and draw.

  • void init() Allows the execution of code before the main thread is started (via start()). Typical usage is to load resources, add additional components to the frame via addToFrame(Component...components) in ChApplication, and to set the application visibility (default is invisible, or ChApplication.Attribute.visible = false).

  • void update() Often called tick in other projects, this method is called a given number of times per second (updates per second / ups) and handles the logic of the program.

  • void render(ChGraphics g) Draw graphics using the custom ChGraphics context g. Some standard methods in ChGraphics include clearing the screen and setting a background gradient.

  • void draw(Graphics g) Draw graphics using the standard java.awt.Graphics context g.

Summary :

  • To use ChEngine, extend either ChApplication or ChApplicationAdapter located in cmurphy.ch.engine.core.
  • Five methods define the program lifecycle, init, update, render, draw, and stop. (actually not stop yet!!)
  • ChApplcation has various static fields in the inner classes Attribute and Flag which are directly configurable.
  • To start the application, instantiate a child of ChApplication and call start(). See the Launcher.java and ChEngineDemo.java below.

Launcher.java

When ready to launch the program, a launcher class is recommended. Below is an example of a launcher class.

import cmurphy.ch.engine.core.ChApplication;

public class Launcher {
    public static void main(String[] args) {
        ChApplication.Flag.verbose = true; // prints additional information to the console
        ChApplication demo = new ChEngineDemo(); // where ChEngineDemo is a child of ChApplication
        demo.start();
    }
}

ChEngineDemo.java

Creates an animated background gradient and then automatically closes the program after five seconds.

import cmurphy.ch.engine.core.*;
import cmurphy.ch.engine.util.ChGraphics;

public class ChEngineDemo extends ChApplicationAdapter {
    
    private static final long serialVersionUID = 1L;

    protected void init() {
        Flag.visible = true;
    }

    protected void update() {
        if(System.nanoTime() - time() > 5e9)
            stop();
    }
    
    protected void render(ChGraphics g) {
        g.gradient(java.awt.Point(0, 0),
                   java.awt.Point(ChApplication.Attribute.width, ChApplication.Attribute.height),
                   0x70F4E5,
                   0xF4707F);
    }
}

chengine's Projects

chengine doesnโ€™t have any public repositories yet.

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.