Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
titaniumnetwork-dev
GitHub Repository: titaniumnetwork-dev/Incognito-old
Path: blob/main/static/src/gs/public/radius-raid/js/powerup.js
1330 views
1
/*==============================================================================
2
Init
3
==============================================================================*/
4
$.Powerup = function( opt ) {
5
for( var k in opt ) {
6
this[k] = opt[k];
7
}
8
var text = $.text( {
9
ctx: $.ctxmg,
10
x: 0,
11
y: 0,
12
text: this.title,
13
hspacing: 1,
14
vspacing: 0,
15
halign: 'top',
16
valign: 'left',
17
scale: 1,
18
snap: 0,
19
render: 0
20
} );
21
this.hpadding = 8;
22
this.vpadding = 8;
23
this.width = text.width + this.hpadding * 2;
24
this.height = text.height + this.vpadding * 2;
25
this.x = this.x - this.width / 2;
26
this.y = this.y - this.height / 2;
27
this.direction = $.util.rand( 0, $.twopi );
28
this.speed = $.util.rand( 0.5, 2 );
29
};
30
31
/*==============================================================================
32
Update
33
==============================================================================*/
34
$.Powerup.prototype.update = function( i ) {
35
/*==============================================================================
36
Apply Forces
37
==============================================================================*/
38
this.x += Math.cos( this.direction ) * this.speed * $.dt;
39
this.y += Math.sin( this.direction ) * this.speed * $.dt;
40
41
/*==============================================================================
42
Check Bounds
43
==============================================================================*/
44
if( !$.util.rectInRect( this.x, this.y, this.width, this.height, 0, 0, $.ww, $.wh ) ){
45
$.powerups.splice( i, 1 );
46
}
47
48
/*==============================================================================
49
Check Collection Collision
50
==============================================================================*/
51
if( $.hero.life > 0 && $.util.arcIntersectingRect( $.hero.x, $.hero.y, $.hero.radius + 2, this.x, this.y, this.width, this.height ) ){
52
$.audio.play( 'powerup' );
53
$.powerupTimers[ this.type ] = 300;
54
$.particleEmitters.push( new $.ParticleEmitter( {
55
x: this.x + this.width / 2,
56
y: this.y + this.height / 2,
57
count: 15,
58
spawnRange: 0,
59
friction: 0.85,
60
minSpeed: 2,
61
maxSpeed: 15,
62
minDirection: 0,
63
maxDirection: $.twopi,
64
hue: 0,
65
saturation: 0
66
} ) );
67
$.powerups.splice( i, 1 );
68
$.powerupsCollected++;
69
}
70
};
71
72
/*==============================================================================
73
Render
74
==============================================================================*/
75
$.Powerup.prototype.render = function( i ) {
76
77
$.ctxmg.fillStyle = '#000';
78
$.ctxmg.fillRect( this.x - 2, this.y - 2, this.width + 4, this.height + 4 );
79
$.ctxmg.fillStyle = '#555';
80
$.ctxmg.fillRect( this.x - 1, this.y - 1, this.width + 2, this.height + 2 );
81
82
$.ctxmg.fillStyle = '#111';
83
$.ctxmg.fillRect( this.x, this.y, this.width, this.height );
84
85
$.ctxmg.beginPath();
86
$.text( {
87
ctx: $.ctxmg,
88
x: this.x + this.hpadding,
89
y: this.y + this.vpadding + 1,
90
text: this.title,
91
hspacing: 1,
92
vspacing: 0,
93
halign: 'top',
94
valign: 'left',
95
scale: 1,
96
snap: 0,
97
render: true
98
} );
99
$.ctxmg.fillStyle = '#000';
100
$.ctxmg.fill();
101
102
$.ctxmg.beginPath();
103
$.text( {
104
ctx: $.ctxmg,
105
x: this.x + this.hpadding,
106
y: this.y + this.vpadding,
107
text: this.title,
108
hspacing: 1,
109
vspacing: 0,
110
halign: 'top',
111
valign: 'left',
112
scale: 1,
113
snap: 0,
114
render: true
115
} );
116
$.ctxmg.fillStyle = 'hsl(' + this.hue + ', ' + this.saturation + '%, ' + this.lightness + '%)';
117
$.ctxmg.fill();
118
119
$.ctxmg.fillStyle = 'hsla(0, 0%, 100%, 0.2)';
120
$.ctxmg.fillRect( this.x, this.y, this.width, this.height / 2 );
121
122
}
123