Posted By

flipace on 07/27/11


Tagged


Versions (?)

Jason Engine Super Mario 1


 / Published in: JavaScript
 

  1. drawMapInterval = false;
  2. drawMapIntervalKey = false;
  3. var ms = 40
  4. x = 0;
  5.  
  6. var cvs = document.getElementById('expcanvas');
  7. var ctx = cvs.getContext('2d');
  8.  
  9. speed = 10;
  10.  
  11. var game = new Jason(60);
  12. game.addMap('map1','marioJump1-1.tmx',0,0);
  13. game.maps['map1'].mapOffsetY=game.maps['map1'].mapheight*game.maps['map1'].maptileheight*-1+cvs.height;
  14. game.addCharacter('mario',0,0,'walk_right',30);
  15. game.addCharacterState('mario','walk_right','mario_char_walk_right_sprite.gif',18.5,32,0,146);
  16. game.addCharacterState('mario','walk_left','mario_char_walk_left_sprite.gif',18.5,32,0,146);
  17. game.addCharacterState('mario','duck_right','mario_char_duck_right.gif',18,21,0,21);
  18. game.addCharacterProperty('mario','sound_jump',new Audio('Mario Jump.wav'));
  19. game.addCharacterProperty('mario','sound_death',new Audio('Death.wav'));
  20. game.addKeyEvent(39,'walk_right');
  21. game.addKeyEvent(37,'walk_left');
  22. game.addKeyEvent(38,'jump');
  23. game.addKeyEvent(40,'duck');
  24.  
  25. $(document).keydown( function(event){
  26. if(event.keyCode==38 || event.keyCode==40 || event.keyCode==83){
  27. game.fireEvent(event.keyCode);
  28. }else{
  29. if(!drawMapInterval){
  30. drawMapIntervalKey = event.keyCode;
  31. drawMapInterval = setInterval(function(){
  32. game.fireEvent(event.keyCode);
  33. },ms);
  34. }
  35. }
  36. });
  37.  
  38. $(document).keyup( function(event){
  39. if(event.keyCode == drawMapIntervalKey){
  40. if(game.characters['mario'].currentState=="duck_right"){
  41. game.characters['mario'].setState('walk_right');
  42. }
  43. game.characters['mario'].setAnimated(false);
  44. clearInterval(drawMapInterval);
  45. drawMapInterval=false;
  46. drawMapIntervalKey = false;
  47. }
  48. });

Report this snippet  

You need to login to post a comment.