Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function(){
- var Game = {
- canvas : undefined,
- c : undefined,
- spriteHeight: 20,
- spriteWidth: 20,
- backgroundColor: 'black',
- foregroundColor: 'white',
- xPos : 0,
- yPos : 0
- };
- Game.start = function(){
- Game.canvas = document.getElementById('myCanvas');
- Game.c = Game.canvas.getContext("2d");
- Game.canvas.width = window.innerWidth;
- Game.canvas.height = window.innerHeight;
- Game.mainLoop();
- };
- Game.update = function(){
- if (Game.xPos == Game.canvas.width){
- Game.xPos = 0;
- }else{
- Game.xPos++;
- }
- if (Game.yPos == Game.canvas.height){
- Game.yPos = 0;
- }else{
- Game.yPos++;
- }
- };
- Game.draw = function(){
- Game.c.fillStyle = Game.backgroundColor;
- Game.c.fillRect(0,0,Game.canvas.width, Game.canvas.height);
- Game.c.fillStyle = Game.foregroundColor;
- Game.c.fillRect(Game.xPos,Game.yPos,Game.spriteWidth, Game.spriteHeight);
- };
- Game.mainLoop = function(){
- Game.update();
- Game.draw();
- setTimeout(Game.mainLoop, 1000/60);
- }
- Game.start();
- });
Add Comment
Please, Sign In to add comment