Skip to content

Commit

Permalink
add explosion
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatamo committed Sep 27, 2018
1 parent b61d9c5 commit 3e3565f
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/game/component/entities/effect/target/charge/orb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ namespace States {
this.parent.y = this.parent.cy + this.parent.r * Math.sin(rad);
this.parent.degree = (this.parent.degree + this.parent.vd) % 360;
this.parent.r = r_org * (1 - e);
this.parent.sprite.scale.set(scale_org * (1 - e));
this.parent.sprite.scale.set(scale_org * (0.05 + 0.95 * (1 - e)));
yield;
}
yield* this.sleep(10);
}
}
}
48 changes: 48 additions & 0 deletions src/game/component/entities/effect/target/explode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Entity } from "../../entity";
import * as PIXI from "pixi.js";
import { Level } from "../../../../levels/level";
import { AbstractState } from "../../../../statemachine";
import { easeOutExpo } from "../../../../../utils/easing";

export class Explode extends Entity {
public readonly sprite: PIXI.Sprite;
constructor(level: Level, x: number, y: number) {
super(level, x, y);
const { resource } = this.api;
this.sprite = new PIXI.Sprite(resource.images["bullet_blue_large"]);
this.sprite.scale.set(0);
this.sprite.anchor.set(0.5);
this.sprite.blendMode = PIXI.BLEND_MODES.ADD;
this.container.addChild(this.sprite);
this.setState(new States.Default(this), false);
}
}

namespace States {
export class Default<P extends Explode> extends AbstractState<P> {
*update(): IterableIterator<void> {
const timespan = 20;
for (let i = 0; i < timespan; i++) {
this.parent.sprite.scale.set(8 * easeOutExpo(i / timespan));
this.checkCollision();
yield;
}
for (let i = 0; i <= timespan; i++) {
this.parent.sprite.alpha = 1 - easeOutExpo(i / timespan);
yield;
}
}
checkCollision(): void {
const { jss } = this.parent.api;
const r = 24 * this.parent.sprite.scale.x;
const m_x = jss.getMyXReal() + 16;
const m_y = jss.getMyYReal() + 16;
const dx = this.parent.x - m_x;
const dy = this.parent.y - m_y;
// 主人公にダメージ
if (dx * dx + dy * dy < r * r) {
this.damage(jss, 35, 1);
}
}
}
}
2 changes: 1 addition & 1 deletion src/game/component/entities/effect/target/trace/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class Trace extends Entity {
this.sprite.scale.set(0.5 + 0.25 * Math.random());
this.sprite.anchor.set(0.5);
this.sprite.alpha = 0.1;
this.sprite.blendMode = PIXI.BLEND_MODES.ADD;
this.sprite.blendMode = PIXI.BLEND_MODES.SCREEN;
this.container.addChild(this.sprite);
this.setState(new States.Default(this), false);
}
Expand Down
26 changes: 25 additions & 1 deletion src/game/component/entities/enemy/boss1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { LockOnEffect } from "../effect/target/lockon";
import { RotateEffect } from "../effect/target/rotate";
import { TraceEffect } from "../effect/target/trace";
import { ChargeEffect } from "../effect/target/charge";
import { Explode } from "../effect/target/explode";

/**
* ボス1
Expand Down Expand Up @@ -268,7 +269,30 @@ namespace Boss1States {
}
yield* this.sleep(35);
this.parent.level.add(new ChargeEffect(this.parent.level, tx, ty));
yield* this.sleep(80);
yield* this.sleep(74);

const entities = new EntityContainer(this.parent.container);
for (let i = 0; i < 3; i++) {
entities.add(
new SmoothShockWaveEffect(
this.parent.level,
tx - this.parent.x,
ty - this.parent.y,
0,
400,
400,
0,
0,
24 - i
)
);
entities.update();
yield;
}
yield* this.sleep(6, () => entities.update());
this.parent.level.add(new Explode(this.parent.level, tx, ty));
yield* this.sleep(12, () => entities.update());
this.parent.container.removeChild(entities.container);
this.parent.popState();
}
}
Expand Down

0 comments on commit 3e3565f

Please sign in to comment.