Commit 6a30f9f6 authored by 谌继荃's avatar 谌继荃

gameOver

parent ff302404
...@@ -2,36 +2,41 @@ import Movable from "../lib/Movable"; ...@@ -2,36 +2,41 @@ import Movable from "../lib/Movable";
import MovableManager from "../lib/MovableManager"; import MovableManager from "../lib/MovableManager";
import Vector2 from "../lib/Vector2"; import Vector2 from "../lib/Vector2";
class BackgroundItem extends Movable { class BackgroundItem extends Movable {
constructor() { constructor() {
super(); super();
this.texture = FYGE.Texture.fromUrl('//yun.duiba.com.cn/aurora/assets/bd7b3b10169265123e52d02acf8739db5ff59b3d.png'); this.texture = FYGE.Texture.fromUrl(
this.velocity = new Vector2(0, 10) "//yun.duiba.com.cn/aurora/assets/bd7b3b10169265123e52d02acf8739db5ff59b3d.png"
} );
getCanRemove() { return false } this.velocity = new Vector2(0, 10);
}
getCanRemove() {
return false;
}
} }
const height = 1624; const height = 1624;
export default class Background { export default class Background {
constructor(stage: FYGE.Stage, movableManager: MovableManager) {
var bg = new BackgroundItem();
var bg2 = new BackgroundItem();
constructor(stage: FYGE.Stage, movableManager: MovableManager) { movableManager.add(bg);
var bg = new BackgroundItem(); movableManager.add(bg2);
var bg2 = new BackgroundItem();
movableManager.add(bg); stage.addChild(bg);
movableManager.add(bg2); stage.addChild(bg2);
stage.addChild(bg); bg.x = 0;
stage.addChild(bg2); bg2.y = height;
bg.x = 0; stage.addEventListener(FYGE.Event.ENTER_FRAME, () => {
bg2.y = height; console.log("bg.y", bg.y);
console.log("bg2.y", bg2.y);
stage.addEventListener(FYGE.Event.ENTER_FRAME, () => { if (bg.y > height) {
if (bg.y > height) { bg.y = bg2.y - height;
bg.y = bg2.y - height; }
} if (bg2.y > height) {
if (bg2.y > height) { bg2.y = bg.y - height;
bg2.y = bg.y - height; }
} });
}); }
} }
}
\ No newline at end of file
...@@ -4,27 +4,25 @@ import Background from "./Background"; ...@@ -4,27 +4,25 @@ import Background from "./Background";
import EnemyFactory from "./EnemyFactory"; import EnemyFactory from "./EnemyFactory";
import Hero from "./Hero"; import Hero from "./Hero";
export function addGame(stage: FYGE.Stage) { export function addGame(stage: FYGE.Stage) {
const movableManager = new MovableManager(stage);//创建管理器 const movableManager = new MovableManager(stage); //创建管理器
const dragDropManager = new DragDropManager(); const dragDropManager = new DragDropManager();
const background = new Background(stage, movableManager);
const hero = stage.addChild(new Hero(movableManager));
hero.position.set(300, 1000);
const enemyFactory = new EnemyFactory(stage, movableManager); const background = new Background(stage, movableManager);
dragDropManager.add(hero); const hero = stage.addChild(new Hero(movableManager));
hero.position.set(300, 1000);
movableManager.hero = hero; const enemyFactory = new EnemyFactory(stage, movableManager);
function onGamOver() { dragDropManager.add(hero);
dragDropManager.remove(hero);
}
movableManager.addEventListener('gameover', onGamOver);
movableManager.hero = hero;
} function onGamOver() {
\ No newline at end of file alert("gameOver");
dragDropManager.remove(hero);
enemyFactory.destroy();
}
movableManager.addEventListener("gameover", onGamOver);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment