Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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="notGame">

  <link href="https://fonts.googleapis.com/css?family=Chango&display=swap" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css?family=Shadows+Into+Light&display=swap" rel="stylesheet">

  <h1>POTHOLES<br><span>got you down?</span></h1>
  <h4>Arrow keys to move <br> Avoid the potholes <br> Tap car to choose color</h4>
  <div id="scoreBox">SCORE&nbsp;<span id="score">0</span>&nbsp;/&nbsp;50</div>
  <div id="startBtn" onclick="start()">START GAME</div>
  <div id="game-box">
    <div id="ground"></div>
    <div id="dealership" class="dealer-on"></div>

    <div id="roadBox">
      <div class="roadBlox "></div>
      <div class="roadBlox "></div>
      <div class="roadBlox "></div>

      <div class="roadBlox"></div>
      <div class="roadBlox"></div>
      <div class="roadBlox"></div>


      <div class="roadBlox"></div>
      <div class="roadBlox"></div>
      <div class="roadBlox"></div>

      <div class="roadBlox"></div>
      <div class="roadBlox"></div>
      <div class="roadBlox"></div>

      <div class="roadBlox"></div>
      <div class="roadBlox car"></div>
      <div class="roadBlox"></div>

      <div class="roadBlox" style="visibility:hidden"></div>
      <div class="roadBlox" style="visibility:hidden"></div>
      <div class="roadBlox" style="visibility:hidden"></div>
      
      <div id='leftBtn' class='moveBtn'></div>
      <div id='rightBtn' class='moveBtn'></div>  
    </div>

    <div id="offer" class="dealer-on">
      <h3>POTHOLE SPECIAL</h2>
      <p>Complimentary Aligment Check</p>
      <h2><strong style="font-size:30px">+10% Off</strong><br>Recommended Service</h3>
      <a href="#" class="offer-btn">Get This Service</a>
      <p class="offer-disc">Present upon arrival. Per axle. One per customer. No cash value. Max value $[XXX]. No further discounts apply. See dealer for details. Expires %%todaysDatePlus30%%.</p>
    </div>
  </div>
</div>
              
            
!

CSS

              
                :root {
  --pink:white;
  --carColor:hue-rotate(0deg);
  --roadAnimation:road .25s steps(3) infinite;
  --carAnimation:carBounce 1s linear infinite;
  --treeAnimation:tree 10s steps(5) infinite;
  --carText:'Woo-hoo!';
  --carDisplay:none;
}

body {
  margin:0;
}

#notGame {
  font-family:monospace;
  background-color:#b4d142;
  background-image:linear-gradient(to bottom,skyblue,#b4d142 50%);
  background-repeat:no-repeat;
  text-align:center;
  overflow-x:hidden;
  padding:0;
  margin:0;
}

#notGame h1 {
  position:relative;
  font-family: 'Chango', cursive;
  font-size:60px;
  line-height:87.5%;
  color:white;
  text-shadow:-2px -2px black, 1px 1px black,2px 2px black,3px 3px black,4px 4px black,5px 5px black, 6px 6px black,7px 7px black,8px 8px black,9px 9px black,10px 10px black;  
}

#notGame h1 span {
  font-size:36px;
}
#scoreBox {
  font-size:36px;
  font-weight:900;
  font-family: 'Shadows Into Light', cursive;
}

#startBtn {
  padding:10px 15px;
  background:rgba(0,0,0,.1);
  width:fit-content;
  border-radius:5px;
  cursor:pointer;
  margin:25px auto 100px auto;
  user-select:none;
  font-size:24px;
  transition:.5s;
}
#startBtn:hover {
  background:rgba(0,0,0,.25);
}
#game-box {
  position:relative;
  width:100%;
  max-width:606px;
  margin:0 auto;
}

#ground {
  width: 606px;
  height: 310px;
  background: url(https://contentservice.mc.reyrey.net/image_v1.0.0/?id=92798608-6152-51c5-bfee-2465bc2ffe08&637176306636242654);
  background-size: cover;
  position: absolute;
  left: 0%;
  top: 220px;
  filter:sepia(1);
}
#roadBox {
  max-width:321px;
  height:535px;
  background-color:#4c516f;
  position:relative;
  margin:0 auto;
  transform:rotateX(45deg) rotateZ(45deg);
  box-shadow:1px 1px #222,2px 2px #222,3px 3px #222,4px 4px #222,5px 5px #222,6px 6px #222,7px 7px #222,8px 8px #222,9px 9px #222,10px 10px #222;
}
#roadBox:before {
  content:'';
  width:107px;
  height:107px;
  position:absolute;
  left:-107px;
  top:0; background:url('https://contentservice.mc.reyrey.net/image_v1.0.0/?id=b2ef21f9-97f8-5953-9d6a-159ed802fb74&637178907728385415');
  background-size:50% 100%;
  background-repeat:no-repeat;
  background-position:50% 0%;
  transform:rotateZ(-45deg);
  animation:var(--treeAnimation);
  opacity:0;
}
@keyframes tree {
  0% { opacity:1 }
  7% { opacity:1 }
  10% { top:100%; opacity:0; }
  100% { top:100%; opacity:0; }
}
#roadBox:after {
  content:'';
  width:34%;
  height:100%;
  position:absolute;
  left:33%;
  top:0;
  background:linear-gradient(to bottom, #4c516f 50%, transparent 50%), linear-gradient(to right, white 5%, transparent 5%, transparent 95%, white 95%);
  background-size:100% 107px, 100% 25px;
  background-position:0 0, 0 0;
  opacity:.25;
  z-index:1;
  animation:var(--roadAnimation);
}
@keyframes road {
  100% { background-position:0 100%, 0 0; }
}

#dealership {
  width:397px;
  height:376px;  background:url('https://contentservice.mc.reyrey.net/image_v1.0.0/?id=9372fa3d-ae04-5651-9689-833d110afff6&637179027416303704');
  background-size:100%;
  background-repeat:no-repeat;
  background-position:50% 0%;
  transform:scale(.95);
  position:absolute;
  top: -76px;
  right: -50px;
  z-index:9;
  visibility:hidden;
  pointer-events:none;
}
.dealer-on {
  visibility:visible !important;
  animation:dealership 1s linear forwards;
}
@keyframes dealership {
  0% { transform:scale(.95) translate(50%, -40%); opacity:0;  }
}

#offer {
  position: absolute;
  top: -35px;
  left: -50px;
  background: white;
  padding: 10px;
  border-radius: 5px;
  max-width: 50%;
  box-shadow: 0 0 0px 3px black, 0 0 0px 6px white;
  z-index: 9;
  visibility:hidden;
}
#offer:after {
  content:'';
  width:30px;
  height:75px;
  background:linear-gradient(to right, gray, silver, gray);
  box-shadow:0 5px 10px -5px black, inset 0 0 5px 5px rgba(0,0,0,.25);
  border-radius:0 0 3px 3px;
  position:absolute;
  top:calc(100% + 6px);
  left:50%;
  transform:translateX(-50%);
  z-index:-1;
}
#offer:before {
  content:'' ;
  width:50px;
  height:30px;
  border-radius:50% ;
  box-shadow:inset 0px 7px 1px #222;
  background-color:#564519;
  background-image:url('https://contentservice.mc.reyrey.net/image_v1.0.0/?id=f6e8901a-c9e2-5904-a36e-bbea4344ce46&637176356968248654');
  background-size:contain;  
  display:block ;
  position:absolute;
  left:50%;
  transform:translateX(-50%);
  top:123%;
  z-index:-1;
}

#notGame h3 {
  margin:0;
  padding-bottom:10px;
  border-bottom:2px solid black;
}
.offer-btn {
  color:white;
  background:black;
  display:block;
  padding:10px;
  border-radius:5px;
  text-decoration:none;
}
.offer-btn:hover {
  color:black;
  background:gold;  
}
.offer-disc {
  font-size:11px;
  font-family:sans-serif;
}

.roadBlox {
  width:calc(100% / 3);
  height:calc(100% / 5);
  float:left;
  position:relative;
}

.car {  
  z-index:3;
  filter:var(--carColor);
}
.car:before {
  content:'';
  width:100%;
  height:100%;
  position:absolute;
  top:0;
  left:0;
  background:url('https://contentservice.mc.reyrey.net/image_v1.0.0/?id=911fde3e-96eb-574e-a446-910439f46adb&637175592079141420');
  background-size:75% 75%;
  background-position:35% 35%;
  background-repeat:no-repeat;
  z-index:3;
  transform:rotateZ(-50deg);
  animation:var(--carAnimation);
}
.car:after {
  content:var(--carText);
  display:var(--carDisplay);
  font-size:20px;
  font-weight:900;
  white-space:nowrap;
  position:absolute;
  left:0;
  top:0;
  padding:10px 10px 20px 10px;
  background:white;
  clip-path:polygon(0% 0%, 100% 0%, 100% 90%, 55% 90%, 50% 100%, 45% 90%, 0% 90%);
  transform:translate(-50%, -50%) rotateZ(-45deg);
  z-index:99;
}
@keyframes carBounce {
  50% { background-position:25% 25%; }
}
.carHit {
  filter:drop-shadow(5px 5px 5px red);
}

.pothole:before {
  content:'' ;
  width:100%;
  height:100%;
  background-image:url('https://contentservice.mc.reyrey.net/image_v1.0.0/?id=6da8e8e1-fd81-5354-82f6-da00fbeb95ce&637178898587243415');
  background-size:75% 75%;
  background-position:10% 0%;
  background-repeat:no-repeat;
  transform:rotateZ(-45deg);
  display:block;
  position:absolute;
  left:0%;
  top:30%;
  z-index:3;
  pointer-events:none;
}

.pothole:after {
  content:'' ;
  width:30% ;
  height:30% ;
  border-radius:50% ;
  box-shadow:inset 7px 7px 1px #222;
  background-color:#564519;
  background-image:url('https://contentservice.mc.reyrey.net/image_v1.0.0/?id=f6e8901a-c9e2-5904-a36e-bbea4344ce46&637176356968248654');
  background-size:contain;  
  display:block ;
  position:absolute;
  left:35%;
  top:35%;
  z-index:2;
  pointer-events:none;
}

.moveBtn {
  position:absolute;
  bottom:0px;
  width:35%;
  height:250px;
/*   visibility:hidden; */
  z-index:2;
}
#rightBtn {
  right:0;
}
#leftBtn:after, #rightBtn:after {
  content:'>';
  position:absolute;
  bottom:15px;
  left:0;
  width:100%;
  text-align:center;
  font-size:60px;
  font-weight:900;
  color:white;
  opacity:.5;
}
#leftBtn:after {
  content:'<';
}

@media screen and (max-width:700px) {
  #notGame h1 {
    font-size:36px;
  }
  #roadBox {
  width:100%;
  max-width:321px;
  height:535px;
  position:relative;
  margin:0 auto;
  transform:none;
  box-shadow:1px 1px #222,2px 2px #222,3px 3px #222,4px 4px #222,5px 5px #222,6px 6px #222,7px 7px #222,8px 8px #222,9px 9px #222,10px 10px #222;
  }
  #ground {
    display:none;
  } 
  
  #dealership {
    display:none;
  }
  #offer {
    top:0;
    left:50%;
    transform-origin:top center;
    transform:translate(-50%,5%) scale(.8);
    width: 310px;
    max-width: none;
  }
  #startBtn {
    margin:35px auto;
  }
  .moveBtn {
  visibility:visible;
 }
  .car:before {  
    background:url('https://contentservice.mc.reyrey.net/image_v1.0.0/?id=9583850c-e8d2-5ac8-9807-44c456ccc0f5&637213686794645167');
    transform:rotateZ(0deg);  
  }
  .car:after {
    transform:translate(-50%, -50%) rotateZ(0deg);
    animation:var(--carAnimation);
  }
  .pothole:before {
    background-image:url('https://contentservice.mc.reyrey.net/image_v1.0.0/?id=00d05607-bc6d-50eb-aa99-e134f55a5555&637213686812145090');
    transform:rotateZ(0deg);
  }
}
              
            
!

JS

              
                var blox = document.querySelectorAll('.roadBlox')
var dealer = document.querySelector('#dealership')
var offer = document.querySelector('#offer')
var lBtn = document.querySelector('#leftBtn')
var rBtn = document.querySelector('#rightBtn')
var root = document.documentElement;

var videoElement = document.getElementById("game-box");    
function toggleFullScreen() {
  if (window.innerWidth < 700 && !document.mozFullScreen && !document.webkitFullScreen) {
    if (videoElement.mozRequestFullScreen) {
      videoElement.mozRequestFullScreen();
    } else {
      videoElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
    }
  } else {
    if (document.mozCancelFullScreen) {
      document.mozCancelFullScreen();
    } else {
      document.webkitCancelFullScreen();
    }
  }
}

window.addEventListener('keyup', function(e){
  var carHit = document.querySelector('.car')
  if(e.keyCode == 37) {
    if(document.querySelectorAll('.roadBlox')[13].classList.contains('car')){
      carHit.classList.remove('car')
      blox[12].classList.add('car')
    } 
    if(document.querySelectorAll('.roadBlox')[14].classList.contains('car')){
      carHit.classList.remove('car')
      blox[13].classList.add('car')
    }        
  }

  if(e.keyCode == 39) {
    if(document.querySelectorAll('.roadBlox')[13].classList.contains('car')) {
      carHit.classList.remove('car')
      blox[14].classList.add('car')
    }    
    if(document.querySelectorAll('.roadBlox')[12].classList.contains('car')) {
      carHit.classList.remove('car')
      blox[13].classList.add('car')
    }
  }
})

lBtn.addEventListener('click', function(e){
  var carHit = document.querySelector('.car')
  if(document.querySelectorAll('.roadBlox')[13].classList.contains('car')){
    carHit.classList.remove('car')
    blox[12].classList.add('car')
  } 
  if(document.querySelectorAll('.roadBlox')[14].classList.contains('car')){
    carHit.classList.remove('car')
    blox[13].classList.add('car')
  }  
})
rBtn.addEventListener('click', function(e){
  var carHit = document.querySelector('.car')
  if(document.querySelectorAll('.roadBlox')[13].classList.contains('car')) {
    carHit.classList.remove('car')
    blox[14].classList.add('car')
  }    
  if(document.querySelectorAll('.roadBlox')[12].classList.contains('car')) {
    carHit.classList.remove('car')
    blox[13].classList.add('car')
  }
})

function carDisplay() {
  root.style.setProperty('--carDisplay', 'block');
  setTimeout(function(){
    root.style.setProperty('--carDisplay', 'none');
  },500)
}

function countdown(){
  var secs = 3
  root.style.setProperty('--carDisplay', 'block');
  root.style.setProperty('--carText', "'"+secs+"'");
  setTimeout(function(){
    secs--
    root.style.setProperty('--carText', "'"+secs+"'");
  },1000)
  setTimeout(function(){
    secs--
    root.style.setProperty('--carText', "'"+secs+"'");
  },2000)
  setTimeout(function(){
    secs--
    root.style.setProperty('--carText', "'"+secs+"'");
  },3000)
  setTimeout(function(){
    root.style.setProperty('--carDisplay', 'none');
  },3500)
}

var ooo = ["Ouch!","Ugh!","Ahh!","Doink!","Whoa!"]
var holeCount = 0
var ouchCount = 0
function start() {
  dealer.classList.remove('dealer-on')
  offer.classList.remove('dealer-on')
  root.style.setProperty('--roadAnimation', 'road .25s steps(3) infinite');
  root.style.setProperty('--carAnimation', 'carBounce 1s linear infinite');
  root.style.setProperty('--treeAnimation', 'tree 10s steps(5) infinite');
  document.querySelector('.car').classList.remove('car')
  document.querySelectorAll('.roadBlox')[13].classList.add('car')
  countdown()
  document.querySelector('#startBtn').style.pointerEvents = "none"
  document.querySelector('#startBtn').style.visibility = 'hidden'
  document.querySelector('#startBtn').setAttribute('onclick','skip()')

  var holeCount = 0
  var ouchCount = 0  

  setTimeout(function(){
    var move = setInterval(movePotholes,250)
    var holes = setInterval(addPotholes,500)  

    function ouchy() {
      var ouch = (document.querySelector('.car.pothole') || document.querySelector('.pothole.car'))
      if(ouch) {
        document.querySelector('.car.pothole').classList.remove('pothole')
        ouchCount++
        console.log(ouchCount)
        var phrase = Math.floor(Math.random()*ooo.length)
        root.style.setProperty('--carText', "'"+ooo[phrase]+"'");
        carDisplay()
        
      }
    }
    
    function movePotholes() {  
      var block = document.querySelectorAll('.roadBlox')
      for(var i = block.length - 1; i >= 0; i--) {
        if(block[i].classList.contains('pothole') && (i + 3) < block.length) {
          block[i].classList.remove('pothole')      
          block[i+3].classList.add('pothole')        
        }    
      } 
      
      ouchy()
      document.querySelector('#score').innerHTML = holeCount - ouchCount
    }

    var pots = 750
    function addPotholes() {
      var num = Math.floor(Math.random()*3)
      document.querySelectorAll('.roadBlox')[num].classList.add('pothole')
      if(holeCount > 30) {
        var num = Math.floor(Math.random()*3)
        document.querySelectorAll('.roadBlox')[num].classList.add('pothole')
      }
      holeCount++   

      // endgame endgame endgame
      if(holeCount >= 50) {
        clearInterval(holes)
        document.querySelector('#startBtn').style.pointerEvents = ""
        document.querySelector('#startBtn').style.visibility = ""
        document.querySelector('#startBtn').innerText = "START GAME"
        document.querySelector('#startBtn').setAttribute('onclick','start()')
        
        setTimeout(function(){
          clearInterval(move)  
          document.querySelector('.car').classList.remove('car')
          document.querySelectorAll('.roadBlox')[10].classList.add('car')
          dealer.classList.add('dealer-on')
          offer.classList.add('dealer-on')
        },2000)   
        
        setTimeout(function(){       
          root.style.setProperty('--roadAnimation', 'none');
          root.style.setProperty('--carAnimation', 'none');
          root.style.setProperty('--treeAnimation', 'none');
        },2500)
      }
    }
  },3500) 
}

document.querySelector('.car').classList.remove('car')
document.querySelectorAll('.roadBlox')[10].classList.add('car')         
root.style.setProperty('--roadAnimation', 'none');
root.style.setProperty('--carAnimation', 'none');
root.style.setProperty('--treeAnimation', 'none');

var color = 0
document.querySelector('.car').addEventListener('click', function(e){
  e = this  
  if(color + 45 == 360) {
    color = 0
  } else {
    color = color + 45
  }
  root.style.setProperty('--carColor', 'hue-rotate('+color+'deg)');
})
              
            
!
999px

Console