http://orpgcreator.com/3blocks/newBlock.html
I have this in my class
HTML
Code: Select all
<body>
<canvas id="myCanvas1" width="320" height="320"></canvas>
<canvas id="myCanvas2" width="320" height="320"></canvas>
<script>
var canvas1 = document.getElementById('myCanvas1');
var context1 = canvas1.getContext('2d');
var canvas2 = document.getElementById('myCanvas2');
var context2 = canvas2.getContext('2d');
</script>
<script src="3blocks_class.js"></script>
<script src="3blocks_game.js"></script>
</body>
3blocks_game.js
Code: Select all
var Player1 = new BlockGame("", canvas1, context1);
var Player2 = new BlockGame("", canvas2, context2);
setTimeout(function() {
game_loop();
}, 1000);
window.requestAnimFrame = (function(callback)
{
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame ||
function(callback)
{
window.setTimeout(callback, 1000 / 60);
};
})();
function game_loop()
{
//RUN GAME for players
Player1.execu();
Player2.execu();
// request new frame
requestAnimFrame(function()
{
game_loop();
});
}
Code: Select all
window.addEventListener("keydown", this.moveBlock);
Code: Select all
window.addEventListener("keydown", Player1.moveBlock);