Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var blackbox = {}
- blackbox.positionX = 370;
- blackbox.positionY = 50;
- blackbox.init = function() {
- $('.myChar').css({
- 'left':this.positionX+'px'
- });
- $('.myChar').css({
- 'top':this.positionY+'px'
- });
- };
- blackbox.run = function(where) {
- if (where === 'left') {
- blackbox.positionX-=10;
- $('.myChar').animate({
- 'left' : blackbox.positionX}, 00);
- movingInterval.clearInterval();
- }
- if (where === 'right') {
- blackbox.positionX+=10;
- $('.myChar').animate({
- 'left' : blackbox.positionX}, 00);
- }
- }
- blackbox.idle = function() {
- $('.myChar')
- .stop()
- .clearQueue();
- }
- var main = function () {
- blackbox.init();
- $(window).keydown (function (event) {
- switch (event.which) {
- case 37: //left
- event.preventDefault();
- blackbox.run('left');
- break;
- case 39: //right
- event.preventDefault();
- blackbox.run('right');
- break;
- }
- });
- $(window).keyup (function() {
- blackbox.idle();
- });
- }
- $(document).ready(main);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement