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 Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

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.

            
              <!-- GAME MUSIC/SOUNDS -->
<audio id="floorup">
  <source src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1319/Jump.wav" type="audio/mpeg">
</audio>
<audio id="floordown">
  <source src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1319/Hit_Hurt5.wav" type="audio/mpeg">
</audio>
<audio id="goal">
  <source src="http://themushroomkingdom.net/sounds/wav/mk64/mk64_announcer11-jp.wav" type="audio/mpeg">
</audio>
<audio id="gamemusic">
  <source src="http://www.joacimnilsson.se/DST-AngryMod.mp3" type="audio/mpeg">
</audio>
<!-- END GAME MUSIC/SOUNDS -->

<div id="world">
  <ul id="cube">
    <li></li><!-- TOP -->
    <li></li><!-- BOTTOM -->
    <li></li><!-- LEFT -->
    <li></li><!-- RIGHT -->
    <li></li><!-- BACK -->
    <li></li><!-- FRONT -->
  </ul>
  <ul id="floors">
  </ul>  
  <div id="result">Start by move the block!</div>
  <div id="stats"></div>
</div>
            
          
!
            
              html, body {
  width:100%;
  height:100%;
  -webkit-perspective:500;
  background:black;
  overflow:hidden;
}

#world {
  transform-style:preserve-3d;
  width:500px;
  height:500px;
  background:#333;
  position:relative;
  margin:0 auto 0;
  transform:rotateX(45deg) rotate(0deg) translateZ(-300px);
  transform-origin:250px 250px -250px;
  transition:1s;
}

#cube {
  width:100px;
  height:100px;
  position:absolute;
  transform:translateZ(50px);
  transform-style:preserve-3d;
  transition:.1s;
  transform-origin:50px 50px 50px;
}

ul#cube li {
  width:100px;
  height:100px;
  position:absolute;
  background:rgba(0,255,0,.4);
  box-shadow:0 0 10px rgba(0,255,0,1);
}

ul#cube li:nth-child(1) { transform:translateZ(50px); }
ul#cube li:nth-child(2) { transform:translateZ(-50px); }
ul#cube li:nth-child(3) { transform:rotateX(90deg) rotateY(90deg) translateZ(-50px); }
ul#cube li:nth-child(4) { transform:rotateX(90deg) rotateY(90deg) translateZ(50px); }
ul#cube li:nth-child(5) { transform:rotateX(90deg) translateZ(50px); }
ul#cube li:nth-child(6) { transform:rotateX(90deg) translateZ(-50px); }

ul#floors {
  width:500px;
  height:500px;
  transform-style:preserve-3d;
}

.floor {
  width:500px;
  height:500px;
  position:absolute;
  transition:1s;
  opacity:0;
  box-shadow:0 0 10px #fff;
}

.floordown, .floorup {
  position:absolute;
  height:100px;
  width:100px;
  background:rgba(255,0,0,.4);
  box-shadow:inset 0 0 0 2px #fff;
}

.floorup {
  background:rgba(0,255,0,.4);
}



$blockSize : 100px;

@for $x from 0 through 4 {
  @for $y from 0 through 4{
    .x#{$x}y#{$y}{
      top:  $x * $blockSize;
      left: $y * $blockSize;
    }
  }
}


.floor0 {  background:rgba(200,200,200,.9); opacity:1; box-shadow:none; }
.floor1 {  background:rgba(205,205,205,.9); transform:translateZ(100px); }
.floor2 { background:rgba(210,210,210,.9); transform:translateZ(200px); }
.floor3 { background:rgba(215,215,215,.9); transform:translateZ(300px); }
.floor4 { background:rgba(220,220,220,.9); transform:translateZ(400px); }
.floor5 { background:rgba(225,225,225,.9); transform:translateZ(500px); }
.floor6 { background:rgba(230,230,230,.9); transform:translateZ(600px); }
.floor7 { background:rgba(235,235,235,.9); transform:translateZ(700px); }
.floor8 { background:rgba(240,240,240,.9); transform:translateZ(800px); }
.floor9 { background:rgba(245,245,245,.9); transform:translateZ(900px); }
.floor-gameover { background:rgba(0,255,0,.9); transform:translateZ(1000px); }

#result {
  width:500px;
  height:250px;
  text-align:center;
  line-height:250px;
  font-family:helveticaNeue-light;
  color:#fff;
  font-size:2em;
  transform:translateY(-625px) translateZ(125px) rotateX(-90deg);
  transition:1s;
  position:absolute;
}

#stats {
  width:500px;
  height:250px;
  text-align:center;
  line-height:250px;
  position:absolute;
  font-family:helveticaNeue-light;
  color:#fff;
  font-size:1em;
  transform:translateY(-625px) translateZ(200px) rotateX(-90deg);
  transition:1s;
}
            
          
!
            
              var maps = [
  // 1 = Red block
  // 2 = Green block
  [[0, 0, 0, 0, 0], // FLOOR 0
   [0, 0, 0, 0, 0], 
   [0, 0, 0, 0, 0], 
   [0, 0, 0, 0, 0], 
   [0, 0, 0, 0, 2]],
  
  [[2, 1, 0, 0, 0], // FLOOR 1
   [0, 1, 0, 1, 0], 
   [0, 0, 0, 1, 0], 
   [1, 1, 1, 1, 0], 
   [1, 1, 1, 1, 0]],
  
  [[0, 1, 0, 0, 0], // FLOOR 2
   [0, 1, 0, 1, 0], 
   [0, 1, 0, 1, 0], 
   [0, 1, 0, 1, 0], 
   [0, 0, 0, 1, 2]],
  
  [[0, 0, 0, 1, 1], // FLOOR 3
   [0, 1, 0, 1, 1], 
   [0, 1, 0, 1, 1], 
   [0, 1, 0, 0, 0], 
   [2, 1, 1, 1, 0]],
  
  [[0, 0, 0, 0, 0], // FLOOR 4
   [0, 1, 1, 1, 0], 
   [0, 1, 2, 1, 0], 
   [0, 1, 0, 1, 0], 
   [0, 1, 0, 0, 0]],
  
  [[2, 0, 0, 0, 0], // FLOOR 5
   [1, 1, 1, 1, 0], 
   [0, 0, 0, 1, 0], 
   [0, 1, 1, 1, 0], 
   [0, 0, 0, 0, 0]],
  
  [[0, 1, 0, 0, 2], // FLOOR 6
   [0, 1, 0, 1, 1], 
   [0, 1, 0, 0, 0], 
   [0, 1, 1, 1, 0], 
   [0, 0, 0, 0, 0]],
  
  [[1, 1, 1, 1, 0], // FLOOR 7
   [0, 0, 0, 1, 0], 
   [0, 1, 0, 1, 0], 
   [0, 1, 0, 1, 0], 
   [2, 1, 0, 0, 0]],
  
  [[1, 1, 0, 0, 2], // FLOOR 8
   [1, 0, 0, 1, 0], 
   [0, 0, 1, 0, 0], 
   [0, 1, 0, 0, 1], 
   [0, 0, 0, 1, 1]],
  
  [[1, 1, 1, 1, 0], // FLOOR 9
   [0, 0, 0, 1, 0], 
   [0, 1, 2, 1, 0], 
   [0, 1, 1, 1, 0], 
   [0, 0, 0, 0, 0]] 
];

$('#gamemusic')[0].play();

var cube = $('#cube'), /* <ul id="cube"> ... </ul> */
    world = $('#world'), /* <div id="world"> ... </div> */
    result = $('#result'), /* <div id="result"> ... </div> */
    stats = $('#stats'), /* <div id="stats"> ... </div> */
    floors = $('#floors'), /* <div id="floors"> ... </div> */
    x = 0, /* X CORDINATES */
    y = 0; /* Y CORDINATE */
    z = 0, /* Z CORDINATES */
    moves = 0,
    goal = 0;


(function (){
  var mapHTML = '';
  
  var mapAction = [
    0,
    function (){ return "floordown";},
    function (){ return "floorup";}
  ];
  
  maps.forEach(function(map, i){
    var floor = 'floor' + i;
    mapHTML += '<li class="floor '+floor+'">';
      map.forEach(function(row, x){
        row.forEach(function ( action, y ){
          if ( action > 0 ){
            mapHTML += '<div class="' + mapAction[action]() + ' x' + x + 'y' + y + '"></div>';
          }
        });
      });
    mapHTML += '</li>';
  });
  // Last floor
  mapHTML += '<li class="floor floor'+(maps.length)+' floor-gameover"><li>';
  
  floors.html(mapHTML);
})(); // Render Maps

$('body').keydown(function (e) { /* On keydown */
  
  if (e.keyCode == 40) { //CHECK KEYCODE IF DOWN ARROW
    if (x !== 4) {
      moves++;
      x++;
    }
  } else if (e.keyCode == 39) { //CHECK KEYCODE IF UP ARROW
    if (y !== 4) {  
      moves++;
      y++;
    }
  } else if (e.keyCode == 38) { //CHECK KEYCODE IF RIGHT ARROW
    if (x !== 0) {
      moves++;
      x--;
    }  
  } else if (e.keyCode == 37) { //CHECK KEYCODE IF LEFT ARROW
    if (y !== 0) {
      moves++;
      y--;
    }
  }

  var actions = [
    0, // NO ACTION
    function (){ // Go Down
      z--;
      $('#floordown')[0].play();
    },  
    function (){    // Go up
      z++;
      $('#floorup')[0].play();
    }  
  ]
  
  var action = maps[z][x][y];
  
  if ( action > 0) {
    actions[action]();
  }
  
  /* HIDE THE ABOVE FLOORS */
  var floor = $('.floor' + z + '');
  if ( z >= z ) { floor.css({ "opacity": "1" }); }
  $('.floor' + (z+1) + '').css({ "opacity": "0" });
  /* END HIDE ABOVE FLOORS */
  
  /* BASIC WORLD FLOATING DEPENDING ON WHICH FLOOR */
  world.css({
    "-webkit-transform": "rotateX(45deg) rotate(0deg) translateZ(" + (z * -100 - 300) + "px)" 
  });
  result.css({
    "-webkit-transform": "translateY(-625px) translateZ(" + (z * 100 + 125) + "px) rotateX(-90deg)" 
  });
  stats.css({
    "-webkit-transform": "translateY(-625px) translateZ(" + (z * 100 + 200) + "px) rotateX(-90deg)" 
  });
  /* END BASIC WORLD FLOATING DEPENDING ON WHICH FLOOR */
  
  /* MOVEMENT OF THE CUBE ITSELF */
  cube.css({
    "-webkit-transform":
    "translateX(" + y * 100 + "px)" +
    "translateY(" + x * 100 + "px)" + 
    "translateZ(" + (z * 100 + 51) + "px)"
  });
  /* END MOVEMENT OF THE CUBE ITSELF */
  
  /* RESULTS & FLOOR maps.length */
  if ((x >= 0) && (y >= 0) && (z == maps.length)) { 
    result.html("Congratulations!");
    goal++;
    if ( goal == 1 ) {
      stats.html("You've scored: " + moves * 79 + "/10428 points");
      $('#goal')[0].play();
      $('#cube li').css({
        "background":"rgba(255,255,255,.9)",
        "box-shadow":"0 0 10px rgba(255,255,255,1)"
      });
    }
  } else {
    result.html("Moves " + moves + " Floor " + z + "/10");
  }
  /* END RESULTS & FLOOR 10 */
  
});
            
          
!
999px
Loading ..................

Console