Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(init);
- var currentState = 'pacman_right';
- function init()
- {
- $('#pacman').addClass(currentState);
- var rows = Math.floor($(window).height() / 90);
- var cols = Math.floor($(window).width() / 90);
- console.log("rijen: " +rows);
- for(var i=0;i<rows;i++){
- for(var j=0 ; j<cols ;j++){
- $('.dot:last').clone().appendTo('body');
- }
- }
- $('.dot:last').remove();
- $(document).keydown(keyDownHandler);
- }
- function keyDownHandler(e){
- console.log(e.which);
- //rechts 39
- //links 37
- //Omhoog 38
- //omlaag 40
- switch(e.which){
- case 37:
- moveLeft();
- break;
- case 38:
- moveUp();
- break;
- case 39:
- moveRight();
- break;
- case 40:
- moveDown();
- break;
- }
- }
- function moveRight(){
- //console.log("Going right, currentstate is " + currentState);
- $('#pacman').animate({left:"+=90"},500, 'swing').removeClass(currentState).addClass('pacman_right');
- currentState = 'pacman_right';
- var lal = $('.dot:last').remove();
- console.log(lal);
- }
- function moveLeft(){
- //console.log("Going left, currentstate is " + currentState);
- $('#pacman').animate({left:"-=90"},500, 'swing').removeClass(currentState).addClass('pacman_left');
- currentState = 'pacman_left';
- }
- function moveUp(){
- //console.log("Going up, currentstate is " + currentState);
- $('#pacman').animate({top:"-=90"},500, 'swing').removeClass(currentState).addClass('pacman_up');
- currentState = 'pacman_up';
- }
- function moveDown(){
- //console.log("Going down, currentstate is " + currentState);
- $('#pacman').animate({top:"+=90"},500, 'swing').removeClass(currentState).addClass('pacman_down');
- currentState = 'pacman_down';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement