o.O
This commit is contained in:
parent
83c6a43fae
commit
b23a0fc187
@ -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>
|
||||||
|
@ -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
5
src/js/game.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { App } from './app.js';
|
||||||
|
|
||||||
|
window.addEventListener('DOMContentLoaded', () => {
|
||||||
|
new App(400, 400);
|
||||||
|
});
|
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user