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

            
                <body>
  </body>
            
          
!

CSS

            
                    label {
          margin: 0;
      }
      input[type=text] {
          width: 100%;
          padding: 6px 10px;
          margin: 8px 0;
          display: inline-block;
          border: 1px solid #ccc;
          border-radius: 4px;
          box-sizing: border-box;
      }
      input[type=submit] {
          width: 100%;
          background-color: #4CAF50;
          color: white;
          padding: 14px 20px;
          margin: 16px 0;
          border: none;
          border-radius: 4px;
          cursor: pointer;
      }
      input[type=submit]:hover {
          background-color: #45a049;
      }
      #signinDiv {
          display:inline-block;
          vertical-align:top;
          border-radius: 5px;
          background-color: #f2f2f2;
          padding: 20px;
          width: 425px;
          height: 600px;
          top: 0px;
      }
            
          
!

JS

            
              (function () {
//function GoApp() {
  'use strict';

  //const bot = new Bot({onRx:Receive, regName:'BigNum2', id:1480868749, apiKey:'527a42577f747ad0', botName:'MyBot', chatName:'wwe4'});
  const bot = new Bot({onRx:Receive});
  //const  tx = bot.tx;
  const lib = new Lib(bot);

  let sm = ['smile','biggrin','wink','eek','tongue','cool','mad','confused','redface','frown','crying','sleepy','rolleyes','d','vampire','pirate2'];
  let board = [];
  let size = 38;
  let gc = 7e7;
  setInterval(gameTick, 1000);

  //entry point
  function main() {   
    console.log("main");   
    let ua = 0;//Object.keys(player); //get an array of all the users
    board = []; // new board
    lib.Init({Commands:'on', Invite:'off'}); // Init the library, trin on the @start command (and set 'game' container)

    tx(ua, {name:'title', parent:'game', type:'Text', x:425/2, y:0, text:'Drag and drop matching smilie!'});        
    tx(ua, {name:'timer', parent:'game', type:'Text', x:330, y:552, text:'30', countDown:true});
    gc = 30; // 30s to finish the game

    lib.StartRaceGame();

    for(let a=0;board.length<sm.length && a<100;a++) {
      let x = Math.floor(Math.random()*(425-size))+size/2;
      let y = Math.floor(Math.random()*(520-size))+size/2;

      //check if new smilie is too close
      let b;
      for(b=0;b<board.length;b++)
        if(Math.abs(x-board[b].x)<size && Math.abs(y-board[b].y)<size)
          break;

      if(board.length===b) //no smilie is too close
        board.push({sm:sm[board.length], x:x, y:y, r:Math.random()*2*Math.PI});
    }

    board[sm.length-1].sm = sm[0];

    let j = [];  
    for(let a=0;a<board.length;a++)
      j.push({name:String(a), type:'StripSprite', parent:'game', smilie:board[a].sm, size:30, animationSpeed:0.20, x:board[a].x, y:board[a].y, scale:{x:1, y:1}, rotation:board[a].r, interactive:true, buttonMode:true, draggable:true/*,, tween:{ from:{rotation:r}, to:{rotation:r+6.2831}, time:2094, loop:true}*/ });
    tx(ua, j);
  }

  //a player has sent us a command
  function Receive(u, j) {
    if(j.action=='dragEnd') {
      if(bot.invited && !bot.invited[u]) return; // ignore if not invited

      let id = parseInt(j.name);
      let hit;

      for(let b=0;b<board.length;b++)
        if(id!=b && Math.abs(j.x-board[b].x)<size && Math.abs(j.y-board[b].y)<size) {
          hit = b;
          break;
        }

      if(hit===undefined || board[id].sm!==board[hit].sm)
        tx(u, {name:j.name, tween:{ to:{x:board[id].x, y:board[id].y}, time:300, easing:'inOutQuad' } });
      else {
        if(0)tx(u, {name:'game', destroyChildren:true});

        //tx(u, {name:'result', type:'Text',  parent:'game', x:425/2, y:520/2, text:'winner!'});        
        lib.UserFinishedGame(u);
        lib.SendLeaderBoard();
      }
    }
    else if(j.action=='main')
      main();
  }

  function gameTick(e)
  {
    gc--;
    if(gc == 0) // game over
    {
      //tx(0, {name:'game', destroyChildren:true}); // clear screen
      lib.SendLeaderBoard(1); // send to all
    }

    if(gc == -5) // restart
    {
      tx(0, {name:'game', destroyChildren:true}); // clear screen
      //tx(0, {name:'leader_container', destroyChildren:true}); // clear screen
      main() ;
    }
  }

  function tx(u, j)
  {
    //console.log(u, j);
    bot.tx(u, j);
  };

}
)();
            
          
!
999px

Console