Commit 3442846d authored by wildfirecode13's avatar wildfirecode13

init

parent cc0f1529
import Vector2 from "./lib/Vector2";
import Movable from "./Movable";
import MovableManager from "./MovableManager";
import { IWeaponHost } from "./weapon/IWeaponHost";
import Weapon from "./weapon/Weapon";
export default class Enemy extends Movable {
constructor() {
export default class Enemy extends Movable implements IWeaponHost {
movableManager: MovableManager;
constructor(movableManager: MovableManager) {
super();
this.movableManager = movableManager;
movableManager.add(this);
this.texture = FYGE.Texture.fromUrl('//yun.duiba.com.cn/spark/assets/enemy2_fly1.0f4acd3728e90763d98a7328a5a32dbc78ec204e.png')
const weapon = new Weapon(this);
}
getShootVelocity() { return new Vector2(0, 4) }
getShootPoint() {
return new FYGE.Point(this.x + this.width / 2, this.y + this.height)
}
}
\ No newline at end of file
import DragDropable from "./dragdrop/DragDropable";
import Vector2 from "./lib/Vector2";
import MovableManager from "./MovableManager";
import { IWeaponHost } from "./weapon/IWeaponHost";
import Weapon from "./weapon/Weapon";
......@@ -15,6 +16,8 @@ export default class Hero extends DragDropable implements IWeaponHost {
const weapon = new Weapon(this);
}
getShootVelocity(){return new Vector2(0, -4)}
getShootPoint() {
return new FYGE.Point(this.x + this.width / 2, this.y)
}
......
......@@ -28,6 +28,7 @@ export default class MovableManager {
if (this.calcCanRemove(item)) {
this._movableList.splice(index, 1);
index--;
item.destroy();
}
}
}
......
import DragDropable from "./dragdrop/DragDropable";
import DragDropManager from "./dragdrop/DragDropManager";
import Enemy from "./Enemy";
import Hero from "./Hero";
import Vector2 from "./lib/Vector2";
import MovableManager from "./MovableManager";
export function addGame(stage: FYGE.Stage) {
......@@ -8,7 +10,11 @@ export function addGame(stage: FYGE.Stage) {
const dragDropManager = new DragDropManager();
const hero = stage.addChild(new Hero(movableManager)) as DragDropable;
dragDropManager.add(hero);
hero.position.set(300, 1000);
const enemy = stage.addChild(new Enemy(movableManager));
enemy.position.set(0, 0);
enemy.velocity=new Vector2(1,1);
dragDropManager.add(hero);
}
\ No newline at end of file
import Vector2 from "../lib/Vector2";
import MovableManager from "../MovableManager";
export interface IWeaponHost extends FYGE.Sprite {
movableManager: MovableManager;
getShootPoint(): FYGE.Point;
getShootVelocity(): Vector2;
}
\ No newline at end of file
......@@ -30,9 +30,9 @@ export default class Weapon {
}
createBullet = () => {
console.log('发射了一个子弹')
console.log('武器在发射子弹')
const bullet: Movable = this._host.parent.addChild(new Bullet());
bullet.velocity = new Vector2(0, -4);
bullet.velocity = this._host.getShootVelocity();
const shootPoint = this._host.getShootPoint();
bullet.position.set(shootPoint.x, shootPoint.y);
this._host.movableManager.add(bullet);
......
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