Coder Social home page Coder Social logo

alge's Introduction

alge

Scene -> Entity -> Component based game engine written in Typescript.

Created and used for personal purpose only, use at your own risk.

There is no documentation available at the moment.

Usage

Basic player controlled entity example:

File structure:

.
+-- index.ts
+-- entities
|   +-- Player.ts
+-- components
    +-- PlayerController.ts

Create a PlayerController component to manage inputs from the player:

// components/PlayerController.ts
import { Component, InputManager, Key, Cursor, TimeManager } from "alge";

export default class PlayerController extends Component {
	
	protected input : InputManager = this.parent.engine.getManager("Input");
	protected time : TimeManager = this.parent.engine.getManager("Time");;
	public speed : number = 10;

	public init() {
		this.input.SetCursor(Cursor.Hidden);
	}
	
	public update() {

		if (this.input.getKeyDown(Key.UpArrow)) {
			this.parent.transform.position.y -= this.speed * this.time.deltaTime * 100;
		}
		if (this.input.getKeyDown(Key.DownArrow)) {
			this.parent.transform.position.y += this.speed * this.time.deltaTime * 100;
		}
		if (this.input.getKeyDown(Key.LeftArrow)) {
			this.parent.transform.position.x -= this.speed * this.time.deltaTime * 100;
		}
		if (this.input.getKeyDown(Key.RightArrow)) {
			this.parent.transform.position.x += this.speed * this.time.deltaTime * 100;
		}
	}
}

Create a Player entity and add a Sprite component to display a sprite and the PlayerController component previously created:

// entities/Player.ts
import { Entity, Sprite, Engine} from "alge";
import PlayerController from "../components/PlayerController";

export default class Player extends Entity {

	protected sprite : Sprite;
	protected controller : PlayerController;

	public create() {
		this.sprite = new Sprite(this, "Sprite", { 
			src: this.properties["sprite"],
		});
		this.addComponent(this.sprite);

		this.controller = new PlayerController(this, "Controller");
		this.addComponent(this.controller);
	}
}

Instanciate the alge's Engine class and create a PIXIScene using the PIXISceneManager. Then add a Camera and your Player entity to the scene and run the engine:

// index.ts
import { Engine, PIXIScene } from 'alge';
import Player from "./entities/Player";

const game = new Engine({fullscreen: true});

let mainScene : PIXIScene = game.getManager("Scene").createScene("MainScene");

let camera = new Camera("MainCamera");
mainScene.addEntity(camera);

let player = new Player("Player", { sprite:"path/to/sprite" });
mainScene.addEntity(player);

game.run();

License

alge is distributed under the MIT License. See LICENSE for more information.

Contact

Buy me a coffee badge LinkedIn badge

Colin Espinas - Website - [email protected]

Project link: https://github.com/ColinEspinas/alge

alge's People

Contributors

colinespinas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

alge's Issues

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.