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.

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

              
                <html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Epic Race</title>
</head>
<body>
  <div id="drum" class="drum">
    <div id="broasca" class="broasca">
      <div class="cap"></div>
      <div class="picior"></div>
      <div class="picior"></div>
      <div class="coada"></div>
    </div>
    
    <div id="bolovan" class="bolovan"></div>
  </div>
</body>
</html>
              
            
!

CSS

              
                body { margin: 0; padding: 0; }
.drum { width: 100vw; height: 50vh; margin-top: 25vh; background: gray; position: relative; }

.broasca { width: 200px; height: 70px; background: lime; border-radius: 100px 100px 0 0; position: absolute; top: 50px; }

.cap { width: 30px; height: 30px; position: relative; left: 175px; background: black; border-radius: 30px; top: 50px; }

.bolovan { position: absolute; background: brown; width: 30px; height: 20px; border-radius: 30px; }
              
            
!

JS

              
                var broasca = document.getElementById("broasca");
var bolovan = document.getElementById("bolovan");
var pozitiah = 0;
var pozitiav = 50;

var toleranta = 15;

var pozitie_bolovan_h = 520;
var pozitie_bolovan_v = 140;

var stanga_minim_b = pozitie_bolovan_h + toleranta;
var stanga_maxim_b = pozitie_bolovan_h + 30 - toleranta;
var top_minim_b = pozitie_bolovan_v + toleranta;
var top_maxim_b = pozitie_bolovan_v + 20 - toleranta;

var stanga_minim_broasca = 0;
var stanga_maxim_broasca = 0 + 200;

var top_minim_broasca = 50;
var top_maxim_broasca = 50 + 70;

var coliziune_pe_verticala = false;
var coliziune_pe_orizontala = false;


document.addEventListener("keydown", miscabroasca);
bolovan.setAttribute("style", "left: " + pozitie_bolovan_h + "px; top: " + pozitie_bolovan_v + "px;");


function miscabroasca (event) {
  
  coliziune_pe_orizontala = false;
  coliziune_pe_verticala = false;
  
  var tasta = event.keyCode;

  if(tasta == 39) {
    if(pozitiah < 700) {
      pozitiah = pozitiah + 10;
      broasca.setAttribute("style", "left: " + pozitiah + "px; " + "top: " + pozitiav + "px;");
    }
  }
  if(tasta == 37) {
    if(pozitiah >= 0) {
      pozitiah = pozitiah - 10;
      broasca.setAttribute("style", "left: " + pozitiah + "px; " + "top: " + pozitiav + "px;");
    }
  }

  if(tasta == 38) {
    if(pozitiav >= 0) {
      pozitiav = pozitiav - 10;
      broasca.setAttribute("style", "left: " + pozitiah + "px; " + "top: " + pozitiav + "px;");
    }
  }

  if(tasta == 40) {
    if(pozitiav < 180) {
      pozitiav = pozitiav + 10;
      broasca.setAttribute("style", "left: " + pozitiah + "px; " + "top: " + pozitiav + "px;");
    }
  }
  
  stanga_minim_broasca = pozitiah;
  stanga_maxim_broasca = pozitiah + 200;
  top_minim_broasca = pozitiav;
  top_maxim_broasca = pozitiav + 70;
  
  if (
    ( stanga_minim_b > stanga_minim_broasca && stanga_minim_b < stanga_maxim_broasca ) || 
    ( stanga_maxim_b > stanga_minim_broasca && stanga_maxim_b < stanga_maxim_broasca )
  ) {
    coliziune_pe_orizontala = true;
  }
  
  if(
    ( top_minim_b > top_minim_broasca && top_minim_b < top_maxim_broasca ) || 
    ( top_maxim_b > top_minim_broasca && top_maxim_b < top_maxim_broasca)
  ) {
     coliziune_pe_verticala = true;
  }
  
  if(coliziune_pe_orizontala === true && coliziune_pe_verticala === true) {
    var reiajocul = confirm("Te-ai busit. Vrei sa reiei jocul ?");
    if(reiajocul == true) {
      coliziune_pe_orizontala = false;
      coliziune_pe_verticala = false;
      pozitiah = 0;
      pozitiav = 50;   
      broasca.setAttribute("style", "left: " + pozitiah + "px; " + "top: " + pozitiav + "px;");
    
    }
  }
  
}
              
            
!
999px

Console