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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

            
              @import url(https://fonts.googleapis.com/css?family=Creepster|Open+Sans:400,700);


* {
  box-sizing:border-box;
}

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
}
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
  display: block;
}
ol, ul {
  list-style: none;
}

html {
  height: 100%;
}

body {
  font-family: 'Open Sans', sans-serif;

  position: relative;
  background-color: #000;
  display: flex;
  justify-content: center;
  
  background-image: url(https://www.dropbox.com/s/vr3ft858lif130r/background.jpg?raw=1);
  background-repeat: no-repeat;
  background-position: center;
  background-size: auto 100%;

  height: 100%;

  align-items: center;

  // @media (min-height: 700px) {
  //   align-items: center;
  // }

  &.hasvideo {
    background: #000;
  }

}

strong {
  font-weight: 600;
}

p {
  color: #FFF;
  font-size: 19px;
  padding: 0 20px;
}



.gameheading {
  color: #FFF;
  font-size: 38px;
  text-align: center;
  text-transform: uppercase;
  font-family: 'Creepster', cursive;
  margin-bottom: 40px;
  text-shadow: 1px 1px 30px #783323;
  letter-spacing: 1px;
  span {
    display: block;
    font-size: 80px;
  }
}


#game {
  margin: 0 auto;
  width: 420px;
  min-height: 495px;
  // padding: 20px 0 0;
  // height: calc(100vh - 120px);
  position: relative;
  

  @media (min-height: 800px) {
    min-height: 570px;
  }
  &:not(.in-game) {
    padding-bottom: 60px;
  }
  &:not(.in-game):after {
    content: "";
    width: 91px;
    height: 43px;
    background-image: url(https://www.dropbox.com/s/0hca3eajfs7in4r/bluegrasscomslogo.svg?raw=1);
    position: absolute;
    bottom: 0;
    left: 50%;
    margin-left: -45px;
  }
}
#game-target {
  width: 135px;
  height: 135px;
  border: 6px solid #999;
  border-radius: 30px;
  margin: 30px auto 10px;

  background-size: 60%;
  background-repeat: no-repeat;
  background-position: center;

}

#game-main {
  width: 420px;
  height: 368px;
  // border: 1px solid #000;
  padding: 10px;
  &.clicked {
    .icon:not(.correct) {
      opacity: 0.2;
    }
  }
}

@keyframes points {
  0%   { top: -10px; opacity: 1;}
  100% { top: -30px; opacity: 0;}
}

.icon {
  width: 46px;
  height: 46px;
  margin: 10px;
  display: inline-block;
  cursor: pointer;
  position: relative;
  background-repeat: no-repeat;
  background-position: center;

  transition: opacity 0.3s ease-in-out;

  &:before {
    position: absolute;
    top: -10px;
    color: #FFF;
    font-size: 25px;
    font-weight: 800;
    text-shadow: 1px 1px 5px #000;
    opacity: 0;
  }

  &.correct {
    &:before {
      content: "+5";
      animation: points 0.8s;
    }
  }
  &.wrong {
    &:before {
      content: "-1";
      animation: points 0.8s;
    }
  }
}


#score {
  font-size: 24px;
  background-color: #333;
  color: #FFF;
  display: inline-block;
  padding: 7px 0;
  width: 50px;
  text-align: center;
  position: absolute;
  top: 60px;
  left: 186px;
}


#counter {
  border: 1px solid #000;
  font-size: 18px;
  background-color: #FFF;
  color: #000;
  display: inline-block;
  padding: 7px 0;
  float: right;
  margin-top: -1px;
  position: absolute;
  top: 204px;
  right: 120px;
  width: 40px;
  height: 40px;
  text-align: center;
  border-radius: 50%;
}


.icon0 {
  background-image: url(https://www.dropbox.com/s/t0lizpej78xcpns/bluepumpkin.svg?raw=1);
}
.icon1 {
  background-image: url(https://www.dropbox.com/s/6v1yfw3wtjni914/orangepumpkin.svg?raw=1);
}
.icon2 {
  background-image: url(https://www.dropbox.com/s/2flwgc6ehaz405a/orangehat.svg?raw=1);
}
.icon3 {
  background-image: url(https://www.dropbox.com/s/leip0g735z20mmx/bats.svg?raw=1);
}
.icon4 {
  background-image: url(https://www.dropbox.com/s/usuql0kcflqqqyv/cauldron.svg?raw=1);
}
.icon5 {
  background-image: url(https://www.dropbox.com/s/1z9stgz1rw07t7x/ghosts.svg?raw=1);
}


button {
  background-color: orange;
  font-weight: bold;
  letter-spacing: 0.5px;
  padding: 12px 28px;
  border: 0;
  font-size: 16px;
  border-radius: 4px;
  text-transform: uppercase;
  outline: 0;
  cursor: pointer;
  transition: background 0.2s ease-in-out;
  &:hover {
    background-color: lighten(orange, 5);
  }
}

@keyframes countdown {
  0%   { font-size: 70px;opacity: 1;}
  100% { font-size: 300px;opacity: 0;}
}

.countdown {
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.6);
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.number {
  font-size: 70px;
  color: #FFF;
  font-weight: bold;
  &.active {
    animation: countdown 1s infinite;
  }
}

#startgame {
  margin-top: 40px;
}

.social-share {
  color: #FFF;
  margin-top: 20px;
  font-size: 14px;
  @media (min-height: 800px) {
    margin-top: 30px;
  }
  ul {
    text-align: center;
    margin-top: 12px;
    li {
      max-width: 25px;
      display: inline-block;
      margin: 0 8px;
      a {
        display: block;
        img {
          width: 25px;
          display: block;
        }
      }
    }
  }
}

.scored {
  color: #FFF;
  font-size: 19px;
  margin-top: 15px;
  margin-bottom: 10px;
  font-weight: 700;
  @media (min-height: 800px) {
    margin-top: 20px;
  }
}

.intro {
  text-align: center;
}

.congratsimg {
  display: block;
  max-width: 250px;
  margin: 0 auto;
  @media (min-height: 800px) {
    max-width: 300px;
  }
}

#gameVideo {
  position: fixed;
  left: 50%;
  top: 0;
  height: 100%;
  transform: translateX(-50%);
}

            
          
!
            
              // PLAY THE GAME HERE: https://bluegrasscoms.com/halloween/
// Created by Mike Samways and Rachel Russell for @Bluegrasscoms

function randomExcluded(min, max, excluded) {
  var n = Math.floor(Math.random() * (max-min) + min);
  if (n >= excluded) n++;
  return n;
}


var score = 0,
    previousTarget = 0;


function gameEnd() {

  var endgifs = ["https://www.dropbox.com/s/x56jqmgqdh4weh9/congrats.gif?raw=1", "https://www.dropbox.com/s/zpcj50qk7unal91/congrats2.gif?raw=1", "https://www.dropbox.com/s/agsedov8mlnxh9j/congrats3.gif?raw=1", "https://www.dropbox.com/s/ck1ptya4uxthtl8/congrats4.gif?raw=1"];
  $('#game').removeClass('in-game').html('<div style="text-align: center"><img class="congratsimg" src="'+endgifs[Math.floor((Math.random() * 4))]+'"/><p class="scored">YOU SCORED <strong style="font-size: 53px;display: block;">'+score+'</strong></p><button id="playgame">Play Again</button><div class="social-share">Share your score: <ul><li><a href="https://www.facebook.com/sharer/sharer.php?u=https%3A//bluegrasscoms.com/halloween" target="_blank"><img src="https://www.dropbox.com/s/vsfuchbzym4cl7i/facebook.svg?raw=1"/></a></li><li><a href="https://twitter.com/home?status=I%20scored%20'+score+'%20on%20the%20Wanted%20-%20Dead%20or%20Alive%20Halloween%20Game,%20try%20and%20beat%20my%20score%20here%20https%3A//bit.ly/2ECobCh%20%23WantedDeadOrAlive%20%23Halloween%20%23Bluegrasscoms" target="_blank"><img src="https://www.dropbox.com/s/ulp7ittyz8wbgy5/twitter.svg?raw=1"/></a></li></ul></div></div>');
  $('#playgame').on('click', function() {
    score = 0;
    startgame();
  });
}

function roundFunction() {

  var icons = ["icon0", "icon1", "icon2", "icon3", "icon4", "icon5"];

  var target = randomExcluded(0,5,previousTarget),
      hasTarget = false,
      iconhtml = '';

  previousTarget = target;

  $('#game-target').addClass('icon'+target);

  var count = 30;

  for (i = 0; i < count; i++) {

    if(i === 29) {
   
      setTimeout(function() {

        var theTarget = $('#game-main').find('.icon'+target);

        if(theTarget.length > 0) {

          var number = randomExcluded(0,5,target);
          $('#game-main').append('<div class="icon '+icons[number]+'"></div>');

        } else {

          $('#game-main').append('<div class="icon icon'+target+'"></div>');

        }

      }, 1);


    } else {

      var number = Math.floor(Math.random() * 6);
      
      if(number == target && hasTarget == false) {

        iconhtml += '<div class="icon '+icons[number]+'"></div>';
        hasTarget = true;
        
      } else {

        var number = randomExcluded(0,5,target);
        iconhtml += '<div class="icon '+icons[number]+'"></div>';

      }

    }

  }

  $('#game-main').html(iconhtml);

}

function round() {

  $('#game-main').html('');

  roundFunction();

  $('#game-main').on('click', '.icon', function() {

    var targetClass = $('#game-target').attr('class');

    if($(this).hasClass(targetClass)) {

      $(this).addClass('correct');

      score += 5;
      $('#score').html(score);

      $('#game-main').addClass('clicked');

      setTimeout(function() {
        $('#game-main').removeClass('clicked');
        $('#game-target').attr('class', '');
        roundFunction();
      }, 700);

    } else {

      var that = $(this);
      that.addClass('wrong');

      if(score > 0) {
        score -= 1;
        $('#score').html(score);
      }
 
      setTimeout(function() {
        that.removeClass('wrong');
      }, 700)

    }

  });

}

function startgame() {

  $('#game').addClass('in-game').html('<h2 class="gameheading">Happy Halloween</h2><div id="game-target"></div><div id="game-main"></div><div id="score">0</div><div id="counter">30</div>');

  round();

  countdown();


  setTimeout(function() {

    var timer = setInterval(function() {
    var firsticon = $('#game-main .icon:first-child');

      firsticon.clone().appendTo('#game-main');
      firsticon.remove();

    }, 1000);
    
    var number = 30,
        gameCounter = $('#counter');

    var counter = setInterval(function() {
      number = (number -= 1);
      gameCounter.html(number);
    }, 1000);

    setTimeout(function() {
      clearInterval(timer);
      clearInterval(counter);
      gameEnd();
    }, 30000)

  }, 3000);

}

function countdown() {

  $('<div class="countdown"><div class="number active">3</div></div>').appendTo('body');

  var countdownNumber = 3,
      numberContainer = $('.number');


  var counter = setInterval(function() {
    countdownNumber = (countdownNumber -= 1);
    numberContainer.html(countdownNumber).addClass('active');
  }, 1000);

  setTimeout(function() {
    clearInterval(counter);
     $('.countdown').remove();
  }, 3000);

}

$(document).ready(function() {

  if ($(window).width() > 800) {
    var video = '<video autoplay muted loop id="gameVideo"><source src="https://www.dropbox.com/s/pqdvbksztp2wyri/background.mp4?raw=1" type="video/mp4"></video>';
    $(video).prependTo('body');
    $('body').addClass('hasvideo');
  }

  $('#game').html('<div class="intro"><h2 class="gameheading"><span>Wanted</span> Dead or alive</h2><p>Find the wanted character quickly before they move to earn 5 points, click on the wrong ghoul and lose a point but work fast, you only have <strong>30 seconds</strong>! <span style="display: block;margin-top: 10px"><strong>Ghooooooood luuuck!</strong></span></p><button id="startgame">Start Game</button></div>');
  $('#game').on('click', '#startgame', function() {
    startgame();
  });

});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console