Skip to content

Commit

Permalink
base game added
Browse files Browse the repository at this point in the history
  • Loading branch information
javisantana committed Jul 24, 2011
1 parent 2e2fa5a commit 3dbde3e
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
51 changes: 51 additions & 0 deletions public/game1/js/game.js
@@ -0,0 +1,51 @@

function Game() {
this.initialize();
}

_.extend(Game.prototype, {

initialize: function() {
this.setupDOM();
this.init();
},

setupDOM: function() {
var doc = document, body = doc.body;
doc.body.style.margin = '0px';
doc.body.style.overflow = 'hidden';
this.doc = doc;
},

add_layer: function() {
var doc = this.doc;
var canvas = doc.createElement('canvas');
doc.body.appendChild(canvas);
var width = innerWidth;
var height = innerHeight;
var widthHalf = width >> 1;
var heightHalf = height >> 1;

canvas.style.position = 'absolute';
canvas.style.top = '0';
canvas.style.left= '0';

canvas.width = width;
canvas.height = height;

var c = canvas.getContext( '2d' );
c.width = width;
c.height = height;
c.translate( widthHalf, heightHalf );
return c;
},

start: function() {
var game = this;
setInterval(function() {
game.update(20);
game.render();
}, 20);
}

});
1 change: 1 addition & 0 deletions public/game1/js/underscore.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions public/game1/lines.html
@@ -0,0 +1,29 @@
<!doctype html>
<html>
<head>
<title>G</title>
<meta charset="utf-8" />
</head>
<body>
<script src="js/underscore.js"> </script>
<script src="js/game.js"> </script>
<script>
_.extend(Game.prototype, {
init: function() {
this.layer = this.add_layer();
this.pos = 0;
},

update: function() {
},

render: function() {
this.layer.fillRect(this.pos++, 0, 100, 100);
}
});
var g = new Game();
g.start();
</script>
</body>
</html>

0 comments on commit 3dbde3e

Please sign in to comment.