cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <a-scene>
  <a-assets timeout="10000">
    <a-mixin id="circle" geometry="primitive: circle; radius: 0.3;" material="color: black;" rotation="-90 0 0"></a-mixin>
    <template id="chris" type="text/html">
      <a-sphere color="#ffe0bd">
        <a-entity id="#eyes" position="0 0.3 1">
            <a-circle color="#333" radius="0.1" position="0.3 0 0"></a-circle>
            <a-circle color="#333" radius="0.1" position="-0.3 0 0"></a-circle>
            <a-animation attribute="rotation"
               delay="3200"
               dur="250"
               fill="forwards"
               to="360 0 0"
               repeat="indefinite"></a-animation>
          </a-entity>
        <a-box color="#ffad60" height="0.5" width="0.2" depth="0.2" position="0 0.2 0.9" rotation="-25 0 0" ></a-box>
        <a-sphere color="#6a4e42" radius="1.01" phi-start="0" phi-length="50" rotation="-30 0 90"  opacity="0.2"></a-sphere>
        <a-torus color="#333" arc="135" radius="0.25" rotation="2d0 0 200" position="0 -0.25 1" radius-tubular="0.01"></a-torus>
      </a-sphere>
    </template>
    <template id="dave" type="text/html">
      <a-sphere color="#ffe0bd">
        <a-entity id="#eyes" position="0 0.3 1">
            <a-circle color="#333" radius="0.1" position="0.3 0 0"></a-circle>
            <a-circle color="#333" radius="0.1" position="-0.3 0 0"></a-circle>
            <a-animation attribute="rotation"
               delay="3000"
               dur="250"
               fill="forwards"
               to="360 0 0"
               repeat="indefinite"></a-animation>
          
          </a-entity>
        <a-box color="#ffad60" height="0.5" width="0.2" depth="0.2" position="0 0.2 0.9" rotation="-25 0 0" ></a-box>
        
          <a-sphere color="#6a4e42" radius="1.05" position="0 0.2 -0.05" phi-start="0" phi-length="180" rotation="-115 22 0"  side="double"></a-sphere>
          <a-sphere color="#6a4e42" radius="1.05" position="0 0.2 -0.07" phi-start="0" phi-length="180" rotation="-130 -20 0"  side="double"></a-sphere>

        
        <a-torus color="#6a4e42" arc="180" radius="1" radius-tubular="0.05" rotation="30 180 180" position="0 0.2 0.2" ></a-torus>
        <a-torus color="#6a4e42" arc="180" radius="0.5" radius-tubular="0.05" rotation="-45 180 0" position="0 -0.55 0.6"></a-torus>
      </a-sphere>
  </a-entity>     

    </template>
    <template id="hole" type="text/html">
	   	<a-circle mixin="circle">      
      	<a-sphere radius="0.2" position="0 0 -1" color="transparent" rotation="62.5 0 0">
          <a-entity template="src: #${mole}" scale="0.21 0.21 0.21"></a-entity>
          <a-animation begin="down" dur="1000" easing="ease-out" attribute="position" fill="forwards" from="0 0 0.25" to="0 0 -0.5"></a-animation>
          <a-animation begin="up" easing="ease-out" attribute="position" fill="forwards" from="0 0 -1" to="0 0 0.25"></a-animation>
          <a-animation begin="shake" attribute="rotation" dur="500" fill="backwards" to="360 360 0"></a-animation>
  		  </a-sphere>
      </a-circle>
    </template>
    <img id="wood" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/17/reclaimed_wood.jpg"  crossorigin="anonymous">
  </a-assets>

  <!-- Environment -->
  <a-box color="#F96C06" position="0 0.25 -3" width="3" depth="2" rotation="15 0 0">
    <a-entity id="decorative-holes">
      <a-entity template="src: #hole" data-mole="dave" position="0 0.51 -0.5"></a-entity>
      <a-entity template="src: #hole" data-mole="chris" position="0 0.51 0.5"></a-entity>
      <a-entity template="src: #hole" data-mole="chris" position="1 0.51 -0.5"></a-entity>
      <a-entity template="src: #hole" data-mole="dave" position="1 0.51 0.5"></a-entity>
      <a-entity template="src: #hole" data-mole="chris" position="-1 0.51 -0.5"></a-entity>
      <a-entity template="src: #hole" data-mole="dave" position="-1 0.51 0.5"></a-entity>
    </a-entity>

    <a-sphere id="startBtn" color="green" radius="0.1" position="1.3 0.3 0.95">
      <a-animation begin="click" dur="100" attribute="position" fill="backwards" to="1.3 0.3 0.93"></a-animation>
    </a-sphere>
  </a-box>

  <!-- UI -->
  <a-text value="TIME" position="-1.2 2.2 -4" font='mozillavr' wrap-count="30"></a-text>
  <a-text id="timer" value="60" position="-1.3 2 -4" font='mozillavr' wrap-count="10"></a-text>
  <a-text value="SCORE" position="0.3 2.2 -4" font='mozillavr' wrap-count="30"></a-text>
  <a-text id="score" value="0" position="0.3 2 -4" font='mozillavr' wrap-count="10"></a-text>

  <!-- Environment -->
  <a-sky color="#000000"></a-sky>
  <a-plane color="#6a4e42" material="src: #wood; repeat: 10 10" height="20" width="20" rotation="-90 0 90" shader="flat"></a-plane>
<!--   <a-entity id="muzak" sound="src: https://s3-us-west-2.amazonaws.com/s.cdpn.io/17/carnival.mp3; volume: 0.4; poolSize: 4;"></a-entity>
   -->
<!-- Camera -->
  <a-camera universal-controls>
    <a-cursor fuse-timeout="200" color="#0099FF"></a-cursor>
  </a-camera>
</a-scene>

<audio id="audio2" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/17/carnival.mp3"></audio>
            
          
!
            
              var moles = document.querySelectorAll('a-circle > a-sphere');
var score = 0;
var scoreEl = document.querySelector('#score');
var timerEl = document.querySelector('#timer');
// var musicEl = document.querySelector('#muzak');
var musicEl2 = document.querySelector('#audio2');
var startBth = document.querySelector('#startBth');
var gameover = true;
var gameTimer;

// Let's automate them moles!
var automateMoles = function(){
  for(let i=0;i<moles.length;i++) {

    let mole = moles[i];

    // Make the mole pop up.
    let up = function(){

      if(!mole.is('up') && !gameover) {
        mole.emit('jump');
        mole.addState('up');

        if(!gameover) {
          moleTimer = window.setTimeout(down, Math.max(1000, Math.random() * 3000));
        } else {
          down();
        }
      }
    };

    // Make the mole go down, either on timeout or click.
    let down = function() {
      mole.emit('down');
      mole.removeState('up');

      if(!gameover) {
        moleTimer = window.setTimeout(up, Math.max(2000, Math.random() * 15000));    
      }
    };

    // When clicked or focus-clicked...
    // Update the scoreboard.
    mole.addEventListener('click', function(){
      if(mole.is('up')) {
        mole.emit('shake');
        score++;
        scoreEl.setAttribute('value', score);
        down();
      }
    });

    let moleTimer = window.setTimeout(up, Math.random() * 12000);
  }
}

// Update the timer every 1s.
var updateTimer = function(){
  let currTime = parseInt(timerEl.getAttribute('value'), 10);
  
  if(currTime === 0) {
    // Finish State
    gameover = true;
//    musicEl.components.sound.stopSound();
    musicEl2.pause();
    musicEl2.currentTime = 0;
  } else {
    // Update Timer
    timerEl.setAttribute('value', currTime - 1);
    gameTimer = window.setTimeout(updateTimer, 1000);
 }
};

// Start the game
// Reset the scoreboard and timer
// Unfreeze the gameover state
// Start the timer
var startGame = function() {
  score = 0;
  
  scoreEl.setAttribute('value', 0);
  timerEl.setAttribute('value', 60);
  
  gameover = false;
  
//  musicEl.components.sound.playSound();
  musicEl2.play();
  window.clearTimeout(gameTimer);

  window.setTimeout(automateMoles, 100);
  gameTimer = window.setTimeout(updateTimer, 100);  
}

// When the start button is clicked... 
// start the the game.
startBtn.addEventListener('click', startGame);

            
          
!
999px
Loading ..................

Console