Skip to content

Instantly share code, notes, and snippets.

@andresgutierrez
Created April 9, 2015 01:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andresgutierrez/defb9947504ccce627eb to your computer and use it in GitHub Desktop.
Save andresgutierrez/defb9947504ccce627eb to your computer and use it in GitHub Desktop.
namespace Zafiro;
class Map
{
public data = [];
public map = [];
public mask = [];
public min = 0;
public max = 0;
public width = 0;
public height = 0;
public scale = 2;
public brush = 5;
public function __construct(int width, int height, int brush = null, int scale = null)
{
if !brush {
let this->brush = (int) brush;
}
if !scale {
let this->scale = (int) scale;
}
let this->width = (int) floor(width / this->scale);
let this->height = (int) floor(height / this->scale);
}
public function setData(array data)
{
let this->data = data;
return this;
}
public function generate()
{
int x, y, center, current, scale;
var row, map;
let scale = (double) this->scale;
let center = (int) floor(this->width >> 1);
let map = this->map;
for row in this->data {
let x = center + floor(row["x"] / scale);
let y = (int)floor(row["y"] / scale);
if !isset map[x][y] {
let current = 0;
} else {
let current = (int) map[x][y];
}
let current += row["val"],
map[x][y] = current;
}
let this->map = map;
return map;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment