forked from serprex/openEtG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Effect.js
84 lines (84 loc) · 2.29 KB
/
Effect.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"use strict";
var ui = require("./ui");
var etg = require("./etg");
function maybeTgtPos(pos){
return pos instanceof etg.Thing ? ui.tgtToPos(pos) : pos;
}
function Death(pos){
PIXI.Graphics.call(this);
this.step = 0;
this.position = maybeTgtPos(pos);
}
function Text(text, pos){
if (!pos){
console.log("Blank position " + text);
pos = new PIXI.math.Point(-99, -99);
}
PIXI.Sprite.call(this, ui.getTextImage(text, 16, "white"));
this.step = 0;
this.position = maybeTgtPos(pos);
this.anchor.x = .5;
}
function SpriteFade(texture, pos, anchor) {
PIXI.Sprite.call(this, texture);
if (!anchor) this.anchor.set(0.5, 0.5);
else this.anchor.set(anchor.x, anchor.y);
this.step = 0;
this.position = maybeTgtPos(pos) || new PIXI.math.Point(450, 300);
}
function nop(){}
function make(cons){
return typeof PIXI === "undefined" ? nop : function(){
if (exports.disable || !anims) return;
var effect = Object.create(cons.prototype);
var effectOverride = cons.apply(effect, arguments);
anims.addChild(effectOverride === undefined ? effect : effectOverride);
}
}
if (typeof PIXI === "undefined"){
exports.disable = true;
exports.register = exports.next = nop;
}else{
var anims;
exports.disable = false;
exports.register = function(doc){
anims = doc;
}
exports.next = function(p2cloaked){
if (anims){
for (var i = anims.children.length - 1;i >= 0;i--) {
var child = anims.children[i];
if ((p2cloaked && new PIXI.math.Rectangle(130, 20, 660, 280).contains(child.position.x, child.position.y)) || child.next()){
anims.removeChild(child);
}
}
}
}
Death.prototype = Object.create(PIXI.Graphics.prototype);
Text.prototype = Object.create(PIXI.Sprite.prototype);
SpriteFade.prototype = Object.create(PIXI.Sprite.prototype);
Death.prototype.next = function(){
if (++this.step==15){
return true;
}
this.clear();
this.beginFill(0, 1-this.step/15);
this.drawRect(-30, -30, 60, 60);
}
Text.prototype.next = function(){
if (++this.step==20){
return true;
}
this.position.y -= 2;
this.alpha = 1-Math.sqrt(this.step)/5;
}
SpriteFade.prototype.next = function() {
if (++this.step == 100) {
return true;
}
if (this.step > 50) this.alpha = 1 - ((this.step-50) / 50);
}
}
exports.mkDeath = make(Death);
exports.mkText = make(Text);
exports.mkSpriteFade = make(SpriteFade);