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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

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.

HTML

            
              <main class="gameboy">
    <div class="elements">
      <div class="element element-1"></div>
      <div class="element element-2"></div>
      <div class="element element-3"></div>
      <div class="element element-4"></div>
      <div class="element element-5"></div>
    </div>
    <div class="console">
      <div class="gameboy-body">
        <header></header>
        <section class="screen">
          <span id="bright"></span>
          <div class="glass">
              <canvas id="snakegame" width="190" height="150"></canvas>
          </div>
          <div id="score" class="none"></div>
        </section>
        <section class="actions">
          <div class="directions">
            <button class="arrow-left" id="turn-left"></button>
            <button class="arrow-top" id="turn-top"></button>
            <button class="arrow-right" id="turn-right"></button>
            <button class="arrow-bottom" id="turn-bottom"></button>
          </div>
          <div class="buttons">
              <button class="button-a" id="more">+</button>
              <button class="button-b" id="less">-</button>
          </div>
          <ul class="start-reset">
              <li><button class="start" id="start"></button><span>START</span></li>
              <li><button class="reset" id="reset"></button><span>RESET</span></li>
          </ul>
          
          <div class="points">
              <span>•••••</span><br>
              <span>•••••••</span><br>
              <span>•••••</span><br>
              <span>••••••</span><br>
              <span>••••</span>
          </div>
        </section>
      </div>
    </div>
  </main>
            
          
!

CSS

            
              @import url('https://fonts.googleapis.com/css?family=Lato&display=swap');

*, *::before, *::after{
  box-sizing:border-box;
}
:root{
  --pink: #FAD1D9;
  --red: #FC6963;
  --blue: #C5F6FF;
  --stroke: #522438;
  --green: #C2EC88;
  --brown: #614b48;
  --light-green: #E6FB9F;
  --light-brown: #846662;
  --light-blue: #bdf5ff;
  --dark-pink: #F1A1D9;
  --gray: #AAA;
  --light-gray: #BBB;
}

html, body{
  min-height:100vh;
  margin:0;
  font-family: 'Lato', sans-serif;
  display:flex;
  flex-direction: column;
  flex-shrink: 0;
}

body{
  background-color: var(--pink);
  animation-name: bg-color-moving;
  animation-duration:15s;
  animation-direction: alternate;
  animation-iteration-count: infinite;
  animation-fill-mode:forwards;
  animation-delay:1s;
}
@keyframes bg-color-moving {
  0%{
    background-color: var(--pink);
  }
  50%{
    background-color: var(--red);
  }
  100%{
    background-color: var(--stroke);
  }
}
.console{
  display:flex;
  align-items: center;
  justify-content: center;
  height:100vh;
}
.gameboy-body{
  background: linear-gradient(to top, var(--blue), var(--light-blue));
  width: 350px;
  height: 620px;
  border-radius:20px 20px 50px;
  border: 5px solid var(--stroke);
  box-shadow: inset 10px 0 rgba(255,255,255,0.7),
  inset -10px 0 rgba(0,0,0,0.2);
  position: relative;
  z-index: 2;
}
header{
  width: 100%;
  height: 36px;
  border-bottom: 6px solid var(--stroke);
  display: block;
  position: relative;
  box-shadow:0 6px rgba(0,0,0,0.2)
}
header::after, header::before{
  content:"";
  height: 100%;
  width:6px;
  background-color: var(--stroke);
  position: absolute;
}
header::after{
  right:30px;
}
header::before{
  left:30px;
}
canvas{
  position: absolute;
  top:0;
  bottom: 0;
  right: 0;
  left:0;
}
.screen{
  width: 80%;
  background: linear-gradient(to left, var(--brown), var(--light-brown));
  margin:30px 0 0 30px;
  border: 6px solid var(--stroke);
  padding: 30px;
  border-radius: 10px 10px 30px;
  position: relative;
}
.screen .glass{
  width: 100%;
  height: 160px;
  background-color: var(--green);
  border:6px solid var(--stroke);
  box-shadow:inset 6px 6px rgba(0,0,0,0.2);
  overflow: hidden;
  position: relative;
}
.glass::after, .glass::before{
  content:"";
  height:200%;
  width: 30px;
  background-color: rgba(255,255,255,0.2);
  position: absolute;
  transform: rotate(45deg);
  top: -80px;
}
.glass::after{
  right:-20px;
  width: 50px !important;
}
.glass::before{
  left:0;
  z-index: 8;
}
.screen span{
  width: 10px;
  height: 10px;
  background-color: var(--red);
  position:absolute;
  left:10px;
  border-radius:50%;
  border: 2px solid var(--stroke);
  top: 50%;
  margin-top:-10px;
}
.screen span.active{
  transition-duration: 500ms;
  transition-timing-function: ease-in;
  box-shadow:0px 0px 9px #FFF,
             0px 0px 9px #FFF,
             0px 0px 9px #FFF,
             0px 0px 9px #FFF,
             0px 0px 9px #FFF,
             0px 0px 9px #FFF,
             0px 0px 9px #FFF,
             0px 0px 9px #FFF
}
.screen span.noactive{
  transition-duration: 500ms;
  transition-timing-function: ease-out;
  box-shadow:none !important;
}
.screen::after, .screen::before{
  content: "";
  height: 3px;
  position:absolute;
  background-color: var(--stroke);
  top:12px;
  border-radius:10px;
}
.screen::before{
  width: 100px;
  left:10px;
}
.screen::after{
  width: 30px;
  right: 10px;
}

.actions{
  padding:30px 25px 0;
}
.directions{
  width:120px;
  height:120px;
  border-radius:50%;
  border:6px solid var(--stroke);
  background:linear-gradient(to bottom, var(--gray), var(--light-gray));
  position: relative;
  display: flex;
  float: left;
  box-shadow:2px 3px 4px rgba(0,0,0,0.2);
}
.directions button{
  cursor: pointer;
  border:6px solid var(--stroke);
  background-color: var(--light-brown);
  width: 30px;
  height: 30px;
  position: absolute;
  z-index: 9;
}
.arrow-left{
  border-right:none !important;
  box-shadow: inset 0 4px #FFF, 
              inset 0 -4px rgba(255,255,255,0.2);
  top: 50%;
  margin-top:-15px;
  left: 13.5px;
}
.arrow-top{
  border-bottom:none !important;
  box-shadow: inset 0 4px #FFF;
  left:50%;
  margin-left:-15px;
  top:13.5px;
}
.arrow-right{
  border-left:none !important;
  box-shadow: inset 0 4px #FFF, inset 0 -4px rgba(255,255,255,0.2);
  right:13.5px;
  margin-top:-15px;
  top:50%;
}
.arrow-bottom{
  border-top:none !important;
  box-shadow: inset 0 -4px rgba(0,0,0,0.2);
  left:50%;
  margin-left:-15px;
  bottom:13.5px;
}
.directions button:active{
  box-shadow:inset 0 4px var(--light-brown);
  background-color: var(--brown);
}
.directions:after{
  content: "";
  width: 30px;
  height: 30px;
  background-color: var(--light-brown);
  position: relative;
  top: 50%;
  left: 50%;
  margin: -15px;
  z-index: 1; 
} 
#score{
  position: absolute;
  bottom: 89px;
  left: 12px;
  font-family: 'Lato-Bold', sans-serif;
  font-size: 12px;
  color: #fff;
}
.none{
  display:none;
}
.buttons{
  border:6px solid var(--stroke);
  padding: 8px 3px;
  background:linear-gradient(to bottom, var(--gray), var(--light-gray));
  border-radius:100px;
  float: right;
  position: relative;
  transform: rotate(-20deg);
  top:30px;
  box-shadow:2px 3px 4px rgba(0,0,0,0.2);
}
.buttons button{
  font-family: 'Lato-Bold', sans-serif;
  color:#FFF;
  font-size:1rem;
  cursor:pointer;
  width:40px;
  height:40px;
  border-radius:50%;
  padding: 0;
  background-color: var(--red);
  border:6px solid var(--stroke);
  box-shadow:inset 4px 0 rgba(255,255,255,0.7),
            inset -4px 0 rgba(0,0,0,0.2);
  margin:0 5px;
}
.buttons button:active{
  background-color: var(--stroke);
}

.start-reset{
  list-style:none;
  text-align: center;
  width: 100%;
  float: left;
  margin-top:30px;
}
.start-reset li{
  display: inline-block;
  margin:0 15px;
  position: relative;
}
.start-reset li button{
  cursor: pointer;
  border: 6px solid var(--stroke);
  background-color: var(--light-brown);
  box-shadow:inset 3px 0 #FFF,
            3px 0 rgba(0,0,0,0.2);
  width: 20px;
  height: 50px;
  border-radius:10px;
  padding: 0;
  transform: rotate(60deg);
  position: relative;
  left:-25px;
  top:-10px;
}
.start-reset li span{
  font-family: 'Lato', sans-serif;
  color:var(--stroke);
  transform: rotate(-31deg);
  display: block;
  position: absolute;
  top: 25px;
  font-size: .65rem;
  left: -21px;
  margin: 0;
}
.start-reset li button:active{
  box-shadow:inset 3px 0 rgba(255,255,255,0.8);
  background-color:#000;
}
.points{
  text-align: center;
  position: absolute;
  right:20px;
  bottom: 20px;
}
.points span{
  font-size:25px;
  line-height: 0;
  color:var(--stroke);
  letter-spacing: 3px;
  display: block;
  margin-top:-5px;
}
.elements{
  position: fixed;
  height:100vh;
  width: 100vw;
}
@keyframes bg-moving-1 {
  0%{
    left:0;
    transform:rotate(0deg);
  }
  100%{
    left:95%;
    top:60%;
    transform:rotate(360deg);
  }
}
@keyframes bg-moving-2 {
  0%{
    left:10%;
    transform:rotate(0deg);
  }
  100%{
    left:100%;
    bottom:50%;
    transform:rotate(360deg);
  }
}
@keyframes bg-moving-3 {
  0%{
    left:30%;
    transform:rotate(0deg);
  }
  100%{
    left:100%;
    bottom:6%;
    transform:rotate(50deg);
  }
}
@keyframes bg-moving-4 {
  0%{
    right:5%;
    transform:rotate(0deg);
  }
  100%{
    right:95%;
    bottom:6%;
    transform:rotate(360deg);
  }
}
@keyframes bg-moving-5 {
  0%{
    left:10%;
    transform:rotate(0deg);
  }
  100%{
    left:100%;
    bottom:0%;
    transform:rotate(180deg);
  }
}
.element{
  width: 60px;
  height: 60px;
  position: absolute;
  z-index:1;
  animation-direction: alternate;
  animation-iteration-count: infinite;
  animation-fill-mode:forwards;
}
.element-1{
  animation-name: bg-moving-1;
  animation-delay:1s;
  animation-timing-function:linear;
  animation-duration: 30s;
  border:3px solid rgba(255,255,255,0.15);
  border-radius:50%;
  top: 5%;
}
.element-2{
  animation-name: bg-moving-2;
  animation-delay:2s;
  animation-timing-function:ease-in;
  animation-duration:20s;
  bottom: 5%;
  left:10%;
}
.element-2::before{
  content:"";
  border:3px solid rgba(255,255,255,0.15);
  transform: rotate(45deg);
  width:0px;
  height:60px;
  display: inline-block;
  position: absolute;
  left: 28px;
}
.element-2::after{
  content:"";
  border:3px solid rgba(255,255,255,0.15);
  transform: rotate(-45deg);
  width:0px;
  height:60px;
  display: inline-block;
  position: absolute;
  left: 28px;
}
.element-3{
  animation-name: bg-moving-3;
  animation-timing-function:ease-out;
  animation-duration: 20s;
  border:3px solid rgba(255,255,255,0.15);
  top:15%;
  left:30%;
}
.element-4{
  animation-name: bg-moving-4;
  animation-delay:5s;
  animation-timing-function:linear;
  animation-duration: 16s;
  border-top:none;
  border-right:none;
  border-left:none;
  border-bottom:3px solid rgba(255,255,255,0.15);
  top:30%;
  right:5%;
}
.element-5{
  animation-name: bg-moving-5;
  animation-duration: 22s;
  animation-delay:1s;
  animation-timing-function:ease;
  border:3px solid rgba(255,255,255,0.15);
  border-radius: 50%;
  width:100px;
  height:45px;
  top:50%;
  left:10%;
}
            
          
!

JS

            
              window.onload = function(){
      var stage = document.getElementById("snakegame");
      var ctx = stage.getContext("2d");
      document.addEventListener("keydown", keyPush);

      var timeGame = 90;
      var jogo = setInterval(game, timeGame);

      const vel = 1;

      var vx = vy = 0;
      var px = 10;
      var py = 15;
      var tp = 12;
      var qp = 15;
      var ax = ay = 5;

      var trail = [];
      var tail = 5;

      function game(){
				px += vx;
				py += vy;
				if (px < 0) {
					px = qp-1;
				}
				if (px > qp-1) {
					px = 0;
				}
				if (py < 0) {
					py = qp-1;
				}
				if (py > qp-1) {
					py = 0;
				}

				ctx.fillStyle = "#C2EC88";
				ctx.fillRect(0,0, stage.width, stage.height);

				ctx.fillStyle = "red";
				ctx.fillRect(ax*tp, ay*tp, tp,tp);

				ctx.fillStyle = "gray";
				for (var i = 0; i < trail.length; i++) {
					ctx.fillRect(trail[i].x*tp, trail[i].y*tp, tp-1,tp-1);
					if (trail[i].x == px && trail[i].y == py){
            vx = vy = 0;
            tail = 5;
            var score = document.getElementById("score");
            score.innerText = "";
            score.classList.add("none");
					}
				}

				trail.push({x:px,y:py })
				while (trail.length > tail) {
					trail.shift();
				}

				if (ax==px && ay==py){
					tail++
          
					ax = Math.floor(Math.random()*qp);
					ay = Math.floor(Math.random()*(qp-3));

          document.getElementById("bright").classList.add("active");
          document.getElementById("bright").classList.remove("noactive");
          var score = document.getElementById("score");
          score.innerText = (tail - 5);
          score.classList.remove("none");

          setTimeout(removeShineButton, 1000);
          
          console.log(ax);
          console.log(ay);
				}
			}

      function removeShineButton(){
        document.getElementById("bright").classList.remove("active");
        document.getElementById("bright").classList.add("noactive");
      }

      function reset(){
        vx = vy = 0;
				tail = 5;
      }

      function start(timeGame){
        console.log(timeGame)
        if(timeGame > 0){
          for (var i = 1; i <= jogo; i++){
            clearInterval(i);
          }
        
          jogo = setInterval(game, timeGame);
        }
      }
      
      function more(){
        timeGame -= 50;
        start(timeGame);
      }

      function less(){
        timeGame += 50;
        start(timeGame);
      }
      
      function keyPush(event){
          switch (event.keyCode) {
              case 37: // Left
                  vx = -vel;
                  vy = 0;
                  break;
              case 38: // up
                  vx = 0;
                  vy = -vel;
                  break;
              case 39: // right
                  vx = vel;
                  vy = 0;
                  break;
              case 40: // down
                  vx = 0;
                  vy = vel;
                  break;         
              default: // down
                  vx = 0;
                  vy = vel;
                  break;
          }
      }
      
      document.getElementById('start').onclick = keyPush;
      document.getElementById('reset').onclick = reset;
      document.getElementById('more').onclick = more;
      document.getElementById('less').onclick = less;

      document.getElementById('turn-left').onclick = function(){
        vx = -vel;
        vy = 0;
      };
      document.getElementById('turn-right').onclick = function(){
        vx = vel;
        vy = 0;
      };
      document.getElementById('turn-top').onclick = function(){
        vx = 0;
        vy = -vel;
      };
      document.getElementById('turn-bottom').onclick = function(){
        vx = 0;
        vy = vel;
      };
    }
            
          
!
999px

Console