/* エレベータの位置は回数で表現する (小数OK) + 速度は - 停止階の3F前になったら、残り階数 / 3 - そうでなない場合: 1フレームに 1F + 停止カウントは   - 0F では 10 フレーム - それ以外では 1 フレーム */ class Elevator { var cur_floor:Number, num_floors:Number; var btm_y:Number; var floor_h:Number = 80; var next_floor:Number, prev_floor:Number; var ev_mc:MovieClip, ev_light:MovieClip; var ev_halls:Array; var upward:Boolean; var stop_count:Number = 0; var hilight_floor:Number; function Elevator(ev_mc:MovieClip, ev_halls:Array, ev_light:MovieClip, btm_x:Number, btm_y:Number, num_floors:Number){ this.ev_mc = ev_mc; this.ev_light = ev_light; this.ev_halls = ev_halls; this.ev_mc._x = btm_x;// 横には動かないから。 this.btm_y = btm_y; this.num_floors = num_floors; this.cur_floor = int(Math.random() * num_floors); for(;;){ this.next_floor = int(Math.random() * num_floors); if(cur_floor != next_floor) break; } this.upward = (this.cur_floor < this.next_floor); if(this.upward) this.prev_floor = 0; else this.prev_floor = num_floors - 1; this.hilight_floor = int(Math.random() * num_floors) } function calc_speed(){ var speed:Number = Math.abs((next_floor - cur_floor) / 6); var speed_ref:Number = Math.abs((prev_floor - cur_floor) / 6) + 1/6; if(speed > speed_ref) speed = speed_ref; if(speed > 0.5) speed = 0.5; if(!upward) speed = - speed; return speed; } function addTime(){ /*まず、停止中かどうかを判定*/ if(stop_count > 0){ // 停止中 // 停止中だったら、カウントを減らす // もしカウントが 0 になったら、再開する。 stop_count--; if(stop_count == 0){ if(cur_floor == 0) upward = true; if(cur_floor == num_floors - 1) upward = false; prev_floor = next_floor; if(upward){//上向き next_floor = cur_floor + 1 + int((num_floors - cur_floor - 1) * Math.random()); } else {//上向き next_floor = cur_floor - 1 - int((cur_floor - 1) * Math.random()); } } } else if(Math.abs(cur_floor - next_floor) < 0.01){ cur_floor = next_floor; stop_count = 5;// 停止 } else { cur_floor += calc_speed(); } if(upward){ this.hilight_floor += 1/4; if(this.hilight_floor >= num_floors) hilight_floor %= num_floors; } else { this.hilight_floor -= 1/4; if(this.hilight_floor < 0) hilight_floor += num_floors; } apply_ev_pos(); apply_hilight(); } function apply_ev_pos(){ ev_mc._y = btm_y - 80 * cur_floor; } function apply_hilight(){ for(var i:Number = 0; i < num_floors; i++){ var hall_mc:MovieClip = ev_halls[i]; var fl:Number = int((cur_floor - i)*2 + 10); if(fl > 20) fl = 20; if(fl < 1) fl = 1; hall_mc.gotoAndStop(fl); } } }