To check what can we reach with Heaps we tried the official samples and we tried to combine them. The result is a 3D world with wandering 3D models – of course with pathfinding. Try it now! Do you want to check the source code? Let’s download!

Set up Heaps

class Main extends App
  static function main()

    new Main();

  override function init()

It’s really simple. Just extends the App and init the Resources.


To get the basics knowledge try the Skin sample from Heaps source.
I made a really simple Character class based on it. With this modification it can move in the world. Here is a little part from this modification:

function move(targetPoint:SimplePoint, onComplete:Void->Void):Void
  // Change target point to world point (Yeah maybe it's not the best place for this calculation)
  targetPoint.x = targetPoint.x * GameWorld.instance.blockSize + GameWorld.instance.blockSize / 2;
  targetPoint.y = targetPoint.y * GameWorld.instance.blockSize + GameWorld.instance.blockSize / 2;

  // Calculate tween time based on distance and character speed
  var distance = GeomUtil.getDistance(targetPoint, { x: view.x, y: view.y });
  var tweenTime = (distance / baseSpeedBlock) * speed;

  Actuate.tween(view, tweenTime, { x: targetPoint.x, y: targetPoint.y }).ease(Linear.easeNone).onUpdate(updateHack).onComplete(onComplete);
  // Rotate with tween
  Actuate.tween(this, .3, { viewRotation: Math.atan2(targetPoint.y - view.y, targetPoint.x - view.x) + Math.PI / 2 }).ease(Linear.easeNone).onUpdate(updateRotation);

// If we don't call this method the character "jumping" instead of moving, it looks an Actuate bug with haxe 4.0.0 or some Heaps problem.
function updateHack():Void
  view.x = view.x;

// There was some issue with the rotation so I decided I will handle it with a helper rotation variable
function updateRotation():Void
  view.setRotate(0, 0, viewRotation);


Our GameWorld class is based on the official World sample but we extended it with some pathfinding logic. The pathfinding logic is really simple, it’s based on our HPP AStarUtil class.

// Simple world matrix - true means the Node is walkable, false means it's not walkable.
var map:Array<Array<Node>> = [
  [new Node(true),new Node(false),new Node(true)],
  [new Node(true),new Node(false),new Node(true)],
  [new Node(true),new Node(true),new Node(true)],
  [new Node(true),new Node(false),new Node(true)],
  [new Node(false),new Node(false),new Node(true)]

// You can get easily the best available path from the world.
var path:Path = AStarUtil.getPath({
  startPosition: {x:0, y:0},
  endPosition: {x:2, y:4},
  mapNodes: map

Let’s download and try this demo! You will see, Heaps is amazing fast!

Of course it was just a really sort description but we hope you will like our first Heaps demo. Next time we will share more details about Havoc core.

Leave a Comment

Your email address will not be published. Required fields are marked *