Home

Awesome

mgl (Mini Game programming Library)

Mgl is a mini game programming library written in Haxe + OpenFL. Mgl is useful for creating a simple Flash game in short term. HTML5/Windows build targets are partially supported.

Using the SiON synthesizer library.

Using the as3gif animated gif encoder.

Sample games

SCAFFOLD NOW / DON'T SEE ME / MISSILE COMES BACK TO ME / PROMINENT MOUNTAIN / BADDALION / SUM10 / WASD THRUST / LURE AWAY / FROM FOUR SIDES / PINCER ATTACK / STRONG BUY STRONG SELL / OVEREXPLODE / DETERMINISTIC PANELS / CUT OFF LINE AMEBA / EARTH DEFENSE STICKS / SIDE WALLS MULTI KICKS / POLE SLIP DOWN / CALC +-*/ / TYPHOON AVENUE / LEFT RIGHT HAND RULE / REFLECTOR SATELLITES / BALLOON BURROWER / SATELLITE CATCH / POLAR NS

Sample games (using the older version mgl)

LONG EDGE WINS / REVGRAV / SPACE SHIPS CONTACT ACCIDENTAL / YOU HAVE ONE SHOT / SIDE SHOT BOOSTER / MAGNETIC ACTION

Advantages

Limitations

Sample code

BALL 28 IN SPACE

import mgl.*;
using mgl.Fiber;
using mgl.Util;
// A basic game loop handling class.
class Main extends Game {
	static public function main() {
		new Main();
	}
	function new() {
		super(this);
	}
	var bgmDrumSound:Sound;
	var endGameSound:Sound;
	// initialize() --> Title -> begin() -> update()(every frame) -> Begin the game -v
	//                    ^    v-----------------------------------------------------<
	//                    ^  begin() -> update()(every frame) -> End the game -v
	//                    ^----------------------------------------------------<
	// First initializer.
	override function initialize() {
		Ball.main = this;
		// Apply quarter-note quantization.
		Sound.setDefaultQuant(4);
		// Generate sounds.
		bgmDrumSound = new Sound().setDrumMachine();
		endGameSound = new Sound().major().setMelody()
			.addTone(.3, 10, .7).addTone(.6, 10, .4).end();
		// Set the title.
		setTitle("BALL 28 IN SPACE");
	}
	public var ballLeft:Int;
	var nextBallCount:Int;
	var time:Int;
	// Begin the title/game.
	override function begin() {
		Ball.player = new Player();
		nextBallCount = 0;
		ballLeft = 28;
		time = 0;
		// Play the bgm.
		bgmDrumSound.play();
	}
	// Update every frame.
	override function update() {
		var sc = Std.int(time / 1000);
		var ms = '00${time % 1000}';
		ms = ms.substr(ms.length - 3);
		// Draw elapsed time at the upper right aligned right.
		new Text().setXy(.99, .01).alignRight().setText('TIME: $sc.$ms').draw();
		// If the game isn't begun then return.
		if (!Game.isInGame) return;
		time += 16;
		// Draw the number of left balls at the upper left.
		new Text().setXy(.01, .01).setText('LEFT: $ballLeft').draw();
		if (ballLeft <= 0) {
			// Play the game ending sound.
			endGameSound.play();
			// End the game.
			Game.endGame();
		// Get all ball actors and check a total of them.
		} else if (Actor.getActors("Ball").length <= 0) {
			nextBallCount++;
			for (i in 0...nextBallCount) new Ball();
		}
		// Instructions drawn only once.
		if (Game.ticks == 0) {
			new Text().setXy(.1, .1).setText("[urdl]: MOVE").setTicks(180).addOnce();
		}
		if (Game.ticks == 60) {
			new Text().setXy(.1, .15).setText("[Z]: BRAKE").setTicks(180).addOnce();
		}
	}
}
// Player actor.
class Player extends Actor {
	static var tickSound:Sound;
	// Static initializer called only once.
	override function initialize() {
		// Generate the green shape.
		dotPixelArt = new DotPixelArt().setColor(Color.green).generateShape(.04, .05);
		// Set the hir rect.
		setHitRect(.04, .05);
		// Set the tick sound.
		tickSound = new Sound().minor().addTone(.5, 3, .3).end();
	}
	// Begin this actor.
	override function begin() {
		// Set the position to (.5, .5).
		position.setNumber(.5);
		// Create the fiber to play the tick sound every 30 frames.
		new Fiber(this).wait(30).doIt( { tickSound.play(); } );
	}
	// Update every frame.
	override function update() {
		// Get the joystick input and add to the velocity.
		velocity.add(Key.stick.multiply(.003)).multiply(Key.isButtonPressing ? .6 : .95);
		// Loop the position between -.05 and 1.05.
		position.setXy(position.x.loopRange(-.05, 1.05), position.y.loopRange(-.05, 1.05));
		// Set the way to the velocity way.
		way = v.way;
		// Add the reddish green particle from the position.
		new Particle().setPosition(position).setColor(Color.green.goRed())
			.setWay(way + 180, 45).setSpeed(velocity.length).add();
		// Check the hit to the Ball actors.
		isHit("Ball", function(ball) {
			// If the player hit the ball, erase the ball.
			ball.erase();
		});
	}
}
// Ball actor.
class Ball extends Actor {
	static public var main:Main;
	static public var player:Player;
	static var removeSound:Sound;
	override function initialize() {
		// Set the circle yellow shape.
		dotPixelArt = new DotPixelArt().setColor(Color.yellow).generateCircle(.04);
		setHitRect(.04);
		// Set the removing sound.
		removeSound = new Sound().minor().addTone(.7).addRest().addTone(.7).end();
	}
	override function begin() {
		for (i in 0...10) {
			// Set the random position from .1 to .9.
			position.setXy(.1.randomFromTo(.9), .1.randomFromTo(.9));
			// If the distance to the player is far enough then break.
			if (position.distanceTo(player.position) > .3) break;
		}
	}
	public function erase() {
		// Add 20 particles.
		new Particle().setPosition(position).setColor(Color.yellow.goRed())
			.setCount(20).setSize(.03).add();
		main.ballLeft--;
		// Play the removing sound.
		removeSound.play();
		// Remove this actor.
		remove();
	}
}

Classes

A shortened form of a class/method name is described in ( ).

Game (G)

A basic game loop handler. You have to override the initialize(), begin() and update() method.

Methods
Overriden methods

Actor (A)

An actor moves on a screen. An actor has a position, a velocity and a dot pixel art.

Variables
Methods
Overriden methods

DotPixelArt (D)

A pixel art for an actor. You can write a rectangle, a circle and an auto generated shape.

Methods

Sound (S)

A 8-bit era style sound effect.

Methods

Particle (P)

Particles splashed from a specified position.

Methods

Text (T)

Showing a text on a screen in a certain duration ticks.

Methods

Random (R)

Random number generator.

Methods

Fiber (F)

Set the do block and the block runs constantly for a specified wait ticks.

Methods

Color (C)

RGB color.

Variables
Methods

Key (K)

Key and joystick input status.

Variables
Methods

Mouse (M)

Mouse input status.

Variables

Vector (V)

2D vector.

Variables
Methods

Util (U)

Utility methods.

Methods

License

Copyright © 2013-2014 ABA Games

Distributed under the MIT License.