Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
FogNetwork
GitHub Repository: FogNetwork/Tsunami
Path: blob/main/public/games/files/garbage-collector/js/entities/trash.js
1036 views
1
/*jshint bitwise: false*/
2
/*globals define*/
3
define([
4
'entities/physics-entity',
5
'entities/explosion',
6
'config/colors',
7
'config/material'
8
], function( PhysicsEntity, Explosion, Colors, Material ) {
9
'use strict';
10
11
function Trash( options, lifeTime ) {
12
PhysicsEntity.call( this, options );
13
14
// In seconds.
15
this.lifeTime = lifeTime || 0;
16
this.time = 0;
17
}
18
19
Trash.prototype = new PhysicsEntity();
20
Trash.prototype.constructor = Trash;
21
22
Trash.prototype.update = function( dt ) {
23
PhysicsEntity.prototype.update.call( this, dt );
24
25
this.time += dt;
26
27
var explosion, fill;
28
if ( this.time > this.lifeTime ) {
29
this.game.removed.push( this );
30
31
fill = Colors.Explosion[ Material.type( this.material ) ];
32
33
if ( fill ) {
34
explosion = new Explosion( this.x, this.y );
35
explosion.fill.set( fill );
36
this.game.add( explosion );
37
}
38
}
39
};
40
41
Trash.prototype.draw = function( ctx ) {
42
ctx.lineJoin = 'round';
43
PhysicsEntity.prototype.draw.call( this, ctx );
44
ctx.lineJoin = 'miter';
45
};
46
47
return Trash;
48
});
49
50