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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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.

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='scene-layout'>
  <div id='plant'><div id='col'></div></div>
</div>

<div id='score-box' class=''>SCORE: <span id='score'>0</span></div>

<div id='intro'>
  <h1>PLANTY</h1>
  <p>You have been tasked with the safe keeping of the last known plant specimen in existence. Use your mouse to avoid all hazards!</p>
  <p id='start'>> START <</p>
</div>

<link href="https://fonts.googleapis.com/css?family=Montserrat:300,500,700,900&display=swap" rel="stylesheet">
              
            
!

CSS

              
                :root {
  --plant:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAYAAACOEfKtAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAC+lJREFUeNrsXHtsU9cZ/851wjOAQ6EdoHSGPaVpqqNKSwgkOJq6ShsTYVNVoa0i0fYHHdWStGW81iahG2NrR4JWbZU6yZ7aqZ2QGqNO61ZU4oCxQ7cVQx+MV7ktbYkgwA0JCUl879n33Ydz4/cjsWM3R/q419fn+J77u7/veU5gME3aPu86OwOoQ7kPGNjxki1mZw4eDiDi2Sk8unes7RZzNW+WS9Ce8dTYGGONOIl6nIk17R/iICqcH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4HndrMcqrAn0tz2ODfR8rgBE4A4pevahjIMQcwsbe7SCylaxNhOJyp9y40Byx0Dtr8qlsNJUU9HWCkcM8JxxwpcDkMOWEwBH/nCCwDugmOygLp1o60Igsi0V9BdMzjjBH3lfVy4BnJINltvWf9mBtq1L/VsMNc1T1KxF0c/pqGiVl8hzUm1lgn2knBnGCw760VSAAK2AYcpGeLTMpPbIpduegmBgIbUZAGcAnAEwr9tUZSIUl6nFhRv9w/ZbgyPteqU6lIFA+GeT4eemf8bPTSkfn/DnCeMe0XCJnKnnOLqZVvRMc8oPLxzeHvhSSU6qdYcvDrJ8ZeDEt8TYjApnyHORweTuNk0i2xELBkCBMXqYrALICgnAGRXOlIGCWq9zZPnZugtJhWcYmKEKizl4tgJyIsIMgBk1i1C4Kpy1J3uofElWs5GDJ/tYwTBQY2Fh1i2yBiDaQSmj/+o4tTREKjgALRYWyGIsGCg4AIssMyqcqQoHGDBHdjSYFyQD+7MYXPQXHIAWiyBlK2bK5l7BrAFYXCRkc/vFjBPJl/Z/AQYAwwAbw8zyWDIAAAAASUVORK5CYII=');
}
body {
  font-family:'Montserrat', sans-serif;
  margin:0;
  padding:0;
  background:linear-gradient(to bottom right, #111 48%, #222 48%, #222 52%, #111 52%);
  background-size:20px 20px;
  color:white;
}

#scene-layout {
  width: 640px;
  height: 480px;
  background:#222;
  position:absolute;
  left:50%;
  top:50%;
  transform:translate(-50%,-50%);
  cursor:none;
  overflow:hidden;
  border-radius:5px;
}
#score-box {
  position:absolute;
  transform:translate(-100%,-125%);
}
.high:before {
  content: '';
  position: absolute;
  left:100%;
  transform: translate(10px, -35%) rotate(45deg);
  text-align: center;
  padding: 5px;
  background: gold;
  color: black;
  border-radius: 5px;
  width: 30px;
  height: 30px;
  line-height: 30px;
}
.high:after {
  content: 'HS';
  position: absolute;
  transform: translate(10px, -35%);
  text-align: center;
  padding: 5px;
  background: gold;
  color: black;
  border-radius: 5px;
  width: 30px;
  height: 30px;
  line-height: 30px;
}

#intro {
  position:absolute;
  max-width:320px;
  left:50%;
  top:50%;
  transform:translate(-50%,-50%);
  background:white;
  border-radius:5px;
  color:black;
  text-align:center;
  transition:.5s;
}

h1 {
  font-size:60px;
  font-weight:900;
  margin-bottom:0;
  text-shadow:3px 3px limegreen;
}

p {
  margin:15px 15px;
}

#start {
  padding:10px;
  background:black;
  color:white;
  cursor:pointer;
  border-radius:5px;
}
#start:hover {
  background:limegreen;
  color:black;
}

#plant {
  width:40px;
  height:40px;
/*   border-radius:40px 0 40px 0; */
/*   background:limegreen; */
  position:absolute;
  background-image:var(--plant);
  background-repeat:no-repeat;
  background-size:contain;
}
#col {
  position:absolute;
  width:60%;
  height:60%;
  left:20%;
  top:20%;
/*   outline:1px solid red; */
}

.dead {
  z-index:99;
  transform:rotate(1520deg);
  transition:2s;
  filter:sepia(1);
}

.beam {
  position:absolute;
  width:40px;
  height:40px;
  left:-20px;
  background:#222;
  box-shadow:0 0 5px 5px DodgerBlue;
  border-radius:20px;
  animation:beam 3s linear forwards;
}

@keyframes beam {
  5% { opacity:0; }
  10% { opacity:1; }
  15% { opacity:0; }
  20% { opacity:1; width:40px; }
  60% { width:700px; left:-20px;}
  100% { left:700px; }
}
.beamRight {
  position:absolute;
  width:700px;
  height:40px;
  left:620px;
  background:#222;
  box-shadow:0 0 5px 5px gold;
  border-radius:20px;
  animation:beamRight 3s linear forwards;
}

@keyframes beamRight {
  5% { opacity:0; }
  10% { opacity:1; }
  15% { opacity:0; }
  20% { opacity:1; left:620px; }
  60% { width:700px; left:-100px; }
  100% { width:40px; left:-100px; }
}

.beamTop {
  position:absolute;
  width:40px;
  height:40px;
  top:-20px;
  background:#222;
  box-shadow:0 0 5px 5px red;
  border-radius:20px;
  animation:beamTop 3s linear forwards;
}
@keyframes beamTop {
  5% { opacity:0; }
  10% { opacity:1; }
  15% { opacity:0; }
  20% { opacity:1; height:40px; }
  60% { height:600px; top:-20px;}
  100% { top:600px; }
}

.beamBottom {
  position:absolute;
  width:40px;
  height:600px;
  top:460px;
  background:#222;
  box-shadow:0 0 5px 5px magenta;
  border-radius:20px;
  animation:beamBottom 3s linear forwards;
}
@keyframes beamBottom {
  5% { opacity:0; }
  10% { opacity:1; }
  15% { opacity:0; }
  20% { opacity:1; top:460px; }
  60% { height:600px; top:-100px; }
  100% { height:40px; top:-100px; }
}
              
            
!

JS

              
                setTimeout(function() {
  var s = document.querySelector('#scene-layout')
  var ss = s.getBoundingClientRect()
  var p = document.querySelector('#plant')
  var sb = document.querySelector('#score-box')
  var sc = document.querySelector('#score')
  sb.style.top = (window.innerHeight - 480)*.5 + 'px'
  sb.style.left = ((window.innerWidth - 640)*.5) + ss.width + 'px'
  var x = 0
  var y = 0
  var t = 0

  s.addEventListener('mousemove', function(e) {  
    x = e.clientX - ss.left
    y = e.clientY - ss.top
    // s.innerHTML = x + " / " + y

    if(x > 0 && x < ss.width) {
      p.style.left = x - 20 + 'px'
    }
    if(y > 0 && y < ss.height) {
      p.style.top = y - 20 + 'px'
    }  
  })

  document.querySelector('#start').addEventListener('click', function() {
    document.querySelector('#intro').style.top = '-400px'
    if(document.querySelector('.dead')){      
      p.classList.remove('dead')
      p.style.width = '40px'
      p.style.height = '40px'
      sc.innerHTML = 0
      if(document.querySelector('.high')){
        document.querySelector('.high').classList.remove('high')
      }
      document.querySelectorAll('.beams').forEach(function(elm){
        elm.remove()
      })
    }    

    function beam() {
      var b = document.createElement('div')
      b.className = Math.random() < .5 ? 'beams beamRight' : 'beams beam';
      // b.style.top = Math.random() < .5 ? '33%' : '66%'
      b.style.top = Math.random() < .5 ? y + 'px' : Math.random()*(ss.height - 40) + 'px'
      if(document.querySelectorAll('.beams').length >= 6) {
        b.style.animationDuration = '1.5s'      
      }
      s.appendChild(b)

      var b = document.createElement('div')
      b.className = Math.random() < .5 ? 'beams beamTop' : 'beams beamBottom';
      b.style.left = Math.random() < .5 ? x + 'px' : Math.random()*(ss.width - 40) + 'px'
      // b.style.left = Math.random() < .5 ? '33%' : '66%'
      s.appendChild(b)    
    }  

    function collison() {   
      var rocks = document.querySelectorAll('.beams')
      var s_rect = document.querySelector('#col').getBoundingClientRect()
      var pp = p.getBoundingClientRect()
      t++
      if(t % 30 === 0) {
        p.style.width = pp.width + 1 + 'px'
        p.style.height = pp.height + 1 + 'px'
      }

      rocks.forEach(function(elm) {
        var b = elm.getBoundingClientRect()         
        var ouch = !(s_rect.right < b.left || 
                     s_rect.left > b.right || 
                     s_rect.bottom < b.top || 
                     s_rect.top > b.bottom)
        if(ouch){
          elm.remove()
          p.classList.add('dead')
          setTimeout(function(){
            if(localStorage.getItem('plantyy')) {            
              if(localStorage.getItem('plantyy') < parseInt(sc.innerHTML)) {
                localStorage.setItem('plantyy', sc.innerHTML);
                sb.classList.add('high')
              }
            } else {
              localStorage.setItem('plantyy', sc.innerHTML);
              sb.classList.add('high')
            }
            document.querySelector('#intro').style.top = '50%'  
            document.querySelector('#start').innerHTML = '> TRY AGAIN <'
          },2000)        
          clearInterval(kill)
          clearInterval(addBeams)    
          // document.localStorage.set('plantyy', sc.innerHTML)
        }
      })

      sc.innerHTML = rocks.length
    }

    var addBeams = setInterval(beam,2500)
    var kill = setInterval(collison,1000/30)  
    })

},500)
              
            
!
999px

Console