Pen Settings

HTML

CSS

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.

+ add another resource

JavaScript

Babel includes JSX processing.

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.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="overlay" class="">
  <div class="overlay-logo">
    <img src="http://ilovespidey.com/images/starwars.png" />
    <h1>Shooter</h1>
    
  </div>
  <div class="team-select">
    <h2>Choose your side:</h2>
    <ul id="teams">
      <li id="empire-logo">
        <img  src="http://vignette4.wikia.nocookie.net/clubpenguin/images/d/d2/Starwars_2013_Emote_Galactic_Empire.png" />
        <h3>Join the Empire!</h3>
        <h4>Shoot the rebels!</h4>
      </li>
      <li id="rebel-logo">
        <img src="http://vignette1.wikia.nocookie.net/clubpenguin/images/6/6f/Starwars_2013_Emote_Rebel_Alliance.png" />
        <h3>Join the Rebellion!</h3>
        <h4>Shoot stormtroopers!</h4>
      </li>
    </ul>
    <p class="directions"></p>
  </div>
</div>


<!-- MAIN PAGE -->
<div id="wrapper" class="hidden">
  <header>
  <div id="logo">
    <img src="http://ilovespidey.com/images/starwars.png" />
    <img id="gameid" src="http://vignette4.wikia.nocookie.net/clubpenguin/images/d/d2/Starwars_2013_Emote_Galactic_Empire.png" />
    <p><span id="identity">Stormtrooper</span> Shooter</p>
    <p id="button" class="button">Change Sides</p>
    <h1 id="clock">4:00</h1>
    <span id="line"></span>
  </div>
  <section id="scoreboard">
    <p id="points"></p>
    <p>Kills:
      <span id="kills">0</span>
    </p>  
    <p>Score:
      <span id="score">0</span>
    </p>
  </section>
    <ul id="stats">
      <li>Shots fired: 
        <span id="shots">0</span>
      </li>
      <li>Accuracy:
        <span id="accuracy">0%</span>
      </li>
    </ul>
    <ul id="legend">
      <li><span id="actor1name">Standing: </span>1pts</li>
      <li><span id="actor2name">Double: </span>2pts</li>
      <li><span id="actor3name">Pointing: </span>3pts</li>
      <li><span id="actor4name">Shooting: </span>4pts</li>
      <li><span id="actor5name">Running: </span>5pts</li>
    </ul>
  </header>
  
  <!-- Location Selector -->
  <nav>
    <p>Location: <span id="title"></span></p>
    <ul id="location">
      <li id="coruscant">
          <span>Coruscant</span>
          <img src="https://www.outerplaces.com/images/user_upload/temple.jpg" />
      </li>
      <li id="tatooine">
          <span>Tatooine</span>
          <img src="https://starwarsanon.files.wordpress.com/2013/08/tatooine-twin-suns.jpg" />
      </li>
      <li id="hoth" >
          <span>Hoth</span>
          <img src="https://starwarsanon.files.wordpress.com/2013/08/hoth-kotor.jpg" />
      </li>
      <li id="dagobah">
          <span>Dagobah</span>
          <img src="https://4.bp.blogspot.com/-FJa52w5dP4I/ViVkW2GBS8I/AAAAAAABP2c/V63QARdL5cY/s1600/Dark_Side_Cave_TFUII.png" />
      </li>
      <li id="executor" >
          <span>Executor</span>
          <img src="https://s-media-cache-ak0.pinimg.com/736x/af/9a/ca/af9acaf2574e5c3348b2f78c796b44f3.jpg" />
      </li>
      <li id="reset">Reset</li>
  </nav>
  
  <!-- Shoot Stormtroopers as the REBEL ALLIANCE -->
  <section id="playing-area">
    
    <article id="empire" class="">
    <!-- Stormtroopers -->
    <img id="actor1" src="https://www.sideshowtoy.com/wp-content/uploads/2014/10/902292-product-silo.png" /> 
    <img id="actor2" src="https://www.sideshowtoy.com/wp-content/uploads/2014/10/902291-product-silo1.png" /> 
    <img id="actor3" src="https://media.popcultcha.com.au/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/n/e/new.png" /> 
    <img id="actor4" src="http://pre03.deviantart.net/a4cb/th/pre/f/2015/211/b/1/stormtrooper__render__by_aracnify-d93gitr.png" /> 
    <img id="actor5" src="http://orig06.deviantart.net/1f07/f/2015/261/a/c/stormtrooper__1__render__by_aracnify-d9a1aew.png" /> 
  </article>
  
  <!-- Shoot the rebels as the GALACTIC EMPIRE -->
  <article id="rebels" class="hidden">
    
    <!-- Heroes -->
    <img id="actor1" src="https://media.popcultcha.com.au/media/catalog/product/s/t/starwarsc3por2d2artfxstatue.png" /> 
    <img id="actor2" src="https://www.sideshowtoy.com/wp-content/uploads/2014/09/902268-product-silo2.png" /> 
    <img id="actor3" src="https://www.sideshowtoy.com/wp-content/uploads/2013/08/901399-product-silo.png" /> 
    <img id="actor4" src="https://milnersblog.files.wordpress.com/2015/09/finn-star-wars-ep7-the-force-awakens-characters-cut-out-with-transparent-background_14.png" /> 
    <img id="actor5" src="https://milnersblog.files.wordpress.com/2015/09/rey-skywalker-star-wars-ep7-the-force-awakens-characters-cut-out-with-transparent-background_11.png" /> 
    </article>
  </section>
  
  <!-- Footer -->
  <footer>
    <p>Copyright &copy; 2015 Aaron Snowberger</p>
  </footer>
</div>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  position: relative;
}
.hidden {
  display: none;
}
body {
  background-color: black;
  background: url(http://images4.alphacoders.com/190/19098.jpg) bottom center no-repeat;
  background-size: cover!important;
  color: white;
  text-shadow: 0px 0px 3px black;
  font-size: 12px;
  font-family: Montserrat;
  overflow: hidden;
}
li {
  list-style: none;
}

/* OVERLAY (GAME START SCREEN) */
#overlay,
#wrapper {
  padding: 40px;
}
#overlay {
  background-color: rgba(0,0,0,0.7);
}
.overlay-logo {
  text-align: center;
}
.overlay-logo img {
  width: 200px;
}
.overlay-logo h1 {
  margin-top: 5px;
  font-size: 3em;
}
.team-select {
  max-width: 700px;
  margin: 10px auto;
  text-align: center;
}
.team-select h2 {
  padding: 10px;
  border-top: 1px solid #333;
  border-bottom: 1px solid #333;
  margin-bottom: 20px;
  color: gray;
}
.team-select li {
  display: inline-block;
  margin: 10px 40px;
  width: 250px;
}
#empire-logo img,
#rebel-logo img {
  box-shadow: 0 0 10px #777; 
}
#empire-logo img {
  border-radius: 100%;
  margin-bottom: 20px;
}
#empire-logo img:hover { box-shadow: 0 0 30px red; }
#rebel-logo img {
  border-radius: 100%;
  margin-bottom: 20px;
}
#rebel-logo img:hover { box-shadow: 0 0 30px #01befe; }

.team-select li h3 {
  font-size: 2em;
  margin-bottom: 10px;
}
.team-select li h4 {
  font-size: 1.5em;
  color: #777;
  font-weight: normal;
}

/* Logo */
#logo {
  margin-bottom: 20px;
  height: 60px;
}
#logo img {
  width: 80px;
  float: left;
  margin-right: 15px;
}
#gameid {
  height: 40px;
  width: 40px!important;
  margin: auto 0;
}
#logo p {
  font-size: 2em;
  margin-top: 5px;
  display: inline-block;
}
.button {
  position: relative;
  top: 0;
  margin-left: 10px;
  background: #bababa;
  text-shadow: none;
  box-shadow: 0 0 3px #777;
  border: 1px solid #777; 
  font-size: 0.75em!important;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 5px 10px;
  border-radius: 5px;
  vertical-align: bottom;
}
.button:hover {
  background: #ddd;
  cursor: pointer;
  box-shadow: 0 0 5px black;
}
#line {
  border-top: 2px solid white;
  box-shadow: 0px 0px 2px black;
  width: 100%;
  display: inline-block;
}
#title {
  position: absolute;
  top: -8px;
  left: 80px;
  font-size: 1.5em;
}
#clock {
  position: absolute;
  left: 49%;
  top: 0;
  padding: 5px 10px;
  border: 1px solid white;
  border-radius: 5px;
  background-color: rgba(0,0,0,0.3);
}
#stats {
  position: absolute;
  top: 30px;
  right: 0;
}
#stats li {
  display: inline-block;
  margin-left: 10px;
}
#legend {
  position: absolute;
  right: 0;
  padding: 20px;
  border: 1px solid white;
  border-radius: 10px;
  background-color: rgba(0,0,0,0.3);
}
#legend li {
  padding: 3px 0;
}
#legend span {
  display: inline-block;
  width: 85px;
}

/* Nav */
header {
  clear: both;
}
nav {
  width: 170px;
}
nav p {
  font-size: 1.3em;
  padding-bottom: 5px;
}
#location li {
  width: 80px;
  padding: 5px 0;
  margin-right: 5px;
  color: #dadada;
  display: block;
  text-align: center;
}
#location span {
  text-align: center;
  display: block;
  position: absolute;
  z-index: 3;
  width: 80px;
  height: 60px;
  padding-top: 22px;
  background-color: rgba( 60,60,60,0.7 );
  opacity: 0;
}
#location span:hover,
#location li:hover {
  opacity: 1;
  cursor: pointer;
}
#location img {
  width: 100%;
  height: 60px;
  border: 2px solid #ffffff;
  opacity: 0.8;
}
/* Scoreboard */
#scoreboard {
  position: absolute;
  right: 0;
  top: 10px;
  font-size: 1.3em;
}
#scoreboard p {
  display: inline-block;
}
#kills {
  margin-right: 20px;
}
#points {
  color: red;
  margin-right: 50px;
}

/* Playing Area */
#playing-area {
  position: absolute;
  bottom: 50px;
  right: 40px;
  /* border: 1px solid; */
  cursor: url(http://i54.tinypic.com/15q8yt0.jpg), auto;
}
#playing-area img {
  max-width: 200px;
  max-height: 300px;
  position: absolute;
  vertical-align: bottom;
  bottom: -300px;
}
@keyframes nudge {
  0%, 100% { transform: translate(100px, 0); }
  50% { transform: translate(300px, 0); }
  80% { transform: translate(-100px, 0); }
}

#actor1 {
  left: 5%;
  animation: nudge 5s linear infinite alternate;
}
#actor2 {
  left: 15%;
  animation: nudge 4.5s linear infinite alternate;
}
#actor3 {
  left: 30%;
  animation: nudge 4s linear infinite alternate;
}
#actor4 {
  left: 45%;
  animation: nudge 3.5s linear infinite alternate;
}
#actor5 {
  left: 55%;
  animation: nudge 3s linear infinite alternate;
}


/* Footer */
footer {
  position: absolute;
  bottom: 0;
  padding-bottom: 20px;
  text-align: center;
  width: 100%;
}
              
            
!

JS

              
                var $height = window.innerHeight;
var $width = window.innerWidth;
var $location = document.getElementById( "location" );
var $enemies = document.getElementById( "playing-area" );
var $button = document.getElementById( "button" );
var $teams = document.getElementById( "teams" );

/* Document Setup */
function setup() {
  var fiveMinutes = 60 * 2,
        display = document.querySelector('#clock');
    startTimer( fiveMinutes, display );
  
  
  var $wrapper = document.getElementById( "wrapper" );
  var $overlay = document.getElementById( "overlay" );
  $enemies.style.width = $width - 260 + "px";
  $enemies.style.top = $height - 360 + "px";

  $overlay.style.height = $height + "px";
  $wrapper.style.height = $height + "px";
  ( function() {
    if( $height < 600 ) {
      $location.style.display = "none";
    }
  });
}

/* Setup Event Listeners */
$location.addEventListener( "click", changeLocation, false ); 
$enemies.addEventListener( "click", shootTrooper, false );
$button.addEventListener( "click", changeSides, false );
$teams.addEventListener( "click", function(e) {
  document.getElementById( "overlay" ).className = "hidden";
  document.getElementById( "wrapper" ).className = "";
  if ( e.target.parentElement.id == "empire-logo" ) {
    loadRebels();
  } else {
    loadTroopers();
  }
});

/* Functions */
function changeSides(e) {
  if( document.getElementById( "empire" ).className != "hidden" ) {
    loadRebels();
  } else {
    loadTroopers();
  }
}

function changeLocation(e) {
  if( e.target.id == "reset" ) {
    reset();
  } else {
    document.getElementById( "title" ).innerHTML =  e.target.parentElement.id.charAt(0).toUpperCase() + e.target.parentElement.id.slice(1);
    document.getElementsByTagName( "BODY" )[0].style.background = "url(" + e.target.nextElementSibling.src + ") bottom center no-repeat";
  }
}

function loadRebels() {
  document.getElementById( "empire" ).className = "hidden";
  document.getElementById( "rebels" ).className = "";
  document.getElementById( "identity" ).innerHTML = "Rebel";
  document.getElementById( "gameid" ).src = "http://vignette1.wikia.nocookie.net/clubpenguin/images/6/6f/Starwars_2013_Emote_Rebel_Alliance.png";
  
  document.getElementById( "actor1name" ).innerHTML = "3PO/R2:";
  document.getElementById( "actor2name" ).innerHTML = "Han/Chewie:";
  document.getElementById( "actor3name" ).innerHTML = "Skywalker:";
  document.getElementById( "actor4name" ).innerHTML = "Finn:";
  document.getElementById( "actor5name" ).innerHTML = "Rey:";
}

function loadTroopers() {
  document.getElementById( "empire" ).className = "";
  document.getElementById( "rebels" ).className = "hidden";
  document.getElementById( "identity" ).innerHTML = "Stormtrooper";
  document.getElementById( "gameid" ).src = "http://vignette4.wikia.nocookie.net/clubpenguin/images/d/d2/Starwars_2013_Emote_Galactic_Empire.png";
  
  document.getElementById( "actor1name" ).innerHTML = "Standing:";
  document.getElementById( "actor2name" ).innerHTML = "Double:";
  document.getElementById( "actor3name" ).innerHTML = "Pointing:";
  document.getElementById( "actor4name" ).innerHTML = "Shooting:";
  document.getElementById( "actor5name" ).innerHTML = "Running:";
} 

var $killnum = 0;
var $totalpts = 0;
var $fired = 0;
var $accuracy = 0;

function shootTrooper( e ) {
  var $kills = document.getElementById( "kills" );
  var $score = document.getElementById( "score" );
  var $points = document.getElementById( "points" );
  var $shots = document.getElementById( "shots" );
  var $stats = document.getElementById( "accuracy" );
  var $num = 0; 
  
  $fired++;
  
  switch(e.target.id) {
    case 'actor1':
      $num = 1; $killnum++;
      break;
    case 'actor2':
      $num = 2; $killnum++;
      break;
    case 'actor3':
      $num = 3; $killnum++;
      break;
    case 'actor4':
      $num = 4; $killnum++;
      break;
    case 'actor5':
      $num = 5; $killnum++;
      break;
    default:
      $num = 0;
  }
  
  $kills.innerHTML = $killnum;
  $score.innerHTML = $totalpts += $num;
  $points.innerHTML  = "+" + $num;
  $shots.innerHTML = $fired;
  $stats.innerHTML = Math.round($killnum/$fired * 100) + "%";
  
  if ( e.target.id == "playing-area" ) { 
    // Do nothing
  } else {
    e.target.style.display = "none";
    respawn( e.target, $num );
  }
}

function respawn( actor, time ) {
  setTimeout( function() {
    actor.style.top = Math.random()*90 + "%";
    actor.style.left = Math.random()*90 + "%";
    actor.style.display = "block";
  }, time*1000 );
}

function startTimer( duration, display ) {
    var timer = duration, minutes, seconds;
    setInterval( function () {
        minutes = parseInt( timer / 60, 10 );
        seconds = parseInt( timer % 60, 10 );

        minutes = minutes < 10 ? minutes : minutes;
        seconds = seconds < 10 ? "0" + seconds : seconds;

        display.textContent = minutes + ":" + seconds;

        if (--timer < 0) {
          reset();  
          // timer = duration;
        } 
    }, 1000);
}

window.onload = setup();
/* want to resize everything on screen or window resize... */

function reset() {
  document.getElementById( "overlay" ).className = "";
  document.getElementById( "wrapper" ).className = "hidden";
  document.getElementById( "title" ).innerHTML = "";
  document.getElementsByTagName( "BODY" )[0].style.background = "url(http://images4.alphacoders.com/190/19098.jpg) bottom center no-repeat";
}
              
            
!
999px

Console