-
-
Save andresgutierrez/defb9947504ccce627eb to your computer and use it in GitHub Desktop.
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
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