diff --git a/src/index.html b/src/index.html index 9191c3e..0b57a83 100644 --- a/src/index.html +++ b/src/index.html @@ -3,9 +3,9 @@ - gameEngine + ujs - + diff --git a/src/js/main.js b/src/js/app.js similarity index 74% rename from src/js/main.js rename to src/js/app.js index 19d4c9b..ddd1d1d 100644 --- a/src/js/main.js +++ b/src/js/app.js @@ -2,9 +2,11 @@ import { Scene } from './scene.js'; import { Settings } from './settings.js'; import { Pointer } from './pointer.js'; -class Game { - constructor() { - this.scene = new Scene(); +export class App { + + + constructor(w, h) { + this.scene = new Scene(w, h); this.prevTime = Date.now(); Pointer.init(); @@ -22,7 +24,3 @@ class Game { requestAnimationFrame(this.run); } } - -window.addEventListener('DOMContentLoaded', () => { - new Game(); -}); diff --git a/src/js/game.js b/src/js/game.js new file mode 100644 index 0000000..0f73560 --- /dev/null +++ b/src/js/game.js @@ -0,0 +1,5 @@ +import { App } from './app.js'; + +window.addEventListener('DOMContentLoaded', () => { + new App(400, 400); +}); diff --git a/src/js/scene.js b/src/js/scene.js index 949d1f4..0df82d8 100644 --- a/src/js/scene.js +++ b/src/js/scene.js @@ -1,25 +1,25 @@ import { Pointer } from './pointer.js'; export class Scene { - constructor() { - this.init(); + constructor(width, height) { + this.init(width, height); } - init = async () => { + init = async (width, height) => { this.canvas = document.querySelector('canvas'); this.context = this.canvas.getContext('2d'); - this.setScreenSize(); + this.setScreenSize(width, height); } run() { - console.log(Pointer.pos); + // clear canvas + this.context.clearRect(0, 0, this.canvas.width, this.canvas.height); + this.context.fillRect(0, 0, 100, 100); + // console.log(Pointer.pos); } - setScreenSize() { - let w = 640; - let h = 480; - + setScreenSize(w, h) { this.canvas.width = w; this.canvas.height = h; }