Commit cc0f1529 authored by wildfirecode13's avatar wildfirecode13

init

parent 1c1d7c4e
export default class Hero extends FYGE.Sprite {
constructor() {
import DragDropable from "./dragdrop/DragDropable";
import MovableManager from "./MovableManager";
import { IWeaponHost } from "./weapon/IWeaponHost";
import Weapon from "./weapon/Weapon";
export default class Hero extends DragDropable implements IWeaponHost {
movableManager: MovableManager;
constructor(movableManager) {
super();
this.texture = FYGE.Texture.fromUrl('//yun.duiba.com.cn/spark/assets/enemy2_fly1.0f4acd3728e90763d98a7328a5a32dbc78ec204e.png')
this.movableManager = movableManager;
this.texture = FYGE.Texture.fromUrl('//yun.duiba.com.cn/spark/assets/hero_fly1.f292cb1c04589c6ee395fe29538d5385540755f7.png');
const weapon = new Weapon(this);
}
getShootPoint() {
return new FYGE.Point(this.x + this.width / 2, this.y)
}
getDropPoint() { return {} }
onDragEnd() { }
}
\ No newline at end of file
import Vector2 from "./Vector2";
import Vector2 from "./lib/Vector2";
export default class Movable extends FYGE.Sprite {
private _velocity: Vector2;
......
......@@ -11,7 +11,7 @@ export default class MovableManager {
onEnterFrame = () => {
this.step();
this.checkRemove();
console.log('移动对象的数量:',this._movableList.length)
// console.log('移动对象的数量:',this._movableList.length)
}
private calcCanRemove(item: FYGE.DisplayObject) {
......
import DragDropable from "./dragdrop/DragDropable";
import DragDropManager from "./dragdrop/DragDropManager";
import Hero from "./Hero";
import MovableManager from "./MovableManager";
export function addGame(stage: FYGE.Stage) {
const movableManager = new MovableManager(stage);//创建管理器
const dragDropManager = new DragDropManager();
const hero = stage.addChild(new Hero());
const hero = stage.addChild(new Hero(movableManager)) as DragDropable;
dragDropManager.add(hero);
hero.position.set(300, 1000);
}
\ No newline at end of file
......@@ -3,7 +3,6 @@ import DragDropEvent from "./DragDropEvent";
//管理一个拖放实例
export default class DragDropManager extends FYGE.EventDispatcher {
//初始化拖放对象事件
public add(item: DragDropable) {
item.addEventListener('DROP', this.onDisplayItemDrop, this)
......@@ -36,5 +35,4 @@ export default class DragDropManager extends FYGE.EventDispatcher {
drag.onDragEnd(drop);
this.dispatchEvent(DragDropEvent.DRAG_END, { drop, drag });
}
}
\ No newline at end of file
import MovableManager from "../MovableManager";
export interface IWeaponHost extends FYGE.Sprite {
movableManager: MovableManager;
getShootPoint(): FYGE.Point;
}
\ No newline at end of file
import Bullet from "../Bullet";
import Vector2 from "../lib/Vector2";
import Movable from "../Movable";
import { IWeaponHost } from "./IWeaponHost";
export default class Weapon {
onCreateBullet: Function
_timer;
_count;
_host: IWeaponHost;
constructor(host) {
this._host = host;
this._timer = setInterval(this.onTimer, 10);
this.reset();
}
reset() {
this._count = 0;
}
onTimer = () => {
this._count++;
if (this.canCreateBullet()) {
this.createBullet();
this.reset();
}
}
canCreateBullet() {
return this._count >= this.getShootInterval();
}
createBullet = () => {
console.log('发射了一个子弹')
const bullet: Movable = this._host.parent.addChild(new Bullet());
bullet.velocity = new Vector2(0, -4);
const shootPoint = this._host.getShootPoint();
bullet.position.set(shootPoint.x, shootPoint.y);
this._host.movableManager.add(bullet);
}
getShootInterval() {
return 20;
}
destroy() {
clearInterval(this._timer);
}
}
\ No newline at end of file
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