0 Replies Latest reply on Sep 14, 2006 5:23 AM by kanukukreja

    mario game

    kanukukreja Level 1
      *********************************code written on Player_mc*************************

      onClipEvent (load) {
      _root.restart();
      jumpSpeed = 6;
      bounds = this.getBounds(this);
      function move(x, y) {
      //trace(x);
      jump = false;
      if (!_root.map.hitTest(_x+x+bounds.xMin, _y+y+bounds.yMin, true)) {
      //trace("move1");
      if (!_root.map.hitTest(_x+x+bounds.xMax, _y+y+bounds.yMin, true)) {
      //trace("move2");
      if (!_root.map.hitTest(_x+x+bounds.xMin, _y+y+bounds.yMax, true)) {
      //trace("move3");
      if (!_root.map.hitTest(_x+x+bounds.xMax, _y+y+bounds.yMax, true)) {
      //trace("move4");
      _x += x;
      _y += y;
      jump = true;
      //trace(_x);
      }
      }
      }
      }
      return jump;
      }
      }
      onClipEvent (enterFrame) {
      if (_root.playGame) {
      _root.falling = move(0, jumpSpeed);
      if (Key.isDown(Key.UP) && !_root.falling && !_root.jumping) {
      gravity = -12;
      _root.jumping = true;
      }
      if (Key.isDown(Key.LEFT) and _x>_root.left) {
      //_x>20) {
      //trace("aaaaaaaaa");
      move(-jumpSpeed, 0);
      this.gotoAndStop("left");
      }
      if (_root._currentframe != 2) {
      if (Key.isDown(Key.LEFT) and _x<=_root.left) {
      _root.prevFrame();
      this._x = _root.right;
      //810;
      move(-jumpSpeed, 0);
      this.gotoAndStop("left");
      }
      }
      if (Key.isDown(Key.RIGHT)) {
      //trace("bbbbbbbbbb");
      //_x<615) {
      move(jumpSpeed, 0);
      this.gotoAndStop("right");
      }
      if (Key.isDown(Key.RIGHT) and _x>=_root.right) {
      //_x>=810){
      _root.restart();
      _root.nextFrame();
      }
      if (_root.jumping) {
      if (gravity<=12) {
      jump = move(0, gravity-jumpSpeed);
      if (jump == false && gravity<0) {
      gravity *= -1;
      }
      gravity++;
      } else {
      _root.jumping = false;
      }
      }
      }
      if (this._y>615) {
      _root.playGame = false;
      _root.hero.gotoAndStop("dead");
      }
      }
      *********************code on root**************************

      var right:Number = _root.border._x+_root.border._width;
      var left:Number = _root.border._x+10;
      var life:Number = 30;
      var score:Number = 0;
      var playGame:Boolean = true;
      function restart() {
      hero.gotoAndStop("right");
      jumping = false;
      playGame = true;
      hero._x = map._x+10;
      hero._y = 550;
      }
      function coin(mc:MovieClip) {
      if (mc.hitTest(_root.hero)) {
      mc.gotoAndStop("end");
      _root.score += 1000;
      removeMovieClip(mc);
      }
      }
      function hit(mc:MovieClip) {
      if (mc.hitTest(_root.hero)) {
      _root.playGame = false;
      _root.hero.gotoAndStop("dead");
      removeMovieClip(mc);
      _root.life--;
      }
      }

      **********************************************
      is there is anything wrong in this code but still right and left move is not working and jumping is working perfectly fine even with right and left keys.