Created
June 3, 2015 23:09
-
-
Save bl4ckb0ne/f498d68d33ef6d7ba1bc to your computer and use it in GitHub Desktop.
Fuck you Array<Array<T>>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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