Posts tagged AGE

iconOneGameAMonth

Planets experiment

1

So now, it’s officially the 1PAM (one prototype a month).

It’s a simple conquest game, my first targeting HTML5. So it was more an excuse to update my game engine, so that it can compile to js.

AGE is still an Haxe framework, but now NME is not required anymore.
The engine will be compatible Flash (again) soon.

Here is the link, if you want to test it.

screenshotsaturday

AGE – How to support physic engines

0

In the previous post, we have seen how to use the Box2D support into the AGE engine. Now I just want to show you how simple it is to add a new framework/engine support.

For example, we are going to add the Nape support.

For those of you who don’t know, Nape is a Haxe/AS3 physics engine. Since Nape is really close to Box2D, it will be simple to understand how box2d has been added to AGE.

The behavior

Since AGE is based on a behaviors system, we are just going to create a new behavior, that we will call NapeMovementBehavior :

class NapeMovementBehavior implements IBehavior
{
    private var _entity : BasicEntity;
    public var enabled(default, null) : Bool;
 
    public function update():Void {}
 
    public function enable()
    {
	enabled = true;
    }
 
    public function disable()
    {
	enabled = false;
    }
 
    public function destroy():Void {}
}

Now we are going to initialize the data needed by Nape for the behavior’s entity :

private var _body : Body;
public static var world : Space;
public function new(pEntity: BasicEntity, pDynamic:Bool)
{
    if(world == null)
        world = new Space( new Vec2(0, 500) );
 
    _body = new Body( (pDynamic ? BodyType.DYNAMIC : BodyType.STATIC), 
                       new Vec2(pEntity.x + pEntity.halfWidth, pEntity.y + pEntity.halfHeight)
                   );
 
    var block:Polygon = new Polygon(Polygon.box(pEntity.width,pEntity.height));
 
    _body.shapes.add(block);
    _body.align();
 
    _body.space = world;
 
    _entity = pEntity;
}

If you need more information on how Nape is working, go check the documentation.
So for now, we have a basic entity initialized for working into Nape.
(more…)

Box2D_logo

AGE – Box2D support

1

Since Box2D is one of the most used physics engine, I’ve started to implement it into the AGE game engine.

I’ve used the box2d version from haxelib, so don’t forget to add the following to your nmml file :

<haxelib name="box2d"></haxelib>

I’ve implemented it with the behaviors system. So now we have a Box2dEntity that has a special Behavior (Box2dMovementBehavior) which initialize and update all the Box2D stuff.

For example, to define an entity :

import com.revolugame.age.display.Box2dEntity;
 
class Block extends Box2dEntity
{
    public function new (pX: Int, pY: Int)
    {
        super(pX, pY);
        makeGraphic(32, 32, 0xFF000000);
        initBox2dStuff(30, true, 0, 0, 0);
//                                     ^ friction
//                                  ^ restitution
//                               ^ density
//                          ^ if the entity is dynamic
//                     ^ conversion meters to pixels
    }
}
add(new Block(10, 50));

And that’s it !

The Box2D support works with Flash and C++ but needs some optimization for now.
(more…)

tree2

AGE – QuadTree implementation

3

What is the QuadTree ?

If we look at the wikipedia page, we can find a small explanation (it’s the best one I have found so far) :

A quadtree is a tree data structure in which each internal node has exactly four children. Quadtrees are most often used to partition a two dimensional space by recursively subdividing it into four quadrants or regions.

Why would I add it ?

The first approach to detect collisions between entities was to check for each entity if it collided with one of the others entities in the world. So you can use this method for a really small game, because the number of tests is not that big. But if you have, for example, a game with 100 entities moving around the screen, which can collide with each other, the number of tests between entities will be 100×100 !! And at least half (probably more) of them are not necessary.
The Quadtree allows you to eliminate those unnecessary checks.

How does it work ?

Each time an entity is added to the stage, we just have to look into the tree and find where to put it. A node is simply a rectangular zone with entities and other nodes in it.

So basically, any node will be divided in 4 nodes if more than n entities are completely contained within the node. For AGE, I have decided to use n = 2.

Here is a more concrete example :

The world has 1 entity, the entity is added to the root node (depth = 0).

 

A second entity is added, so the world has been divided. The first entity (the red one) is pushed down to the top left node, and the second one is pushed down to the top right node (depth = 1).

 

A third entity is added to the stage. This one is contained in the top left node. This node has already another entity, so we just divide this node in 4. Now the first entity (the red one) does not fit entirely in a sub node, so this entity is going to stay on the same node (top left at depth 1). But the other entity (the blue one) is pushed down to the bottom right node at depth 2. For the last entity, nothing has to change for now.

 

Now, our tree has been set. Before checking for collisions, we have to query the tree to determine which entities are worth testing for a rectangular zone (the rectangular zone can correspond to the theoretical position of an entity, to know if we can move it or not). So, the quadtree is going to return each entity contained in a node that have an intersection with our request zone (we have to return entities that are not entirely in a sub node too).
(more…)

AGE project setup

2

Since the 0.2 version, you can quickly and easily install AGE in haxelib, just by using the ant task :

git clone https://github.com/po8rewq/AGE.git
ant

For now, you can run the following command to setup a new project :

haxelib run AGE

This will generate a basic structure for your project, with the nmml file, and the MonoDevelopFlashDevelop project files.

Here is the list of all arguments you can use :

  • -help : the help screen
  • -output : /your/project/directory (default: the current directory)
  • -name : Your Project Name
  • -main : MainProjectClass (default: Main)
  • -size : WIDTH HEIGHT (default: 800×600)
  • -fps : FPS (default: 30)
  • -bgColor : COLOR (default: 0xCECECE, you can use both 0xFF0000 and #FF0000 syntax)

This tool has only been tested on Linux …

AGE : Another Game Engine

12

I’ve tried a lot of game engines since I’ve started making games. And I’ve never been completely happy with them… so I have decided to develop and share my new Haxe/NME game engine.

Why another engine ?

For the past two years I have built game engines, first for AS3, then for Haxe just to learn how it works. I have made games with Flixel, Flashpunk (for the most known), but each time there is something I am not confortable with (how collisions are handled in Flixel for example). So as they say, if you want something done, it’s better to do it yourself: that’s why I decided to create my own game engine, in order to use a tool that’s best suited for me. Despite the specificities I wanted to add, I tried to keep it as simple and as generic as possible.

Basic concepts : the behaviors

Ever since I discovered this behaviors concept, it seems that I can’t do without it!

But what is this ? It’s a small concept, but it’s so simple that I don’t understand why no other game engines (that I am aware of) use it.

For example, you can have a default jump behavior, and if the player catches a power up, you can enable the jet pack behavior :

class Player extends Entity
{
    private var _jumpBehavior : JumpBehavior;
    private var _jetpackBehavior : JetPackBehavior;
 
    public function new()
    {
        super(0, 0);
 
        _jumpBehavior = new JumpBehavior(this);
        addBehavior(_jumpBehavior);
 
        _jetpackBehavior = new JetPackBehavior(this);
        addBehavior(_jetpackBehavior, false);
    }
 
    public override function update()
    {
        super.update();
        if( powerup )
        {
            _jumpBehavior.disable();
            _jetpackBehavior.enable();
        }
    }
}

And all the player needs to do is in the update() function of the Behavior Class.
So simple, and you can add it to any entity you like.

By default, there is two behaviors : Collisions and Movements.
You can decide not to use them. But if you want collisions and movement, just activate them:

solid = true;
movable = true;

Follow the work on github.

Go to Top