RPG風バトルインターフェース

by kagehinata forked from GYAOS_sample (diff: 438)
Copyright hacker_9vjnvtdz ( http://wonderfl.net/user/hacker_9vjnvtdz )
MIT License ( http://www.opensource.org/licenses/mit-license.php )
Downloaded from: http://wonderfl.net/c/f6f2

ギャオスの新しいバトルインターフェースを考えてみました
ですが時間の都合上たこ殴りです;;

操作方法
 アタックボタン―攻撃力は弱いがスキルポイントを溜めることができる、クリティカルボタンを押すと一気に逆転可能!?
 スキルボタン-必要なスキルポイントが溜まったら使うことのできる特殊な攻撃を選択できます
 
 相手に一定のダメージを与えると勝ちです
 
 ほかにもいろいろと隠し技を入れていますのでソースを見るか自分で確かめてみてください
♥0 | Line 393 | Modified 2011-02-01 02:06:52 | MIT License | (replaced)
play

ActionScript3 source code

/**
 * Copyright kagehinata ( http://wonderfl.net/user/kagehinata )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/bsGV
 */

// forked from kagehinata's forked from: GYAOS_sample
// forked from hacker_9vjnvtdz's GYAOS_sample
/**
 * Copyright hacker_9vjnvtdz ( http://wonderfl.net/user/hacker_9vjnvtdz )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/f6f2
 */

/*
    ギャオスの新しいバトルインターフェースを考えてみました
    ですが時間の都合上たこ殴りです;;
    アイテムと逃げるコマンドも入れるつもりでしたが今のところ断念していますww残骸のコメントがちらほらw
  コメントも修正しながら入れていったので矛盾していたり間違ったコメントがあるかもしれません
  今度はもっと名前の付け方にルールをつけてコードを書きたいですwww
   ちなみにイメージ的には自分も相手と同じ狼(?)を操作している感じです
    
    操作方法
     アタックボタン-攻撃力は弱いがスキルポイントを溜めることができる、クリティカルボタンを押すと一気に逆転可能!?
     スキルボタン-必要なスキルポイントが溜まったら使うことのできる特殊な攻撃を選択できます
     
     相手のHPを0にすると勝ちです
     
     ほかにもいろいろと隠し技を入れていますのでソースを見るか自分で確かめてみてください 
*/
package
{
    import flash.display.Shape;
    import com.bit101.components.PushButton;
    
    import flash.display.Loader;
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.events.TimerEvent;
    import flash.net.URLRequest;
    import flash.system.LoaderContext;
    import flash.utils.Timer;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    import com.pblabs.engine.components.TickedComponent;
    
    [SWF(width="465", height="465", frameRate="30", backgroundColor="#FFFFFF")]

    public class FlashTest extends MovieClip
    {
  
        private var imgUrl:String="http://assets.wonderfl.net/images/related_images/6/6d/6d2a/6d2aac9165308e05d07f52232f99bfe9d52a06fb"; // モンスターURL
//その他のモンスターのパス
//http://assets.wonderfl.net/images/related_images/9/9a/9a67/9a674310835d956620db269594b14241d8c079ba
//http://assets.wonderfl.net/images/related_images/5/57/5728/5728bb5057da70c62a2bff824fac59cf139bcb44
        
        
        
        private var loader:Loader; // モンスター表示用コンテナ
        
        private var attackButton:PushButton; // 攻撃ボタン
        private var attackButton2:PushButton; //通常攻撃ボタン
        private var attackButton3:PushButton; //クリティカルボタン
        private var skillButton:PushButton; //スキルボタン 
        private var skill1:PushButton;
        private var skill2:PushButton;
        private var skill3:PushButton;
        private var chainButton:PushButton;
        private var spSkill:PushButton;
        private var backButton:PushButton;
        
        private var hpView:HpView; // HP表示
        private var hp:int=200; // モンスターのHP
        private var stBox:Sprite;
        private var skillBox:TextField;
        private var textBox:TextField;
        private var skillPoint:uint = 0;
        private var skillPointUp:uint;
        private var atk:uint = 0;
        private var stkUp:uint;
        private var _r:int;
        
        private var blinkTimer:Timer; // 攻撃エフェクト用のタイマー
        private var attackTimer:Timer;//攻撃開始用タイマー
        private var skillPointTimer:Timer;//スキルポイント更新用タイマー
        private var criticalTimer:Timer;//クリティカル用タイマー
        private var missTimer:Timer;//ミス用タイマー
        private var battleMenuTimer:Timer;//バトルメニューに戻る用タイマー
        private var rashTimer:Timer;
        
        public function FlashTest()
        {
            // モンスターをロードする
            loader=new Loader();
            var context:LoaderContext=new LoaderContext(true);
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, picsOnComplete);
            loader.load(new URLRequest(imgUrl), context);
            addChild(loader);
            
            // タイマーを初期化する
            blinkTimer=new Timer(80, 4);
            blinkTimer.addEventListener("timer", timerHandler);

            // 攻撃ボタンを配置する
            attackButton = new PushButton(this, 0, 0, "Attack", atc);
            attackButton.y=(stage.stageHeight - attackButton.height) / 2 + 170;
            attackButton.x=(stage.stageWidth - attackButton.width) / 2-100;
                        
            //スキルボタンを配置する
            skillButton = new PushButton(this,0,0,"Skill",skl);
            skillButton.y=(stage.stageHeight - skillButton.height) / 2 + 170;
            skillButton.x=(stage.stageWidth - skillButton.width) / 2+100;
                    
            // モンスターのHPを表示する
            hpView=new HpView(hp, hp);
            hpView.y=attackButton.y - hpView.height - 250;
            hpView.x=(stage.stageWidth - hpView.width)/2 -10;
            hpView.visible = true;
            addChild(hpView);            
                 
            //スキル1ボタン(攻撃力アップ)
            skill1 = new PushButton(this ,0,0,"AttackUP",attackUp);
            skill1.x = (stage.stageWidth - skill1.width) /2;
            skill1.y = (stage.stageHeight - skill1.height) /2 +125;
            skill1.visible = false;
                        
            //スキル2ボタン(攻撃 中)
            skill2 = new PushButton(this,0,0,"Fang",skillAttack1);
            skill2.x = (stage.stageWidth - skill1.width) /2;
            skill2.y = (stage.stageHeight - skill1.height) /2 +155;
            skill2.visible = false;
            
            //スキル3ボタン(攻撃 大)
            skill3 = new PushButton(this,0,0,"Rush",skillAttack2);
            skill3.x = (stage.stageWidth - skill3.width) /2;
            skill3.y = (stage.stageHeight - skill3.height) /2 +185;
            skill3.visible = false;
            
            //戻るボタン
            backButton = new PushButton(this,0,0,"Back",back);
            backButton.x = (stage.stageWidth - backButton.width) /2;
            backButton.y = (stage.stageHeight - backButton.height) /2 + 215;
            backButton.visible = false;
            //連撃ボタン
            chainButton = new PushButton(this,0,0,"Chain",chain);
            chainButton.y = (stage.stageHeight - chainButton.height)/2;
            chainButton.x = (stage.stageWidth - chainButton.width)/2;
            chainButton.visible = false;
            
            //スペシャル
            spSkill = new PushButton(this,0,0,"Special",special);
            spSkill.y = (stage.stageHeight - spSkill.height)/2;
            spSkill.x = (stage.stageWidth - spSkill.width)/2;
            spSkill.visible = false;
            
                        
            //アイテムボタンを配置する
            //逃げるボタンを配置する
            
            //通常攻撃ボタンを配置する
            attackButton2 = new PushButton(this,0,0,"Attack!!",normal);
            attackButton2.y = (stage.stageHeight - attackButton2.height)/2;
            attackButton2.x = (stage.stageWidth - attackButton2.width)/2;
            attackButton2.visible = false;
            
            //クリティカルボタンを配置する
           attackButton3 = new PushButton(this,0,0,"Clitical!!",critical);
           attackButton3.y = Math.random()*(stage.stageHeight - attackButton3.height - 120);
           attackButton3.x = Math.random()*(stage.stageWidth - attackButton3.width);
           attackButton3.visible = false;
            
            //ボックスを表示する
            stBox = new Sprite();
            stBox.graphics.lineStyle(1,0x000000);
            stBox.graphics.drawRect(0,0,stage.stageWidth - 2,120);
            stBox.y = stage.stageHeight - stBox.height - 1;
            stBox.x = 1;
            addChild(stBox);
            
            //攻撃テキスト表示時間タイマー
            attackTimer = new Timer(1000,1);
            attackTimer.addEventListener(TimerEvent.TIMER,attack);
                        
            //クリティカル表示時間タイマー
            //criticalTimer = new Timer(Math.random()*3000,1);
            criticalTimer = new Timer(2400,1);
            criticalTimer.addEventListener(TimerEvent.TIMER,criticalTime);
                        
            //ミス表示用タイマー
            missTimer = new Timer(3200,1);
            missTimer.addEventListener(TimerEvent.TIMER,miss);
            
            //スキルポイント用タイマー
            skillPointTimer = new Timer(1000,1);
            skillPointTimer.addEventListener(TimerEvent.TIMER,skillUp);
            
            //バトルメニュー用タイマー
            battleMenuTimer = new Timer(2000,1);
            battleMenuTimer.addEventListener(TimerEvent.TIMER,battleMenu);
            
            //ラッシュ開始用タイマー
            rashTimer = new Timer(2500,3);
            rashTimer.addEventListener(TimerEvent.TIMER,rash);
                        
            //スキルポイント表示
            skillBox = new TextField();
            skillBox.autoSize = TextFieldAutoSize.LEFT;
            skillBox.defaultTextFormat = new TextFormat(null,50);
            skillBox.text = "Sp" + String(skillPoint);
            addChild(skillBox);
            
            //テキストの表示
            textBox = new TextField;
            textBox.autoSize = TextFieldAutoSize.CENTER;
            textBox.defaultTextFormat = new TextFormat(null,20);
            textBox.visible = false;
            addChild(textBox);
        }
        
        // モンスターのロード完了時の処理
        private function picsOnComplete(eventObj:Event):void
        {
            // モンスターをステージ中央に配置する
            loader.x=stage.stageWidth / 2 - loader.width / 2;
            loader.y=stage.stageHeight / 2 - loader.height / 2;
        }

        // 攻撃処理
        private function atc(e:MouseEvent):void
        {
            //攻撃フェイズ開始
            attackButton.visible = false;
            skillButton.visible = false;
            textBox.text = "こうげき!!";
            textBox.x = (stage.stageWidth - textBox.width)/2;
            textBox.y = (stage.stageHeight - textBox.height)/2 +170;
            textBox.visible = true;
            attackTimer.reset();
            attackTimer.start();
        }
        
        //通常攻撃処理
        private function normal(event:MouseEvent):void{
            attackButton2.visible = false;
            attackButton3.visible = false;
            criticalTimer.stop();
            missTimer.stop();
            criticalTimer.stop();
            skillPointUp = 2;
            skillPoint += skillPointUp;
            // ダメージを計算する
            var r:int=Math.floor(Math.random() * 4 )+1 + atk;
            hp-=r;
            textBox.text = "あいてに" + String(r) + "のダメージ!!";
            textBox.x = (stage.stageWidth - textBox.width)/2;
            textBox.y = (stage.stageHeight - textBox.height)/2 +170;
            blinkTimer.reset();
            blinkTimer.start();
            //HP表示を更新する
            hpView.update(hp);
        }
                
        //クリティカル処理
        private function critical(event:MouseEvent):void{
            attackButton2.visible = false;
            attackButton3.visible = false;
            missTimer.stop();
            skillPointUp = 5;
            skillPoint += skillPointUp;
            // ダメージを計算する
            var r:int=Math.floor(Math.random() * 4 ) + 5 + 2 * atk;
            hp-=r;
            textBox.text = "あいてに" + String(r) + "のダメージ!!";
            textBox.x = (stage.stageWidth - textBox.width)/2;
            textBox.y = (stage.stageHeight - textBox.height)/2 +170;
            blinkTimer.reset();
            blinkTimer.start();
            //HP表示を更新する
            hpView.update(hp);
        }

        
        //スキルメニュー処理
        private function skl(event:MouseEvent):void{
            attackButton.visible = false;
            skillButton.visible = false;
            backButton.visible = true;
            if(skillPoint >= 1){
                      skill1.visible = true;
            }
            if(skillPoint >= 2){
                      skill2.visible = true;
            }
            if(skillPoint >= 3){
                      skill3.visible = true;
            }
                    
        }
                
        //スキル処理
                
        //スキル1 攻撃力アップ処理
        private function attackUp(event:MouseEvent):void{
            skill1.visible = false;
            skill2.visible = false;
            skill3.visible = false;
            backButton.visible = false;
                    
            skillPoint -= 1;
            skillBox.text = "Sp" + String(skillPoint);
            var a:int=Math.floor(Math.random() * 4 )+1;
            atk += a;
            textBox.text = "攻撃力が" + String(a) + "あがった!!"
            textBox.x = (stage.stageWidth - textBox.width)/2;
            textBox.y = (stage.stageHeight - textBox.height)/2 +170;
            textBox.visible = true;
            battleMenuTimer.reset();
            battleMenuTimer.start();
        }
                
        //スキル2 攻撃 中攻撃
        private function skillAttack1(event:MouseEvent):void{
            skill1.visible = false;
            skill2.visible = false;
            skill3.visible = false;
            backButton.visible = false;
                    
            skillPoint -= 2;
            skillBox.text = "Sp" + String(skillPoint);
            // ダメージを計算する
            var r:int=Math.floor(Math.random() * 20 ) + 10 + atk;
            hp -= r;
            _r = r;
            textBox.text = "噛み付く攻撃!あいてに" + String(r) + "のダメージ!!";
            textBox.x = (stage.stageWidth - textBox.width)/2;
            textBox.y = (stage.stageHeight - textBox.height)/2 +170;
            textBox.visible = true;
            r = _r;
            blinkTimer.reset();
            blinkTimer.start();
            //HP表示を更新する
            hpView.update(hp);
       }
       //スキル3 攻撃 大攻撃
       private function skillAttack2(event:Event):void{
           skill1.visible = false;
           skill2.visible = false;
           skill3.visible = false;
           backButton.visible = false;
           
           textBox.text = "ラッシュ!!"
           textBox.x = (stage.stageWidth - textBox.width)/2;
           textBox.y = (stage.stageHeight - textBox.height)/2 +170;
           textBox.visible = true;
           rashTimer.reset();
           rashTimer.start();
       }
       
       //戻るボタン
       private function back(event:Event):void{
           skill1.visible = false;
           skill2.visible = false;
           skill3.visible = false;
           backButton.visible = false;
           
           attackButton.visible = true;
           skillButton.visible = true;
           
       }

       
       //連撃
       private function chain(event:MouseEvent):void{
           battleMenuTimer.stop();
           chainButton.visible = false;
           skillPoint -= 3;
           skillBox.text = "Sp" + String(skillPoint);
           // ダメージを計算する
           var r:int=Math.floor(Math.random() *  15) + 10 + atk;
           hp -= r;
           _r = r;
           textBox.text = "こうげき!! " + String(r) + "のダメージ!!";
           textBox.x = (stage.stageWidth - textBox.width)/2;
           textBox.y = (stage.stageHeight - textBox.height)/2 +170;
           textBox.visible = true;
           r = _r;
           blinkTimer.reset();
           blinkTimer.start();
           //HP表示を更新する
           hpView.update(hp);
       }
       
       //スペシャル攻撃
       private function special(event:Event):void{
           spSkill.visible = false;
           skillPoint -= 5;
           skillBox.text = "Sp" + String(skillPoint);
           // ダメージを計算する
           var r:int=Math.floor(Math.random() *  50) + 50 + (50 * atk);
           hp -= r;
           _r = r;
           textBox.text = "どとうのこうげき!! " + String(r) + "の大ダメージ!!!";
           textBox.x = (stage.stageWidth - textBox.width)/2;
           textBox.y = (stage.stageHeight - textBox.height)/2 +170;
           textBox.visible = true;
           r = _r;
           blinkTimer.reset();
           blinkTimer.start();
           //HP表示を更新する
           hpView.update(hp);
       }


        
        // タイマー処理
        private function timerHandler(event:TimerEvent):void
        {
            if (blinkTimer.currentCount % 2 == 1)
            {
                loader.visible=false;
            }
            else
            {
                loader.visible=true;
                if (blinkTimer.currentCount == 4){
                                    if (textBox.text == "噛み付く攻撃!あいてに" + String(_r) + "のダメージ!!" || textBox.text == "こうげき!! " + String(_r) + "のダメージ!!" || textBox.text == "どとうのこうげき!! " + String(_r) + "の大ダメージ!!!"){
                     battleMenuTimer.reset();
                                         battleMenuTimer.start();
                                    }else{
                                         skillPointTimer.reset();
                     skillPointTimer.start();
                                    }
                    if (hp < 1) // モンスター死亡時
                    {
                        //win表示
                       var winText=new TextField();
                       var format:TextFormat=new TextFormat();
                       format.size = 100;
                       winText.autoSize = TextFieldAutoSize.CENTER;
                       winText.defaultTextFormat=format;
                       winText.text="win";
                       addChild(winText);
                       winText.x=loader.x;
                       winText.y=loader.y;
                       
                       textBox.text = "たたかいにしょうりした"
                       textBox.x = (stage.stageWidth - textBox.width)/2;
                       textBox.y = (stage.stageHeight - textBox.height)/2 +170;
                       
                       hpView.visible = false;
                       rashTimer.removeEventListener(TimerEvent.TIMER,rash);
                       battleMenuTimer.removeEventListener(TimerEvent.TIMER,battleMenu);      
                
                       hp=0;
                       // モンスターを非表示にする
                       loader.visible=false; 
                    }
               }

            }
        }
        
        //攻撃ボタン表示時間
        private function attack(event:Event):void{
            attackButton2.visible = true;
                        criticalTimer.reset();
                        criticalTimer.start();
                        missTimer.reset();
                        missTimer.start();
        }
                
                //クリティカル表示時間
                private function criticalTime(event:Event):void{
                      attackButton3.visible = true;
                }
                
                //ミス時間
                private function miss(event:Event):void{
                    attackButton2.visible = false;
                    attackButton3.visible = false;
                    textBox.text = "ミス!!"
                    textBox.x = (stage.stageWidth - textBox.width)/2;
                    textBox.y = (stage.stageHeight - textBox.height)/2 +170;
                    battleMenuTimer.reset();
                    battleMenuTimer.start();
                    
                }
        
        //スキルポイント更新用
        private function skillUp(event:Event):void{
             textBox.text = "スキルポイントが" + String(skillPointUp) + "あがった!";
             skillBox.text = "Sp" + String(skillPoint);
             textBox.x = (stage.stageWidth - textBox.width)/2;
             textBox.y = (stage.stageHeight - textBox.height)/2 +170;
             battleMenuTimer.reset();
             battleMenuTimer.start();
        }
        
        //バトルメニューに戻る
        private function battleMenu(event:Event):void{
            attackButton.visible = true;
            skillButton.visible = true;
            textBox.visible = false;
            chainButton.visible = false;
            spSkill.visible = false;
            rashTimer.stop();
            attackButton3.y = Math.random()*(stage.stageHeight - attackButton3.height - 120);
            attackButton3.x = Math.random()*(stage.stageWidth - attackButton3.width);
            //criticalTimer(Math.random()*3000,1);
        }
        
        //ラッシュ
        private function rash(event:Event):void{
            battleMenuTimer.reset();
            battleMenuTimer.start();
            if(skillPoint >= 3){
            if (rashTimer.currentCount == 3 && skillPoint >= 5){
                spSkill.visible = true;
            }else{
             chainButton.visible = true;
            }
          }
        }
    }
}






import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;

// HP表示
class HpView extends Sprite
{
    private var _text:TextField;
    private var _hpMax:int;

    function HpView(hp:int, hpMax:int)
    {
        _hpMax=hpMax;
        
        _text=new TextField();
        var format:TextFormat=new TextFormat();
        _text.autoSize = TextFieldAutoSize.LEFT;
        _text.defaultTextFormat=format;
        addChild(_text);

        update(hp);
    }
    
    // HP表示を更新する
    public function update(hp:int):void
    {
        _text.text="HP : " + String(hp) + "/" + _hpMax;
    }
}