Git Product home page Git Product logo

graphgame's Introduction

Graphgame

Graphgame is a game engine for Desmos. It has an object system based on Unity, where objects have behaviors that control what they do. It makes it easy to write and apply behaviors to objects and interact with other objects. Below is a quick overview of Graphgame's foundation.

Foundation

The foundation document explains certain concepts that Graphgame uses (such as objects and behaviors) in detail.

API

The API reference is available here.

Usage

Logimat

Graphgame is a template library for Logimat. That means that you write your code in Logimat, and use Graphgame's templates to do special functions such as creating objects/behaviors. Logimat is a language based on Javascript that compiles to either raw math, or in this case, Desmos.

Templates

Templates are how Graphgame functions. In essence, they are calls to Javascript code that get replaced by the output by said code. When they are ran, templates get replaced by Logimat code, and they help to abstract away a lot of the work of managing the game. Templates look like functions, although their name ends with a "!".

Using Graphgame

To use Graphgame, you should first take a look at a few of its examples, which showcase how Logimat and Graphgame templates work. You should also take a look at the and for more detailed information on how to do certain things in Graphgame.

Main file

One important way that Graphgame projects are structured is through a main file (called main.lm). This main file is responsible for importing and initializing Graphgame, as well as importing other files.

Graphgame studio

The recommended way to use Graphgame is through Graphgame Studio. Graphgame Studio is an online (although it can be installed as offline) IDE for Graphgame, and includes many useful features, such as a built-in Desmos viewer, basic Github integration, and a code editor. The main benefits to using it are:

  • A fully setup development environment.
  • A streamlined process for sending compiled output to Desmos.
  • Support for display options.
  • Syntax highlighting.
  • Faster compile times.

Graphgame Studio is available at https://graphgame.js.org.

Examples

Here is a basic example of how you might use Graphgame. Below is a ball that will move upwards every frame, and will go back to zero if it reaches the top of the screen:

//These statements allows you to use Graphgame.
import templates from "graphgame";

initialize!();

//Create a max_y. This will be used below.
inline const max_y = 20;

//First, we need a behavior to move the ball. We'll call it "mover".
createBehavior!("mover", {
    //Next, we need to actually move the ball. We use setValAction to do this. It sets a variable to something each frame, as opposed to setVal, which sets the object's starting value.
    //The "{}" is called an action body. It contains code statements.
    setValAction!("base.transform.y", {
        //First, add 1 to the current y value.
        //We can access the variable we're updating like this. Other variables need to be accessed with getVal.
        const new_y = y + 1;
        
        //Next, we'll check if it's above our max y.
        //If it is, we'll set the state to 0, otherwise we'll set it to the new y value.
        //The state is like our return value. In Logimat, we can't early return, so we set the return value throughout the code. At the end of the function, whatever the state is will be the result of the function.
        //At each branch of an if statement (if, else if, else) the state must be set. Additionally, if an if has no else, the state must be set at some point before the if is used.
        if(new_y > max_y) {
            0
        } else {
            new_y
        }
    });
});

//Now that we have our behavior, we can create an object.
//We'll first create an object.
createObject!({
    //Next, we'll attach the mover behavior to it to make it move.
    useBehavior!("mover");
    
    //Finally, we'll add a circle renderer to it so that it displays.
    useBehavior!("circle");
});

//That's it. Now, if we compile it, we'll see a ball moving upwards until it hits the top, and going back to 0.

graphgame's People

Contributors

uellenberg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

ericlloydnsc-cs

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.