よくわかんないけど最近つくってるゲームで RxJava つかってみてる

よくわかんないけど最近つくってるゲームで RxJava つかってみてる

社内RxJava勉強会で発表した時の資料です。

0e463e4432ba6d9b7ef02dbebe99c70d?s=128

Tomohiro Moro

March 18, 2015
Tweet

Transcript

  1. 5.
  2. 9.

    ೖྗΠϕϯτ • touchDown -> δϟϯϓ४උ • tap -> δϟϯϓ •

    fling -> ࠨӈҠಈ • panStop -> δϟϯϓΩϟϯηϧ
  3. 13.

    // Input PublishSubject<GameMaster.Action> subject = PublishSubject.create(); ! @Override public boolean

    touchDown(float x, float y, int pointer, int button) { subject.onNext(GameMaster.Action.CHARACTER_PREPARE_JUM return false; } ! @Override public boolean tap(float x, float y, int count, int button) { subject.onNext(GameMaster.Action.CHARACTER_JUMP); return false; } ! … ! public Observable<GameMaster.Action> getActions() {return subject;}
  4. 14.

    // GameMaster public enum Action { CHARACTER_MOVE_LEFT, CHARACTER_MOVE_RIG ! public

    GameMaster(Observable<Action> input) { this.input = input; this.character = new Character(input); … ! // Character public enum Action { MOVE_LEFT, MOVE_RIGHT, JUMP, … } public Character(Observable<GameMaster.Action> input) { this.input = input; } ! public Observable<Action> getActions() { return input.map(new ActionConverter()); } !
  5. 15.

    // Character private class ActionConverter implements Func1<GameMaster.Action, Action> { !

    @Override public Action call(GameMaster.Action action) { Action result = null; switch (action) { case CHARACTER_MOVE_LEFT: result = Action.MOVE_LEFT; break; case CHARACTER_MOVE_RIGHT: result = Action.MOVE_RIGHT; break; case CHARACTER_PREPARE_JUMP: result = Action.PREPARE_JUMP; break; … } return result; }
  6. 17.

    Model Instance • LibGDX (3D) Ͱඳը͢ΔϞσϧΛ දݱ͢ΔΫϥε • xyz࠲ඪ ճస

    εέʔϧ ͳͲΛࢦఆ͢Δ • ύϥϝʔλΛม͑ΔΞχϝʔγϣϯΛ࣮ߦ͢Δ
  7. 18.

    ҠಈͱΞχϝʔγϣϯ • δϟϯϓ४උ -> ্͔Βԡ͞ΕͨΑ͏ʹͭͿΕΔ • δϟϯϓ -> ͭͿΕΛ໭্ͭͭ͠ԼҠಈ •

    ࠨӈҠಈ -> ࠨӈʹඳըҐஔΛҠಈ • δϟϯϓΩϟϯηϧ -> ͭͿΕΛ໭͢
  8. 20.

    // CharacterModelInstance public CharacterModelInstance(Model model, Character character) { super(model); …

    character.getActions().subscribe(new Action1<Character.Action>() { @Override public void call(Character.Action action) { switch (action) { case MOVE_LEFT: transform.translate(GroundBlockModel.SIZE, 0.0f, 0.0f); break; case MOVE_RIGHT: transform.translate(-GroundBlockModel.SIZE, 0.0f, 0.0f); break; case PREPARE_JUMP: animationController.animate("shrink", 0.0f); break; …
  9. 21.
  10. 24.

    // CameraMan public CameraMan(final OrthographicCamera camera, Character character) { this.camera

    = camera; this.character = character; character.getActions().subscribe(new Action1<Character.Action>() { @Override public void call(Character.Action action) { switch (action) { case MOVE_LEFT: Tween.to(camera, CameraTween.POSITION_X, cameraMoveDuration) .targetRelative(-GroundBlockModel.SIZE) .ease(TweenEquations.easeOutExpo) .start(tweenManager); break; …
  11. 28.

    0.12 0.32 0.14 0.21 update update update update 0.12 0.44

    0.58 0.79 Observable<Float> timeline = updates.scan((t1, t2) -> return t1 + t2);
  12. 29.

    // GameMaster private PublishSubject<Action> actions = PublishSubject.create(); public GameMaster(Observable<Action> input)

    { this.input = input; this.character = new Character(input); this.groundGenerator = new GroundGenerator(); this.groundLineEmitter = new GroundLineEmitter(timeline, GROUND_LINE_SPAWN_INTERVAL); actions .mergeWith(input) .mergeWith(groundLineEmitter.getEmits()) .subscribe(new ActionProcessor());
  13. 31.

    Ground Generator Ground Ground Layouter Ground Line #MPDL #MPDL #MPDL

    #MPDL *OTUBODF #MPDL *OTUBODF #MPDL *OTUBODF getNewLines() putLine(line) Layout next()
  14. 32.