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.

            
              <div class="container">
 <input id="intro" type="checkbox">
 <input id="rules" type="checkbox">

 <section class="intro">
  <h2>Space Game</h2>
  <p>Jogo só com CSS, sem Javascript ;D</p>
  <label for="intro">Play!</label>
 </section>

 <section class="rules">
  <div>
   <h3>Regras</h3>
   <ul>
    <li>Mova seu personagem com o mouse</li>
    <li>Clique nas moedas para coletá-las</li>
    <li>Fuja dos tiros</li>
   </ul>
   <label for="rules">Entendi :)</label>
  </div>
 </section>

 <main class="game">
  <input type="checkbox" id="pause-button"></input>
  <label for="pause-button"></label>
  <div class="inimigo" id="i1"></div>
  <div class="inimigo" id="i2"></div>
  <div class="inimigo" id="i3"></div>
  <input tabindex="-1" type="checkbox" id="c1" class="coin"></input>
  <div class="inimigo" id="i4"></div>
  <input tabindex="-1" type="checkbox" id="c2" class="coin"></input>
  <div class="inimigo" id="i5"></div>
  <div class="inimigo" id="i6"></div>
  <input tabindex="-1" type="checkbox" id="c3" class="coin"></input>
  <div class="inimigo" id="i7"></div>
  <div class="inimigo" id="i8"></div>
  <div class="inimigo" id="i9"></div>
  <input tabindex="-1" type="checkbox" id="c4" class="coin"></input>
  <div class="inimigo" id="i10"></div>
  <input tabindex="-1" type="checkbox" id="c5" class="coin"></input>

  <div class="pause-container"></div>

  <div class="oops">
   Game over
  </div>
  <div class="venceu">
   Venceu! :)
  </div>
 </main>
</div>
            
          
!
            
              body {
    padding: 0;
    margin: 0;
    font-family: 'Audiowide', cursive;
}

/* CURSOR BOB ESPONJA */
.container {
    width: 100vw;
    height: 100vh;
    margin: 0 auto;
    cursor: url('https://github.com/FernandaBernardo/space-game/blob/master/images/bob.png?raw=true'), default;
    position: relative;
    border: 4px solid darkblue;
    box-sizing: border-box;
}

.game {
    background: url('https://github.com/FernandaBernardo/space-game/blob/master/images/fundo.jpg?raw=true');
    counter-reset: pontos;
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
}

.inimigo {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background-color: white;
    position: absolute;
    z-index: -1;
}

.coin {
    width: 20px;
    height: 20px;
    background-color: yellow;
    border-radius: 50%;
    box-shadow: 0px 0px 10px 4px darkgoldenrod;
    position: absolute;
    -webkit-appearance: none;
    -moz-appearance: none;
    z-index: -1;
}

/* ANIMACAO BOLINHAS */

.game:hover > .coin,
.game:hover > .inimigo {
    animation-name: moving;
    animation-fill-mode: backwards;
}

.coin:checked {
    counter-increment: pontos;
    visibility: hidden;
    /* NAO FUNCIONA display: none; */
}

#i1, #i6 {
    left: 9%;
    animation-duration: 6s;
    animation-iteration-count: 2;
}

#i2, #c3 {
    left: 23%;
    animation-duration: 5s;
    animation-iteration-count: 2;
}

#i3, #i7 {
    left: 37%;
    animation-duration: 7s;
    animation-iteration-count: 2;
}

#c1, #i8 {
    left: 51%;
    animation-duration: 6s;
    animation-iteration-count: 2;
}

#i4, #i9 {
    left: 65%;
    animation-duration: 12s;
    animation-iteration-count: 1;
}

#c2, #c4 {
    left: 79%;
    animation-duration: 7s;
    animation-iteration-count: 2;
}

#i5, #i10 {
    left: 90%;
    animation-duration: 10s;
    animation-iteration-count: 1;
}

#c5 {
    left: 29%;
    animation-duration: 10s;
    animation-iteration-count: 1;
}

#i6, #c3, #i7, #i8, #i9, #c4, #i10, #c5 {
    animation-delay: 10s;
}

@keyframes moving {
    0% {
        top: 0;
        z-index: -1;
    }
    1% {
        z-index: 2;
    }
    100% {
        top: calc(100% - 25px);
        z-index: 2;
    }
}

/* COUNTER */
.game:after {
    content: counter(pontos) '/5';
    font-size: 2em;
    text-align: center;
    float: right;
    padding: 0.3em;
    z-index: 5;
    color: white;
    vertical-align: middle;
}

.game:before {
    content: '';
    width: 20px;
    height: 20px;
    background-color: yellow;
    border-radius: 50%;
    box-shadow: 0px 0px 10px 4px darkgoldenrod;
    float: right;
    margin-top: 1.2em;
    margin-right: 0.5em;
}

/* PAUSE / PLAY BUTTON */
.pause-container {
    display: none;
    width: 100%;
    height: calc(100% - 32px - 0.3em);
    position: absolute;
    background-color: black;
    opacity: 0.7;
    z-index: 10;
    top: calc(32px + 0.3em); 
}

.pause-container:before {
    content: '';
    left: calc(32px + 0.3em);
    top: calc(-32px - 0.3em);
    width: calc(100% - 32px - 0.3em);
    height: calc(32px + 0.3em);
    position: absolute;
    background-color: black;
}

#pause-button + label {
    background-image: url('https://github.com/FernandaBernardo/space-game/blob/master/images/pause.png?raw=true');
    width: 32px;
    height: 32px;
    display: inline-block;
    position: absolute;
    top: 0;
    left: 0;
    margin: 0.3em;
}

#pause-button:checked + label {
    background-image: url('https://github.com/FernandaBernardo/space-game/blob/master/images/play.png?raw=true');
}

#pause-button {
    display: none;
}

#pause-button ~ .inimigo,
#pause-button ~ .coin {
    animation-play-state: running;
}

#pause-button:checked ~ .inimigo,
#pause-button:checked ~ .coin {
    animation-play-state: paused;
}

#pause-button:checked ~ .pause-container {
    display: block;
}

/* PERDEU */
.oops {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: red;
    z-index: 10;
    font-size: 3em;
    color: white;
    text-align: center;
}

.oops:hover {
    display: block;
}

.inimigo:hover ~ .oops {
    display: block;
}

/* VENCEU */
.venceu {
    display: none;
    position: absolute;
    width: 100%;
    height: 100%;
    background-color: green;
    top: 0;
    left: 0;
    z-index: 10;
    font-size: 3em;
    color: white;
    text-align: center;
}

#c1:checked ~ #c2:checked ~ #c3:checked ~ #c4:checked ~ #c5:checked
~ .venceu {
    display: block;
}


/* TELAS DE INTRO */
.intro {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    background-color: black;
    z-index: 15;
    text-align: center;
    color: white;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

#intro, #rules {
    display: none;
}

label[for="intro"], label[for="rules"] {
    padding: 1em;
    font-size: 1.2em;
    background-color: purple;
    border-radius: 5px;
    margin: 1em 25%;
    display: inline-block;
    border: 1px solid purple;
}

label[for="intro"]:hover, label[for="rules"]:hover {
    color: purple;
    background-color: white;
}

#intro:checked ~ .intro {
    display: none;
}

#intro:checked + #rules:checked ~ .rules {
    display: none;
}

.rules {
    display: block;
    z-index: 14;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    background-color: rgba(0, 0, 0, 0.5);
}

.rules div {
    background-color: white;
    display: inline-block;
    margin: 0 auto;
    z-index: 19;
    text-align: center;
    overflow: visible;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 2em;
}

.rules ul {
    list-style: none;
    padding: 0;
}

.rules ul > li {
    margin: 1em auto;
}
            
          
!
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