Advertisement
yskang

threejs-minecraft-28

Apr 21st, 2020 (edited)
1,011
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Creeper extends THREE.Group {
  2.     constructor( scene ) {
  3.         // ... other code snippet
  4.  
  5.         this.scene = scene;
  6.  
  7.         // ... other code snippet
  8.        
  9.         this.counter = 0;
  10.         this.explosions = [];
  11.         this.isExposed = false;
  12.  
  13.         // ... other code snippet
  14.     }
  15.  
  16.     init() {
  17.         // ... other code snippet
  18.  
  19.         this.scene.add( this );
  20.     }
  21.  
  22.     // ... other code snippet
  23.  
  24.     animate() {
  25.         // ... other code snippet
  26.  
  27.         this.explosionAnimate();
  28.     }
  29.  
  30.    // ... other code snippet
  31.  
  32.     explosionAnimate() {
  33.         if( !this.isExposed ) return;
  34.  
  35.         for( let i=0; i < this.explosions.length; i++ ) {
  36.             this.explosions[i].update();
  37.         }
  38.     }
  39.  
  40.     trigger() {
  41.         this.counter++;
  42.  
  43.         if( this.counter < 3 ) return;
  44.  
  45.         setTimeout(() => {
  46.             this.explosion();
  47.         }, 100 );
  48.     }
  49.  
  50.     explosion() {
  51.         this.rotateHeadOffset = 0;
  52.         this.walkOffset = 0;
  53.         this.scaleHeadOffset = 0;
  54.  
  55.         this.walking = false;
  56.         this.headSwinging = false;
  57.         this.bodyScaling = false;
  58.         this.counter = 0;
  59.  
  60.         const scene = this.scene;
  61.         scene.remove( this );
  62.         this.explosions[0] = new Explosion( 0, 0, 0, 0x000000, scene );
  63.         this.explosions[1] = new Explosion( 5, 5, 5, 0x333333, scene );
  64.         this.explosions[2] = new Explosion( -5, 5, 10, 0x666666, scene );
  65.         this.explosions[3] = new Explosion( -5, 5, 5, 0x999999, scene );
  66.         this.explosions[4] = new Explosion( 5, 5, -5, 0xcccccc, scene );
  67.  
  68.         this.isExposed = true;
  69.     }
  70.  
  71.     reset() {
  72.         if( !this.isExposed ) return;
  73.  
  74.         for( let i=0; i < this.explosions.length; i++ ) {
  75.             this.explosions[i].destroy();
  76.         }
  77.  
  78.         this.explosions.length = 0;
  79.         this.isExposed = false;
  80.  
  81.         this.scene.add( this );
  82.         this.position.set( 0, 0, 0 );
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement