ok last email under this subject from me.. a quick demo where few more Haxe
features are used. the "engine" is also at total beginning..

http://itmmetelko.com/storage/neko_plus_ptk_2.zip

screenie: http://itmmetelko.com/storage/neko_plus_ptk_2.jpg

---->>

import lib.Base;

class NekoPtkGame extends Base
{

    static var entities = new List<Entity>();

    static function cb_quickLoad() : Void
    {
        // load few images
        Base.loadImg("img\\bg\\golf_s.jpg");
        Base.loadImg("img\\spr\\tank1.png");
        Base.loadImg("img\\spr\\ball1.png");
        Base.loadImg("img\\spr\\ball_shadow.png");

        //create few entities
        entities.push(new Tank(100, 500));
        entities.push(new Tank(600, 400));
        entities.push(new Ball(10, 120));
        entities.push(new Ball(200, 160));
        entities.push(new Ball(400, 120));
        entities.push(new Ball(600, 160));
    }

    static function cb_update() : Void
    {
        Base.drawImg(800, 600, 0, 0, 0);
        Lambda.iter(entities, function (e:Entity) { e.update(); e.draw(); }
);
    }

}

class Tank implements Entity
{

    var x:Int;
    var y:Int;
    var dir:Int;

    public function new(x_:Int, y_:Int)
    {
        x = x_;
        y = y_;
        dir = 1;
    }

    public function update()
    {
        x = 3 * dir + x;
        if ( x < 0 ) dir = 1;
        if ( x > 700 ) dir = -1;
    }

    public function draw()
    {
        Base.drawImg(105, 95,  x, y, 1);
    }

}

class Ball implements Entity
{

    var x:Float;
    var y:Float;
    var dx:Float;
    var dy:Float;

    public function new(x_:Int, y_:Int)
    {
        x = x_;
        y = y_;
        dx = 2.0;
        dy = 0;
    }

    public function update()
    {
        x += dx;
        y += dy;
        dy += 0.1;
        if ( x < 0 || x > 700) dx *= -1.0;
        if ( y < 0 || y > 300) dy *= -1.0;
    }

    public function draw()
    {
        Base.drawImg(131, 31, Std.int(x)+10, 405, 3);
        Base.drawImg(162, 129, Std.int(x), Std.int(y), 2);
    }

}


interface Entity
{
    public function update():Void;
    public function draw():Void;
}
-- 
Neko : One VM to run them all
(http://nekovm.org)

Reply via email to