Skip to content

Commit

Permalink
Merge pull request #1 from AsheUrban/dr
Browse files Browse the repository at this point in the history
add logic to solve for window not defined error; fix line indents
  • Loading branch information
AsheUrban authored Jul 6, 2022
2 parents 1f27323 + 423d0bf commit 6296c24
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,34 @@ import ControlInput from '../src/js/controls.js';
// import 'bootstrap/dist/css/bootstrap.min.css';
// import './css/styles.css';

window.addEventListener("load", function(){
const canvas = document.getElementById("canvas-1");
const ctx = canvas.getContext("2d");
canvas.width = 800;
canvas.height = 720;
if (typeof window !== 'undefined') { //You are on the browser; can use window here
window.addEventListener("load", function(){
const canvas = document.getElementById("canvas-1");
const ctx = canvas.getContext("2d");
canvas.width = 800;
canvas.height = 720;

const input = new ControlInput();
const player = new Player(canvas.width, canvas.height);
const background = new Background(canvas.width, canvas.height);

const input = new ControlInput();
const player = new Player(canvas.width, canvas.height);
const background = new Background(canvas.width, canvas.height);

// Display score || Game Over text

// Display score || Game Over text

// function displayStatus(){
// function displayStatus(){

// }
function animationLoop(){
ctx.clearRect(0,0,canvas.width, canvas.height);
background.draw(ctx);
//background.update();
player.draw(ctx);
player.update(input);
requestAnimationFrame(animationLoop);
// }
function animationLoop(){
ctx.clearRect(0,0,canvas.width, canvas.height);
background.draw(ctx);
//background.update();
player.draw(ctx);
player.update(input);
requestAnimationFrame(animationLoop);

}
animationLoop();
});
}
animationLoop();
});

} else { //You are on the server; don't use window here
}

0 comments on commit 6296c24

Please sign in to comment.