Item.prototype.setPosition = function setPosition(x, y, z) { this.x = x; this.y = y; this.z = z; this.rx = round(x); this.ry = round(y); this.rz = round(z); // Move map if player has moved this.ui.handleMove(this); // Cache new projection point var p = this.ui.project(x, y, z); this.projectionX = p.x; this.projectionY = p.y; // And projection of rounded point var p = this.ui.project(this.rx, this.ry, this.rz); this.projectionRX = p.x; this.projectionRY = p.y; // Update sprite position this.spriteX = this.projectionX - this.sprite.x; this.spriteY = this.projectionY - this.sprite.y; this.spriteRight = this.spriteX + this.spriteWidth; this.spriteBottom = this.spriteY + this.spriteHeight; // Force rerender this.ui._changed = true; this.zone._changed = true; };
Zone.prototype.getItemAtPos = function getItemAtPos(x, y, z) { // Fast case if (this.items.length === 0) return false; // Binary-search var cell = { _sortId: -1, rx: x, ry: y, rz: z }, i = 0, j = this.items.length - 1, middle = 0; while (i <= j) { middle = (i + j) >> 1; var cmp = Item.compare(cell, this.items[middle]); if (cmp == 0) { break; } else if (cmp < 0) { j = middle - 1; } else { i = middle + 1; } } if (cmp > 0) { middle++; } // Start searching from middle for (var i = middle; i < this.items.length; i++) { var item = this.items[i], cmp = Item.compare(cell, item); if (cmp > 0) break; if (round(x) === item.rx && round(y) === item.ry && round(z) === item.rz) { return item; } } return false; };