Commit bf202af7 authored by 谌继荃's avatar 谌继荃

初始化bird

parent 986c1c4e
import Movable from "./Movable";
export default class Bullet extends Movable {
constructor() {
super();
this.texture = FYGE.Texture.fromUrl('//yun.duiba.com.cn/aurora/assets/0bcb2c26a85addb1714b4c63f2a873aafe210749.png')
}
}
\ No newline at end of file
import Bird from "./Bird";
import MovableManager from "./MovableManager";
import Vector2 from "./Vector2";
export function addGame(stage: FYGE.Stage) {
const movableManager = new MovableManager(stage);//创建管理器
const bird = stage.addChild(new Bird());//有加速度
bird.position.set(300, 200);
bird.velocity = new Vector2(0, 0);
bird.acceleration=new Vector2(0, 1);
movableManager.add(bird);
stage.addEventListener(FYGE.MouseEvent.CLICK,onclick);
function onclick() {
bird.velocity.y = -20;
}
}
\ No newline at end of file
import Movable from "../lib/Movable";
import MovableManager from "../lib/MovableManager";
import Vector2 from "../lib/Vector2";
class BackgroundItem extends Movable {
constructor() {
super();
this.texture = FYGE.Texture.fromUrl(
"//yun.duiba.com.cn/aurora/assets/bd7b3b10169265123e52d02acf8739db5ff59b3d.png"
);
this.velocity = new Vector2(1, 0);
}
getCanRemove() {
return false;
}
}
const width = 375;
export default class Background {
constructor(stage: FYGE.Stage, movableManager: MovableManager) {
var bg = new BackgroundItem();
var bg2 = new BackgroundItem();
movableManager.add(bg);
movableManager.add(bg2);
stage.addChild(bg);
stage.addChild(bg2);
bg.y = 0;
bg2.x = width;
stage.addEventListener(FYGE.Event.ENTER_FRAME, () => {
console.log("bg.x", bg.x);
console.log("bg2.x", bg2.x);
if (bg.x > width) {
bg.x = bg2.x - width;
}
if (bg2.x > width) {
bg2.x = bg.x - width;
}
});
}
}
import Movable from "../lib/Movable";
export default class Bullet extends Movable {
constructor() {
super();
this.texture = FYGE.Texture.fromUrl(
"//yun.duiba.com.cn/aurora/assets/0bcb2c26a85addb1714b4c63f2a873aafe210749.png"
);
}
}
import Bird from "./Bird";
import MovableManager from "../lib/MovableManager";
import Vector2 from "../lib/Vector2";
import Background from "./Background";
export function addGame(stage: FYGE.Stage) {
const movableManager = new MovableManager(stage); //创建管理器
const background = new Background(stage, movableManager);
const bird = stage.addChild(new Bird()); //有加速度
bird.position.set(300, 200);
bird.velocity = new Vector2(0, 0);
bird.acceleration = new Vector2(0, 1);
movableManager.add(bird);
stage.addEventListener(FYGE.MouseEvent.CLICK, onclick);
function onclick() {
bird.velocity.y = -20;
}
}
import { addGame } from "./addGame";
var canvas: any = document.getElementById("canvas")
canvas.width = document.body.clientWidth * 1
canvas.height = document.body.clientHeight * 1
import { addGame } from "./bird/addGame";
var canvas: any = document.getElementById("canvas");
canvas.width = document.body.clientWidth * 1;
canvas.height = document.body.clientHeight * 1;
var stage = new FYGE.Stage(
canvas,
750,
......@@ -11,21 +11,21 @@ var stage = new FYGE.Stage(
FYGE.RENDERER_TYPE.CANVAS,
false,
false
)
);
var mouseEvent = stage.onMouseEvent.bind(stage);
canvas.addEventListener("touchstart", mouseEvent, false);
canvas.addEventListener('touchmove', mouseEvent, false);
canvas.addEventListener('touchend', mouseEvent, false);
canvas.addEventListener("touchmove", mouseEvent, false);
canvas.addEventListener("touchend", mouseEvent, false);
stage.addEventListener(FYGE.Event.INIT_STAGE, onInitStage, this);
function onInitStage() {
new addGame(stage)
new addGame(stage);
}
(function loop() {
FYGE.Tween.flush()
FYGE.Tween.flush();
stage.flush();
requestAnimationFrame(loop);
})();
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