Skip to content

Instantly share code, notes, and snippets.

@bl4ckb0ne
Created June 3, 2015 23:09
Show Gist options
  • Save bl4ckb0ne/f498d68d33ef6d7ba1bc to your computer and use it in GitHub Desktop.
Save bl4ckb0ne/f498d68d33ef6d7ba1bc to your computer and use it in GitHub Desktop.
Fuck you Array<Array<T>>
package utils;
// From https://github.com/nadako/HaxeDungeons/blob/master/src/dungeons/utils/Grid.hx
class Vector2D<T>
{
public var width(default, null):UInt;
public var height(default, null):UInt;
private var grid:Array<T>;
public function new(width:UInt, height:UInt, fillVal:T = null)
{
this.width = width;
this.height = height;
clear(fillVal);
}
public function get(x:UInt, y:UInt):T
{
return grid[y * width + x];
}
public function set(x:UInt, y:UInt, val:T):Void
{
grid[y * width + x] = val;
}
public function clear(fillVal:T = null):Void
{
grid = [for (i in 0 ... width * height) fillVal];
}
public function display():Void
{
var line:String;
for(i in 0 ... height) {
line = "";
for(j in 0 ... width) {
line = line + get(i, j) + " ";
}
trace(line);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment