Sie sind auf Seite 1von 13

features:

adds a light effect to light emitting objects… so now using deke’s day
night script you can have a fire that glows at night… real street lights
even with ground effect lighting…

the script:

code
#=======================================#
# ■ class game_title
#
# written by deke
# rewiten by near fantastica
# 16.02.05
#---------------------------------------------------------------------------
---#
#=======================================#
class game_time

attr_accessor :minute_length

def initialize
@minute_length=2.0 #length of game minute in real seconds
@hour_length= 60.0 #minute in an hour
@day_length=24.0 #hours in a day
@month_length=30.0 #days in a month
@year_length=12.0 #months in a year
@minutes=0 #starting minute count
start_minute=56
add_minutes(start_minute)
start_hour=23 #starting hour count
add_hours(start_hour)
start_day=5 #starting day count
add_days(start_day)
start_month=1 #starting month count
add_months(start_month-1)
start_year=129 #starting year count
add_years(start_year)
end

def add_minutes(minutes)
@minutes +=minutes
end

def add_hours(hours)
@minutes +=hours*@hour_length
end

def add_days(days)
@minutes += days*@hour_length*@day_length
end

def add_months(months)
@minutes +=months * @hour_length*@day_length*@month_length
end
def add_years(years)
@minutes += years * @hour_length*@day_length*@month_length * @year_length
end

def get_year
minutes=get_total_minutes
year=minutes / @hour_length / @day_length / @month_length /
@year_length
return year
end

def get_month
minutes=get_total_minutes
month=minutes / @hour_length / @day_length / @month_length %
@year_length + 1
return month
end

def get_day
minutes=get_total_minutes
day=minutes / @hour_length / @day_length % @month_length
return day
end

def get_hour
minutes=get_total_minutes
hour=minutes / @hour_length % @day_length
return hour
end

def get_total_minutes
total_sec=graphics.frame_count / graphics.frame_rate
minute=(total_sec/@minute_length+@minutes)
return minute
end

def get_minute
minutes=get_total_minutes % @hour_length
return minutes
end

def get_tone
period_length=math::pi*(get_hour / @day_length)
red_shift= -100+ 115*math.sin(period_length)
green_shift= -140+ 155*math.sin(period_length)
blue_shift= -150+ 165*math.sin(period_length)
return tone.new(red_shift, green_shift, blue_shift, 0)
end

end # of class game_time

#=======================================#
# ■ class window_time
#
# written by deke
#
#---------------------------------------------------------------------------
---#
#=======================================#
class window_time < window_base

#--------------------------------------------------------------------------
def initialize
super(0, 0, 160, 96)
self.contents = bitmap.new(width - 32, height - 32)
self.contents.font.name = $defaultfonttype # "time" window font
self.contents.font.size = $defaultfontsize
refresh
end

#--------------------------------------------------------------------------
def refresh
self.contents.clear
@total_sec = graphics.frame_count / graphics.frame_rate
@minute=$game_time.get_minute.floor
hour = $game_time.get_hour
pm_flag= hour >=12 ? true : false
hour= hour >= 12 ? hour-12 : hour
day=$game_time.get_day
month=$game_time.get_month
year=$game_time.get_year
if hour.floor==0
text=sprintf("%02d:%02d",12,@minute)
else
text=sprintf("%02d:%02d",hour,@minute)
end
if pm_flag
text += " pm"
else
text += " am"
end
self.contents.font.color = normal_color
self.contents.draw_text(4, 0, 120, 32, text, 2)
text = sprintf("%02d-%02d-%02d", month, day, year)
self.contents.font.color=system_color
self.contents.draw_text(4,32,120,32,text)
end

#--------------------------------------------------------------------------
def update
if $game_time.get_minute.floor != @minute
refresh
end
end
end # of class

#=======================================
class game_temp

#--------------------------------------------------------------------------
# ● refer setup to game temp

#--------------------------------------------------------------------------
alias dns_game_temp_initalize initialize

#--------------------------------------------------------------------------
# ● refer the attr

#--------------------------------------------------------------------------
attr_reader :map_infos #added lines
attr_reader :outside_array #added lines

#--------------------------------------------------------------------------
# ● refer setup to scene map

#--------------------------------------------------------------------------
def initialize
dns_game_temp_initalize
@outside_array = array.new
@map_infos = load_data("data/mapinfos.rxdata")
for key in @map_infos.keys
@outside_array[key] = @map_infos[key].name.include?("*")
end
end
end

#=======================================
class scene_map

#--------------------------------------------------------------------------
# ● refer setup to scene map

#--------------------------------------------------------------------------
alias dns_scene_map_main main
alias dns_scene_map_update update

#--------------------------------------------------------------------------
# ● main

#--------------------------------------------------------------------------
def main
if $game_temp.outside_array[$game_map.map_id]
tone=$game_time.get_tone
@minute=$game_time.get_minute.floor
$game_screen.start_tone_change(tone, 0)
end
# スプライトセットを作成
@spriteset = spriteset_map.new
# メッセージウィンドウを作成
@message_window = window_message.new
# トランジション実行
graphics.transition
# メインループ
loop do
$light_effects.refresh
# ゲーム画面を更新
graphics.update
# 入力情報を更新
input.update
# フレーム更新
update
# 画面が切り替わったらループを中断
if $scene != self
break
end
end
# トランジション準備
graphics.freeze
# スプライトセットを解放
@spriteset.dispose
# メッセージウィンドウを解放
@message_window.dispose
# タイトル画面に切り替え中の場合
if $scene.is_a?(scene_title)
# 画面をフェードアウト
graphics.transition
graphics.freeze
end
$light_effects.hide
end

#--------------------------------------------------------------------------
# ● update

#--------------------------------------------------------------------------
def update
$light_effects.update
conditional1 =$game_temp.outside_array[$game_map.map_id] and
$game_time.get_minute.floor != @minute
conditional2 =$game_temp.outside_array[$game_map.map_id] and
@current_id != $game_map.map_id
if conditional1 or conditional2
tone=$game_time.get_tone
$game_screen.start_tone_change(tone, 0)
@minute = $game_time.get_minute.floor
$game_map.need_refresh=true
@current_id=$game_map.map_id
end
if $game_temp.outside_array[$game_map.map_id] == false and @current_id
!= $game_map.map_id
$game_screen.start_tone_change(tone.new(0,0,0,0),0)
@current_id=$game_map.map_id
end
dns_scene_map_update
end
end

#======================================================
class scene_title
#--------------------------------------------------------------------------
# ● refer setup to scene map

#--------------------------------------------------------------------------
alias dns_scene_title_update update

#--------------------------------------------------------------------------
# ● refer setup to scene map

#--------------------------------------------------------------------------
def update
$game_time=game_time.new
#dubealex addition (from xrxs) to show map name on screen
dns_scene_title_update
end
end

#========================================================
class scene_load
def read_save_data(file)
characters = marshal.load(file)
graphics.frame_count = marshal.load(file)
$game_system = marshal.load(file)
$game_switches = marshal.load(file)
$game_variables = marshal.load(file)
$game_self_switches = marshal.load(file)
$game_screen = marshal.load(file)
$game_actors = marshal.load(file)
$game_party = marshal.load(file)
$game_troop = marshal.load(file)
$game_map = marshal.load(file)
$game_player = marshal.load(file)
$game_time =marshal.load(file) #added line
if $game_system.magic_number != $data_system.magic_number
$game_map.setup($game_map.map_id)
$game_player.center($game_player.x, $game_player.y)
end
$game_party.refresh
end
end # of scene_load updates

#=======================================================
class scene_save
def write_save_data(file)
characters = []
for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
characters.push([actor.character_name, actor.character_hue])
end
marshal.dump(characters, file)
marshal.dump(graphics.frame_count, file)
$game_system.save_count += 1
$game_system.magic_number = $data_system.magic_number
marshal.dump($game_system, file)
marshal.dump($game_switches, file)
marshal.dump($game_variables, file)
marshal.dump($game_self_switches, file)
marshal.dump($game_screen, file)
marshal.dump($game_actors, file)
marshal.dump($game_party, file)
marshal.dump($game_troop, file)
marshal.dump($game_map, file)
marshal.dump($game_player, file)
marshal.dump($game_time,file) # added line
end
end # of scene_save updates

#========================================================

class game_map

#--------------------------------------------------------------------------
# ● refer the attr

#--------------------------------------------------------------------------
attr_reader :outside
attr_reader :map_id

#--------------------------------------------------------------------------
# ● outside

#--------------------------------------------------------------------------
def outside
return $game_temp.outside_array[@map_id]
end
end

#===========================================================================
===
# ■ light effect system
#---------------------------------------------------------------------------
---
#  by: near fantastica
# date: 13/2/05
#
# addes light effects to the dns so objects glow and have ground effect
lighting...
#===========================================================================
===

class light_effect_system

#--------------------------------------------------------------------------
# ● refer the attr

#--------------------------------------------------------------------------
attr_accessor :picture_le
attr_accessor :event_list
attr_accessor :type_list

#--------------------------------------------------------------------------
# ● initialization

#--------------------------------------------------------------------------
def initialize
@event_counter = 0
@picture_le = array.new
@event_list = array.new
@type_list = array.new
end

#--------------------------------------------------------------------------
# ● setup light effects on map change

#--------------------------------------------------------------------------
def setup
# setup event max
@event_counter = 0
for i in 1..999
if $game_map.map.events[i].id > @event_counter
@event_counter = $game_map.map.events[i].id
end
end
#
for i in 1..@event_counter
if $game_map.map.events[i] == nil
next
end
case $game_map.map.events[i].name
when "ground"
ground(i)
when "fire"
fire(i)
when "lamp post"
lamp(i)
when "left lantern"
left_lantern(i)
when "right lantern"
right_lantern(i)
end
end
end

#--------------------------------------------------------------------------
# ● updates the array based on time of day

#--------------------------------------------------------------------------
def update
if $game_time.get_hour > 7 and $game_time.get_hour < 14
hide
else
show
end
end

#--------------------------------------------------------------------------
# ● updates the xy of the sprites

#--------------------------------------------------------------------------
def refresh
for i in 0..$light_effects.picture_le.size - 1
case $light_effects.type_list[i]
when "ground"
$light_effects.picture_le[i].x =
($game_map.events[$light_effects.event_list[i]].real_x - 200 -
$game_map.display_x) / 4
$light_effects.picture_le[i].y =
($game_map.events[$light_effects.event_list[i]].real_y - 200 -
$game_map.display_y) / 4
$light_effects.picture_le[i].visible = true
when "fire"
$light_effects.picture_le[i].x =
($game_map.events[$light_effects.event_list[i]].real_x - 300 -
$game_map.display_x) / 4
$light_effects.picture_le[i].y =
($game_map.events[$light_effects.event_list[i]].real_y - 300 -
$game_map.display_y) / 4
$light_effects.picture_le[i].visible = true
when "left lamp post"
$light_effects.picture_le[i].x = (-0.25 * $game_map.display_x) +
($game_map.events[$light_effects.event_list[i]].x * 32) - 5
$light_effects.picture_le[i].y = (-0.25 * $game_map.display_y) +
($game_map.events[$light_effects.event_list[i]].y * 32) - 15
when "right lamp post"
$light_effects.picture_le[i].x = (-0.25 * $game_map.display_x) +
($game_map.events[$light_effects.event_list[i]].x * 32) - 25
$light_effects.picture_le[i].y = (-0.25 * $game_map.display_y) +
($game_map.events[$light_effects.event_list[i]].y * 32) - 15
$light_effects.picture_le[i].visible = true
when "left lantern"
$light_effects.picture_le[i].x = (-0.25 * $game_map.display_x) +
($game_map.events[$light_effects.event_list[i]].x * 32) - 20
$light_effects.picture_le[i].y = (-0.25 * $game_map.display_y) +
($game_map.events[$light_effects.event_list[i]].y * 32) - 5
$light_effects.picture_le[i].visible = true
when "right lantern"
$light_effects.picture_le[i].x = (-0.25 * $game_map.display_x) +
($game_map.events[$light_effects.event_list[i]].x * 32) - 10
$light_effects.picture_le[i].y = (-0.25 * $game_map.display_y) +
($game_map.events[$light_effects.event_list[i]].y * 32) - 5
$light_effects.picture_le[i].visible = true
end
end
end

#--------------------------------------------------------------------------
# ● redraws the array

#--------------------------------------------------------------------------
def redraw
if @picture_le != []
for i in 0..@picture_le.size - 1
@picture_le[i].bitmap.dispose
end
@picture_le = array.new
@event_list = array.new
@type_list = array.new
end
end
#--------------------------------------------------------------------------
# ● shows array

#--------------------------------------------------------------------------
def show
if @picture_le != []
for i in 0..@picture_le.size - 1
@picture_le[i].visible = true
end
end
end

#--------------------------------------------------------------------------
# ● hides array

#--------------------------------------------------------------------------
def hide
if @picture_le != []
for i in 0..@picture_le.size - 1
@picture_le[i].visible = false
end
end
end

#--------------------------------------------------------------------------
# ● setup light effects for ground

#--------------------------------------------------------------------------
def ground(event_index)
light_effects = sprite.new
light_effects.bitmap = rpg::cache.picture("le.png")
light_effects.zoom_x = 200 / 100.0
light_effects.zoom_y = 200 / 100.0
light_effects.z = 1000
light_effects.opacity = 50
light_effects.visible = false
@picture_le.push(light_effects)
@event_list.push(event_index)
@type_list.push("ground")
end

#--------------------------------------------------------------------------
# ● setup light effects for fire

#--------------------------------------------------------------------------
def fire(event_index)
light_effects = sprite.new
light_effects.bitmap = rpg::cache.picture("le.png")
light_effects.zoom_x = 300 / 100.0
light_effects.zoom_y = 300 / 100.0
light_effects.z = 1000
light_effects.opacity = 100
light_effects.visible = false
@picture_le.push(light_effects)
@event_list.push(event_index)
@type_list.push("fire")
end
#--------------------------------------------------------------------------
# ● setup light effects for lamp

#--------------------------------------------------------------------------
def lamp(event_index)
light_effects = sprite.new
light_effects.bitmap = rpg::cache.picture("le.png")
light_effects.z = 1000
light_effects.opacity = 100
light_effects.visible = false
@picture_le.push(light_effects)
@event_list.push(event_index)
@type_list.push("left lamp post")
light_effects = sprite.new
light_effects.bitmap = rpg::cache.picture("le.png")
light_effects.z = 1000
light_effects.opacity = 100
light_effects.visible = false
@picture_le.push(light_effects)
@event_list.push(event_index)
@type_list.push("right lamp post")
end

#--------------------------------------------------------------------------
# ● setup light effects for lantern

#--------------------------------------------------------------------------
def left_lantern(event_index)
light_effects = sprite.new
light_effects.bitmap = rpg::cache.picture("le.png")
light_effects.z = 1000
light_effects.opacity = 150
light_effects.visible = false
@picture_le.push(light_effects)
@event_list.push(event_index)
@type_list.push("left lantern")
end

#--------------------------------------------------------------------------
# ● setup light effects for lantern

#--------------------------------------------------------------------------
def right_lantern(event_index)
light_effects = sprite.new
light_effects.bitmap = rpg::cache.picture("le.png")
light_effects.z = 1000
light_effects.opacity = 150
light_effects.visible = false
@picture_le.push(light_effects)
@event_list.push(event_index)
@type_list.push("right lantern")
end
end

#===========================================================================
===
# ■ game_map
#---------------------------------------------------------------------------
---
#  add defenision of the names to game map class
#===========================================================================
===

class game_map

#--------------------------------------------------------------------------
# ● refer the attr

#--------------------------------------------------------------------------
attr_accessor :map

#--------------------------------------------------------------------------
# ● refer setup to game map

#--------------------------------------------------------------------------
alias les_game_map_setup setup

#--------------------------------------------------------------------------
# ● refers the map setup

#--------------------------------------------------------------------------
def setup(map_id)
$light_effects.redraw
les_game_map_setup(map_id)
$light_effects.setup
end
end

#===========================================================================
===
# ■ scene_title
#---------------------------------------------------------------------------
---
#  it is the class which processes the title picture
#===========================================================================
===

class scene_title
#--------------------------------------------------------------------------
# ● refer setup to scene title
#--------------------------------------------------------------------------
alias les_scene_title_update update
#--------------------------------------------------------------------------
# ● sets up the light effects
#--------------------------------------------------------------------------
def update
$light_effects = light_effect_system.new
les_scene_title_update
end
end

instructions:
to make the script work you must name the events right…

fire type light effects - fire


right lantern effects - right lantern
left lantern effects - left lantern
lamp post effects - lamp post
ground effects – ground

note:

this script needs the file called le.png, found below, in the pictures
folder of your game directory

you can find it in the demo as well... if done right you can make some
really cool things...

take care,
near

[net play online] [come join the army of evil cats ~!]
[near fantastica online] [camthalion of helyanwe ||||| 40%] [current
script : abs version 3]
[near fantastica corporation] [visit my weblog for information on up
coming scripts, updates, and projects ~!]

Das könnte Ihnen auch gefallen