com.jtransc.game.util.Array2 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jtransc-media-game Show documentation
Show all versions of jtransc-media-game Show documentation
JVM AOT compiler currently generating Javascript and Haxe, with initial focus on Kotlin and games.
package com.jtransc.game.util;
import java.util.ArrayList;
public class Array2 {
public final int width;
public final int height;
public final ArrayList values;
public interface Generator {
T generate();
}
public Array2(int width, int height, Generator generate) {
final int size = width * height;
this.width = width;
this.height = height;
this.values = new ArrayList();
for (int n = 0; n < size; n++) this.values.add(generate.generate());
}
private int index(int x, int y) {
return y * width + x;
}
public T get(int x, int y) {
return values.get(index(x, y));
}
public void set(int x, int y, T value) {
values.set(index(x, y), value);
}
}