Advertisement
Guest User

lallal

a guest
Feb 27th, 2012
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. $(document).ready(init);
  2.  
  3. var currentState = 'pacman_right';
  4.  
  5. function init()
  6. {
  7. $('#pacman').addClass(currentState);
  8.  
  9. var rows = Math.floor($(window).height() / 90);
  10. var cols = Math.floor($(window).width() / 90);
  11.  
  12. console.log("rijen: " +rows);
  13.  
  14. for(var i=0;i<rows;i++){
  15. for(var j=0 ; j<cols ;j++){
  16. $('.dot:last').clone().appendTo('body');
  17. }
  18. }
  19.  
  20. $('.dot:last').remove();
  21.  
  22. $(document).keydown(keyDownHandler);
  23.  
  24. }
  25.  
  26. function keyDownHandler(e){
  27. console.log(e.which);
  28.  
  29. //rechts 39
  30. //links 37
  31. //Omhoog 38
  32. //omlaag 40
  33.  
  34. switch(e.which){
  35. case 37:
  36. moveLeft();
  37. break;
  38. case 38:
  39. moveUp();
  40. break;
  41. case 39:
  42. moveRight();
  43. break;
  44. case 40:
  45. moveDown();
  46. break;
  47. }
  48. }
  49.  
  50. function moveRight(){
  51. //console.log("Going right, currentstate is " + currentState);
  52. $('#pacman').animate({left:"+=90"},500, 'swing').removeClass(currentState).addClass('pacman_right');
  53. currentState = 'pacman_right';
  54.  
  55. var lal = $('.dot:last').remove();
  56. console.log(lal);
  57. }
  58.  
  59. function moveLeft(){
  60. //console.log("Going left, currentstate is " + currentState);
  61. $('#pacman').animate({left:"-=90"},500, 'swing').removeClass(currentState).addClass('pacman_left');
  62. currentState = 'pacman_left';
  63. }
  64.  
  65. function moveUp(){
  66. //console.log("Going up, currentstate is " + currentState);
  67. $('#pacman').animate({top:"-=90"},500, 'swing').removeClass(currentState).addClass('pacman_up');
  68. currentState = 'pacman_up';
  69. }
  70.  
  71. function moveDown(){
  72. //console.log("Going down, currentstate is " + currentState);
  73. $('#pacman').animate({top:"+=90"},500, 'swing').removeClass(currentState).addClass('pacman_down');
  74. currentState = 'pacman_down';
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement