Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Creeper extends THREE.Group {
- constructor( scene ) {
- // ... other code snippet
- this.scene = scene;
- // ... other code snippet
- this.counter = 0;
- this.explosions = [];
- this.isExposed = false;
- // ... other code snippet
- }
- init() {
- // ... other code snippet
- this.scene.add( this );
- }
- // ... other code snippet
- animate() {
- // ... other code snippet
- this.explosionAnimate();
- }
- // ... other code snippet
- explosionAnimate() {
- if( !this.isExposed ) return;
- for( let i=0; i < this.explosions.length; i++ ) {
- this.explosions[i].update();
- }
- }
- trigger() {
- this.counter++;
- if( this.counter < 3 ) return;
- setTimeout(() => {
- this.explosion();
- }, 100 );
- }
- explosion() {
- this.rotateHeadOffset = 0;
- this.walkOffset = 0;
- this.scaleHeadOffset = 0;
- this.walking = false;
- this.headSwinging = false;
- this.bodyScaling = false;
- this.counter = 0;
- const scene = this.scene;
- scene.remove( this );
- this.explosions[0] = new Explosion( 0, 0, 0, 0x000000, scene );
- this.explosions[1] = new Explosion( 5, 5, 5, 0x333333, scene );
- this.explosions[2] = new Explosion( -5, 5, 10, 0x666666, scene );
- this.explosions[3] = new Explosion( -5, 5, 5, 0x999999, scene );
- this.explosions[4] = new Explosion( 5, 5, -5, 0xcccccc, scene );
- this.isExposed = true;
- }
- reset() {
- if( !this.isExposed ) return;
- for( let i=0; i < this.explosions.length; i++ ) {
- this.explosions[i].destroy();
- }
- this.explosions.length = 0;
- this.isExposed = false;
- this.scene.add( this );
- this.position.set( 0, 0, 0 );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement