Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add logic to solve for window not defined error; fix line indents #1

Merged
merged 1 commit into from
Jul 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}