Code:
#==============================================================================
# Simple Flashlight 1.0.1
#------------------------------------------------------------------------------
# Credit: XthemeCore
#==============================================================================
$Flashlight_Switch = 1 # ต้องมีค่ามากกว่า 0
$Flashlight_Picture_Id = 1 # ต้องมีค่าระหว่าง 1 - 50
$Flashlight_Picture = "Lantern"
$Flashlight_Key = Input::X
$Flashlight_Darkness = 128
#==============================================================================
# **Game_Picture
#------------------------------------------------------------------------------
# เขียนทับตัวแปร angle ใน Game_Picture เพื่อให้สามารถเข้าถึงค่าองศาของรูปได้
#==============================================================================
class Game_Picture
attr_accessor :angle # องศาของรูปภาพ
end
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
# เขียนทับ Update เพื่อตรวจสอบการกดปุ่มเปิดไฟฉาย
#==============================================================================
class Scene_Map
alias overwrite_update update
def update
overwrite_update
flashlight_update
end
#--------------------------------------------------------------------------
# อัพเดตระบบไฟฉาย
#--------------------------------------------------------------------------
def flashlight_update
if $game_switches[$Flashlight_Switch] == true
if $flashlight_spark == nil
$game_screen.start_tone_change(Tone.new(-$Flashlight_Darkness, -$Flashlight_Darkness, -$Flashlight_Darkness,0), 2)
$flashlight_spark = false
end
if Input.trigger?($Flashlight_Key)
if $flashlight_spark == false
$game_screen.start_tone_change(Tone.new(0,0,0,0), 0)
$game_screen.pictures[$Flashlight_Picture_Id].show($Flashlight_Picture, 1, $game_player.screen_x, $game_player.screen_y, 100, 100, $Flashlight_Darkness, 2)
flashlight_direction_update
$flashlight_spark = true
else
$game_screen.start_tone_change(Tone.new(-$Flashlight_Darkness, -$Flashlight_Darkness, -$Flashlight_Darkness,0), 2)
$flashlight_spark = false
$game_screen.pictures[$Flashlight_Picture_Id].move(2, 1, $game_player.screen_x, $game_player.screen_y, 100, 100, 0, 2)
flashlight_direction_update
end
elsif $flashlight_spark == true
$game_screen.pictures[$Flashlight_Picture_Id].move(2, 1, $game_player.screen_x, $game_player.screen_y, 100, 100, $Flashlight_Darkness, 2)
flashlight_direction_update
end
end
end
#--------------------------------------------------------------------------
# อัพเดตทิศทางไฟฉาย
#--------------------------------------------------------------------------
def flashlight_direction_update
case $game_player.direction
when 2
$game_screen.pictures[$Flashlight_Picture_Id].angle = 0
when 4
$game_screen.pictures[$Flashlight_Picture_Id].angle = 270
when 6
$game_screen.pictures[$Flashlight_Picture_Id].angle = 90
when 8
$game_screen.pictures[$Flashlight_Picture_Id].angle = 180
end
end
end