#==============================================================================
# ★ Skrypt RPGVXAce (RGSS3) - prosty system czasu ★
#==============================================================================
=begin
Autor: tomoaky
Strona internetowa: (http://hikimoki.sakura.ne.jp/)
Skrypt pokazuje czas i dynamicznie zmienia zabarwienie mapy.
* Gdy przełącznik CLOCK_HIDDEN (domyślnie 16) jest włączony, zegar zostaje
schowany.
* Gdy przełącznik CLOCK_STOP (domyślnie 17) jest włączony, czas zostaje
zatrzymany.
* W zmiennych VN_TIME_H i VN_TIME_M (domyślnie: 10, 11) przechowywany jest
czas, który minął od godziny początkowej.
* Nie zmieniaj godziny za pomocą zmiennych! Do tego służy komenda Skrypt:
set_time(h, m)
Zmienia ona aktualną godzinę i minutę.
Przykład: set_time(15, 30) - zmienia na 15:30.
* Pisząc w nazwie mapy <wnetrze> nie zmieniają się zabarwienie mapy i można
spokojnie zmienić na swoje wartości.
* Do skryptu są potrzebne grafiki w folderze /Graphics/System:
- minute_hand
- hour_hand
=end
#==============================================================================
# □ 設定項目
#==============================================================================
module TMTIMEC
TIME_START = 7 # Czas po rozpoczęciu gry
TIME_RATE = 60 # In-game time magnification (reality: 60)
TIME_SPEED = 100 # Im większe, tym szybciej mija czas
TONE_DURATION = 300 # Szybkość zabarwiania ekranu
SW_CLOCK_HIDDEN = 16 # Przełącznik chowający zegarek
SW_CLOCK_STOP = 17 # Przełącznik stopujący zegarek
VN_TIME_H = 10 # Zmienna przetrzymująca aktualnie godzinę
VN_TIME_M = 11 # /-/ aktualnie minutę
CLOCK_X = Graphics.width - 64 - 8 #Położenie X zegara
CLOCK_Y = 8 # Położenie Y zegara
# Czcionki zegara, po przecinku, w cudzysłowach ("").
CLOCK_FONT_NAME = ["Arial Black", "VL Gothic"]
end
#==============================================================================
# □ コマンド
#==============================================================================
module TMTIMEC
module Commands
#--------------------------------------------------------------------------
# ○ 時間の強制変更
#--------------------------------------------------------------------------
def set_time(h = TIME_START, m = 0)
$game_map.set_time(h, m)
end
end
end # module TMTIMEC
#==============================================================================
# ■ Game_Map
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# ● 公開インスタンス変数
#--------------------------------------------------------------------------
attr_reader :day_time # 時刻
#--------------------------------------------------------------------------
# ● オブジェクト初期化
#--------------------------------------------------------------------------
alias tmtimec_game_map_initialize initialize
def initialize
tmtimec_game_map_initialize
init_time
end
#--------------------------------------------------------------------------
# ○ 時刻の初期化
#--------------------------------------------------------------------------
def init_time
@day_time = TMTIMEC::TIME_START * 3600 * TMTIMEC::TIME_RATE
end
#--------------------------------------------------------------------------
# ● セットアップ
#--------------------------------------------------------------------------
alias tmtimec_game_map_setup setup
def setup(map_id)
tmtimec_game_map_setup(map_id)
refresh_time(0)
end
#--------------------------------------------------------------------------
# ○ 指定した時間に変更する
#--------------------------------------------------------------------------
def set_time(h = TMTIMEC::START_TIME, m = 0)
@day_time = [[h, 0].max, 23].min * 3600 * TMTIMEC::TIME_RATE
@day_time += [[h, 0].max, 59].min * 60 * TMTIMEC::TIME_RATE
refresh_time(0)
end
#--------------------------------------------------------------------------
# ○ Zmiana zabarwienia wraz z czasem
#--------------------------------------------------------------------------
def refresh_time(duration = TMTIMEC::TONE_DURATION)
return if /<wnetrze>/ =~ @map.note
case @day_time / (3600 * TMTIMEC::TIME_RATE)
when 0; @screen.start_tone_change(Tone.new(-68, -68, 0, 68), duration)
when 1; @screen.start_tone_change(Tone.new(-68, -68, 0, 68), duration)
when 2; @screen.start_tone_change(Tone.new(-68, -68, 0, 68), duration)
when 3; @screen.start_tone_change(Tone.new(-68, -68, 0, 68), duration)
when 4; @screen.start_tone_change(Tone.new(-68, -68, 0, 68), duration)
when 5; @screen.start_tone_change(Tone.new(-68, -68, 0, 68), duration)
when 6; @screen.start_tone_change(Tone.new(-17, 0, 17, 17), duration)
when 7; @screen.start_tone_change(Tone.new(-17, 0, 17, 17), duration)
when 8; @screen.start_tone_change(Tone.new(-17, 0, 17, 17), duration)
when 9; @screen.start_tone_change(Tone.new(0, 0, 0, 0), duration)
when 10; @screen.start_tone_change(Tone.new(0, 0, 0, 0), duration)
when 11; @screen.start_tone_change(Tone.new(0, 0, 0, 0), duration)
when 12; @screen.start_tone_change(Tone.new(0, 0, 0, 0), duration)
when 13; @screen.start_tone_change(Tone.new(0, 0, 0, 0), duration)
when 14; @screen.start_tone_change(Tone.new(0, 0, 0, 0), duration)
when 15; @screen.start_tone_change(Tone.new(17, -34, -34, 0), duration)
when 16; @screen.start_tone_change(Tone.new(17, -34, -34, 0), duration)
when 17; @screen.start_tone_change(Tone.new(17, -34, -34, 0), duration)
when 18; @screen.start_tone_change(Tone.new(-68, -68, 0, 68), duration)
when 19; @screen.start_tone_change(Tone.new(-68, -68, 0, 68), duration)
when 20; @screen.start_tone_change(Tone.new(-68, -68, 0, 68), duration)
when 21; @screen.start_tone_change(Tone.new(-68, -68, 0, 68), duration)
when 22; @screen.start_tone_change(Tone.new(-68, -68, 0, 68), duration)
when 23; @screen.start_tone_change(Tone.new(-68, -68, 0, 68), duration)
end
end
#--------------------------------------------------------------------------
# ● フレーム更新
# main : インタプリタ更新フラグ
#--------------------------------------------------------------------------
alias tmtimec_game_map_update update
def update(main = false)
update_time
tmtimec_game_map_update(main)
end
#--------------------------------------------------------------------------
# ○ 時刻の更新
#--------------------------------------------------------------------------
def update_time
return if $game_switches[TMTIMEC::SW_CLOCK_STOP]
last_time = @day_time / (3600 * TMTIMEC::TIME_RATE)
@day_time += TMTIMEC::TIME_SPEED
h = (@day_time / (3600 * TMTIMEC::TIME_RATE)) % 24
if last_time != h
@day_time = 0 if h == 0
$game_variables[TMTIMEC::VN_TIME_H] = h
refresh_time
@need_refresh = true
end
$game_variables[TMTIMEC::VN_TIME_M] = (@day_time / (60 * TMTIMEC::TIME_RATE)) % 60
end
end
#==============================================================================
# ■ Game_Event
#==============================================================================
class Game_Event
include TMTIMEC::Commands
end
#==============================================================================
# ■ Game_Interpreter
#==============================================================================
class Game_Interpreter
include TMTIMEC::Commands
end
#==============================================================================
# ■ Sprite_Clock
#==============================================================================
class Sprite_Clock < Sprite
#--------------------------------------------------------------------------
# ● オブジェクト初期化
#--------------------------------------------------------------------------
def initialize(viewport = nil)
super(viewport)
self.bitmap = Bitmap.new(64, 64)
self.bitmap.font.size = 12
self.bitmap.font.name = TMTIMEC::CLOCK_FONT_NAME
self.x = TMTIMEC::CLOCK_X
self.y = TMTIMEC::CLOCK_Y
self.z = 210
create_hour_hand
create_minute_hand
refresh
end
#--------------------------------------------------------------------------
# ● 表示フラグの設定
#--------------------------------------------------------------------------
def visible=(visible)
super
@hour_hand.visible = self.visible if @hour_hand
@minute_hand.visible = self.visible if @minute_hand
end
#--------------------------------------------------------------------------
# ● 短針の作成
#--------------------------------------------------------------------------
def create_hour_hand
@hour_hand = Sprite.new
@hour_hand.bitmap = Cache.system("hour_hand")
@hour_hand.ox = 19
@hour_hand.oy = 32
@hour_hand.x = self.x + 32
@hour_hand.y = self.y + 32
@hour_hand.z = self.z + 1
end
#--------------------------------------------------------------------------
# ● 長身の作成
#--------------------------------------------------------------------------
def create_minute_hand
@minute_hand = Sprite.new
@minute_hand.bitmap = Cache.system("minute_hand")
@minute_hand.ox = 19
@minute_hand.oy = 32
@minute_hand.x = self.x + 32
@minute_hand.y = self.y + 32
@minute_hand.z = self.z + 2
end
#--------------------------------------------------------------------------
# ● 解放
#--------------------------------------------------------------------------
def dispose
@hour_hand.dispose
@minute_hand.dispose
self.bitmap.dispose
super
end
#--------------------------------------------------------------------------
# ● リフレッシュ
#--------------------------------------------------------------------------
def refresh
self.bitmap.clear
pi = Math::PI * 3
(1..12).each do |i|
x = 32 + (Math.sin(pi - Math::PI * 2 * i / 12) * 26).to_i - 12
y = 32 + (Math.cos(pi - Math::PI * 2 * i / 12) * 26).to_i - 6
self.bitmap.draw_text(x, y, 24, 12, i, 1)
end
end
#--------------------------------------------------------------------------
# ● フレーム更新
#--------------------------------------------------------------------------
def update
self.visible = !$game_switches[TMTIMEC::SW_CLOCK_HIDDEN]
@hour_hand.visible = self.visible if @hour_hand
@minute_hand.visible = self.visible if @minute_hand
super
time = $game_map.day_time / 60 / TMTIMEC::TIME_RATE
@minute_hand.angle = 360 - time % 60 * 360 / 60
@hour_hand.angle = 360 - time % 720 * 360 / 720
end
end
#==============================================================================
# ■ Spriteset_Map
#==============================================================================
class Spriteset_Map
#--------------------------------------------------------------------------
# ● オブジェクト初期化
#--------------------------------------------------------------------------
alias tmtimec_spriteset_map_initialize initialize
def initialize
tmtimec_spriteset_map_initialize
create_clock
update_clock
end
#--------------------------------------------------------------------------
# ○ 時計スプライトの作成
#--------------------------------------------------------------------------
def create_clock
@clock_sprite = Sprite_Clock.new(@viewport2)
end
#--------------------------------------------------------------------------
# ● 解放
#--------------------------------------------------------------------------
alias tmtimec_spriteset_map_dispose dispose
def dispose
dispose_clock
tmtimec_spriteset_map_dispose
end
#--------------------------------------------------------------------------
# ○ 時計スプライトの解放
#--------------------------------------------------------------------------
def dispose_clock
@clock_sprite.dispose
end
#--------------------------------------------------------------------------
# ● フレーム更新
#--------------------------------------------------------------------------
alias tmtimec_spriteset_map_update update
def update
update_clock
tmtimec_spriteset_map_update
end
#--------------------------------------------------------------------------
# ○ 時計スプライトの更新
#--------------------------------------------------------------------------
def update_clock
@clock_sprite.update if @clock_sprite
end
end