001| package oddmaple{
002|     import com.game2d.SimpleObject;
003|     import com.util.rouden.DoAfterMan;
004|     import flash.display.DisplayObject;
005|     import flash.display.Graphics;
006|     import flash.display.MovieClip;
007|     import flash.display.Sprite;
008|     import flash.events.*;
009|     import com.util.rouden.MyKey;
010|     import flash.geom.Point;
011|     
012|     public class PlayerCharacter extends Character {
013|         /* 定数 */
014|         private const CLIMB_SPEED:Number = 2;
015|         
016|         /* 変数 */
017|         private var mycharacter:Rouden;
018|         private var mycharactermanager:PlayerCharacterManager;
019|         private var isMuteki:Boolean;
020|         private var mutekiCheckMan:DoAfterMan;
021|         private var cleared:Boolean;
022|         private var m_isClimbing:Boolean;    // デフォルトのfalse
023|         
024|         
025|         /* コンストラクタ */
026|         public function PlayerCharacter(x:Number, y:Number){
027|             type = TYPE_HERO;
028|             super(22, 60, true);
029|             maxLife = 51;
030|             life = maxLife;
031|             
032|             mycharacter = new Rouden();
033|             mutekiCheckMan = new DoAfterMan();
034|             mycharactermanager = new PlayerCharacterManager(mycharacter);
035|             addChild(mycharacter);
036|             this.x = x;
037|             this.y = y;
038|             scaleX = -1;
039|         }
040|         override public function onAppear():void {
041|             /* ライフゲージの描画を委託 */
042|             appear(new MegaManLifeGageDrawer(this));
043|         }
044|         public override function release():void{
045|             super.release();
046|             mycharactermanager.release();
047|         }
048|         override protected function onLifeZero():void {
049|             /* ティウンティウンの作成 */
050|             for (var i:int = 0 ; i < 8 ; i++ ){
051|                 var angle:Number = i * 45 / 180 * Math.PI;
052|                 appear(new ThiunThiun(x+Math.cos(angle)*60, y-30+Math.sin(angle)*60, angle , 4));
053|                 appear(new ThiunThiun(x+Math.cos(angle)*30, y-30+Math.sin(angle)*30, angle , 2));
054|             }
055|             die();
056|         }
057|         
058|         protected override function onHitBottom():void{
059|             if(! isClimbing)mycharactermanager.stand();
060|             //trace("bottom");
061|         }
062|         /*
063|         protected override function onHitLeft():void{trace("left");}
064|         protected override function onHitRight():void{trace("right"); }
065|         protected override function onHitTop():void{trace("top"); }
066|         */

067|         protected override function onReleaseBottom():void{
068|             if(! isClimbing)mycharactermanager.jump();
069|         }
070|         
071|         
072|         protected override function action():void{
073|             
074|             /* 敵との衝突 */
075|             for each(var e:SimpleObject in chars[TYPE_ENEMY]){
076|                 if (crashTo(e)){
077|                     kb(e.x < x);
078|                     life -= e.grav;
079|                     e.die();
080|                 }
081|             }
082|             /* 旗との衝突 */
083|             if (cleared == false){
084|                 for each(var spe:SimpleObject in chars[TYPE_SPECIAL]){
085|                     if (crashTo(spe) && spe is TheClearFlag){
086|                         cleared = true;
087|                         /* クリア時のイベント */
088|                         appear(new FireWork(1760, 400));
089|                         var f:Function = function(){
090|                             appear(new FireWork(2000, 380));
091|                         }
092|                         new DoAfterMan(2000, f);
093|                     }
094|                 }
095|             }
096|             /* デバッグ用 */
097|             if (MyKey.isPushed(MyKey.KEY_MOUSE_LEFT) && MyKey.isPress(MyKey.KEY_D)){
098|                 trace(new Point(gameStage.mouseX,gameStage.mouseY));
099|             }
100|             
101|             if (isClimbing || vy >= 0 && MyKey.isPress(MyKey.KEY_UP) && gameStage.map.getTable(x, y) == 3
102|                 || vy==0 && gameStage.map.getTable(x, y+1)==3 && MyKey.isPress(MyKey.KEY_DOWN)){
103|                 /* 縦速度が上向き, (x,y)がロープ, しかも上キーが押されてるのとき */
104|                 /* または, 縦速度が0, 足元(x, y+1)が梯子, しかも下キーが押されている状態 */
105|                 
106|                 if (! isClimbing && MyKey.isPress(MyKey.KEY_DOWN)){
107|                     /* 座標修正 */
108|                     y += CLIMB_SPEED;
109|                 }
110|                 
111|                 /* 梯子モードにする */
112|                 isClimbing = true;
113|                 
114|                 /* 上下移動 */
115|                 vy = 0;
116|                 if (MyKey.isPress(MyKey.KEY_UP)) vy -= CLIMB_SPEED;
117|                 else if (MyKey.isPress(MyKey.KEY_DOWN)) vy += CLIMB_SPEED;
118|                 
119|                 /* 足元が梯子でない || 足元が床 で 梯子モード終了 */
120|                 if (gameStage.map.getTable(x, y) != 3){
121|                     isClimbing = false;
122|                     y -= CLIMB_SPEED; // めり込み修正分
123|                 }
124|                 
125|                 /* 左右キーを押している && ジャンプキー でジャンプ飛び降り */
126|                 if (MyKey.isPress(MyKey.KEY_C)){
127|                     if (MyKey.isPress(MyKey.KEY_RIGHT)){
128|                         vx = 3;
129|                         vy = -8;
130|                     }else if (MyKey.isPress(MyKey.KEY_LEFT)){
131|                         vx = -3;
132|                         vy = -8;
133|                     }
134|                     isClimbing = false;
135|                 }
136|                 
137|             }else if (isReachingBottom){
138|                 /* 地面に立っているときのアクション */
139|                 if (MyKey.isPress(MyKey.KEY_RIGHT)){
140|                     /* 右に移動 */
141|                     mycharactermanager.walk();
142|                     scaleX = -1;
143|                     if(vx <3)vx += 0.8;
144|                 }else if (MyKey.isPress(MyKey.KEY_LEFT)){
145|                     /* 左に移動 */
146|                     mycharactermanager.walk();
147|                     scaleX = 1;
148|                     if ( -3 < vx) vx -= 0.8;
149|                 }else{
150|                     mycharactermanager.stand();
151|                     vx *= 0.7;
152|                 }
153|                 if (MyKey.isPress(MyKey.KEY_C)){
154|                     vy = -12;
155|                 }
156|             }else{
157|                 /* 空中の動作 */
158|                 if (MyKey.isPress(MyKey.KEY_RIGHT)){
159|                     /* 右に移動 */
160|                     scaleX = -1;
161|                     if(vx <1)vx += 0.05;
162|                 }else if (MyKey.isPress(MyKey.KEY_LEFT)){
163|                     /* 左に移動 */
164|                     scaleX = 1;
165|                     if ( -1 < vx) vx -= 0.05;
166|                 }
167|             }
168|             if (vy > 20) vy = 20;
169|             
170|             /* スクロール */
171|             scrollTo(x - stage.stageWidth / 2, y - stage.stageHeight / 2);
172|             //gameStage.scrollTo(0, frameCount);
173|         }
174|         public function kb(fromLeft:Boolean):void{
175|             mycharactermanager.beDamaged();
176|             isMuteki = true;
177|             mutekiCheckMan.setNew(1500, finishMuteki);
178|             
179|             if (isClimbing && MyKey.isPress(MyKey.KEY_UP)){
180|                 /* 梯子で上に登っている間はKBしない */
181|             }else{
182|                 /* 梯子で上に登っている間以外はKBする */
183|                 if (fromLeft) vx = 3;
184|                 else vx = -3;
185|                 if (isReachingBottom || isClimbing) vy = -8;
186|                 isClimbing = false;
187|                 mycharactermanager.jump();
188|             }
189|         }
190|         private function finishMuteki():void{
191|             isMuteki = false;
192|         }
193|         public override function crashTo(obj:SimpleObject):Boolean{
194|             if (isMuteki) return false;
195|             else return super.crashTo(obj);
196|         }
197|         private function get isClimbing():Boolean{
198|             return m_isClimbing;
199|         }
200|         private function set isClimbing(flag:Boolean):void{
201|             if (flag == m_isClimbing) return// 何もしない
202|             if (flag){
203|                 /* 梯子につかまるとき */
204|                 
205|                 /* 見た目(キャラクタ画像)を変更 */
206|                 mycharactermanager.climb();
207|                 /* 重力を無視 */
208|                 useGravity = false;
209|                 /* 背景との当たり判定をなくす */
210|                 usePhysicalMove = false;
211|                 /* 速度ベクトルを0にする */
212|                 vx = vy = 0;
213|                 /* ロープの真ん中につかまっているように見せるために座標を修正 */
214|                 x = int(x);
215|                 x = x - x % 16 + 8 ;
216|                 y = int(y);
217|             }else{
218|                 
219|                 /* 梯子から離れるとき */
220|                 
221|                 /* 見た目を戻す */
222|                 if (isReachingBottom) mycharactermanager.stand();
223|                 else mycharactermanager.jump();
224|                 
225|                 /* 重力を戻す */
226|                 useGravity = true;
227|                 /* 背景との当たり判定を戻す */
228|                 usePhysicalMove = true;
229|                 
230|             }
231|             m_isClimbing = flag;
232|         }
233|     }
234| }