o.O
This commit is contained in:
parent
83c6a43fae
commit
b23a0fc187
@ -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>
|
||||
|
@ -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
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';
|
||||
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user