忍者ブログ

[PR]

2024年03月29日
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

移動処理改良

2009年03月30日

今まで流用していた移動処理を見直したところ あまりにも無駄だらけだったので改良↓
新移動処理--------------------------------------------------------------------------------------------

 onClipEvent(load){
  charax=5;
  charay=4;
  checkx=0;
  checky=1;
  this.gotoAndStop(3);
  move=false;
 }
 -
 onClipEvent(enterFrame){

  if(move==false){
   if(key.isdown(key.up) || key.isdown(key.down) || key.isdown(key.left) || key.isdown(key.right)){
    if(key.isdown(key.up)){
     checkx=0;
     checky=-1;
    }else if(key.isdown(key.down)){
     checkx=0;
     checky=1;
    }else if(key.isdown(key.left)){
     checkx=-1;
     checky=0;
    }else if(key.isdown(key.right)){
     checkx=1;
     checky=0;
    }
    xx=this._x;
    yy=this._y;
    move=true;
    this.gotoAndStop((checkx+1)*checkx*checkx+(checky+2)*checky*checky+5);
   }
  }
  if(move==true){
   if((_root.mo[charax+checkx][charay+checky]>-1)){
    if((this._x-xx)*(this._x-xx)<256 && (this._y-yy)*(this._y-yy)<256){
     this._x+=checkx*2;
     this._y+=checky*2;
    }else{
     this.gotoAndStop((checkx+1)*checkx*checkx+(checky+2)*checky*checky+1);
     move=false;
     charax+=checkx;
     charay+=checky;
    }
   }else{
    this.gotoAndStop((checkx+1)*checkx*checkx+(checky+2)*checky*checky+1);
    move=false;
   }
  }

 }

PalaFla! の SWF6で組んでるんですが 2乗って ^2 じゃ駄目なんですかね
どうもキチンと動いてくれず 仕方がないので x*x で代用する破目に

ちなみに 今までの処理はこんな感じ↓
旧移動処理--------------------------------------------------------------------------------------------

 onClipEvent(load){
  charax=5;
  charay=4;
  this.gotoAndStop("d");
  move_up=false;
  move_down=false;
  move_left=false;
  move_right=false;
  mf=false;
 }
 -
 onClipEvent(enterFrame){

  if(mf==false){
   if(key.isdown(key.up)){
    this.gotoAndStop("up");
    yy=_root.chara._y;
    move_up=true;
    mf=true;
   }else if(key.isdown(key.down)){
    this.gotoAndStop("down");
    yy=_root.chara._y;
    move_down=true;
    mf=true;
   }else if(key.isdown(key.left)){
    this.gotoAndStop("left");
    xx=_root.chara._x;
    move_left=true;
    mf=true;
   }else if(key.isdown(key.right)){
    this.gotoAndStop("right");
    xx=_root.chara._x;
    move_right=true;
    mf=true;
   }
  }

  if(move_up==true){
   if((_root.mo[charax][charay-1]>-1)){
    if(yy-this._y<16){
     this._y-=2;
    }else{
     this.gotoAndStop("u");
     mf=false;
     move_up=false;
     charay-=1;
    }
   }else{
    this.gotoAndStop("u");
    mf=false;
    move_up=false;
   }
  }else if(move_down==true){
   if(_root.mo[charax][charay+1]>-1){
    if(this._y-yy<16){
     this._y+=2;
    }else{
     this.gotoAndStop("d");
     mf=false;
     move_down=false;
     charay+=1;
    }
   }else{
    this.gotoAndStop("d");
    mf=false;
    move_down=false;
   }
  }else if(move_left==true){
   if(_root.mo[charax-1][charay]>-1){
    if(xx-this._x<16){
     this._x-=2;
    }else{
     this.gotoAndStop("l");
     mf=false;
     move_left=false;
     charax-=1;
    }
   }else{
    this.gotoAndStop("l");
    mf=false;
    move_left=false;
   }
  }else if(move_right==true){
   if(_root.mo[charax+1][charay]>-1){
    if(this._x-xx<16){
     this._x+=2;
    }else{
     this.gotoAndStop("r");
     mf=false;
     move_right=false;
     charax+=1;
    }
   }else{
    this.gotoAndStop("r");
    mf=false;
    move_right=false;
   }
  }

 }

うん 行数の無駄遣いだった

拍手

PR
« 前のページ | HOME |