Advertisement
Guest User

123

a guest
Apr 29th, 2015
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var blackbox = {}
  2.     blackbox.positionX = 370;
  3.     blackbox.positionY = 50;
  4.     blackbox.init = function() {
  5.         $('.myChar').css({
  6.             'left':this.positionX+'px'
  7.         });
  8.         $('.myChar').css({
  9.             'top':this.positionY+'px'
  10.         });
  11.     };
  12.     blackbox.run = function(where) {
  13.         if (where === 'left') {
  14.             blackbox.positionX-=10;
  15.             $('.myChar').animate({
  16.                         'left' : blackbox.positionX}, 00);
  17.             movingInterval.clearInterval();
  18.         }
  19.         if (where === 'right') {
  20.             blackbox.positionX+=10;
  21.             $('.myChar').animate({
  22.                     'left' : blackbox.positionX}, 00);
  23.         }
  24.     }
  25.     blackbox.idle = function() {
  26.         $('.myChar')
  27.             .stop()
  28.             .clearQueue();
  29.     }
  30.  
  31. var main = function () {
  32.     blackbox.init();
  33.     $(window).keydown (function (event) {
  34.         switch (event.which) {
  35.             case 37: //left
  36.                 event.preventDefault();
  37.                 blackbox.run('left');
  38.                 break;
  39.             case 39: //right
  40.                 event.preventDefault();
  41.                 blackbox.run('right');
  42.                 break;
  43.            
  44.         }
  45.     });
  46.     $(window).keyup (function() {
  47.             blackbox.idle();
  48.     });
  49. }
  50.  
  51. $(document).ready(main);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement