matthewdvista

Untitled

Dec 16th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /////here is my code
  2.  
  3. package {
  4. import flash.display.MovieClip;
  5. import flash.events.KeyboardEvent;
  6. import flash.events.Event;
  7.  
  8. public class marioV2Code extends MovieClip {
  9.  
  10. public function marioV2Code() {
  11.  
  12. //variables
  13. var dir:String = "stop";
  14. var wCheck :Boolean = false;
  15.  
  16. //putting the map on the stage
  17. var w:map = new map();
  18. addChild(w);
  19. //putting the tube on the stage
  20. var t:tube = new tube();
  21. w.addChild(t);
  22.  
  23.  
  24.  
  25.  
  26.  
  27. //putting mario at the bottom
  28. var m:mario = new mario();
  29. addChild(m);
  30. m.gotoAndStop(1);
  31. m.x = 20;
  32. m.y = 307;
  33.  
  34. stage.addEventListener(KeyboardEvent.KEY_DOWN, dFun);
  35. function dFun(evt:KeyboardEvent):void {
  36. if (evt.keyCode == 39 && wCheck == false) {
  37. dir = "right";
  38. m.gotoAndPlay(2);
  39. wCheck = true;
  40. }
  41. if (evt.keyCode == 37 && wCheck == false) {
  42. dir = "left";
  43. m.gotoAndPlay(14);
  44. wCheck = true;
  45. }
  46.  
  47. if (evt.keyCode == 32) {
  48. m.y -=6;
  49. }
  50. }
  51.  
  52. stage.addEventListener(KeyboardEvent.KEY_UP, uFun);
  53. function uFun(evt:KeyboardEvent):void {
  54. if (evt.keyCode == 39) {
  55. dir = "stop";
  56. m.gotoAndStop(2);
  57. wCheck = false;
  58. }
  59. if (evt.keyCode == 37) {
  60. dir = "stop";
  61. m.gotoAndStop(14);
  62. wCheck = false;
  63. }
  64. }
  65.  
  66. addEventListener(Event.ENTER_FRAME, mainFun);
  67. function mainFun(evt:Event):void {
  68. moveMario();
  69.  
  70. if ( m.hitTestObject(t) ) {
  71.  
  72. if (dir == "right") {
  73. m.x -=1;
  74. w.x +=3;
  75. }
  76. }
  77. }
  78.  
  79. //functions......
  80. function moveMario():void {
  81. if (dir == "right" && wCheck == true && m.x < 535) {
  82. m.x += 1;
  83. w.x -=3;
  84. if (m.currentFrame == 13) m.gotoAndPlay(3);
  85. } else if (dir == "left" && wCheck == true && m.x > 15) {
  86. m.x -= 1;
  87. w.x += 3;
  88. if (m.currentFrame == 27) m.gotoAndPlay(15);
  89. }
  90. if (m.y < 307) m.y += .6;
  91. }
  92.  
  93. }
  94.  
  95. }
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment