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;
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|
061| }
062|
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|
104|
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|
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|
181| }else{
182|
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|
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| }