Created
August 2, 2014 20:26
-
-
Save IdahoEv/a23e6d9161743d9f9724 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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