This commit is contained in:
Alexander Popov 2023-04-06 14:44:41 +03:00
parent 83c6a43fae
commit b23a0fc187
Signed by: iiiypuk
GPG Key ID: E47FE0AB36CD5ED6
4 changed files with 21 additions and 18 deletions

View File

@ -3,9 +3,9 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>gameEngine</title>
<title>ujs</title>
<link rel="stylesheet" type="text/css" href="styles.css">
<script src="./js/main.js" type="module"></script>
<script src="./js/game.js" type="module"></script>
</head>
<body>
<canvas></canvas>

View File

@ -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();
});

5
src/js/game.js Normal file
View File

@ -0,0 +1,5 @@
import { App } from './app.js';
window.addEventListener('DOMContentLoaded', () => {
new App(400, 400);
});

View File

@ -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;
}