Skip to content

Commit

Permalink
added dynamic centering of context
Browse files Browse the repository at this point in the history
  • Loading branch information
dale-bang committed Jun 6, 2015
1 parent 761f5b3 commit cf58acc
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
var MAP_W = 600,
MAP_H = 600,
TILE_W = 10,
OFF_X = 400 - TILE_W/2,
OFF_X,
COLS = MAP_W / TILE_W,
ROWS = MAP_H / TILE_W,
curCellMap = null,
Expand All @@ -20,31 +20,29 @@
var canvas = {
canvas: null,
context: null,
canvasW: null,
gridStroke: "#eee",
cellAliveColour: null,
cellImg: null,
cellDimensions: {
height: null,
width: null,
side: {
x: null,
y: null
}
},
cellDimensions: {},

//Canvas functions
init: function() {
this.canvas = document.getElementById('game');
this.context = this.canvas.getContext('2d');
this.canvasW = this.canvas.width;
OFF_X = this.canvasW/2 - TILE_W/2
this.context.translate(OFF_X, 0);

this.cellAliveColour = this.generateColourPallete(53, 179, 32);

//Calculate dimensions of side, width and height of cell (relative to isometric view)
this.cellDimensions.height = utilities.twoDToIso(1*TILE_W, 1*TILE_W).y - utilities.twoDToIso(0, 0).y;
this.cellDimensions.width = Math.abs(utilities.twoDToIso(0, 1*TILE_W).x - utilities.twoDToIso(1*TILE_W, 0).x);
this.cellDimensions.side.x = this.cellDimensions.width / 2;
this.cellDimensions.side.y = this.cellDimensions.height / 2;
this.cellDimensions.side = {
x: this.cellDimensions.width / 2,
y: this.cellDimensions.height / 2
}

},

Expand Down

0 comments on commit cf58acc

Please sign in to comment.