add scene manager

This commit is contained in:
nadiarvi 2025-04-30 02:47:44 +09:00
parent 747d1434f7
commit 6413a682d6
4 changed files with 24 additions and 8 deletions

View File

@ -49,5 +49,12 @@ export class Cat {
this.sprite.position.y = y;
};
};
remove() {
if (!this.sprite) return;
this.sprite.remove();
this.sprite = null;
}
}

View File

@ -1,5 +1,3 @@
console.log("start fresh :)");
import { colors } from './theme.js';
import StartScene from './scenes/startScene.js';
import GameScene from './scenes/gameScene.js';
@ -15,7 +13,6 @@ function setup(){
mgr = new SceneManager();
mgr.addScene(StartScene);
mgr.addScene(GameScene);
mgr.showScene(StartScene);
};

View File

@ -2,16 +2,18 @@ import { colors } from '../theme.js';
import { draw as drawWorld, groundHeight } from '../world.js';
import { Cat } from '../cat.js';
export default function GameScene(p) {
export default function GameScene() {
let cat;
this.name = "GameScene";
this.setup = () => {
cat = new Cat(width / 2, height - 200, 200);
// cat = new Cat(width / 2, height - 200, 200);
};
this.draw = () => {
// drawWorld(p, groundHeight);
cat.update();
cat.draw();
// cat.update();
// cat.draw();
text('dan yap', width / 2, height / 2 - 100);
};
}

View File

@ -1,5 +1,6 @@
import { colors } from '../theme.js';
import { Cat } from '../cat.js';
import GameScene from './gameScene.js';
export default function StartScene() {
let cat;
@ -10,6 +11,8 @@ export default function StartScene() {
height: 0,
};
// this.name = "StartScene";
this.setup = () => {
cat = new Cat(width / 2, height - 200, 200);
};
@ -64,7 +67,14 @@ export default function StartScene() {
if (x < button.x || x > button.x + button.width) return;
if (y < button.y || y > button.y + button.height) return;
this.sceneManager.showNextScene();
this.sceneManager.showScene(GameScene);
};
this.exit = function () {
if (cat) {
cat.remove()
}
};
}