モードの状態偏移処理

 heap.ioで、どこまでモード処理のプログラムをしょぼく作れるのか作ってみた(仮組状態)。それぞれのゲームモード処理にはデータなどの前処理、後処理ステートを置くのが前提


------[hoge.Loop.hx]------

class Loop {

  static var mode: String;

  static var state: String;

  public static function nextState (str: String) {

    //trace(str);

    state = str;

  }

  public static function changeMode (str: String) { 

    nextState("start");

    mode = str;

  }

/*  public static function getMode (str: String): String {

     return mode;

  } 

  public static function getState (str: String): String { 

     return state; 

   } 

*/

   public static function loop() { 

     switch (mode){ 

      case "Title": 

        ModeTitle.exec(state);

    }

  }



------[ModeTitle.hx]-------

package mode.title; 

import hoge.*;

class ModeTitle { 

  // Loop systems.

  public static function exec(state: String) { 

    switch(state) {

      case "start": start();

      case "loop": 

      default:

    }

  }

  static function nextState(state: String) {

    hoge.Loop.nextState(state); 

   }

  // Game. 

  static function start() { 

     var tf = new h2d.Text(hxd.res.DefaultFont.get(), pdb.Grap.parent);

    tf.text = "update Hashlink !"; 

    nextState("loop"); 

   }


------[Main.hx]------

override function init() { 

  // Loop seting. 

  hoge.Loop.changeMode("Title"); 

 override function update(dt:Float) { 

  super.update(dt);

  hoge.Loop.loop(); 


kubohisaの『ゲームプログラミングが判らない』

0コメント

  • 1000 / 1000