123

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="wrapper">

  <div class="intro">
    <h1>"Air bomb"</h1>
    <div class="instructions">
      <div>As soon as this message disappears, you'll see airplanes flying above the ground</div>
      <div>Your mission is to bomb them by clicking on them</div>
      <div>Pay attention, the game is on time and you have only 15 seconds to shoot all the airplanes</div>
      <div>The score is change between the airplanes</div>
      <div>Enjoy</div>
    </div>

    <div class="intro--timer">
      <div class="red"></div>
      <div class="yellow"></div>
      <div class="green"></div>
    </div>
  </div>
  
  <div class="stage"></div>

  <div class="cloud cloud-1"></div>
  <div class="cloud cloud-2"></div>
  <div class="cloud cloud-3"></div>
  <div class="cloud cloud-4"></div>
  <div class="cloud cloud-5"></div>
  <div class="cloud cloud-6"></div>
  <div class="cloud cloud-7"></div>
  <div class="cloud cloud-8"></div>
  <div class="cloud cloud-9"></div>
  <div class="cloud cloud-10"></div>

  <!-- Airplanes -->
  <input class="airplane_1" type="radio" id="airplane_1" />
  <input class="airplane_2" type="radio" id="airplane_2"  />
  <input class="airplane_3" type="radio" id="airplane_3"  />
  <input class="airplane_4" type="radio" id="airplane_4"  />
  <input class="airplane_5" type="radio" id="airplane_5"  />
  <input class="airplane_6" type="radio" id="airplane_6"  />
  <input class="airplane_7" type="radio" id="airplane_7"  />
  <input class="airplane_8" type="radio" id="airplane_8"  />
  <input class="airplane_9" type="radio" id="airplane_9"  />
  <input class="airplane_10" type="radio" id="airplane_10"  />
  <input class="airplane_11" type="radio" id="airplane_11"  />
  <input class="airplane_12" type="radio" id="airplane_12"  />
  <input class="airplane_13" type="radio" id="airplane_13"  />


  <label class="airplane airplane-1" for="airplane_1"></label>
  <label class="airplane airplane-2" for="airplane_2"></label>
  <label class="airplane airplane-3" for="airplane_3"></label>
  <label class="airplane airplane-4" for="airplane_4"></label>
  <label class="airplane airplane-5" for="airplane_5"></label>
  <label class="airplane airplane-6" for="airplane_6"></label>
  <label class="airplane airplane-7" for="airplane_7"></label>
  <label class="airplane airplane-8" for="airplane_8"></label>
  <label class="airplane airplane-9" for="airplane_9"></label>
  <label class="airplane airplane-10" for="airplane_10"></label>
  <label class="airplane airplane-11" for="airplane_11"></label>
  <label class="airplane airplane-12" for="airplane_12"></label>
  <label class="airplane airplane-13" for="airplane_13"></label>


  <div class="timer"><span></span></div>

  <div class="gameover">The game is over, you can&nbsp;<a href="">try again</a></div>

  <div class="score">Your score is: <span class="score--current"></span></div>

  <div class="author">Created by <a href="https://www.linkedin.com/in/itzikpop/">Itzik Pop</a>. <span>100% JS free</span></div>
</div>

            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,400,600);

$timer: 10s;

$white: rgb(255, 255, 255);
$black: darken($white, 100%);
$gray: darken($white, 70%);
$green: rgb(55, 200, 123);
$red: rgb(255, 0, 0);
$yellow: rgb(255, 255, 0);

// Clouds
$cloud-items: 10;
$cloud-color: $white;
$cloud-h: 40px;
$cloud-w: 100px;
$cloud-radius: 100%;
$cloud_move--speed: radnom()*#{$cloud-items} + 's';
$cloud_move--delay: random()*#{$cloud-items} + 's';
$cloud-zindex: 1;

// Airplane
$airplane-items: 21;

// Timer
$timer-animation-speed: 15s;
$timer-w: 100%;
$timer-h: 5px;
$timer-bg: $gray;
$timer-duration-bg: $green;
$timer-zindex: $cloud-zindex+2;

// Game Over
$gameover-animation-speed: 0.5s;
$gameover-bg: $green;
$gameover-zindex: $cloud-zindex+10;

// Pixel art
// $colors: (
//   'o': transparent,
//   'b': rgb(0, 0, 255),
//   'g': rgb(160, 160, 160),
//   'w': rgb(200, 200, 200),
//   'd': rgb(0, 0, 0)
//   );

$size: 3px !default;

// $pixel-art: (
//   airplane: (
//     (o o o o o o o o o o o o o o o o o o o g g g g o o o o o o o o o o o o o o o o o o o)
//     (o o o o o o o o o o o o o o o o o o g g b b g g o o o o o o o o o o o o o o o o o o)
//     (o o o o o o o o o o o o o o o o o o g g g g g g o o o o o o o o o o o o o o o o o o)
//     (o o o o o o o o o o o o o o o o o o g g g g g g o o o o o o o o o o o o o o o o o o)
//     (o o o o o o o o o o o o o o o o o o g w g g w g o o o o o o o o o o o o o o o o o o)
//     (o w w w o w w w o w w w o w w w o o g w g g w g o o w w w o w w w o w w w o w w w o)
//     (o o d o o o d o o o d o o o d o o o g w g g w g o o o d o o o d o o o d o o o d o o)
//     (g g g g g g g g g g g g g g g g g g g w g g w g g g g g g g g g g g g g g g g g g g)
//     (g g g w w w w w w g g g g g g g g g g w g g w g g g g g g g g g g w w w w w w g g g)
//     (o o g g g g g g g g g g g g g g g g g w g g w g g g g g g g g g g g g g g g g g o o)
//     (o o o o o o g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g o o o o o o)
//     (o o o o o o o o o o o o o o g g g g g g g g g g g g g g o o o o o o o o o o o o o o)
//     (o o o o o o o o o o o o o o o o o o g g g g g g g o o o o o o o o o o o o o o o o o)
//     (o o o o o o o o o o o o o o o o o o w g g g g w o o o o o o o o o o o o o o o o o o)
//     (o o o o o o o o o o o o o o o o o o w g g g g w o o o o o o o o o o o o o o o o o o)
//     (o o o o o o o o o o o o o o o o o o w g g g g w o o o o o o o o o o o o o o o o o o)
//     (o o o o o o o o o o o o o o o o o o w g g g g w o o o o o o o o o o o o o o o o o o)
//     (o o o o o o o o o o o o o o o o o o w g w w g w o o o o o o o o o o o o o o o o o o)
//     (o o o o o o o o o o o o o o o o o o w g w w g w o o o o o o o o o o o o o o o o o o)
//     (o o o o o o o o o o o o o o o o o o w g w w g w o o o o o o o o o o o o o o o o o o)
//     (o o o o o o o o o o o o o o o o o o g g w w g g o o o o o o o o o o o o o o o o o o)
//     (o o o o o o o o o o o o o o o g g g g g w w g g g g g o o o o o o o o o o o o o o o)
//     (o o o o o o o o o o o o o o w w w w g g w w g g w w w w o o o o o o o o o o o o o o)
//   )
// );

// @function pixelize($matrix, $size) {
//   $sh: '';
//   $rows: length($matrix);

//   @for $row from 1 through $rows {
//     $row-num: nth($matrix, $row);

//     @for $col from 1 through length($row-num) {
//       $dot: nth($row-num, $col);

//       $sh: $sh + ($size*$col) + ' ' + ($size*$row) + ' ' + map-get($colors, $dot);

//       @if not ($col == length($row-num) and $row == $rows) {
//         $sh: $sh + ',';
//       }
//     }
//   };

//   @return unquote($sh);
// }

@function movement-h() {
  $position: random()*75 + 'vh';

  @return #{$position};
}

@function movement-w() {
  $position: random()*90 + 'vw';

  @return #{$position};
}

// Mixins
@mixin size($height, $width) {
  height: $height;
  width: $width;
}

@mixin square($size) {
  @include size($size, $size);
}

@for $clouds from 1 through $cloud-items {

  @keyframes clouds_move-#{$clouds} {
    0% {
      left: -150px;
    }

    100% {
      left: 100vw;
    }
  }
}

@for $airplane from 1 through $airplane-items {

  @keyframes airplane_move-#{$airplane} {
    0% {
      bottom: -100px;
    }

    100% {
      bottom: 100vh;
    }
  }
}

@keyframes intro {
  0%, 90% {
    transform: translateX(0);
  }

  100% {
    transform: translateX(-110vw);
  }
}

@keyframes intro-timer {
  0%, 90% {
    opacity: 1;
  }

  100% {
    opacity: 0;
  }
}

@keyframes intro-timer-2 {
  0% {
    opacity: 0;
  }

  1%, 100% {
    opacity: 1;
  }
}

@keyframes stage_move {
  0% {
    top: 30%;
  }

  100% {
    top: 70%;
  }
}

@keyframes timer {
  0% {
    opacity: 0.25;
    width: 0;
  }
  
  100% {
    display: block;
    opacity: 1;
    width: $timer-w;
  }
}

@keyframes gameover {
  0%, 99% {
    transform: translateY(-120vh);
  }
  
  100% {
    transform: translateY(0);
  }
}

html, body {
  @include size(100vh, 100vw);
  display: flex;
  flex: 1 0 100%;
  font-family: 'Source Sans Pro', sans-serif;
  overflow: hidden;
}

.wrapper {
  counter-reset: game;
  display: flex;
  flex: 1;
  height: 100vh;
  position: relative;
  width: 100vw;
}

.intro {
  @include size(100vh, 100vw);
  animation: intro #{$timer} linear #{$timer - 9} forwards;
  background-color: $white;
  display: flex;
  flex-direction: column;
  font-size: 1rem;
  left: 0;
  padding: 0 10px;
  position: fixed;
  top: 0;
  z-index: $gameover-zindex * 2;

  h1 {
    align-self: center;
    border-bottom: solid 2px $black;
    font-size: 3rem;
    font-weight: 600;
    margin: 30px 0;
  }

  .instructions {
    align-self: center;
    display: flex;
    flex-direction: column;
    margin-bottom: 20px;

    div {
      margin-bottom: 10px;

      &:last-child {
        margin-bottom: 0;
      }
    }
  }

  &--timer {
    align-items: center;
    background-color: $black;
    display: flex;
    flex-direction: column;
    height: 110px;
    margin: 0 auto;
    padding: 10px;
    width: 60px;

    div {
      @include square(30px);
      background-color: rgba($white, 0.6);
      border-radius: 100%;
      margin-bottom: 10px;
      opacity: 0;

      &.red {
        animation: intro-timer (#{$timer - 9}) linear (#{$timer - 5}) forwards;
        background-color: $red;
        opacity: 1;
      }

      &.yellow {
        animation: intro-timer (#{$timer - 9}) linear (#{$timer - 5}) forwards;
        background-color: $yellow;
      }

      &.green {
        animation: intro-timer-2 (#{$timer - 9}) linear (#{$timer - 4}) forwards;
        background-color: $green;
      }

      &:last-child {
        margin-bottom: 0;
      }
    }
  }
}

.stage {
  animation: stage_move (#{$timer * 2}) linear forwards;
  background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/44572/map.jpg);
  background-repeat: no-repeat;
  background-position: 50% 50%;
  background-size: 100% 100%;
  display: flex;
  height: 150vh;
  left: 50%;
  margin: 0 auto;
  position: absolute;
  top: 30%;
  transform: translate(-50%, -50%);
  width: 100vw;
  z-index: 0;
}

input[type="radio"] {
  @include square(0);
  appearance: none;
  left: 0;
  outline: 0;
  position: absolute;
  top: 0;

  &:checked {
    counter-increment: game;
  }

  &:nth-of-type(2n+2) {

    &:checked {
      counter-increment: game 5;
    }
  }

  &:nth-of-type(3n+3) {

    &:checked {
      counter-increment: game 10;
    }
  }
}

// Clouds
// ================================================================================
.cloud {
  @include size($cloud-h, $cloud-w);
  background-color: $cloud-color;
  border-radius: ($cloud-radius/2) / (#{$cloud-radius});
  box-shadow: 0 0 20px 0 rgba(darken($cloud-color, 100%), 0.1);
  left: calc(-100vw - #{$cloud-w});
  position: absolute;
  z-index: $cloud-zindex;

  &:before,
  &:after {
    background-color: $white;
    border-radius: $cloud-radius;
    content: '';
    position: absolute;
  }

  &:before {
    height: $cloud-h;
    left: 10%;
    top: -40%;
    width: ($cloud-w * 0.4);
  }

  &:after {
    height: ($cloud-h * 1.5);
    right: 5%;
    top: -70%;
    width: ($cloud-w * 0.6);
  }

  &:nth-of-type(2n+2) {
    transform: scale(0.7);

    &:before,
    &:after {
      box-shadow: -1px 0 10px 0 rgba(darken($cloud-color, 100%), 0.1);
    }
  }

  &:nth-of-type(3n+3) {
    transform: scale(0.5);

    &:before,
    &:after {
      box-shadow: -1px 0 10px 0 rgba(darken($cloud-color, 100%), 0.1);
    }
  }

  &:nth-of-type(even) {

    &:before,
    &:after {
      box-shadow: 1px 0 10px 0 rgba(darken($cloud-color, 100%), 0.1);
    }

    &:before {
      z-index: 1;
    }
  }

  @for $i from 1 through $cloud-items {
    &:nth-of-type(#{$i}) {
      top: movement-h();
      $speed: random(20)*5 + 's';
      $delay: random($cloud-items/10)*1.5 + 's';

      animation: clouds_move-#{$i} #{$speed} linear #{$delay} infinite;
    }
  }
}

// Ariplane
// ================================================================================
.airplane {
  background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/44572/airplane-04.svg);
  background-repeat: no-repeat;
  background-size: 100% 100%;
  background-position: 0 0;
  bottom: -100px;
  // height: $size*length(map-get($pixel-art, airplane));
  height: 100px;
  left: 50%;
  position: absolute;
  transform: translateX(-50%);
  // width: $size*length(nth(map-get($pixel-art, airplane), 1));
  width: 75px;

  &:nth-of-type(2n+2) {
    transform: translateX(-50%) scale(0.66);
  }

  &:nth-of-type(3n+3) {
    transform: translateX(-50%) scale(0.33);
  }

  // &:after {
  //   @include square($size);
  //   box-shadow: pixelize(map-get($pixel-art, airplane), $size);
  //   content: '';
  //   left: -$size;
  //   position: absolute;
  //   top: -$size;
  // }

  &:hover {
    cursor: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/44572/crosshir.png) 25 15, auto;
  }

  @for $i from 1 through $airplane-items {
    &:nth-of-type(#{$i}) {
      left: movement-w();
      $speed: random(10)*2 + 's';
      $delay: random((($airplane-items - 1)/10)*1.5);

      animation: airplane_move-#{$i} #{$speed} linear #{$delay + $timer} infinite;
    }
  }
}

@for $i from 1 through $airplane-items {
  .airplane_#{$i} {

    &:checked {

      & ~ .airplane-#{$i} {
        opacity: 0;
        transform: translateX(-50%) scale(0.01);
        transition: all 0.5s linear;
      }
    }
  }
}

// Timer
// ================================================================================
.timer {
  @include size($timer-h, $timer-w);
  background-color: $timer-bg;
  border-bottom: solid 1px darken($timer-bg, 100%);
  left: 0;
  position:fixed;
  top: 0;
  z-index: $timer-zindex;

  span {
    @include size($timer-h, $timer-w);
    animation: timer (#{$timer * 1.5}) linear (#{$timer + 2}) forwards;
    background-color: $timer-duration-bg;
    display:block;
    opacity: 0;
  }
}

// Gameover
// ================================================================================
.gameover {
  @include size(100vh, 100vw);
  align-items: center;
  animation: gameover (#{$timer / 20}) linear #{$timer + ($timer * 1.5 + 2)} forwards;
  background-color: rgba($gameover-bg, 0.75);
  color: white;
  display: flex;
  flex-direction: column;
  justify-content: center;
  font-size: 3rem;
  padding: 10px;
  position: fixed;
  top: 0;
  transform: translateY(-120vh);
  z-index: $gameover-zindex;
  
  a {
    color: white;
  }
}

// Score
// ================================================================================
.score, .author {
  background-color: $white;
  border: solid 1px $black;
  font-size: 1.2rem;
  left: 10px;
  padding: 10px;
  position: fixed;
  z-index: $timer-zindex+10;
}

.score {
  bottom: 60px;
  right: 10px;

  @media (min-width: 480px) {
    bottom: 10px;
    right: auto;
  }


  &--current {

    &:after {
      content: counter(game);
      font-weight: 600;
      margin: 0 10px;
    }
  }
}

// Author
// ================================================================================
.author {
  bottom: 10px;
  left: 10px;
  right: 10px;

  @media (min-width: 480px) {
    left: auto;
  }

  span {
    font-weight: 600;
  }

  a {
    color: $black;
  }
}

            
          
!
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.

Console