-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlevelpop.js
More file actions
58 lines (55 loc) · 1.61 KB
/
Copy pathlevelpop.js
File metadata and controls
58 lines (55 loc) · 1.61 KB
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
/*==============================================================================
Init
==============================================================================*/
$.LevelPop = function( opt ) {
for( var k in opt ) {
this[k] = opt[k];
}
this.x = $.cw - 20;
this.y = $.ch - 20;
this.tick = 0;
this.tickMax = 240;
this.baseAlpha = 0.2;
if( $.tick != 0 ) {
$.audio.play( 'levelup' );
}
};
/*==============================================================================
Update
==============================================================================*/
$.LevelPop.prototype.update = function( i ) {
if( this.tick >= this.tickMax ) {
$.levelPops.splice( i, 1 );
} else {
this.tick += $.dt;
}
};
/*==============================================================================
Render
==============================================================================*/
$.LevelPop.prototype.render = function( i ) {
$.ctxmg.beginPath();
$.text( {
ctx: $.ctxmg,
x: this.x,
y: this.y,
text: $.util.pad( this.level, 2 ),
hspacing: 3,
vspacing: 0,
halign: 'right',
valign: 'bottom',
scale: 12,
snap: 1,
render: 1
} );
if( this.tick < this.tickMax * 0.25 ) {
var alpha = ( this.tick / ( this.tickMax * 0.25 ) ) * this.baseAlpha;
} else if( this.tick > this.tickMax - this.tickMax * 0.25 ) {
var alpha = ( ( this.tickMax - this.tick ) / ( this.tickMax * 0.25 ) ) * this.baseAlpha;
} else {
var alpha = this.baseAlpha;
}
alpha = Math.min( 1, Math.max( 0, alpha ) );
$.ctxmg.fillStyle = 'hsla(0, 0%, 100%, ' + alpha + ')';
$.ctxmg.fill();
}