2012-02-03 2nd neuroflux Follow 2012-02-03 00:19:32 License: MIT License Fork1 Fav0 View189 Play Stop Reload Fullscreen Smart Phone Fork tree Readme JavaScript 86 lines HTML 1 lines CSS 1 lines 2012-02-03 2nd var BG = {}; //NameSpace BG.Game = function() { //GameSpace canvas = null; this.ctx = null; //Element and Context this.world = new Array(); //The World this.worldSize = 32; //The Size of the World this.nodeSize = 16; //The Size of Each Square }; BG.Game.prototype = { startGame : function() { /** INITIAL SET UP **/ var tmpCanvas = document.createElement('canvas'); document.body.appendChild(tmpCanvas); tmpCanvas.id = "display"; this.canvas = document.getElementById('display'); this.ctx = this.canvas.getContext('2d'); this.canvas.width = 480; this.canvas.height = 480; for (var x = 0; x < this.worldSize; x++) { this.world[x] = new Array(); for (var y = 0; y < this.worldSize; y++) { this.world[x][y] = new Array(); this.world[x][y].push(0); } } this.gameLoop(); }, drawScene : function() { this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height); //clear view /** DRAWING **/ for (var x = 0; x < world.length; x++) { for (var y = 0; y < world[x].length; y++) { rect(nodeSize*x,nodeSize*y,nodeSize,nodeSize,'red'); } } }, update : function() { /** LOGIC UPDATES **/ /** ENGINE CALLS **/ this.drawScene(); this.gameLoop(); }, gameLoop : function() { setTimeout(function() { requestAnimFrame(this.update, this.canvas); }, 10); } }; /** END NS **/ function rect(x,y,w,h,c) { var col; if (c) { col = c; } else { col = '#c4c4c4'; } this.ctx.fillStyle = col; this.ctx.fillRect(x,y,w,h); } window.onload = function() { var g = new BG.Game(); g.startGame(); }; window.requestAnimFrame = (function(){ return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback, element){ window.setTimeout(callback, 1000 / 60); }; }()); <canvas id='world'></canvas> 2012-02-03 2nd body { background-color: #DDDDDD; font: 30px sans-serif; } var BG = {}; //NameSpace BG.Game = function() { //GameSpace canvas = null; this.ctx = null; //Element and Context this.world = new Array(); //The World this.worldSize = 32; //The Size of the World this.nodeSize = 16; //The Size of Each Square }; BG.Game.prototype = { startGame : function() { /** INITIAL SET UP **/ var tmpCanvas = document.createElement('canvas'); document.body.appendChild(tmpCanvas); tmpCanvas.id = "display"; this.canvas = document.getElementById('display'); this.ctx = this.canvas.getContext('2d'); this.canvas.width = 480; this.canvas.height = 480; for (var x = 0; x < this.worldSize; x++) { this.world[x] = new Array(); for (var y = 0; y < this.worldSize; y++) { this.world[x][y] = new Array(); this.world[x][y].push(0); } } this.gameLoop(); }, drawScene : function() { this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height); //clear view /** DRAWING **/ for (var x = 0; x < world.length; x++) { for (var y = 0; y < world[x].length; y++) { rect(nodeSize*x,nodeSize*y,nodeSize,nodeSize,'red'); } } }, update : function() { /** LOGIC UPDATES **/ /** ENGINE CALLS **/ this.drawScene(); this.gameLoop(); }, gameLoop : function() { setTimeout(function() { requestAnimFrame(this.update, this.canvas); }, 10); } }; /** END NS **/ function rect(x,y,w,h,c) { var col; if (c) { col = c; } else { col = '#c4c4c4'; } this.ctx.fillStyle = col; this.ctx.fillRect(x,y,w,h); } window.onload = function() { var g = new BG.Game(); g.startGame(); }; window.requestAnimFrame = (function(){ return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback, element){ window.setTimeout(callback, 1000 / 60); }; }()); <canvas id='world'></canvas> body { background-color: #DDDDDD; font: 30px sans-serif; } use an iframe compat browser, deer Play on jsdo.it games Author Share ブログに埋め込む QR Tag Download Complete! Description What kind of game? Control Device Smartphone Controllerjsdo.it WebSocket Controller» Mouse Keyboard Touch Device Fullscreen Activated Inactivated jsdo.it games から削除する Submit Author neuroflux Tweet Default Panel Auto play Screenshot Readme JavaScript HTML CSS Size Width: px Height: px code <script type="text/javascript" src="http://jsdo.it/blogparts/wfUK/js"></script> Tweet Twitter Discussion Questions on this code? Forked sort by latest page views favorite forked forked: 2012-02-03 2nd Ben.Harling 00 47 87/1/1