Last active
May 9, 2021 09:36
-
-
Save cacao-soft/5467a3aa3645184ab360d6f0ede8f0db to your computer and use it in GitHub Desktop.
歩行グラフィックの待機アニメーション
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 歩行グラフィックの待機アニメーション | |
module CAO end; module CAO::WChara | |
# 開始までのフレーム数 | |
# このフレーム経過ごとにランダムで隊列の1キャラが待機アニメ | |
# イベント実行時はプレイヤーのみ待機アニメ解除 | |
START_TIME = 180 | |
# 1コマのフレーム数 | |
# このフレーム経過後に次のコマへ | |
# ずっとループする | |
FRAME_SPEED = 16 | |
# アクター ID 毎のファイル名 | |
# Graphics/Characters フォルダ | |
# 幅と高さが同じコマ横並び | |
FILENAMES = { | |
1 => ["a", "b"], | |
2 => ["a", "b"], | |
3 => ["c",], | |
} | |
end | |
class Game_Character | |
#-------------------------------------------------------------------------- | |
# ● getter | |
#-------------------------------------------------------------------------- | |
def start_stop_count | |
@start_stop_count ||= 0 | |
end | |
#-------------------------------------------------------------------------- | |
# ● | |
#-------------------------------------------------------------------------- | |
def mem_stop_count | |
@start_stop_count = @stop_count | |
end | |
#-------------------------------------------------------------------------- | |
# ● | |
#-------------------------------------------------------------------------- | |
def reset_stop_count | |
@start_stop_count = 0 | |
end | |
end | |
class Game_Player < Game_Character | |
#-------------------------------------------------------------------------- | |
# ◎ 歩行/足踏みアニメの更新 | |
#-------------------------------------------------------------------------- | |
def update_animation | |
super | |
return unless normal_walk? | |
if stopping? | |
start_waiting_anime if waiting? | |
elsif @waiting_characters | |
actor.reset_waiting_name | |
@followers.each {|c| c.actor && c.actor.reset_waiting_name } | |
@waiting_characters = nil | |
end | |
end | |
#-------------------------------------------------------------------------- | |
# ● | |
#-------------------------------------------------------------------------- | |
def waiting? | |
return false if @stop_count == 0 | |
return false if @stop_count % CAO::WChara::START_TIME != 0 | |
return true | |
end | |
#-------------------------------------------------------------------------- | |
# ● | |
#-------------------------------------------------------------------------- | |
def start_waiting_anime | |
make_waiting_characters unless @waiting_characters | |
chara = @waiting_characters.pop | |
if chara | |
chara.actor.set_waiting_name | |
chara.mem_stop_count | |
end | |
end | |
#-------------------------------------------------------------------------- | |
# ○ 決定ボタンによるイベント起動判定 | |
#-------------------------------------------------------------------------- | |
alias _cao_waiting_check_action_event check_action_event | |
def check_action_event | |
_cao_waiting_check_action_event.tap do | |
# プライヤーの待機アニメを中止し、アニメ中だったなら次回再開 | |
self.actor.reset_waiting_name | |
if @waiting_characters | |
@waiting_characters << self unless @waiting_characters.include?(self) | |
end | |
end | |
end | |
#-------------------------------------------------------------------------- | |
# ● | |
#-------------------------------------------------------------------------- | |
def make_waiting_characters | |
@waiting_characters = [] | |
if self.actor | |
[self, *@followers.visible_folloers].each do |chara| | |
next if chara.character_name.empty? | |
next unless CAO::WChara::FILENAMES[chara.actor.id] | |
@waiting_characters << chara | |
end | |
@waiting_characters.shuffle! | |
end | |
end | |
#-------------------------------------------------------------------------- | |
# ◎ 停止時の更新 | |
#-------------------------------------------------------------------------- | |
def update_stop | |
super unless $game_map.interpreter.running? | |
end | |
#-------------------------------------------------------------------------- | |
# ● | |
#-------------------------------------------------------------------------- | |
def waiting_name | |
actor.waiting_name | |
end | |
end | |
class Game_Follower < Game_Character | |
#-------------------------------------------------------------------------- | |
# ● | |
#-------------------------------------------------------------------------- | |
def waiting_name | |
visible? ? actor.waiting_name : nil | |
end | |
end | |
class Game_Actor < Game_Battler | |
#-------------------------------------------------------------------------- | |
# ● 公開インスタンス変数 | |
#-------------------------------------------------------------------------- | |
attr_reader :waiting_name # 歩行グラフィック ファイル名 | |
#-------------------------------------------------------------------------- | |
# ● | |
#-------------------------------------------------------------------------- | |
def set_waiting_name | |
fn = CAO::WChara::FILENAMES[id] | |
@waiting_name = fn && fn.sample | |
end | |
#-------------------------------------------------------------------------- | |
# ● | |
#-------------------------------------------------------------------------- | |
def reset_waiting_name | |
@waiting_name = nil | |
end | |
end | |
module SpriteWaitable | |
#-------------------------------------------------------------------------- | |
# ◎ 転送元ビットマップの更新 | |
#-------------------------------------------------------------------------- | |
def update_bitmap | |
return unless graphic_changed? | |
@tile_id = @character.tile_id | |
@character_name = @character.character_name | |
@character_index = @character.character_index | |
@waiting_name = @character.waiting_name | |
if @waiting_name | |
set_waiting_bitmap | |
elsif @tile_id > 0 | |
set_tile_bitmap | |
else | |
set_character_bitmap | |
end | |
end | |
#-------------------------------------------------------------------------- | |
# ◎ グラフィックの変更判定 | |
#-------------------------------------------------------------------------- | |
def graphic_changed? | |
return true if @tile_id != @character.tile_id | |
return true if @character_name != @character.character_name | |
return true if @character_index != @character.character_index | |
return true if @waiting_name != @character.waiting_name | |
return false | |
end | |
#-------------------------------------------------------------------------- | |
# ● キャラクターのビットマップを設定 | |
#-------------------------------------------------------------------------- | |
def set_waiting_bitmap | |
self.bitmap = Cache.character(@waiting_name) | |
@ch = bitmap.height | |
@cw = @ch | |
@cf = bitmap.width / @ch | |
self.ox = @cw / 2 | |
self.oy = @ch | |
end | |
#-------------------------------------------------------------------------- | |
# ○ 転送元矩形の更新 | |
#-------------------------------------------------------------------------- | |
def update_src_rect | |
if @waiting_name | |
cnt = @character.instance_variable_get(:@stop_count) | |
cnt -= @character.start_stop_count | |
pattern = cnt / CAO::WChara::FRAME_SPEED % @cf | |
self.src_rect.set(@cw * pattern, 0, @cw, @ch) | |
else | |
super | |
@character.reset_stop_count | |
end | |
end | |
end | |
class Spriteset_Map | |
#-------------------------------------------------------------------------- | |
# ○ | |
#-------------------------------------------------------------------------- | |
alias _cao_waiting_create_characters create_characters | |
def create_characters | |
_cao_waiting_create_characters | |
@character_sprites.each do |sp| | |
sp.extend(SpriteWaitable) if sp.character.respond_to?(:waiting_name) | |
end | |
end | |
end |
- 待機アニメキャラの抽選時、設定のないアクターを除外するようにした
- グラフィックが設定されていないキャラをスキップするようにした
- 移動のたびに抽選を行なわないようにした(軽量化)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
指定時間、プレイヤーがマスを移動しなかった場合に隊列中からランダムに1キャラが待機アニメーションを開始する。
指定時間毎にアニメーションするキャラは増えていく。
決定キーによるイベント実行時、プレイヤーの待機アニメーションを解除する。
1キャラに複数のアニメーションを設定でき、ランダムに選ばれる。
アニメーションは、最後まで行くと最初に戻り繰り返される。
アニメーション画像は、1コマのサイズが縦横同じでなければならない。
アニメコマは、横一列にいくつでも繋げて1つの画像として保存する。