Created
September 2, 2015 00:00
-
-
Save brenolf/3e69f1a352ae63d54aa3 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
let lines = []; | |
export default class Grid { | |
constructor (game, rows, columns) { | |
if (game === undefined || columns === undefined || rows === undefined) { | |
throw new TypeError(); | |
} | |
let w = Math.floor(game.width / columns); | |
let h = Math.floor(game.height / rows); | |
for (let i = 1; i <= rows; i++) { | |
lines.push(new Phaser.Line(0, i * h, game.width, i * h)); | |
} | |
for (let i = 1; i <= columns; i++) { | |
lines.push(new Phaser.Line(i * w, 0, i * w, game.height)); | |
} | |
this.game = game; | |
this.w = w; | |
this.h = h; | |
this.columns = columns; | |
this.rows = rows; | |
} | |
render () { | |
lines.forEach(line => this.game.debug.geom(line)); | |
} | |
position (blocks_x, blocks_y) { | |
return [blocks_x * this.w, blocks_y * this.h]; | |
} | |
normalize (x, y) { | |
return [Math.floor(x / this.w), Math.floor(y / this.h)]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment