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> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <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"> <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> </head>
<body> <body>
<canvas></canvas> <canvas></canvas>

View File

@ -2,9 +2,11 @@ import { Scene } from './scene.js';
import { Settings } from './settings.js'; import { Settings } from './settings.js';
import { Pointer } from './pointer.js'; import { Pointer } from './pointer.js';
class Game { export class App {
constructor() {
this.scene = new Scene();
constructor(w, h) {
this.scene = new Scene(w, h);
this.prevTime = Date.now(); this.prevTime = Date.now();
Pointer.init(); Pointer.init();
@ -22,7 +24,3 @@ class Game {
requestAnimationFrame(this.run); 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'; import { Pointer } from './pointer.js';
export class Scene { export class Scene {
constructor() { constructor(width, height) {
this.init(); this.init(width, height);
} }
init = async () => { init = async (width, height) => {
this.canvas = document.querySelector('canvas'); this.canvas = document.querySelector('canvas');
this.context = this.canvas.getContext('2d'); this.context = this.canvas.getContext('2d');
this.setScreenSize(); this.setScreenSize(width, height);
} }
run() { 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() { setScreenSize(w, h) {
let w = 640;
let h = 480;
this.canvas.width = w; this.canvas.width = w;
this.canvas.height = h; this.canvas.height = h;
} }