mirror of
https://github.com/chenasraf/strange-tactics.git
synced 2026-05-18 01:59:02 +00:00
45 lines
831 B
JavaScript
45 lines
831 B
JavaScript
import Sprite from './sprite'
|
|
import { cols } from './game-settings'
|
|
|
|
class Tile extends Sprite {
|
|
constructor(i, j, options = {}) {
|
|
super(i, j)
|
|
|
|
this.img = options.img
|
|
this.stroke = options.stroke || [177, 218, 131, 90]
|
|
this.color = options.color
|
|
this._isMouseOver = false
|
|
this.z = 0
|
|
|
|
if (this.hoverImg)
|
|
this.hoverImg.filter(GRAY)
|
|
}
|
|
|
|
show() {
|
|
super.show()
|
|
|
|
if (this.color) {
|
|
fill(this.color)
|
|
rect(this.x, this.y, this.w, this.w)
|
|
|
|
if (this.stroke) {
|
|
strokeWeight(2)
|
|
stroke(...this.stroke)
|
|
}
|
|
|
|
} else {
|
|
image(this._isMouseOver ? this.hoverImg : this.img, this.x, this.y, this.w, this.w)
|
|
}
|
|
|
|
if (this.highlighted) {
|
|
rect(this.x, this.y)
|
|
}
|
|
}
|
|
|
|
static indexOf(i, j) {
|
|
return i + j * cols
|
|
}
|
|
}
|
|
|
|
export default Tile
|