Skip to content

Instantly share code, notes, and snippets.

@ibilon

ibilon/Main.hx Secret

Created January 5, 2021 20:46
Show Gist options
  • Save ibilon/414b820c6bffe36139385d9dced3f929 to your computer and use it in GitHub Desktop.
Save ibilon/414b820c6bffe36139385d9dced3f929 to your computer and use it in GitHub Desktop.
@:forward(x, y)
abstract Point({x:Float, y:Float}) {
public inline function new(x:Float, y:Float) {
this = {x: x, y: y};
}
@:op(A + B) inline function add(other:Point):Point {
return new Point(this.x + other.x, this.y + other.y);
}
@:op(A += B) inline function set_add(other:Point):Void {
this.x += other.x;
this.y += other.y;
}
}
class Player {
public final position = new Point(0, 0);
public function new() {}
}
class Main {
static function main() {
final player = new Player();
player.position += new Point(1, 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment