Help us understand the problem. What is going on with this article?

Rust + Entity Component System で仕様変更に強いゲーム設計 その4ー3〜 アニメーションを動かす

その1
https://qiita.com/mas-yo/items/e7d1e247e5d4a9f47e92
その2
https://qiita.com/mas-yo/items/207244f04dd442cb567c
その3−1
https://qiita.com/mas-yo/items/e1f89bea5f84b7041462
その3−2
https://qiita.com/mas-yo/items/ca97fe6ed961d77be715
その3−3
https://qiita.com/mas-yo/items/9f0459dd942a874c6273
その4−1
https://qiita.com/mas-yo/items/daae411935d138d85c95
その4−2
https://qiita.com/mas-yo/items/678d775e4caf5e14abe7

アニメーションを動かそう

前回は、アニメーションを動かす仕組みを実装しましたので、今回はアニメーションを実際に動かしたいと思います。

実は当初、アニメーションを動かすための、ステートマシンを導入しようとして、実際に実装までやったのですが、今の段階でステートマシンを導入しても、後でいろんな要件が出てきたときに、単純な状態遷移だけでは管理しきれなくなりそうだな、と思ってやめました。

https://github.com/mas-yo/rust-ecs-game/tree/fd15d1d97463d9b5ec00f379c4cb26f7820dfeb3

こちらが、そのステートマシンを導入した状態のソースです。
興味のある方は、見てみてください。
最新コミットでは、ステートマシンの仕組みは削除されています。

ということで今回は単純に

  • スペースキーが押されたら、攻撃アニメーション
  • 攻撃アニメーションが終わったら、待機アニメーション再生(ループ)

だけを実装します。

Animatorを更新するシステムの実装を、下記の様に書き換えます。
(前回まででは、単に update() を呼ぶだけでした)

impl SystemProcess for System<CContainer<CharacterAnimator>, CContainer<Input>>
{
    fn process(animators: &mut Self::Update, inputs: &Self::Refer) {
        animators.iter_mut().zip_entity(inputs).for_each(|(a, i)| {
            if let Some(id) = a.playing_id() {
                if id == CharacterAnimID::Attack && a.is_end() {
                    a.play(CharacterAnimID::Wait);
                }
            }
            if i.attack {
                a.play(CharacterAnimID::Attack);
            }
            a.update()
        });
    }
}

inputの状態を見て、attack (スペースキー)だったら、攻撃アニメを再生、攻撃アニメが終了していたら、待機アニメを再生、としています。

これで、なんか戦えそうな感じになりました。

次は、攻撃の当たり判定を実装してみようと思います。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Loading comments.
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした