Skip to content

Instantly share code, notes, and snippets.

@IdahoEv
Created August 2, 2014 20:26
Show Gist options
  • Select an option

  • Save IdahoEv/a23e6d9161743d9f9724 to your computer and use it in GitHub Desktop.

Select an option

Save IdahoEv/a23e6d9161743d9f9724 to your computer and use it in GitHub Desktop.
var GameWindow = (function () {
var my = {},
//privateVariable = 1,
canvas,
context,
width,
height,
scale = 16; // pixels per unit size. Tank height/width is 1.0 unit size.
//function privateMethod() {
//// ...
//}
//my.moduleProperty = 1;
//my.moduleMethod = function () {
//// ...
//};
function init() {
canvas = document.getElementById('gameCanvas');
context = canvas.getContext('2d');
width = canvas.width;
height = canvas.height;
context.translate(width / 2.0, height / 2.0);
}
function drawField() {
context.beginPath();
context.rect(0, 0, width, height);
context.fillStyle = '#99FA99';
context.fill();
}
function scaleCoords(coords){
{ x: (coords.x * scale),
y: (coords.y * scale);
}
}
my.draw = function(tank){
drawField();
tankCoords = scaleCoords(tank);
context.beginPath();
context.rect(tankCoords.x - scale/2, tankCoords.y - scale/2, scale, scale);
context.fillStyle = 'black';
context.fill();
}
return my;
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment