Skip to content

Instantly share code, notes, and snippets.

@zaynyatyi
zaynyatyi / MessageData.hx
Last active October 11, 2016 17:40
Typed message in hexMachina illustration
package test.message;
/**
* ...
* @author Heorhiy Kharvat
*/
class MessageData
{
public var id:Int;
public var message:String;
@zaynyatyi
zaynyatyi / EventTest.hx
Last active September 8, 2016 08:41
Just a simple test of typed event system in haxe using abstract
abstract DataEvent<T>(String) to String
{
public inline function new(name) this = name;
}
typedef Handler<T> = T->Void;
class GlobalDispatcher
{
static var eventToHandlers = new Map<String,Array<Handler<Dynamic>>>();
@zaynyatyi
zaynyatyi / MainApplication.java
Created August 30, 2016 09:20
Crosswalk building test
package com.crosswalktest;
import android.app.Application;
import android.util.Log;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
@zaynyatyi
zaynyatyi / Test.hx
Created August 26, 2016 13:16
Just a good example to describe why you will like haxe abstracts from @nadako
abstract UserId(Int) {
inline function new(id) {
this = id;
}
public static inline function generate():UserId {
return new UserId(Std.random(100));
}
}
@zaynyatyi
zaynyatyi / Entity.hx
Last active June 2, 2016 07:51
Just pools demonstration
package;
import openfl.Assets;
import openfl.display.Bitmap;
import openfl.display.Graphics;
import openfl.display.Sprite;
import openfl.events.TimerEvent;
import openfl.utils.Timer;
class Entity extends Sprite
@zaynyatyi
zaynyatyi / pieMask.hx
Last active April 4, 2016 12:55
Pie progress mask
function drawProgressMask(graphics:Graphics, progress:Float, radius:Float = 50, x:Float = 0, y:Float = 0, rotation:Float = 0, sides:Int = 6):Void
{
graphics.clear();
graphics.beginFill(0);
// graphics should have its beginFill function already called by now
graphics.moveTo(x, y);
if (sides < 3) sides = 3; // 3 sides minimum
// Increase the length of the radius to cover the whole target
radius /= Math.cos(1 / sides * Math.PI);
// Shortcut function
@zaynyatyi
zaynyatyi / Game.hx
Last active June 28, 2019 21:37
Actuate in kha using manual update
package;
import motion.actuators.SimpleActuator;
class Game
{
public function new()
{
}
@:build(kha.internal.AssetsBuilder.build("image"))
class ImageList {
var images:Map<String, ImageInstance>;
public function new() {
}
}
class ImageInstance {
var image:kha.Image;
var load:Void->Void;