Ascare
09.03.2012, 17:36
Anstoß für dieses Script gab schmoggi (http://www.multimediaxis.de/threads/134379-Lichtquellen-in-Kombination-mit-Spieler-Fackel-%28XP%29)
da er auf der Suche nach einem guten Lichteffekte Script für den XP war. Nach einiger Suche habe ich das Script im gezeigten Video gefunden und
erstmal so gut es ging ins Deutsche übersetzt.
Funktion:
Mit dem Script kann man dynamische Lichteffekte mit Bildern erzeugen. Fackeln, Taschenlampen, Kamine, Licht durch Fenster, Strassenlaternen, Aura, Scheinwerfer uvm.
Kurz noch die Erklärung:
Das Script stammt aus der brasilianischen Community, dort gibt es eine Art SDK, nennt sich Legacy Engine.
Als Teil dieser Engine gibt es ein Script für Lichteffekte.
Teil 1 ist die Basis und wird benötigt für alle Unterscripte der Legacy Engine.
Teil 2 ist das eigentliche Script für die Lichteffekte.
#==============================================================================
# Legacy Engine - Básico (Mapa)
# por Atoa
#==============================================================================
# Atualizações
# v 1.0 - 28 / 06 / 2011 - Script Lançado
# v 1.1 - 05 / 07 / 2011 - Compatibilidade com Loop no Mapa
# v 1.2 - 16 / 07 / 2011 - Compatibilidade com Iluminação
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Este é o script básico para os sistemas de mapa do Legacy Engine, é
# necessário para o funcionamento de todos os scripts de mapa do Legacy Engine.
# Este script em si não oferece nenhuma funcionalidade especial, além do fato
# de re-escrever alguns metodos de forma mais organizada, o que possibilita
# a total compatibilidade entre todos os scripts do sistema.
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Ordem dos scripts:
# Para evitar problemas de compatibilidade, os scripts do Legacy Engine devem
# ser colocados nesta ordem:
#
# - LE | Básico (Mapa)
# - LE | Anti Lag
# - LE | Loop no Mapa
# - LE | Iluminação
# - LE | Multi Frames
# - LE | Movimento Diagonal
# - LE | Controle de Animação
# - LE | Movimento por Pixel
# - LE | Caixas para Colisões
# - LE | Movimento Rotacional
# - LE | Plataformas
# - LE | Salto Livre
# - LE | Caterpillar
# - LE | Corrida
#
# Coloar os scripts em ordens diferentes algumas vezes pode causar bug, por
# isso não é recomendado fazer isto.
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Lista de Métodos re-escritos:
# Scripts que re-escrevam estes mesmos métodos causarão incompatibilidade
# com os scripts do sitema Legacy Engine
#
# class Game_Map
# def passable?
# def update
#
# class Game_Character
# def passable?
# def moveto
# def move_down
# def move_left
# def move_right
# def move_up
# def move_down
# def move_lower_left
# def move_lower_right
# def move_upper_left
# def move_upper_right
# def jump
# def update_move
# def move_toward_player
# def move_away_from_player
# def turn_toward_player
# def turn_away_from_player
#
# class Game_Player < Game_Character
# def update
#
# class Sprite_Character < RPG::Sprite
# def update
#
# class Spriteset_Map
# def initialize
# def dispose
# def update
#
#==============================================================================
$legacy_engine = {} if $legacy_engine.nil?
$legacy_engine["Basic Movement"] = true
#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
# Esta classe engloba o mapa. Isso determina o Scroll e a determinante de
# passagem. Se refere a $game_map para as instâncias desta classe.
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# Determinar se é Passável
# x : coordenada x
# y : coordenada y
# d : direção (0,2,4,6,8,10)
# * 0,10 = determina se todas as direções são passáveis
# self_event : automático (se o Evento for determinado passável)
#--------------------------------------------------------------------------
def passable?(x, y, d, self_event = nil)
return false unless valid?(x, y)
bit = (1 << (d / 2 - 1)) & 0x0f
for event in event_list
result = passable_event(x, y, event, self_event, bit)
return result if result != nil
end
for i in [2, 1, 0]
result = passable_tile(x, y, i, bit)
return result if result != nil
end
return true
end
#--------------------------------------------------------------------------
# Determinar se evento é Passável
# x : coordenada x
# y : coordenada y
# event : evento
# self_event : automático (se o Evento for determinado passável)
# bit : passabilidade
#--------------------------------------------------------------------------
def passable_event(x, y, event, self_event, bit)
if event_tile?(x, y, event, self_event)
return false if @passages[event.tile_id] & bit != 0
return false if @passages[event.tile_id] & 0x0f == 0x0f
return true if @priorities[event.tile_id] == 0
end
return nil
end
#--------------------------------------------------------------------------
# Determinar se evento é um tile
# x : coordenada x
# y : coordenada y
# event : evento
# self_event : automático (se o Evento for determinado passável)
#--------------------------------------------------------------------------
def event_tile?(x, y, event, self_event)
return (event.tile_id >= 0 and event != self_event and
event.x == x and event.y == y and not event.through)
end
#--------------------------------------------------------------------------
# Determinar se tile é Passável
# x : coordenada x
# y : coordenada y
# i : índice
# bit : passabilidade
#--------------------------------------------------------------------------
def passable_tile(x, y, i, bit)
tile_id = data[x, y, i]
return false if tile_id == nil
return false if @passages[tile_id] & bit != 0
return false if @passages[tile_id] & 0x0f == 0x0f
return true if @priorities[tile_id] == 0
return nil
end
#--------------------------------------------------------------------------
# Verificação da coordenada
# x : coordenada X
# y : coordenada Y
#--------------------------------------------------------------------------
def valid?(x, y)
x = round_x(x)
y = round_y(y)
return (x >= 0 and x < width and y >= 0 and y < height)
end
#--------------------------------------------------------------------------
# Determinar as Coordenadas Válidas
# x : coordenada x
# y : coordenada y
#--------------------------------------------------------------------------
def valid_real?(x, y)
return (x >= 0 and x < width * 128 and y >= 0 and y < height * 128)
end
#--------------------------------------------------------------------------
# Atualização do Frame
#--------------------------------------------------------------------------
def update
refresh if $game_map.need_refresh
update_scroll
update_events
update_fog
end
#--------------------------------------------------------------------------
# Atualização do scroll
#--------------------------------------------------------------------------
def update_scroll
if @scroll_rest > 0
distance = 2 ** @scroll_speed
case @scroll_direction
when 2 then scroll_down(distance)
when 4 then scroll_left(distance)
when 6 then scroll_right(distance)
when 8 then scroll_up(distance)
end
@scroll_rest -= distance
end
end
#--------------------------------------------------------------------------
# Atualização dos eventos
#--------------------------------------------------------------------------
def update_events
for event in @events.values
event.update
end
for common_event in @common_events.values
common_event.update
end
end
#--------------------------------------------------------------------------
# Atualização da névoa
#--------------------------------------------------------------------------
def update_fog
@fog_ox -= @fog_sx / 8.0
@fog_oy -= @fog_sy / 8.0
if @fog_tone_duration >= 1
d = @fog_tone_duration
target = @fog_tone_target
@fog_tone.red = (@fog_tone.red * (d - 1) + target.red) / d
@fog_tone.green = (@fog_tone.green * (d - 1) + target.green) / d
@fog_tone.blue = (@fog_tone.blue * (d - 1) + target.blue) / d
@fog_tone.gray = (@fog_tone.gray * (d - 1) + target.gray) / d
@fog_tone_duration -= 1
end
if @fog_opacity_duration >= 1
d = @fog_opacity_duration
@fog_opacity = (@fog_opacity * (d - 1) + @fog_opacity_target) / d
@fog_opacity_duration -= 1
end
end
#--------------------------------------------------------------------------
# Definição de eventos a serem atualizados
#--------------------------------------------------------------------------
def event_list
return events.values
end
#--------------------------------------------------------------------------
# Cálculo de redução da coordenada X padrão
# x : coordenada X
#--------------------------------------------------------------------------
def adjust_x(x)
return x - @display_x
end
#--------------------------------------------------------------------------
# Cálculo de redução da coordenada Y padrão
# y : coordenada Y
#--------------------------------------------------------------------------
def adjust_y(y)
return y - @display_y
end
#--------------------------------------------------------------------------
# Cálculo da coordenada X após o loop
# x : coordenada X
#--------------------------------------------------------------------------
def round_x(x)
return x
end
#--------------------------------------------------------------------------
# Cálculo da coordenada Y após o loop
# y : coordenada Y
#--------------------------------------------------------------------------
def round_y(y)
return y
end
end
#==============================================================================
# ** Game_Character
#------------------------------------------------------------------------------
# Esta classe trata dos Heróis. Esta é usada como uma superclasse para as
# classes Game_Player e Game_Event.
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
# Variáveis Públicas
#--------------------------------------------------------------------------
attr_accessor :sprite
attr_accessor :move_speed
#--------------------------------------------------------------------------
# Determinar se é Passável
# x : coordenada x
# y : coordenada y
# d : direção (0,2,4,6,8)
# * 0 = Determina que todas as direções estão bloqueadas (para pulo)
#--------------------------------------------------------------------------
def passable?(x, y, d)
old_x = $game_map.round_x(x)
old_y = $game_map.round_y(y)
new_x = $game_map.round_x(x + (d == 6 ? 1 : d == 4 ? -1 : 0))
new_y = $game_map.round_y(y + (d == 2 ? 1 : d == 8 ? -1 : 0))
return false unless $game_map.valid?(new_x, new_y)
return true if @through
return false unless $game_map.passable?(old_x, old_y, d, self)
return false unless $game_map.passable?(new_x, new_y, 10 - d)
for event in $game_map.event_list
if event.x == new_x and event.y == new_y
unless event.through
return false if self != $game_player or event.character_name != ""
end
end
end
if $game_player.x == new_x and $game_player.y == new_y
return false if @character_name != "" and not $game_player.through
end
return true
end
#--------------------------------------------------------------------------
# Determinar se está se Movendo
#--------------------------------------------------------------------------
def moving?
return (@real_x != @x * 128 + @move_x or @real_y != @y * 128 + @move_y)
end
#--------------------------------------------------------------------------
# Mover para uma Posição Designada
# x : coordenada x
# y : coordenada y
#--------------------------------------------------------------------------
def moveto(x, y)
@x = x % $game_map.width
@y = y % $game_map.height
@real_x = @x * 128
@real_y = @y * 128
@prelock_direction = 0
@move_x = 0
@move_y = 0
end
#--------------------------------------------------------------------------
# Mover Abaixo
# turn_enabled : flag que permite uma troca de direção
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def move_down(turn_enabled = true, steping = false)
turn_down if turn_enabled
if passable_down?
step_down
else
check_event_trigger_touch(@x, @y + 1)
end
end
#--------------------------------------------------------------------------
# Mover à Esquerda
# turn_enabled : flag que permite uma troca de direção
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def move_left(turn_enabled = true, steping = false)
turn_left if turn_enabled
if passable_left?
step_left
else
check_event_trigger_touch(@x - 1, @y)
end
end
#--------------------------------------------------------------------------
# Mover à Direita
# turn_enabled : flag que permite uma troca de direção
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def move_right(turn_enabled = true, steping = false)
turn_right if turn_enabled
if passable_right?
step_right
else
check_event_trigger_touch(@x + 1, @y)
end
end
#--------------------------------------------------------------------------
# Mover Acima
# turn_enabled : flag que permite uma troca de direção
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def move_up(turn_enabled = true, steping = false)
turn_up if turn_enabled
if passable_up?
step_up
else
check_event_trigger_touch(@x, @y - 1)
end
end
#--------------------------------------------------------------------------
# Mover Esquerda-Abaixo
# turn_enabled : flag que permite uma troca de direção
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def move_lower_left(turn_enabled = true, steping = false)
turn_lower_left if turn_enabled
if passable_lower_left?
step_lower_left
elsif passable_left?
step_left
elsif passable_down?
step_down
else
check_event_trigger_touch(@x - 1, @y + 1)
end
end
#--------------------------------------------------------------------------
# Mover Direita-Abaixo
# turn_enabled : flag que permite uma troca de direção
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def move_lower_right(turn_enabled = true, steping = false)
turn_lower_right if turn_enabled
if passable_lower_right?
step_lower_right
elsif passable_right?
step_right
elsif passable_down?
step_down
else
check_event_trigger_touch(@x + 1, @y + 1)
end
end
#--------------------------------------------------------------------------
# Mover Esquerda-Acima
# turn_enabled : flag que permite uma troca de direção
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def move_upper_left(turn_enabled = true, steping = false)
turn_upper_left if turn_enabled
if passable_upper_left?
step_upper_left
elsif passable_left?
step_left
elsif passable_up?
step_up
else
check_event_trigger_touch(@x - 1, @y - 1)
end
end
#--------------------------------------------------------------------------
# Mover Direita-Acima
# turn_enabled : flag que permite uma troca de direção
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def move_upper_right(turn_enabled = true, steping = false)
turn_upper_right if turn_enabled
if passable_upper_right?
step_upper_right
elsif passable_right?
step_right
elsif passable_up?
step_up
else
check_event_trigger_touch(@x + 1, @y - 1)
end
end
#--------------------------------------------------------------------------
# Pular
# x_plus : valor a mais da coordenada x
# y_plus : valor a mais da coordenada y
#--------------------------------------------------------------------------
def jump(x_plus, y_plus)
if x_plus != 0 or y_plus != 0
if x_plus.abs > y_plus.abs
x_plus < 0 ? turn_left : turn_right
else
y_plus < 0 ? turn_up : turn_down
end
end
new_x = @x + x_plus
new_y = @y + y_plus
if passable_jump?(new_x, new_y, x_plus, y_plus)
jump_move(new_x, new_y, x_plus, y_plus)
end
end
#--------------------------------------------------------------------------
# Determinar Passabilidade para saltos
# new_x : nova coordenada x
# new_y : nova coordenada y
# x_plus : modificador da coordenada x
# y_plus : modificador da coordenada y
#--------------------------------------------------------------------------
def passable_jump?(new_x, new_y, x_plus, y_plus)
return true if x_plus == 0 and y_plus == 0
return true if passable?(new_x, new_y, 0)
return false
end
#--------------------------------------------------------------------------
#
# new_x : nova coordenada x
# new_y : nova coordenada y
# x_plus : modificador da coordenada x
# y_plus : modificador da coordenada y
#--------------------------------------------------------------------------
def jump_move(new_x, new_y, x_plus, y_plus)
straighten
@x = new_x
@y = new_y
distance = Math.sqrt(x_plus * x_plus + y_plus * y_plus).round
@jump_peak = 10 + distance - @move_speed
@jump_count = @jump_peak * 2
@stop_count = 0
end
#--------------------------------------------------------------------------
# Determinar passabilidade Abaixo
#--------------------------------------------------------------------------
def passable_down?
return passable?(@x, @y, 2)
end
#--------------------------------------------------------------------------
# Determinar passabilidade à Esquerda
#--------------------------------------------------------------------------
def passable_left?
return passable?(@x, @y, 4)
end
#--------------------------------------------------------------------------
# Determinar passabilidade à Direita
#--------------------------------------------------------------------------
def passable_right?
return passable?(@x, @y, 6)
end
#--------------------------------------------------------------------------
# Determinar passabilidade Acima
#--------------------------------------------------------------------------
def passable_up?
return passable?(@x, @y, 8)
end
#--------------------------------------------------------------------------
# Determinar passabilidade Esquerda-Abaixo
#--------------------------------------------------------------------------
def passable_lower_left?
return ((passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) and
(passable?(@x, @y, 4) and passable?(@x - 1, @y, 2)))
end
#--------------------------------------------------------------------------
# Determinar passabilidade Direita-Abaixo
#--------------------------------------------------------------------------
def passable_lower_right?
return ((passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) and
(passable?(@x, @y, 6) and passable?(@x + 1, @y, 2)))
end
#--------------------------------------------------------------------------
# Determinar passabilidade Esquerda-Acima
#--------------------------------------------------------------------------
def passable_upper_left?
return ((passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) and
(passable?(@x, @y, 4) and passable?(@x - 1, @y, 8)))
end
#--------------------------------------------------------------------------
# Determinar passabilidade Esquerda-Acima
#--------------------------------------------------------------------------
def passable_upper_right?
return ((passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) and
(passable?(@x, @y, 6) and passable?(@x + 1, @y, 8)))
end
#--------------------------------------------------------------------------
# Passo Abaixo
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def step_down(steping = false)
turn_down
@y += 1
increase_steps
end
#--------------------------------------------------------------------------
# Passo à Esquerda
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def step_left(steping = false)
turn_left
@x -= 1
increase_steps
end
#--------------------------------------------------------------------------
# Passo à Direita
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def step_right(steping = false)
turn_right
@x += 1
increase_steps
end
#--------------------------------------------------------------------------
# Passo Acima
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def step_up(steping = false)
turn_up
@y -= 1
increase_steps
end
#--------------------------------------------------------------------------
# Passo Esquerda-Abaixo
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def step_lower_left(steping = false)
turn_lower_left
@x -= 1
@y += 1
increase_steps
end
#--------------------------------------------------------------------------
# Passo Direita-Abaixo
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def step_lower_right(steping = false)
turn_lower_right
@x += 1
@y += 1
increase_steps
end
#--------------------------------------------------------------------------
# Passo Esquerda-Acima
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def step_upper_left(steping = false)
turn_upper_left
@x -= 1
@y -= 1
increase_steps
end
#--------------------------------------------------------------------------
# Passo Direita-Acima
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def step_upper_right(steping = false)
turn_upper_right
@x += 1
@y -= 1
increase_steps
end
#--------------------------------------------------------------------------
# Olhar Esquerda-Abaixo
#--------------------------------------------------------------------------
def turn_lower_left
unless @direction_fix
@direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
@stop_count = 0
end
end
#--------------------------------------------------------------------------
# Olhar Direita-Abaixo
#--------------------------------------------------------------------------
def turn_lower_right
unless @direction_fix
@direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
@stop_count = 0
end
end
#--------------------------------------------------------------------------
# Olhar Esquerda-Acima
#--------------------------------------------------------------------------
def turn_upper_left
unless @direction_fix
@direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
@stop_count = 0
end
end
#--------------------------------------------------------------------------
# Olhar Direita-Acima
#--------------------------------------------------------------------------
def turn_upper_right
unless @direction_fix
@direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
@stop_count = 0
end
end
#--------------------------------------------------------------------------
# Atualização do Frame
#--------------------------------------------------------------------------
def update
fix_position
if jumping?
update_jump
elsif moving?
update_move
else
update_stop
end
update_animation
return @wait_count -= 1 if @wait_count > 0
return move_type_custom if @move_route_forcing
return if @starting or lock?
movement_update
end
#--------------------------------------------------------------------------
# Atualização da animação
#--------------------------------------------------------------------------
def update_animation
if @anime_count > 18 - @move_speed * 2
if not @step_anime and @stop_count > 0
@pattern = @original_pattern
else
@pattern = (@pattern + 1) % 4
end
@anime_count = 0
end
end
#--------------------------------------------------------------------------
# Atualização do movimento
#--------------------------------------------------------------------------
def movement_update
if update_frequency and not moving?
case @move_type
when 1 then move_type_random
when 2 then move_type_toward_player
when 3 then move_type_custom
end
end
end
#--------------------------------------------------------------------------
# Verificação de frequencia de movimento
#--------------------------------------------------------------------------
def update_frequency
return (@stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency))
end
#--------------------------------------------------------------------------
# Definição de distancia do movimento
#--------------------------------------------------------------------------
def distance
return (2 ** @move_speed).to_i
end
#--------------------------------------------------------------------------
# Atualização do Frame (Movimento)
#--------------------------------------------------------------------------
def update_move
postion_update
anime_count_update
end
#--------------------------------------------------------------------------
# Atualização da Posição Atual
#--------------------------------------------------------------------------
def postion_update
move_x = (@x * 128 + @move_x)
move_y = (@y * 128 + @move_y)
@real_y = [@real_y + distance, move_y].min.to_i if move_y > @real_y
@real_x = [@real_x - distance, move_x].max.to_i if move_x < @real_x
@real_x = [@real_x + distance, move_x].min.to_i if move_x > @real_x
@real_y = [@real_y - distance, move_y].max.to_i if move_y < @real_y
end
#--------------------------------------------------------------------------
# Correção de Posição
#--------------------------------------------------------------------------
def fix_position
if @x != $game_map.round_x(@x)
plus = $game_map.round_x(@x) - @x
@x += plus
@real_x += plus * 128
end
if @y != $game_map.round_y(@y)
plus = $game_map.round_y(@y) - @y
@y += plus
@real_y += plus * 128
end
end
#--------------------------------------------------------------------------
# Coordenada X da tela
#--------------------------------------------------------------------------
def screen_x
return ($game_map.adjust_x(@real_x) + 3) / 4 + 16
end
#--------------------------------------------------------------------------
# Coordenada Y da tela
#--------------------------------------------------------------------------
def screen_y
y = ($game_map.adjust_y(@real_y) + 3) / 4 + 32
if @jump_count >= @jump_peak
n = @jump_count - @jump_peak
else
n = @jump_peak - @jump_count
end
return y - (@jump_peak * @jump_peak - n * n) / 2
end
#--------------------------------------------------------------------------
# Selecionar a Coordenada Z da Tela
# height : altura do Peronagem
#--------------------------------------------------------------------------
def screen_z(height = 0)
return 999 if @always_on_top
z = ($game_map.adjust_y(@real_y) + 3) / 4 + 32
if @tile_id > 0
return z + $game_map.priorities[@tile_id] * 32
else
return z + ((height > 32) ? 31 : 0)
end
end
#--------------------------------------------------------------------------
# Atualização do Contador de Animação
#--------------------------------------------------------------------------
def anime_count_update
if @walk_anime
@anime_count += 1.5
elsif @step_anime
@anime_count += 1
end
end
#--------------------------------------------------------------------------
# Distância X do character
# character : Personagem
#--------------------------------------------------------------------------
def distance_x_from_character(character)
sx = @x - character.x
return sx
end
#--------------------------------------------------------------------------
# Distância Y do character
# character : Personagem
#--------------------------------------------------------------------------
def distance_y_from_character(character)
sy = @y - character.y
return sy
end
#--------------------------------------------------------------------------
# Seguir herói
#--------------------------------------------------------------------------
def move_toward_player
sx = distance_x_from_character($game_player)
sy = distance_y_from_character($game_player)
if sx != 0 or sy != 0
if sx.abs > sy.abs
sx > 0 ? move_left : move_right
sy > 0 ? move_up : move_down if not moving? and sy != 0
else
sy > 0 ? move_up : move_down
sx > 0 ? move_left : move_right if not moving? and sx != 0
end
end
end
#--------------------------------------------------------------------------
# Fugir do herói
#--------------------------------------------------------------------------
def move_away_from_player
sx = distance_x_from_character($game_player)
sy = distance_y_from_character($game_player)
if sx != 0 or sy != 0
if sx.abs > sy.abs
sx > 0 ? move_right : move_left
sy > 0 ? move_down : move_up if not moving? and sy != 0
else
sy > 0 ? move_down : move_up
sx > 0 ? move_right : move_left if not moving? and sx != 0
end
end
end
#--------------------------------------------------------------------------
# Olhar para o Herói
#--------------------------------------------------------------------------
def turn_toward_player
sx = distance_x_from_character($game_player)
sy = distance_y_from_character($game_player)
return if sx == 0 and sy == 0
if sx.abs > sy.abs
sx > 0 ? turn_left : turn_right
else
sy > 0 ? turn_up : turn_down
end
end
#--------------------------------------------------------------------------
# Girar Herói (Contrário)
#--------------------------------------------------------------------------
def turn_away_from_player
sx = distance_x_from_character($game_player)
sy = distance_y_from_character($game_player)
return if sx == 0 and sy == 0
if sx.abs > sy.abs
sx > 0 ? turn_right : turn_left
else
sy > 0 ? turn_down : turn_up
end
end
#--------------------------------------------------------------------------
# Determinar número de quadros
#--------------------------------------------------------------------------
def frames
return 4
end
#--------------------------------------------------------------------------
# Definição de Largura
#--------------------------------------------------------------------------
def box_width
@box_width = 128
return @box_width
end
#--------------------------------------------------------------------------
# Definição de Altura
#--------------------------------------------------------------------------
def box_height
@box_height = 128
return @box_height
end
#--------------------------------------------------------------------------
# Determinar Jogador
#--------------------------------------------------------------------------
def player?
return false
end
#--------------------------------------------------------------------------
# Determinar Evento
#--------------------------------------------------------------------------
def event?
return false
end
end
#==============================================================================
# ** Game_Player
#------------------------------------------------------------------------------
# Esta classe engloba o Jogador. Suas funções incluem a inicialização das
# determinantes dos eventos e o scroll do mapa. Se refere a "$game_player" para
# as instâncias desta classe.
#==============================================================================
class Game_Player < Game_Character
#--------------------------------------------------------------------------
# Atualização do Frame
#--------------------------------------------------------------------------
def update
last_real_postion
move_by_input
super
update_scroll
update_nonmoving
end
#--------------------------------------------------------------------------
# Definição da ultima posição
#--------------------------------------------------------------------------
def last_real_postion
@last_moving = moving?
@last_real_x = @real_x
@last_real_y = @real_y
end
#--------------------------------------------------------------------------
# Movimento do personagem
#--------------------------------------------------------------------------
def move_by_input
return unless movable?
return if $game_system.map_interpreter.running?
case Input.dir4
when 2 then move_down
when 4 then move_left
when 6 then move_right
when 8 then move_up
end
end
#--------------------------------------------------------------------------
# É possível mover?
#--------------------------------------------------------------------------
def movable?
return false if moving?
return false if @move_route_forcing
return false if $game_temp.message_window_showing
return true
end
#--------------------------------------------------------------------------
# Processo de scroll (movimento de tela no mapa)
#--------------------------------------------------------------------------
def update_scroll
ax1 = $game_map.adjust_x(@last_real_x)
ay1 = $game_map.adjust_y(@last_real_y)
ax2 = $game_map.adjust_x(@real_x)
ay2 = $game_map.adjust_y(@real_y)
$game_map.scroll_down(ay2 - ay1) if ay2 > ay1 and ay2 > CENTER_Y
$game_map.scroll_left(ax1 - ax2) if ax2 < ax1 and ax2 < CENTER_X
$game_map.scroll_right(ax2 - ax1) if ax2 > ax1 and ax2 > CENTER_X
$game_map.scroll_up(ay1 - ay2) if ay2 < ay1 and ay2 < CENTER_Y
end
#--------------------------------------------------------------------------
# Processo de não-movimento
# last_moving : último movimento do jogador
#--------------------------------------------------------------------------
def update_nonmoving
return if moving?
if @last_moving
result = check_event_trigger_here([1,2])
update_encounter unless result
end
if Input.trigger?(Input::C)
check_event_trigger_here([0])
check_event_trigger_there([0,1,2])
end
end
#--------------------------------------------------------------------------
# Processo de encontros aleatórios
#--------------------------------------------------------------------------
def update_encounter
return if $DEBUG and Input.press?(Input::CTRL)
@encounter_count -= 1 if @encounter_count > 0
end
#--------------------------------------------------------------------------
# Determinar Jogador
#--------------------------------------------------------------------------
def player?
return true
end
#--------------------------------------------------------------------------
# Determinar Evento
#--------------------------------------------------------------------------
def event?
return false
end
end
#==============================================================================
# ** Game_Event
#------------------------------------------------------------------------------
# Esta é a classe que engloba os eventos. O que inclui as funções nas páginas de
# evento alterando estas através das Condições de Evento, e faz funcionar os
# Processos Paralelos. Esta classe está inserida na classe Game_Map.
#==============================================================================
class Game_Event < Game_Character
#--------------------------------------------------------------------------
# Nome do Evento
#--------------------------------------------------------------------------
def name
return @event.name
end
#--------------------------------------------------------------------------
# Determinar Jogador
#--------------------------------------------------------------------------
def player?
return false
end
#--------------------------------------------------------------------------
# Determinar Evento
#--------------------------------------------------------------------------
def event?
return true
end
#--------------------------------------------------------------------------
# Retornar lista de comentários do evento
#--------------------------------------------------------------------------
def comments
return [] if @page.nil? or @page.list.nil? or
@page.list.size <= 0
comment_list = []
for item in @page.list
next if item.nil?
next unless item.code == 108 or item.code == 408
comment_list << item.parameters[0]
end
return comment_list
end
end
#==============================================================================
# ** Sprite_Character
#------------------------------------------------------------------------------
# Esta é o script que exibe os sprites dos Heróis. Levando em consideração
# a classe Game_Character fazendo correções quando necessário.
#==============================================================================
class Sprite_Character < RPG::Sprite
#--------------------------------------------------------------------------
# Atualização do Frame
#--------------------------------------------------------------------------
def update
super
update_character
update_rect
update_misc
update_battle_animation
end
#--------------------------------------------------------------------------
# Atualização do gráfico do personagem
#--------------------------------------------------------------------------
def update_character
return unless update_character?
update_character_info
if @tile_id >= 384
set_tile_bitmap
else
set_character_bitmap
end
end
#--------------------------------------------------------------------------
# Determinar atualização do gráfico do personagem
#--------------------------------------------------------------------------
def update_character?
return true if @tile_id != @character.tile_id
return true if @character_name != @character.character_name
return true if @character_hue != @character.character_hue
return false
end
#--------------------------------------------------------------------------
# Atualização das informações do personagem
#--------------------------------------------------------------------------
def update_character_info
@tile_id = @character.tile_id
@character_name = @character.character_name
@character_hue = @character.character_hue
end
#--------------------------------------------------------------------------
# Determinar bitmap se for um tile
#--------------------------------------------------------------------------
def set_tile_bitmap
self.bitmap = RPG::Cache.tile($game_map.tileset_name,
@tile_id, @character.character_hue)
self.src_rect.set(0, 0, 32, 32)
self.ox = 16
self.oy = 32
end
#--------------------------------------------------------------------------
# Determinar bitmap se for um personagem
#--------------------------------------------------------------------------
def set_character_bitmap
self.bitmap = RPG::Cache.character(@character.character_name,
@character.character_hue)
@cw = bitmap.width / @character.frames
@ch = bitmap.height / 4
self.ox = @cw / 2
self.oy = @ch
end
#--------------------------------------------------------------------------
# Determinar direção
#--------------------------------------------------------------------------
def direction
return @character.direction
end
#--------------------------------------------------------------------------
# Atualização do retangulo do bitmap
#--------------------------------------------------------------------------
def update_rect
if @tile_id == 0
sx = @character.pattern * @cw
sy = (direction - 2) / 2 * @ch
self.src_rect.set(sx, sy, @cw, @ch)
end
end
#--------------------------------------------------------------------------
# Atualizações variadas
#--------------------------------------------------------------------------
def update_misc
self.visible = (not @character.transparent)
self.x = @character.screen_x
self.y = @character.screen_y
self.z = @character.screen_z(@ch)
self.opacity = @character.opacity
self.blend_type = @character.blend_type
self.bush_depth = @character.bush_depth
end
#--------------------------------------------------------------------------
# Atualização da animação
#--------------------------------------------------------------------------
def update_battle_animation
if @character.animation_id != 0
animation = $data_animations[@character.animation_id]
animation(animation, true)
@character.animation_id = 0
end
end
end
#==============================================================================
# ** Spriteset_Map
#------------------------------------------------------------------------------
# Esta classe engloba todos os sprites da tela, Tilesets, Heróis, etc
# Esta classe está inserida na classe Scene_Map.
#==============================================================================
class Spriteset_Map
#--------------------------------------------------------------------------
# Inicialização do objeto
#--------------------------------------------------------------------------
def initialize
create_viewports
create_tilemap
create_panorama
create_fog
create_characters
create_weather
create_pictures
create_timer
update
end
#--------------------------------------------------------------------------
# Criação dos viewports
#--------------------------------------------------------------------------
def create_viewports
@viewport1 = Viewport.new(0, 0, 640, 480)
@viewport2 = Viewport.new(0, 0, 640, 480)
@viewport3 = Viewport.new(0, 0, 640, 480)
@viewport2.z = 200
@viewport3.z = 5000
end
#--------------------------------------------------------------------------
# Criação dos tiles
#--------------------------------------------------------------------------
def create_tilemap
@tilemap = Tilemap.new(@viewport1)
@tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name)
for i in 0..6
autotile_name = $game_map.autotile_names[i]
@tilemap.autotiles[i] = RPG::Cache.autotile(autotile_name)
end
@tilemap.map_data = $game_map.data
@tilemap.priorities = $game_map.priorities
end
#--------------------------------------------------------------------------
# Criação do panorama
#--------------------------------------------------------------------------
def create_panorama
@panorama = Plane.new(@viewport1)
@panorama.z = -1000
end
#--------------------------------------------------------------------------
# Criação da névoa
#--------------------------------------------------------------------------
def create_fog
@fog = Plane.new(@viewport1)
@fog.z = 3000
end
#--------------------------------------------------------------------------
# Criação dos characters
#--------------------------------------------------------------------------
def create_characters
@character_sprites = []
for i in $game_map.events.keys.sort
sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
@character_sprites.push(sprite)
end
@character_sprites.push(Sprite_Character.new(@viewport1, $game_player))
end
#--------------------------------------------------------------------------
# Criação do clima
#--------------------------------------------------------------------------
def create_weather
@weather = RPG::Weather.new(@viewport1)
end
#--------------------------------------------------------------------------
# Criação das pictures
#--------------------------------------------------------------------------
def create_pictures
@picture_sprites = []
for i in 1..50
@picture_sprites.push(Sprite_Picture.new(@viewport2,
$game_screen.pictures[i]))
end
end
#--------------------------------------------------------------------------
# Criação do timer
#--------------------------------------------------------------------------
def create_timer
@timer_sprite = Sprite_Timer.new
end
#--------------------------------------------------------------------------
# Dispose
#--------------------------------------------------------------------------
def dispose
dispose_tilemap
dispose_panorama
dispose_fog
dispose_characters
dispose_weather
dispose_pictures
dispose_timer
dispose_viewports
end
#--------------------------------------------------------------------------
# Dispose dos tiles
#--------------------------------------------------------------------------
def dispose_tilemap
@tilemap.tileset.dispose
for i in 0..6
@tilemap.autotiles[i].dispose
end
@tilemap.dispose
end
#--------------------------------------------------------------------------
# Dispose do panorama
#--------------------------------------------------------------------------
def dispose_panorama
@panorama.dispose
end
#--------------------------------------------------------------------------
# Dispose da névoa
#--------------------------------------------------------------------------
def dispose_fog
@fog.dispose
end
#--------------------------------------------------------------------------
# Dispose dos characters
#--------------------------------------------------------------------------
def dispose_characters
for sprite in @character_sprites
sprite.dispose
end
end
#--------------------------------------------------------------------------
# Dispose dos tempos
#--------------------------------------------------------------------------
def dispose_weather
@weather.dispose
end
#--------------------------------------------------------------------------
# Dispose das pictures
#--------------------------------------------------------------------------
def dispose_pictures
for sprite in @picture_sprites
sprite.dispose
end
end
#--------------------------------------------------------------------------
# Dispose do timer
#--------------------------------------------------------------------------
def dispose_timer
@timer_sprite.dispose
end
#--------------------------------------------------------------------------
# Dispose dos viewports
#--------------------------------------------------------------------------
def dispose_viewports
@viewport1.dispose
@viewport2.dispose
@viewport3.dispose
end
#--------------------------------------------------------------------------
# Atualização da tela
#--------------------------------------------------------------------------
def update
update_tilemap
update_panorama
update_fog
update_characters
update_weather
update_pictures
update_timer
update_viewports
end
#--------------------------------------------------------------------------
# Atualização dos tiles
#--------------------------------------------------------------------------
def update_tilemap
@tilemap.ox = $game_map.display_x / 4
@tilemap.oy = $game_map.display_y / 4
@tilemap.update
end
#--------------------------------------------------------------------------
# Atualização do panorama
#--------------------------------------------------------------------------
def update_panorama
if @panorama_name != $game_map.panorama_name or
@panorama_hue != $game_map.panorama_hue
@panorama_name = $game_map.panorama_name
@panorama_hue = $game_map.panorama_hue
if @panorama.bitmap != nil
@panorama.bitmap.dispose
@panorama.bitmap = nil
end
if @panorama_name != ""
@panorama.bitmap = RPG::Cache.panorama(@panorama_name, @panorama_hue)
end
Graphics.frame_reset
end
@panorama.ox = $game_map.display_x / 8
@panorama.oy = $game_map.display_y / 8
end
#--------------------------------------------------------------------------
# Atualização da névoa
#--------------------------------------------------------------------------
def update_fog
if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue
@fog_name = $game_map.fog_name
@fog_hue = $game_map.fog_hue
if @fog.bitmap != nil
@fog.bitmap.dispose
@fog.bitmap = nil
end
if @fog_name != ""
@fog.bitmap = RPG::Cache.fog(@fog_name, @fog_hue)
end
Graphics.frame_reset
end
@fog.zoom_x = $game_map.fog_zoom / 100.0
@fog.zoom_y = $game_map.fog_zoom / 100.0
@fog.opacity = $game_map.fog_opacity
@fog.blend_type = $game_map.fog_blend_type
@fog.ox = $game_map.display_x / 4 + $game_map.fog_ox
@fog.oy = $game_map.display_y / 4 + $game_map.fog_oy
@fog.tone = $game_map.fog_tone
end
#--------------------------------------------------------------------------
# Atualização dos characters
#--------------------------------------------------------------------------
def update_characters
for sprite in @character_sprites
sprite.update
end
end
#--------------------------------------------------------------------------
# Atualização do clima
#--------------------------------------------------------------------------
def update_weather
@weather.type = $game_screen.weather_type
@weather.max = $game_screen.weather_max
@weather.ox = $game_map.display_x / 4
@weather.oy = $game_map.display_y / 4
@weather.update
end
#--------------------------------------------------------------------------
# Atualização das pictures
#--------------------------------------------------------------------------
def update_pictures
for sprite in @picture_sprites
sprite.update
end
end
#--------------------------------------------------------------------------
# Atualização do timer
#--------------------------------------------------------------------------
def update_timer
@timer_sprite.update
end
#--------------------------------------------------------------------------
# Atualização dos viewports
#--------------------------------------------------------------------------
def update_viewports
@viewport1.tone = $game_screen.tone
@viewport1.ox = $game_screen.shake
@viewport3.color = $game_screen.flash_color
@viewport1.update
@viewport3.update
end
end
#==============================================================================
# Legacy Engine - Lighting
# von Atoa
#==============================================================================
# Updates
# v 1.0 - 09 / 03 / 2012 - Deutsche Übersetzung von Ascare
# v 1.0 - 16 / 07 / 2011 - Script veröffentlicht
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Dieses Skript ermöglicht es, verschiedene Lichteffekte auf Maps hinzuzufügen.
# Aber dies funktioniert anders als die meisten anderen Skripte dieser Art.
# In der Regel werden Lichteffekte einfach durch Bilder dargestellt, jedoch
# wird das Licht bei Verdunkelung auch den Lichteffekt beeinflussen,
# da sie nicht auf einer Ebene mit der Schattenebene ist.
# Dieses Skript wirkt sich anders aus, indem Sie die Bilder des Lichteffekts
# auf die gleiche Ebene zeichnet wie die des Schattens. Dadurch bleibt das
# Licht von der Verdunkelung der Map unbeeinflusst und lässt fortgeschrittene
# Lichteffekte zu.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# BILDER FÜR DEN LICHTEFFEKT:
# Die Lichteffekte müssen in den Ordner Graphics/Lights. In der Demo sind
# dort Bilder als Beispiele gespeichert. Diese können auch farblich verändert
# werden um den Lichteffekt zu studieren.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# EINEN LICHTEFFEKT ERSTELLEN
# Zunächst einmal ist es nötig den Schatten als neue Ebene zu kreieren.
# Auf diesem werden dann die Lichter eingefügt.
# Dafür sollte man per Call Script Funktion folgendes aufrufen:
# create_shade(OPAZITÄT, ROT, GRÜN, BLAU, TYP)
# OPAZITÄT : Grad der Opazität des Schatten zwischen 0 und 255. Standard 160.
# ROT : Rotton zwischen 0 und 255. Standard 0.
# GRÜN : Grünton zwischen 0 und 255. Standard 0.
# BLAU : Blauton zwischen 0 und 255. Standard 0.
# TYP : Art des Effekts. 0 = normal, 1 = additiv, 2 = invertiert.
# Standard ist 2 (Farben umgekehrt)
#
# Ist die Schattenebene erstellt, gibt es mehrere Möglichkeiten
# das Licht zu definieren.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# LICHT DURCH KOMMENTARE
# Ein Lichteffekt kann in einem Kommentar eingesetzt werden.
# Diese Lichter sind solange aktiv, wie die Event-Seite, die das Kommentar
# enthält, ebenfalls aktiv ist.
# Als Kommntar geht das wie folgt:
# LIGHT (a) o v s x y z
# a : Name der Bilddatei, in Klammern.
# o : Opazität zwischen 0 und 255.
# v : Grad der Variation der Opazität zwischen 0 und 255.
# s : Geschwindigkeit der Änderung der Opazität zwischen 0 und 255.
# x : Einstellung der Position x
# y : Einstellung der Position y
# z : zoom
# Bsp.:
# LIGHT (licht weiß) 160 0 0 0 5 1
#
# Es gibt auch einige vordefinierte Werte für einen Kommentar.
# SIMPLE LIGHT Opazität
# SIMPLE LAMP Opazität
# SIMPLE TORCH Opazität
# SIMPLE WINDOW A Opazität
# SIMPLE WINDOW B Opazität
# FLASH LIGHT Opazität
# FLASH LAMP Opazität
# FLASH TORCH Opazität
# FLASH WINDOW A Opazität
# FLASH WINDOW B Opazität
# LANTERN Opazität
# Die Opazität ist die Deckkraft des Lichts und kann auch hier ausgelassen
# werden. Der Befehl "SIMPLE" erzeugt ein einfaches Licht, der Befehl
# "FLASH" erzeugt ein pulsierendes Licht. Und LANTERN aktiviert eine Lampe.
# (ein Licht direkt vor dem Charakter).
#
# Bsp.:
# SIMPLE LIGHT
# FLASH TORCH 200
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# LICHT PER SCRIPT
# Der Lichteffekt kann auch per Script Befehl aufgerufen werden. Der Effekt ist
# aber nur solange aktiv, bis ein Mapwechsel stattfindet. Auf jeder neuen Map
# muss das Licht durch einen neuen Scriptaufruf erzeugt werden.
#
# Es gibt dafür zwei Scriptbefehle, jeweils für Charaktere und für Events.
# player_light(img, id, index, o, x, y, v, s, z) # Für Charaktere
# event_light(img, id, index, o, x, y, v, s, z) # Für Events
# img : Name der Bilddatei
# id : ID des Lichteffekts um jedes Licht zu identifizieren, modifizieren
# oder zu entfernen. Verschiedene Lichter sollten auch unterschiedliche
# IDs haben.
# index : Dies ist die Index ID und nur nötig, wenn man das Hintereinander-
# Laufen Script der 'Legacy Engine' verwendet. Standardgemäß ist dies 0.
# o : Opazität zwischen 0 und 255.
# x : Einstellung der Position x
# y : Einstellung der Position y
# v : Grad der Variation der Opazität zwischen 0 und 255.
# s : Geschwindigkeit der Änderung der Opazität zwischen 0 und 255.
# z : zoom
# Alle Werte nach index können auch ausgelassen werden.
# Bsp.:
# player_light("Licht", 1, 0, 200)
# event_light("Fackel", 2, 5, 200, 0, 0, 50, 3)
#
# Es ist auch möglich ein Licht nur einem Tile zuzuordnen. Der Befehl dazu:
# map_light(img, id, mx, my, o, x, y, v, s, z)
# img : Name der Bilddatei
# id : ID des Lichteffekts um jedes Licht zu identifizieren, modifizieren
# oder zu entfernen. Verschiedene Lichter sollten auch unterschiedliche
# IDs haben.
# mx : X-Koordinate der Map
# my : Y-Koordinate der Map
# x : Einstellung der Position x
# y : Einstellung der Position y
# v : Grad der Variation der Opazität zwischen 0 und 255.
# s : Geschwindigkeit der Änderung der Opazität zwischen 0 und 255.
# z : zoom
# Alle Werte nach (index?) können auch ausgelassen werden.
# Bsp.:
# map_light("Lampe", 3, 5, 6, 225)
#
# TASCHENLAMPEN sind Lichter die sich automatisch vor dem Spieler/Event bewegen.
# Folgende Befehle sind zum (de)aktivieren der Taschnelampe:
# player_lantern_on(index, opacity) # Taschenlampe für Spieler aktivieren
# event_lantern_on(index, opacity) # Taschenlampe für Event aktivieren
# player_lantern_off(index) # Taschenlampe für Spieler deaktivieren
# event_lantern_off(index) # Taschenlampe für Event deaktivieren
# index : Dies ist die Index ID des Events. Für den Spieler nur nötig, wenn
# man das Hintereinander-Laufen Script der 'Legacy Engine' verwendet.
# Standardgemäß ist dies 0.
# opacity : Opazität zwischen 0 und 255.
#
# Der Lichteffekt kann durch einen einfachen Befehl deaktiviert werden:
# remove_light(id)
# id : Die ID des Lichteffekts der zuvor angegeben wurde.
#
#==============================================================================
$legacy_engine = {} if $legacy_engine.nil?
$legacy_engine["Light Effect"] = true
#==============================================================================
# ** RPG::Cache
#------------------------------------------------------------------------------
# Modul das Bitmaps lädt und speichert
#==============================================================================
module RPG::Cache
#--------------------------------------------------------------------------
# Lädt die Grafiken für den Lichteffekt
# filename : Dateiname
# hue : Information über den Farbton
#--------------------------------------------------------------------------
def self.lights(filename)
self.load_bitmap('Graphics/Lights/', filename)
end
end
#==============================================================================
# ** Sprite_Light
#------------------------------------------------------------------------------
# Klasse, das die Darstellung des Lichts auf dem Sprite verwaltet
#==============================================================================
class Sprite_Light < RPG::Sprite
#--------------------------------------------------------------------------
# Public Variablen
#--------------------------------------------------------------------------
attr_reader :lights
attr_reader :update_tone
#--------------------------------------------------------------------------
# Objekt-Initialisierung
# args : Einstellungswert
#--------------------------------------------------------------------------
def initialize(*args)
args.flatten!
super(args.last)
self.bitmap = Bitmap.new(640, 480)
self.blend_type = args[0]
self.opacity = args[4]
@new_opacity = $game_map.new_opacity.nil? ? args[4] : $game_map.new_opacity
@max_opacity = $game_map.max_opacity.nil? ? args[4] : $game_map.max_opacity
@change_speed = $game_map.change_speed.nil? ? 0 : $game_map.change_speed
self.z = 100
color(args[1], args[2], args[3])
@lights = {}
@update_list = []
end
#--------------------------------------------------------------------------
# Frames updaten
#--------------------------------------------------------------------------
def update
super
self.ox = $game_map.adjust_x($game_map.display_x) / 4
self.oy = $game_map.adjust_y($game_map.display_y) / 4
update_lights
update_opacity
end
#--------------------------------------------------------------------------
# Lichter updaten
#--------------------------------------------------------------------------
def update_lights
map_x = $game_map.adjust_x($game_map.display_x) / 4
map_y = $game_map.adjust_y($game_map.display_y) / 4
rect = Rect.new(map_x, map_y, 640, 480)
self.bitmap.fill_rect(rect, @color)
for light in @lights.values
light.update
next unless on_screen?(light, map_x, map_y)
draw_light(light, light.x, light.y)
end
end
#--------------------------------------------------------------------------
# Definition des Lichts auf der Map
# light : das Licht Sprite
# map_x : X-Position auf der Karte
# map_y : Y-Position auf der Karte
#--------------------------------------------------------------------------
def on_screen?(light, map_x, map_y)
return false unless (light.x.between?(map_x, map_x + 640) or
(light.x + light.width).between?(map_x, map_x + 640))
return false unless (light.y.between?(map_y, map_y + 480) or
(light.y + light.height).between?(map_y, map_y + 480))
return true
end
#--------------------------------------------------------------------------
# Zeichne Licht
# light : das Licht Sprite
# x : x-Position
# y : y-Position
#--------------------------------------------------------------------------
def draw_light(light, x, y)
img = light.bitmap
rect = Rect.new(x, y, light.width, light.height)
self.bitmap.stretch_blt(rect, img, img.rect, light.opacity)
end
#--------------------------------------------------------------------------
# Farben setzen
# red : rot färben
# green : grün färben
# blue : blau färben
#--------------------------------------------------------------------------
def color(red = 0, green = 0, blue = 0)
if self.blend_type == 2
@color = Color.new(255 - red, 255 - green, 255 - blue, 255)
else
@color = Color.new(red, green, blue, 255)
end
end
#--------------------------------------------------------------------------
# Neues Licht kreieren
# value : Einstellung
#--------------------------------------------------------------------------
def create_light(value)
args = value.dup
remove_light(args[0])
@lights[args[0]] = Light_Sprite.new(args)
end
#--------------------------------------------------------------------------
# Licht entfernen
# id : ID des Bildes
#--------------------------------------------------------------------------
def remove_light(id)
return if @lights[id].nil?
@lights.delete(id)
end
#--------------------------------------------------------------------------
# Opazität updaten
#--------------------------------------------------------------------------
def update_opacity
if @max_opacity != self.opacity
if @max_opacity > self.opacity
@new_opacity += @change_speed
self.opacity = [@new_opacity, @max_opacity].min.to_i
elsif @max_opacity < self.opacity
@new_opacity -= @change_speed
self.opacity = [@new_opacity, @max_opacity].max.to_i
end
end
$game_map.shade_opacity = self.opacity
$game_map.new_opacity = @new_opacity
$game_map.max_opacity = @max_opacity
$game_map.change_speed = @change_speed
end
#--------------------------------------------------------------------------
# Transparenz ändern
# args : Einstellung
#--------------------------------------------------------------------------
def opacity_change(*args)
args.flatten!
@max_opacity = args[0]
@new_opacity = self.opacity.to_f
@change_speed = args[1].to_f
end
#--------------------------------------------------------------------------
# Entsorgen
#--------------------------------------------------------------------------
def dispose
super
@lights.values {|light| light.dispose unless light.bitmap.disposed?}
end
end
#==============================================================================
# ** Light_Sprite
#------------------------------------------------------------------------------
# Klasse, die die einzelnen Sprites von jedem Lichtpunkt verwaltet
#==============================================================================
class Light_Sprite
#--------------------------------------------------------------------------
# Public Variablen
#--------------------------------------------------------------------------
attr_reader :values
attr_reader :bitmap
attr_reader :opacity
attr_reader :x
attr_reader :y
attr_reader :real_x
attr_reader :real_y
attr_reader :width
attr_reader :height
#--------------------------------------------------------------------------
# Objekt-Initialisierung
# args : Einstellungswert
#--------------------------------------------------------------------------
def initialize(*args)
args.flatten!
@values = args.dup
@bitmap = RPG::Cache.lights(args[1])
@target = set_target(args[2])
@opacity = args[3]
@plus_x = args[4]
@plus_y = args[5]
@width = @bitmap.width * args[8]
@height = @bitmap.height * args[8]
@base_opacity = args[3]
@base_variance = args[6]
@speed = args[7]
@variance = 0.0
update
end
#--------------------------------------------------------------------------
# Frames updaten
#--------------------------------------------------------------------------
def update
update_position
update_opacity
end
#--------------------------------------------------------------------------
# Positionen updaten
#--------------------------------------------------------------------------
def update_position
if @target.is_a?(Game_Character)
@x = $game_map.adjust_x(@target.real_x) / 4 - @width / 2 + @plus_x + 16
@y = $game_map.adjust_y(@target.real_y) / 4 - @height / 2 + @plus_y + 16
@real_x = (@target.real_x / 32).to_i
@real_y = (@target.real_y / 32).to_i
else
@x = $game_map.adjust_x(@target[:x] * 128) / 4 - @width / 2 + @plus_x + 16
@y = $game_map.adjust_y(@target[:y] * 128) / 4 - @height / 2 + @plus_y + 16
@real_x = @target[:x]
@real_y = @target[:y]
end
end
#--------------------------------------------------------------------------
# Opazität updaten
#--------------------------------------------------------------------------
def update_opacity
@variance += @speed
@speed *= -1 if (@speed > 0 and @variance > @base_variance) or
(@speed < 0 and @variance < -@base_variance)
@opacity = [[@base_opacity + @variance, 0].max, 255].min
end
#--------------------------------------------------------------------------
# Entsorgen
#--------------------------------------------------------------------------
def dispose
@bitmap.dispose
end
#--------------------------------------------------------------------------
# Das Ziel des Lichts definieren
# value
#--------------------------------------------------------------------------
def set_target(value)
if value.include?('actor')
return (($legacy_engine["Caterpillar"] and value['actor'] > 0) ?
$game_player.actors[value['actor'] - 1] : $game_player)
elsif value.include?('event')
return $game_map.events[value['event']]
else
return value
end
end
end
#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
# Diese Klasse verwaltet die Maps. Dies bestimmt das Scrollen und die
# Passierbarkeit. Bezieh dich auf $game_map für die Instanzen dieser Klasse.
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# Public Variablen
#--------------------------------------------------------------------------
attr_accessor :light_effect
attr_accessor :lights
attr_accessor :remove_lights
attr_accessor :shade_opacity
attr_accessor :opacity_change
attr_accessor :max_opacity
attr_accessor :new_opacity
attr_accessor :change_speed
#--------------------------------------------------------------------------
# Einstellung
# map_id : ID der Map
#--------------------------------------------------------------------------
alias setup_lighteffects setup
def setup(map_id)
clear_lights
setup_lighteffects(map_id)
end
#--------------------------------------------------------------------------
# Werte der Lichter zurücksetzen
#--------------------------------------------------------------------------
def clear_lights
@lights = {}
@remove_lights = []
@shade_opacity = 0
@light_effect = nil
@max_opacity = nil
@new_opacity = nil
@change_speed = nil
end
end
#==============================================================================
# ** Game_Character (Teil 1)
#------------------------------------------------------------------------------
# Diese Klasse beschäftigt sich mit den Helden. Dies wird als Superklasse für
# die Klassen Game_Player und Game_Event verwendet.
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
# Public Variablen
#--------------------------------------------------------------------------
attr_accessor :lantern
#--------------------------------------------------------------------------
# Objekt-Initialisierung
#--------------------------------------------------------------------------
alias initialize_lighteffects initialize
def initialize
initialize_lighteffects
@lantern = 0
end
#--------------------------------------------------------------------------
# Frames updaten
#--------------------------------------------------------------------------
alias update_lighteffects update
def update
update_lighteffects
dir = $legacy_engine["Rotational Move"] ? @new_direction : @direction
if @lantern != 0 and @lantern_direction != dir
@lantern_direction = dir
id = self.event? ? "EL#{@id}" : "AL#{@id}"
tp = self.event? ? 'event' : 'actor'
case @lantern_direction
when 1
img = 'lantern_downleft'
value = [id, img, {tp => @id}, @lantern, -48, 48, 0, 0, 1.0]
when 2
img = 'lantern_down'
value = [id, img, {tp => @id}, @lantern, 0, 64, 0, 0, 1.0]
when 3
img = 'lantern_downright'
value = [id, img, {tp => @id}, @lantern, 48, 48, 0, 0, 1.0]
when 4
img = 'lantern_left'
value = [id, img, {tp => @id}, @lantern, -64, 0, 0, 0, 1.0]
when 6
img = 'lantern_right'
value = [id, img, {tp => @id}, @lantern, 64, 0, 0, 0, 1.0]
when 7
img = 'lantern_upleft'
value = [id, img, {tp => @id}, @lantern, -48, -48, 0, 0, 1.0]
when 8
img = 'lantern_up'
value = [id, img, {tp => @id}, @lantern, 0, -64, 0, 0, 1.0]
when 9
img = 'lantern_upright'
value = [id, img, {tp => @id}, @lantern, 48, -48, 0, 0, 1.0]
end
$game_map.lights[id] = value
elsif @lantern == 0 and @lantern_direction != nil
id = self.event? ? "EL#{@id}" : "AL#{@id}"
$game_map.remove_lights << id if $game_map.remove_lights != nil
@lantern_direction = nil
end
end
end
#==============================================================================
# ** Game_Event
#------------------------------------------------------------------------------
# Diese Klasse verwaltet Events. Es steuert die Funktion der Eventseiten, den
# Wechsel, die Bedingungen, sowie parallele Prozesse. Es wird innerhalb der
# Game_Map Klasse verwendet.
#==============================================================================
class Game_Event < Game_Character
#--------------------------------------------------------------------------
# Entferne den Flag der Initialisierung
#--------------------------------------------------------------------------
alias clear_starting_lighteffects clear_starting
def clear_starting
clear_starting_lighteffects
@lantern = 0
$game_map.remove_lights << "EV#{@id}" if $game_map.remove_lights != nil
refresh_lights unless @page.nil?
end
#--------------------------------------------------------------------------
# Lichter updaten
#--------------------------------------------------------------------------
def refresh_lights
for comment in comments
if comment =~ /SIMPLE[ ]*LIGHT[ ]*(\d+)?/i
set_light("EV#{@id}", "light", $1)
elsif comment =~ /SIMPLE[ ]*LAMP[ ]*(\d+)?/i
set_light("EV#{@id}", "lamp", $1)
elsif comment =~ /SIMPLE[ ]*TORCH[ ]*(\d+)?/i
set_light("EV#{@id}", "torch", $1)
elsif comment =~ /SIMPLE[ ]*WINDOW[ ]*A[ ]*(\d+)?/i
set_light("EV#{@id}", "window", $1)
elsif comment =~ /SIMPLE[ ]*WINDOW[ ]*B[ ]*(\d+)?/i
set_light("EV#{@id}", "window", $1, 0, 0, 0, -14)
elsif comment =~ /FLASH[ ]*LIGHT[ ]*(\d+)?[ ]*(\d+)?[ ]*(\d+)?/i
set_light("EV#{@id}", "light", $1, $2, $3)
elsif comment =~ /FLASH[ ]*LAMP[ ]*(\d+)?[ ]*(\d+)?[ ]*(\d+)?/i
set_light("EV#{@id}", "lamp", $1, $2, $3)
elsif comment =~ /FLASH[ ]*TORCH[ ]*(\d+)?[ ]*(\d+)?[ ]*(\d+)?/i
set_light("EV#{@id}", "torch", $1, $2, $3, 0, 0, 2.0)
elsif comment =~ /FLASH[ ]*WINDOW[ ]*A[ ]*(\d+)?[ ]*(\d+)?[ ]*(\d+)?/i
set_light("EV#{@id}", "window", $1, $2, $3)
elsif comment =~ /FLASH[ ]*WINDOW[ ]*B[ ]*(\d+)?[ ]*(\d+)?[ ]*(\d+)?/i
set_light("EV#{@id}", "window", $1, $2, $3, 0, -14)
elsif comment =~ /LIGHT[ ]\((\w+)\)((?:[ ]*(?:[\+\-]?\d+))*)/i
v = []
name = $1.dup
$2.scan(/\d+/).each {|i| v << i}
set_light("EV#{@id}", name, v[0], v[1], v[1], v[3], v[4], v[5])
elsif comment =~ /LANTERN[ ]*(\d+)?/i
@lantern = ($1.nil? ? 255 : $1.to_i)
end
end
end
#--------------------------------------------------------------------------
# Lichter definieren
# id : ID des Lichts
# name : Name der Bilddatei
# op : Opazität
# vr : Grad der Variation
# sp : Geschwindigkeit der Variation
# x : Einstellung der Position x
# y : Einstellung der Position y
# zm : zoom
#--------------------------------------------------------------------------
def set_light(id, name, op, vr = 0, sp = 0, x = 0, y = 0, zm = 1.0)
op = op.nil? ? 255 : op.to_i
vr = vr.nil? ? 50 : vr.to_i
sp = sp.nil? ? 2 : sp.to_i
x = x.nil? ? 0 : x.to_i
y = y.nil? ? 0 : x.to_i
zm = zm.nil? ? 1.0 : zm.to_f
value = [id, name, {'event' => @id}, op, x, y, vr, sp, zm]
$game_map.lights[id] = value
$game_map.remove_lights.delete(id)
end
end
#==============================================================================
# ** Spriteset_Map
#------------------------------------------------------------------------------
# Zu dieser Klasse gehören alle Sprites auf dem Bildschirm, Tilesets, Helden, etc.
# Diese Klasse ist in der Klasse Scene_Map enthalten.
#==============================================================================
class Spriteset_Map
#--------------------------------------------------------------------------
# Public Variablen
#--------------------------------------------------------------------------
attr_reader :light_effects
#--------------------------------------------------------------------------
# Objekt-Initialisierung
#--------------------------------------------------------------------------
alias initialize_lighteffects initialize
def initialize
initialize_lighteffects
update_light
end
#--------------------------------------------------------------------------
# Frames updaten
#--------------------------------------------------------------------------
alias update_lighteffects update
def update
update_lighteffects
update_light
end
#--------------------------------------------------------------------------
# Entsorgen
#--------------------------------------------------------------------------
alias dispose_lighteffects dispose
def dispose
dispose_lighteffects
dispose_light unless $scene.is_a?(Scene_Map)
end
#--------------------------------------------------------------------------
# Lichter updaten
#--------------------------------------------------------------------------
def update_light
update_shade
update_effects
update_shade_opacity
end
#--------------------------------------------------------------------------
# Lichteffekt entfernen
#--------------------------------------------------------------------------
def dispose_light
if @light_effect != nil
@light_effect.dispose
@light_effect = nil
@light_values = nil
end
end
#--------------------------------------------------------------------------
# Schatten updaten
#--------------------------------------------------------------------------
def update_shade
if $game_map.light_effect != nil and (@light_effect.nil? or
$game_map.light_effect != @light_values)
@light_effect.dispose if @light_effect != nil
@light_values = $game_map.light_effect
@light_effect = Sprite_Light.new(@light_values, @viewport2)
$game_map.event_list.each {|ev| ev.refresh_lights}
elsif $game_map.light_effect != nil and @light_effect != nil
@light_effect.update
elsif $game_map.light_effect.nil? and @light_effect != nil
dispose_lights
end
end
#--------------------------------------------------------------------------
# Lichteffekte updaten
#--------------------------------------------------------------------------
def update_effects
return if @light_effect.nil? or $game_map.lights.empty?
for key in $game_map.lights.keys
if $game_map.remove_lights.include?(key)
@light_effect.remove_light(key)
$game_map.lights.delete(key)
next
end
next if @light_effect.lights[key] != nil and
@light_effect.lights[key].values == $game_map.lights[key]
@light_effect.create_light($game_map.lights[key])
end
$game_map.remove_lights.clear
end
#--------------------------------------------------------------------------
# Opazität des Schattens updaten
#--------------------------------------------------------------------------
def update_shade_opacity
if $game_map.opacity_change != nil
@light_effect.opacity_change($game_map.opacity_change)
$game_map.opacity_change = nil
end
end
end
#==============================================================================
# ** Interpreter
#------------------------------------------------------------------------------
# Es ist die Klasse, die die Befehle der In-Game Events interpretiert.
# Es wird innerhalb der Klasse Game_Event und Game_System verwendet.
#==============================================================================
class Interpreter
#--------------------------------------------------------------------------
# Schatten kreieren
# op : Opazität
# red : Rot färben
# green : Grün färben
# blue : Blau färben
# type : Art des Effekts
#--------------------------------------------------------------------------
def create_shade(op = 160, red = 0, green = 0, blue = 0, type = 2)
$game_map.light_effect = [type, red, green, blue, op, true]
end
#--------------------------------------------------------------------------
# Opazität des Schattens ändern
# op : Neuer Wert für die Opazität
# speed : Geschwindigkeit der Änderung
#--------------------------------------------------------------------------
def change_opacity(op = 160, speed = 1)
return if $game_map.light_effect.nil?
$game_map.opacity_change = [op, speed]
end
#--------------------------------------------------------------------------
# Licht kreieren für den Spieler
# img : Name der Bilddatei
# id : ID des Lichteffekts
# index : Index
# op : Opazität
# x : Einstellung der Position x
# y : Einstellung der Position y
# var : Variation des Lichts
# speed : Geschwindigkeit der Änderung des Lichts
# zoom : zoom des Lichteffektes
#--------------------------------------------------------------------------
def player_light(img, id, index = 0, op = 160, x = 0, y = 0,
var = 0, speed = 0, zoom = 1.0)
actor = ($legacy_engine["Caterpillar"] and index > 0) ?
$game_player.actors[index - 1] : $game_player
return if actor.nil?
actor = {'actor' => index}
$game_map.lights[id] = [id, img, actor, op, x, y, var, speed, zoom]
end
#--------------------------------------------------------------------------
# Licht kreieren für ein Event
# img : Name der Bilddatei
# id : ID des Lichteffekts
# index : ID des Events
# op : Opazität
# x : Einstellung der Position x
# y : Einstellung der Position y
# var : Variation des Lichts
# speed : Geschwindigkeit der Änderung des Lichts
# zoom : zoom des Lichteffektes
#--------------------------------------------------------------------------
def event_light(img, id, index = 0, op = 160, x = 0, y = 0,
var = 0, speed = 0, zoom = 1.0)
return if $game_map.events[index].nil?
event = {'event' => index}
$game_map.lights[id] = [id, img, event, op, x, y, var, speed, zoom]
end
#--------------------------------------------------------------------------
# Licht kreieren auf der Map
# img : Name der Bilddatei
# id : ID des Lichteffekts
# mx : x-Koordinate des Tiles, die Licht erhält
# my : y-Koordinate des Tiles, die Licht erhält
# op : Opazität
# x : Einstellung der Position x
# y : Einstellung der Position y
# var : Variation des Lichts
# speed : Geschwindigkeit der Änderung des Lichts
# zoom : zoom des Lichteffektes
#--------------------------------------------------------------------------
def map_light(img, id, mx = 0, my = 0, op = 160, x = 0, y = 0,
var = 0, speed = 0, zoom = 1.0)
pos = {:x => mx, :y => my}
$game_map.lights[id] = [id, img, pos, op, x, y, var, speed, zoom]
end
#--------------------------------------------------------------------------
# Lichter entfernen
# id : ID des Lichteffektes
#--------------------------------------------------------------------------
def remove_light(id)
$game_map.remove_lights << id if $game_map.remove_lights != nil
end
#--------------------------------------------------------------------------
# Opazität des Schattens ändern
#--------------------------------------------------------------------------
def shade_opacity
return $game_map.shade_opacity
end
#--------------------------------------------------------------------------
# Taschenlampe des Spielers aktivieren
# index : Index
# opacity : Opazität
#--------------------------------------------------------------------------
def player_lantern_on(index = 0, opacity = 255)
actor = ($legacy_engine["Caterpillar"] and index > 0) ?
$game_player.actors[index - 1] : $game_player
return if actor.nil?
actor.lantern = opacity
end
#--------------------------------------------------------------------------
# Taschenlampe des Spielers deaktivieren
# index : Index
#--------------------------------------------------------------------------
def player_lantern_off(index = 0)
actor = ($legacy_engine["Caterpillar"] and index > 0) ?
$game_player.actors[index - 1] : $game_player
return if actor.nil?
actor.lantern = 0
end
#--------------------------------------------------------------------------
# Taschenlampe des Events aktivieren
# index : Index
# opacity : Opazität
#--------------------------------------------------------------------------
def event_lantern_on(index = 0, opacity = 255)
return if $game_map.events[index].nil?
$game_map.events[index].lantern = opacity
end
#--------------------------------------------------------------------------
# Taschenlampe des Events deaktivieren
# index : Index
#--------------------------------------------------------------------------
def event_lantern_off(index = 0)
return if $game_map.events[index].nil?
$game_map.events[index].lantern = 0
end
end
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
# Diese Klasse verarbeitet die Maps.
#==============================================================================
class Scene_Map
#--------------------------------------------------------------------------
# Public Variablen
#--------------------------------------------------------------------------
attr_reader :spriteset
#--------------------------------------------------------------------------
# Teleport
#--------------------------------------------------------------------------
alias transfer_player_lighteffects transfer_player
def transfer_player
@spriteset.dispose_light
$game_map.clear_lights
transfer_player_lighteffects
end
end
Wichtig: Die Demo damit ihr das Ganze mal in Aktion sehen könnt. Download (http://wachowski.kauschinger.net/downloads/Legacy Engine - Lighting.zip)
Screen:
http://ascare.as.ohost.de/rgss/rgss_lichteffekt.png
PS: Würde mich freuen wenn ihr eure Erfahrungen mit dem Script hier teilt. Auch bin ich noch nicht hinter jede Funktion durchgestiegen. Was ist zB der Unterschied zwischen Simple Window A und B?
PPS: Opazität steht übrigens für Deckkraft.
Dann mal viel Spaß mit der Benutzung, ich zumindest kann's SEHR gut gebrauchen. :)
da er auf der Suche nach einem guten Lichteffekte Script für den XP war. Nach einiger Suche habe ich das Script im gezeigten Video gefunden und
erstmal so gut es ging ins Deutsche übersetzt.
Funktion:
Mit dem Script kann man dynamische Lichteffekte mit Bildern erzeugen. Fackeln, Taschenlampen, Kamine, Licht durch Fenster, Strassenlaternen, Aura, Scheinwerfer uvm.
Kurz noch die Erklärung:
Das Script stammt aus der brasilianischen Community, dort gibt es eine Art SDK, nennt sich Legacy Engine.
Als Teil dieser Engine gibt es ein Script für Lichteffekte.
Teil 1 ist die Basis und wird benötigt für alle Unterscripte der Legacy Engine.
Teil 2 ist das eigentliche Script für die Lichteffekte.
#==============================================================================
# Legacy Engine - Básico (Mapa)
# por Atoa
#==============================================================================
# Atualizações
# v 1.0 - 28 / 06 / 2011 - Script Lançado
# v 1.1 - 05 / 07 / 2011 - Compatibilidade com Loop no Mapa
# v 1.2 - 16 / 07 / 2011 - Compatibilidade com Iluminação
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Este é o script básico para os sistemas de mapa do Legacy Engine, é
# necessário para o funcionamento de todos os scripts de mapa do Legacy Engine.
# Este script em si não oferece nenhuma funcionalidade especial, além do fato
# de re-escrever alguns metodos de forma mais organizada, o que possibilita
# a total compatibilidade entre todos os scripts do sistema.
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Ordem dos scripts:
# Para evitar problemas de compatibilidade, os scripts do Legacy Engine devem
# ser colocados nesta ordem:
#
# - LE | Básico (Mapa)
# - LE | Anti Lag
# - LE | Loop no Mapa
# - LE | Iluminação
# - LE | Multi Frames
# - LE | Movimento Diagonal
# - LE | Controle de Animação
# - LE | Movimento por Pixel
# - LE | Caixas para Colisões
# - LE | Movimento Rotacional
# - LE | Plataformas
# - LE | Salto Livre
# - LE | Caterpillar
# - LE | Corrida
#
# Coloar os scripts em ordens diferentes algumas vezes pode causar bug, por
# isso não é recomendado fazer isto.
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Lista de Métodos re-escritos:
# Scripts que re-escrevam estes mesmos métodos causarão incompatibilidade
# com os scripts do sitema Legacy Engine
#
# class Game_Map
# def passable?
# def update
#
# class Game_Character
# def passable?
# def moveto
# def move_down
# def move_left
# def move_right
# def move_up
# def move_down
# def move_lower_left
# def move_lower_right
# def move_upper_left
# def move_upper_right
# def jump
# def update_move
# def move_toward_player
# def move_away_from_player
# def turn_toward_player
# def turn_away_from_player
#
# class Game_Player < Game_Character
# def update
#
# class Sprite_Character < RPG::Sprite
# def update
#
# class Spriteset_Map
# def initialize
# def dispose
# def update
#
#==============================================================================
$legacy_engine = {} if $legacy_engine.nil?
$legacy_engine["Basic Movement"] = true
#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
# Esta classe engloba o mapa. Isso determina o Scroll e a determinante de
# passagem. Se refere a $game_map para as instâncias desta classe.
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# Determinar se é Passável
# x : coordenada x
# y : coordenada y
# d : direção (0,2,4,6,8,10)
# * 0,10 = determina se todas as direções são passáveis
# self_event : automático (se o Evento for determinado passável)
#--------------------------------------------------------------------------
def passable?(x, y, d, self_event = nil)
return false unless valid?(x, y)
bit = (1 << (d / 2 - 1)) & 0x0f
for event in event_list
result = passable_event(x, y, event, self_event, bit)
return result if result != nil
end
for i in [2, 1, 0]
result = passable_tile(x, y, i, bit)
return result if result != nil
end
return true
end
#--------------------------------------------------------------------------
# Determinar se evento é Passável
# x : coordenada x
# y : coordenada y
# event : evento
# self_event : automático (se o Evento for determinado passável)
# bit : passabilidade
#--------------------------------------------------------------------------
def passable_event(x, y, event, self_event, bit)
if event_tile?(x, y, event, self_event)
return false if @passages[event.tile_id] & bit != 0
return false if @passages[event.tile_id] & 0x0f == 0x0f
return true if @priorities[event.tile_id] == 0
end
return nil
end
#--------------------------------------------------------------------------
# Determinar se evento é um tile
# x : coordenada x
# y : coordenada y
# event : evento
# self_event : automático (se o Evento for determinado passável)
#--------------------------------------------------------------------------
def event_tile?(x, y, event, self_event)
return (event.tile_id >= 0 and event != self_event and
event.x == x and event.y == y and not event.through)
end
#--------------------------------------------------------------------------
# Determinar se tile é Passável
# x : coordenada x
# y : coordenada y
# i : índice
# bit : passabilidade
#--------------------------------------------------------------------------
def passable_tile(x, y, i, bit)
tile_id = data[x, y, i]
return false if tile_id == nil
return false if @passages[tile_id] & bit != 0
return false if @passages[tile_id] & 0x0f == 0x0f
return true if @priorities[tile_id] == 0
return nil
end
#--------------------------------------------------------------------------
# Verificação da coordenada
# x : coordenada X
# y : coordenada Y
#--------------------------------------------------------------------------
def valid?(x, y)
x = round_x(x)
y = round_y(y)
return (x >= 0 and x < width and y >= 0 and y < height)
end
#--------------------------------------------------------------------------
# Determinar as Coordenadas Válidas
# x : coordenada x
# y : coordenada y
#--------------------------------------------------------------------------
def valid_real?(x, y)
return (x >= 0 and x < width * 128 and y >= 0 and y < height * 128)
end
#--------------------------------------------------------------------------
# Atualização do Frame
#--------------------------------------------------------------------------
def update
refresh if $game_map.need_refresh
update_scroll
update_events
update_fog
end
#--------------------------------------------------------------------------
# Atualização do scroll
#--------------------------------------------------------------------------
def update_scroll
if @scroll_rest > 0
distance = 2 ** @scroll_speed
case @scroll_direction
when 2 then scroll_down(distance)
when 4 then scroll_left(distance)
when 6 then scroll_right(distance)
when 8 then scroll_up(distance)
end
@scroll_rest -= distance
end
end
#--------------------------------------------------------------------------
# Atualização dos eventos
#--------------------------------------------------------------------------
def update_events
for event in @events.values
event.update
end
for common_event in @common_events.values
common_event.update
end
end
#--------------------------------------------------------------------------
# Atualização da névoa
#--------------------------------------------------------------------------
def update_fog
@fog_ox -= @fog_sx / 8.0
@fog_oy -= @fog_sy / 8.0
if @fog_tone_duration >= 1
d = @fog_tone_duration
target = @fog_tone_target
@fog_tone.red = (@fog_tone.red * (d - 1) + target.red) / d
@fog_tone.green = (@fog_tone.green * (d - 1) + target.green) / d
@fog_tone.blue = (@fog_tone.blue * (d - 1) + target.blue) / d
@fog_tone.gray = (@fog_tone.gray * (d - 1) + target.gray) / d
@fog_tone_duration -= 1
end
if @fog_opacity_duration >= 1
d = @fog_opacity_duration
@fog_opacity = (@fog_opacity * (d - 1) + @fog_opacity_target) / d
@fog_opacity_duration -= 1
end
end
#--------------------------------------------------------------------------
# Definição de eventos a serem atualizados
#--------------------------------------------------------------------------
def event_list
return events.values
end
#--------------------------------------------------------------------------
# Cálculo de redução da coordenada X padrão
# x : coordenada X
#--------------------------------------------------------------------------
def adjust_x(x)
return x - @display_x
end
#--------------------------------------------------------------------------
# Cálculo de redução da coordenada Y padrão
# y : coordenada Y
#--------------------------------------------------------------------------
def adjust_y(y)
return y - @display_y
end
#--------------------------------------------------------------------------
# Cálculo da coordenada X após o loop
# x : coordenada X
#--------------------------------------------------------------------------
def round_x(x)
return x
end
#--------------------------------------------------------------------------
# Cálculo da coordenada Y após o loop
# y : coordenada Y
#--------------------------------------------------------------------------
def round_y(y)
return y
end
end
#==============================================================================
# ** Game_Character
#------------------------------------------------------------------------------
# Esta classe trata dos Heróis. Esta é usada como uma superclasse para as
# classes Game_Player e Game_Event.
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
# Variáveis Públicas
#--------------------------------------------------------------------------
attr_accessor :sprite
attr_accessor :move_speed
#--------------------------------------------------------------------------
# Determinar se é Passável
# x : coordenada x
# y : coordenada y
# d : direção (0,2,4,6,8)
# * 0 = Determina que todas as direções estão bloqueadas (para pulo)
#--------------------------------------------------------------------------
def passable?(x, y, d)
old_x = $game_map.round_x(x)
old_y = $game_map.round_y(y)
new_x = $game_map.round_x(x + (d == 6 ? 1 : d == 4 ? -1 : 0))
new_y = $game_map.round_y(y + (d == 2 ? 1 : d == 8 ? -1 : 0))
return false unless $game_map.valid?(new_x, new_y)
return true if @through
return false unless $game_map.passable?(old_x, old_y, d, self)
return false unless $game_map.passable?(new_x, new_y, 10 - d)
for event in $game_map.event_list
if event.x == new_x and event.y == new_y
unless event.through
return false if self != $game_player or event.character_name != ""
end
end
end
if $game_player.x == new_x and $game_player.y == new_y
return false if @character_name != "" and not $game_player.through
end
return true
end
#--------------------------------------------------------------------------
# Determinar se está se Movendo
#--------------------------------------------------------------------------
def moving?
return (@real_x != @x * 128 + @move_x or @real_y != @y * 128 + @move_y)
end
#--------------------------------------------------------------------------
# Mover para uma Posição Designada
# x : coordenada x
# y : coordenada y
#--------------------------------------------------------------------------
def moveto(x, y)
@x = x % $game_map.width
@y = y % $game_map.height
@real_x = @x * 128
@real_y = @y * 128
@prelock_direction = 0
@move_x = 0
@move_y = 0
end
#--------------------------------------------------------------------------
# Mover Abaixo
# turn_enabled : flag que permite uma troca de direção
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def move_down(turn_enabled = true, steping = false)
turn_down if turn_enabled
if passable_down?
step_down
else
check_event_trigger_touch(@x, @y + 1)
end
end
#--------------------------------------------------------------------------
# Mover à Esquerda
# turn_enabled : flag que permite uma troca de direção
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def move_left(turn_enabled = true, steping = false)
turn_left if turn_enabled
if passable_left?
step_left
else
check_event_trigger_touch(@x - 1, @y)
end
end
#--------------------------------------------------------------------------
# Mover à Direita
# turn_enabled : flag que permite uma troca de direção
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def move_right(turn_enabled = true, steping = false)
turn_right if turn_enabled
if passable_right?
step_right
else
check_event_trigger_touch(@x + 1, @y)
end
end
#--------------------------------------------------------------------------
# Mover Acima
# turn_enabled : flag que permite uma troca de direção
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def move_up(turn_enabled = true, steping = false)
turn_up if turn_enabled
if passable_up?
step_up
else
check_event_trigger_touch(@x, @y - 1)
end
end
#--------------------------------------------------------------------------
# Mover Esquerda-Abaixo
# turn_enabled : flag que permite uma troca de direção
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def move_lower_left(turn_enabled = true, steping = false)
turn_lower_left if turn_enabled
if passable_lower_left?
step_lower_left
elsif passable_left?
step_left
elsif passable_down?
step_down
else
check_event_trigger_touch(@x - 1, @y + 1)
end
end
#--------------------------------------------------------------------------
# Mover Direita-Abaixo
# turn_enabled : flag que permite uma troca de direção
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def move_lower_right(turn_enabled = true, steping = false)
turn_lower_right if turn_enabled
if passable_lower_right?
step_lower_right
elsif passable_right?
step_right
elsif passable_down?
step_down
else
check_event_trigger_touch(@x + 1, @y + 1)
end
end
#--------------------------------------------------------------------------
# Mover Esquerda-Acima
# turn_enabled : flag que permite uma troca de direção
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def move_upper_left(turn_enabled = true, steping = false)
turn_upper_left if turn_enabled
if passable_upper_left?
step_upper_left
elsif passable_left?
step_left
elsif passable_up?
step_up
else
check_event_trigger_touch(@x - 1, @y - 1)
end
end
#--------------------------------------------------------------------------
# Mover Direita-Acima
# turn_enabled : flag que permite uma troca de direção
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def move_upper_right(turn_enabled = true, steping = false)
turn_upper_right if turn_enabled
if passable_upper_right?
step_upper_right
elsif passable_right?
step_right
elsif passable_up?
step_up
else
check_event_trigger_touch(@x + 1, @y - 1)
end
end
#--------------------------------------------------------------------------
# Pular
# x_plus : valor a mais da coordenada x
# y_plus : valor a mais da coordenada y
#--------------------------------------------------------------------------
def jump(x_plus, y_plus)
if x_plus != 0 or y_plus != 0
if x_plus.abs > y_plus.abs
x_plus < 0 ? turn_left : turn_right
else
y_plus < 0 ? turn_up : turn_down
end
end
new_x = @x + x_plus
new_y = @y + y_plus
if passable_jump?(new_x, new_y, x_plus, y_plus)
jump_move(new_x, new_y, x_plus, y_plus)
end
end
#--------------------------------------------------------------------------
# Determinar Passabilidade para saltos
# new_x : nova coordenada x
# new_y : nova coordenada y
# x_plus : modificador da coordenada x
# y_plus : modificador da coordenada y
#--------------------------------------------------------------------------
def passable_jump?(new_x, new_y, x_plus, y_plus)
return true if x_plus == 0 and y_plus == 0
return true if passable?(new_x, new_y, 0)
return false
end
#--------------------------------------------------------------------------
#
# new_x : nova coordenada x
# new_y : nova coordenada y
# x_plus : modificador da coordenada x
# y_plus : modificador da coordenada y
#--------------------------------------------------------------------------
def jump_move(new_x, new_y, x_plus, y_plus)
straighten
@x = new_x
@y = new_y
distance = Math.sqrt(x_plus * x_plus + y_plus * y_plus).round
@jump_peak = 10 + distance - @move_speed
@jump_count = @jump_peak * 2
@stop_count = 0
end
#--------------------------------------------------------------------------
# Determinar passabilidade Abaixo
#--------------------------------------------------------------------------
def passable_down?
return passable?(@x, @y, 2)
end
#--------------------------------------------------------------------------
# Determinar passabilidade à Esquerda
#--------------------------------------------------------------------------
def passable_left?
return passable?(@x, @y, 4)
end
#--------------------------------------------------------------------------
# Determinar passabilidade à Direita
#--------------------------------------------------------------------------
def passable_right?
return passable?(@x, @y, 6)
end
#--------------------------------------------------------------------------
# Determinar passabilidade Acima
#--------------------------------------------------------------------------
def passable_up?
return passable?(@x, @y, 8)
end
#--------------------------------------------------------------------------
# Determinar passabilidade Esquerda-Abaixo
#--------------------------------------------------------------------------
def passable_lower_left?
return ((passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) and
(passable?(@x, @y, 4) and passable?(@x - 1, @y, 2)))
end
#--------------------------------------------------------------------------
# Determinar passabilidade Direita-Abaixo
#--------------------------------------------------------------------------
def passable_lower_right?
return ((passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) and
(passable?(@x, @y, 6) and passable?(@x + 1, @y, 2)))
end
#--------------------------------------------------------------------------
# Determinar passabilidade Esquerda-Acima
#--------------------------------------------------------------------------
def passable_upper_left?
return ((passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) and
(passable?(@x, @y, 4) and passable?(@x - 1, @y, 8)))
end
#--------------------------------------------------------------------------
# Determinar passabilidade Esquerda-Acima
#--------------------------------------------------------------------------
def passable_upper_right?
return ((passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) and
(passable?(@x, @y, 6) and passable?(@x + 1, @y, 8)))
end
#--------------------------------------------------------------------------
# Passo Abaixo
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def step_down(steping = false)
turn_down
@y += 1
increase_steps
end
#--------------------------------------------------------------------------
# Passo à Esquerda
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def step_left(steping = false)
turn_left
@x -= 1
increase_steps
end
#--------------------------------------------------------------------------
# Passo à Direita
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def step_right(steping = false)
turn_right
@x += 1
increase_steps
end
#--------------------------------------------------------------------------
# Passo Acima
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def step_up(steping = false)
turn_up
@y -= 1
increase_steps
end
#--------------------------------------------------------------------------
# Passo Esquerda-Abaixo
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def step_lower_left(steping = false)
turn_lower_left
@x -= 1
@y += 1
increase_steps
end
#--------------------------------------------------------------------------
# Passo Direita-Abaixo
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def step_lower_right(steping = false)
turn_lower_right
@x += 1
@y += 1
increase_steps
end
#--------------------------------------------------------------------------
# Passo Esquerda-Acima
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def step_upper_left(steping = false)
turn_upper_left
@x -= 1
@y -= 1
increase_steps
end
#--------------------------------------------------------------------------
# Passo Direita-Acima
# steping : flag que indica número de passos
#--------------------------------------------------------------------------
def step_upper_right(steping = false)
turn_upper_right
@x += 1
@y -= 1
increase_steps
end
#--------------------------------------------------------------------------
# Olhar Esquerda-Abaixo
#--------------------------------------------------------------------------
def turn_lower_left
unless @direction_fix
@direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
@stop_count = 0
end
end
#--------------------------------------------------------------------------
# Olhar Direita-Abaixo
#--------------------------------------------------------------------------
def turn_lower_right
unless @direction_fix
@direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
@stop_count = 0
end
end
#--------------------------------------------------------------------------
# Olhar Esquerda-Acima
#--------------------------------------------------------------------------
def turn_upper_left
unless @direction_fix
@direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
@stop_count = 0
end
end
#--------------------------------------------------------------------------
# Olhar Direita-Acima
#--------------------------------------------------------------------------
def turn_upper_right
unless @direction_fix
@direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
@stop_count = 0
end
end
#--------------------------------------------------------------------------
# Atualização do Frame
#--------------------------------------------------------------------------
def update
fix_position
if jumping?
update_jump
elsif moving?
update_move
else
update_stop
end
update_animation
return @wait_count -= 1 if @wait_count > 0
return move_type_custom if @move_route_forcing
return if @starting or lock?
movement_update
end
#--------------------------------------------------------------------------
# Atualização da animação
#--------------------------------------------------------------------------
def update_animation
if @anime_count > 18 - @move_speed * 2
if not @step_anime and @stop_count > 0
@pattern = @original_pattern
else
@pattern = (@pattern + 1) % 4
end
@anime_count = 0
end
end
#--------------------------------------------------------------------------
# Atualização do movimento
#--------------------------------------------------------------------------
def movement_update
if update_frequency and not moving?
case @move_type
when 1 then move_type_random
when 2 then move_type_toward_player
when 3 then move_type_custom
end
end
end
#--------------------------------------------------------------------------
# Verificação de frequencia de movimento
#--------------------------------------------------------------------------
def update_frequency
return (@stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency))
end
#--------------------------------------------------------------------------
# Definição de distancia do movimento
#--------------------------------------------------------------------------
def distance
return (2 ** @move_speed).to_i
end
#--------------------------------------------------------------------------
# Atualização do Frame (Movimento)
#--------------------------------------------------------------------------
def update_move
postion_update
anime_count_update
end
#--------------------------------------------------------------------------
# Atualização da Posição Atual
#--------------------------------------------------------------------------
def postion_update
move_x = (@x * 128 + @move_x)
move_y = (@y * 128 + @move_y)
@real_y = [@real_y + distance, move_y].min.to_i if move_y > @real_y
@real_x = [@real_x - distance, move_x].max.to_i if move_x < @real_x
@real_x = [@real_x + distance, move_x].min.to_i if move_x > @real_x
@real_y = [@real_y - distance, move_y].max.to_i if move_y < @real_y
end
#--------------------------------------------------------------------------
# Correção de Posição
#--------------------------------------------------------------------------
def fix_position
if @x != $game_map.round_x(@x)
plus = $game_map.round_x(@x) - @x
@x += plus
@real_x += plus * 128
end
if @y != $game_map.round_y(@y)
plus = $game_map.round_y(@y) - @y
@y += plus
@real_y += plus * 128
end
end
#--------------------------------------------------------------------------
# Coordenada X da tela
#--------------------------------------------------------------------------
def screen_x
return ($game_map.adjust_x(@real_x) + 3) / 4 + 16
end
#--------------------------------------------------------------------------
# Coordenada Y da tela
#--------------------------------------------------------------------------
def screen_y
y = ($game_map.adjust_y(@real_y) + 3) / 4 + 32
if @jump_count >= @jump_peak
n = @jump_count - @jump_peak
else
n = @jump_peak - @jump_count
end
return y - (@jump_peak * @jump_peak - n * n) / 2
end
#--------------------------------------------------------------------------
# Selecionar a Coordenada Z da Tela
# height : altura do Peronagem
#--------------------------------------------------------------------------
def screen_z(height = 0)
return 999 if @always_on_top
z = ($game_map.adjust_y(@real_y) + 3) / 4 + 32
if @tile_id > 0
return z + $game_map.priorities[@tile_id] * 32
else
return z + ((height > 32) ? 31 : 0)
end
end
#--------------------------------------------------------------------------
# Atualização do Contador de Animação
#--------------------------------------------------------------------------
def anime_count_update
if @walk_anime
@anime_count += 1.5
elsif @step_anime
@anime_count += 1
end
end
#--------------------------------------------------------------------------
# Distância X do character
# character : Personagem
#--------------------------------------------------------------------------
def distance_x_from_character(character)
sx = @x - character.x
return sx
end
#--------------------------------------------------------------------------
# Distância Y do character
# character : Personagem
#--------------------------------------------------------------------------
def distance_y_from_character(character)
sy = @y - character.y
return sy
end
#--------------------------------------------------------------------------
# Seguir herói
#--------------------------------------------------------------------------
def move_toward_player
sx = distance_x_from_character($game_player)
sy = distance_y_from_character($game_player)
if sx != 0 or sy != 0
if sx.abs > sy.abs
sx > 0 ? move_left : move_right
sy > 0 ? move_up : move_down if not moving? and sy != 0
else
sy > 0 ? move_up : move_down
sx > 0 ? move_left : move_right if not moving? and sx != 0
end
end
end
#--------------------------------------------------------------------------
# Fugir do herói
#--------------------------------------------------------------------------
def move_away_from_player
sx = distance_x_from_character($game_player)
sy = distance_y_from_character($game_player)
if sx != 0 or sy != 0
if sx.abs > sy.abs
sx > 0 ? move_right : move_left
sy > 0 ? move_down : move_up if not moving? and sy != 0
else
sy > 0 ? move_down : move_up
sx > 0 ? move_right : move_left if not moving? and sx != 0
end
end
end
#--------------------------------------------------------------------------
# Olhar para o Herói
#--------------------------------------------------------------------------
def turn_toward_player
sx = distance_x_from_character($game_player)
sy = distance_y_from_character($game_player)
return if sx == 0 and sy == 0
if sx.abs > sy.abs
sx > 0 ? turn_left : turn_right
else
sy > 0 ? turn_up : turn_down
end
end
#--------------------------------------------------------------------------
# Girar Herói (Contrário)
#--------------------------------------------------------------------------
def turn_away_from_player
sx = distance_x_from_character($game_player)
sy = distance_y_from_character($game_player)
return if sx == 0 and sy == 0
if sx.abs > sy.abs
sx > 0 ? turn_right : turn_left
else
sy > 0 ? turn_down : turn_up
end
end
#--------------------------------------------------------------------------
# Determinar número de quadros
#--------------------------------------------------------------------------
def frames
return 4
end
#--------------------------------------------------------------------------
# Definição de Largura
#--------------------------------------------------------------------------
def box_width
@box_width = 128
return @box_width
end
#--------------------------------------------------------------------------
# Definição de Altura
#--------------------------------------------------------------------------
def box_height
@box_height = 128
return @box_height
end
#--------------------------------------------------------------------------
# Determinar Jogador
#--------------------------------------------------------------------------
def player?
return false
end
#--------------------------------------------------------------------------
# Determinar Evento
#--------------------------------------------------------------------------
def event?
return false
end
end
#==============================================================================
# ** Game_Player
#------------------------------------------------------------------------------
# Esta classe engloba o Jogador. Suas funções incluem a inicialização das
# determinantes dos eventos e o scroll do mapa. Se refere a "$game_player" para
# as instâncias desta classe.
#==============================================================================
class Game_Player < Game_Character
#--------------------------------------------------------------------------
# Atualização do Frame
#--------------------------------------------------------------------------
def update
last_real_postion
move_by_input
super
update_scroll
update_nonmoving
end
#--------------------------------------------------------------------------
# Definição da ultima posição
#--------------------------------------------------------------------------
def last_real_postion
@last_moving = moving?
@last_real_x = @real_x
@last_real_y = @real_y
end
#--------------------------------------------------------------------------
# Movimento do personagem
#--------------------------------------------------------------------------
def move_by_input
return unless movable?
return if $game_system.map_interpreter.running?
case Input.dir4
when 2 then move_down
when 4 then move_left
when 6 then move_right
when 8 then move_up
end
end
#--------------------------------------------------------------------------
# É possível mover?
#--------------------------------------------------------------------------
def movable?
return false if moving?
return false if @move_route_forcing
return false if $game_temp.message_window_showing
return true
end
#--------------------------------------------------------------------------
# Processo de scroll (movimento de tela no mapa)
#--------------------------------------------------------------------------
def update_scroll
ax1 = $game_map.adjust_x(@last_real_x)
ay1 = $game_map.adjust_y(@last_real_y)
ax2 = $game_map.adjust_x(@real_x)
ay2 = $game_map.adjust_y(@real_y)
$game_map.scroll_down(ay2 - ay1) if ay2 > ay1 and ay2 > CENTER_Y
$game_map.scroll_left(ax1 - ax2) if ax2 < ax1 and ax2 < CENTER_X
$game_map.scroll_right(ax2 - ax1) if ax2 > ax1 and ax2 > CENTER_X
$game_map.scroll_up(ay1 - ay2) if ay2 < ay1 and ay2 < CENTER_Y
end
#--------------------------------------------------------------------------
# Processo de não-movimento
# last_moving : último movimento do jogador
#--------------------------------------------------------------------------
def update_nonmoving
return if moving?
if @last_moving
result = check_event_trigger_here([1,2])
update_encounter unless result
end
if Input.trigger?(Input::C)
check_event_trigger_here([0])
check_event_trigger_there([0,1,2])
end
end
#--------------------------------------------------------------------------
# Processo de encontros aleatórios
#--------------------------------------------------------------------------
def update_encounter
return if $DEBUG and Input.press?(Input::CTRL)
@encounter_count -= 1 if @encounter_count > 0
end
#--------------------------------------------------------------------------
# Determinar Jogador
#--------------------------------------------------------------------------
def player?
return true
end
#--------------------------------------------------------------------------
# Determinar Evento
#--------------------------------------------------------------------------
def event?
return false
end
end
#==============================================================================
# ** Game_Event
#------------------------------------------------------------------------------
# Esta é a classe que engloba os eventos. O que inclui as funções nas páginas de
# evento alterando estas através das Condições de Evento, e faz funcionar os
# Processos Paralelos. Esta classe está inserida na classe Game_Map.
#==============================================================================
class Game_Event < Game_Character
#--------------------------------------------------------------------------
# Nome do Evento
#--------------------------------------------------------------------------
def name
return @event.name
end
#--------------------------------------------------------------------------
# Determinar Jogador
#--------------------------------------------------------------------------
def player?
return false
end
#--------------------------------------------------------------------------
# Determinar Evento
#--------------------------------------------------------------------------
def event?
return true
end
#--------------------------------------------------------------------------
# Retornar lista de comentários do evento
#--------------------------------------------------------------------------
def comments
return [] if @page.nil? or @page.list.nil? or
@page.list.size <= 0
comment_list = []
for item in @page.list
next if item.nil?
next unless item.code == 108 or item.code == 408
comment_list << item.parameters[0]
end
return comment_list
end
end
#==============================================================================
# ** Sprite_Character
#------------------------------------------------------------------------------
# Esta é o script que exibe os sprites dos Heróis. Levando em consideração
# a classe Game_Character fazendo correções quando necessário.
#==============================================================================
class Sprite_Character < RPG::Sprite
#--------------------------------------------------------------------------
# Atualização do Frame
#--------------------------------------------------------------------------
def update
super
update_character
update_rect
update_misc
update_battle_animation
end
#--------------------------------------------------------------------------
# Atualização do gráfico do personagem
#--------------------------------------------------------------------------
def update_character
return unless update_character?
update_character_info
if @tile_id >= 384
set_tile_bitmap
else
set_character_bitmap
end
end
#--------------------------------------------------------------------------
# Determinar atualização do gráfico do personagem
#--------------------------------------------------------------------------
def update_character?
return true if @tile_id != @character.tile_id
return true if @character_name != @character.character_name
return true if @character_hue != @character.character_hue
return false
end
#--------------------------------------------------------------------------
# Atualização das informações do personagem
#--------------------------------------------------------------------------
def update_character_info
@tile_id = @character.tile_id
@character_name = @character.character_name
@character_hue = @character.character_hue
end
#--------------------------------------------------------------------------
# Determinar bitmap se for um tile
#--------------------------------------------------------------------------
def set_tile_bitmap
self.bitmap = RPG::Cache.tile($game_map.tileset_name,
@tile_id, @character.character_hue)
self.src_rect.set(0, 0, 32, 32)
self.ox = 16
self.oy = 32
end
#--------------------------------------------------------------------------
# Determinar bitmap se for um personagem
#--------------------------------------------------------------------------
def set_character_bitmap
self.bitmap = RPG::Cache.character(@character.character_name,
@character.character_hue)
@cw = bitmap.width / @character.frames
@ch = bitmap.height / 4
self.ox = @cw / 2
self.oy = @ch
end
#--------------------------------------------------------------------------
# Determinar direção
#--------------------------------------------------------------------------
def direction
return @character.direction
end
#--------------------------------------------------------------------------
# Atualização do retangulo do bitmap
#--------------------------------------------------------------------------
def update_rect
if @tile_id == 0
sx = @character.pattern * @cw
sy = (direction - 2) / 2 * @ch
self.src_rect.set(sx, sy, @cw, @ch)
end
end
#--------------------------------------------------------------------------
# Atualizações variadas
#--------------------------------------------------------------------------
def update_misc
self.visible = (not @character.transparent)
self.x = @character.screen_x
self.y = @character.screen_y
self.z = @character.screen_z(@ch)
self.opacity = @character.opacity
self.blend_type = @character.blend_type
self.bush_depth = @character.bush_depth
end
#--------------------------------------------------------------------------
# Atualização da animação
#--------------------------------------------------------------------------
def update_battle_animation
if @character.animation_id != 0
animation = $data_animations[@character.animation_id]
animation(animation, true)
@character.animation_id = 0
end
end
end
#==============================================================================
# ** Spriteset_Map
#------------------------------------------------------------------------------
# Esta classe engloba todos os sprites da tela, Tilesets, Heróis, etc
# Esta classe está inserida na classe Scene_Map.
#==============================================================================
class Spriteset_Map
#--------------------------------------------------------------------------
# Inicialização do objeto
#--------------------------------------------------------------------------
def initialize
create_viewports
create_tilemap
create_panorama
create_fog
create_characters
create_weather
create_pictures
create_timer
update
end
#--------------------------------------------------------------------------
# Criação dos viewports
#--------------------------------------------------------------------------
def create_viewports
@viewport1 = Viewport.new(0, 0, 640, 480)
@viewport2 = Viewport.new(0, 0, 640, 480)
@viewport3 = Viewport.new(0, 0, 640, 480)
@viewport2.z = 200
@viewport3.z = 5000
end
#--------------------------------------------------------------------------
# Criação dos tiles
#--------------------------------------------------------------------------
def create_tilemap
@tilemap = Tilemap.new(@viewport1)
@tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name)
for i in 0..6
autotile_name = $game_map.autotile_names[i]
@tilemap.autotiles[i] = RPG::Cache.autotile(autotile_name)
end
@tilemap.map_data = $game_map.data
@tilemap.priorities = $game_map.priorities
end
#--------------------------------------------------------------------------
# Criação do panorama
#--------------------------------------------------------------------------
def create_panorama
@panorama = Plane.new(@viewport1)
@panorama.z = -1000
end
#--------------------------------------------------------------------------
# Criação da névoa
#--------------------------------------------------------------------------
def create_fog
@fog = Plane.new(@viewport1)
@fog.z = 3000
end
#--------------------------------------------------------------------------
# Criação dos characters
#--------------------------------------------------------------------------
def create_characters
@character_sprites = []
for i in $game_map.events.keys.sort
sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
@character_sprites.push(sprite)
end
@character_sprites.push(Sprite_Character.new(@viewport1, $game_player))
end
#--------------------------------------------------------------------------
# Criação do clima
#--------------------------------------------------------------------------
def create_weather
@weather = RPG::Weather.new(@viewport1)
end
#--------------------------------------------------------------------------
# Criação das pictures
#--------------------------------------------------------------------------
def create_pictures
@picture_sprites = []
for i in 1..50
@picture_sprites.push(Sprite_Picture.new(@viewport2,
$game_screen.pictures[i]))
end
end
#--------------------------------------------------------------------------
# Criação do timer
#--------------------------------------------------------------------------
def create_timer
@timer_sprite = Sprite_Timer.new
end
#--------------------------------------------------------------------------
# Dispose
#--------------------------------------------------------------------------
def dispose
dispose_tilemap
dispose_panorama
dispose_fog
dispose_characters
dispose_weather
dispose_pictures
dispose_timer
dispose_viewports
end
#--------------------------------------------------------------------------
# Dispose dos tiles
#--------------------------------------------------------------------------
def dispose_tilemap
@tilemap.tileset.dispose
for i in 0..6
@tilemap.autotiles[i].dispose
end
@tilemap.dispose
end
#--------------------------------------------------------------------------
# Dispose do panorama
#--------------------------------------------------------------------------
def dispose_panorama
@panorama.dispose
end
#--------------------------------------------------------------------------
# Dispose da névoa
#--------------------------------------------------------------------------
def dispose_fog
@fog.dispose
end
#--------------------------------------------------------------------------
# Dispose dos characters
#--------------------------------------------------------------------------
def dispose_characters
for sprite in @character_sprites
sprite.dispose
end
end
#--------------------------------------------------------------------------
# Dispose dos tempos
#--------------------------------------------------------------------------
def dispose_weather
@weather.dispose
end
#--------------------------------------------------------------------------
# Dispose das pictures
#--------------------------------------------------------------------------
def dispose_pictures
for sprite in @picture_sprites
sprite.dispose
end
end
#--------------------------------------------------------------------------
# Dispose do timer
#--------------------------------------------------------------------------
def dispose_timer
@timer_sprite.dispose
end
#--------------------------------------------------------------------------
# Dispose dos viewports
#--------------------------------------------------------------------------
def dispose_viewports
@viewport1.dispose
@viewport2.dispose
@viewport3.dispose
end
#--------------------------------------------------------------------------
# Atualização da tela
#--------------------------------------------------------------------------
def update
update_tilemap
update_panorama
update_fog
update_characters
update_weather
update_pictures
update_timer
update_viewports
end
#--------------------------------------------------------------------------
# Atualização dos tiles
#--------------------------------------------------------------------------
def update_tilemap
@tilemap.ox = $game_map.display_x / 4
@tilemap.oy = $game_map.display_y / 4
@tilemap.update
end
#--------------------------------------------------------------------------
# Atualização do panorama
#--------------------------------------------------------------------------
def update_panorama
if @panorama_name != $game_map.panorama_name or
@panorama_hue != $game_map.panorama_hue
@panorama_name = $game_map.panorama_name
@panorama_hue = $game_map.panorama_hue
if @panorama.bitmap != nil
@panorama.bitmap.dispose
@panorama.bitmap = nil
end
if @panorama_name != ""
@panorama.bitmap = RPG::Cache.panorama(@panorama_name, @panorama_hue)
end
Graphics.frame_reset
end
@panorama.ox = $game_map.display_x / 8
@panorama.oy = $game_map.display_y / 8
end
#--------------------------------------------------------------------------
# Atualização da névoa
#--------------------------------------------------------------------------
def update_fog
if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue
@fog_name = $game_map.fog_name
@fog_hue = $game_map.fog_hue
if @fog.bitmap != nil
@fog.bitmap.dispose
@fog.bitmap = nil
end
if @fog_name != ""
@fog.bitmap = RPG::Cache.fog(@fog_name, @fog_hue)
end
Graphics.frame_reset
end
@fog.zoom_x = $game_map.fog_zoom / 100.0
@fog.zoom_y = $game_map.fog_zoom / 100.0
@fog.opacity = $game_map.fog_opacity
@fog.blend_type = $game_map.fog_blend_type
@fog.ox = $game_map.display_x / 4 + $game_map.fog_ox
@fog.oy = $game_map.display_y / 4 + $game_map.fog_oy
@fog.tone = $game_map.fog_tone
end
#--------------------------------------------------------------------------
# Atualização dos characters
#--------------------------------------------------------------------------
def update_characters
for sprite in @character_sprites
sprite.update
end
end
#--------------------------------------------------------------------------
# Atualização do clima
#--------------------------------------------------------------------------
def update_weather
@weather.type = $game_screen.weather_type
@weather.max = $game_screen.weather_max
@weather.ox = $game_map.display_x / 4
@weather.oy = $game_map.display_y / 4
@weather.update
end
#--------------------------------------------------------------------------
# Atualização das pictures
#--------------------------------------------------------------------------
def update_pictures
for sprite in @picture_sprites
sprite.update
end
end
#--------------------------------------------------------------------------
# Atualização do timer
#--------------------------------------------------------------------------
def update_timer
@timer_sprite.update
end
#--------------------------------------------------------------------------
# Atualização dos viewports
#--------------------------------------------------------------------------
def update_viewports
@viewport1.tone = $game_screen.tone
@viewport1.ox = $game_screen.shake
@viewport3.color = $game_screen.flash_color
@viewport1.update
@viewport3.update
end
end
#==============================================================================
# Legacy Engine - Lighting
# von Atoa
#==============================================================================
# Updates
# v 1.0 - 09 / 03 / 2012 - Deutsche Übersetzung von Ascare
# v 1.0 - 16 / 07 / 2011 - Script veröffentlicht
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Dieses Skript ermöglicht es, verschiedene Lichteffekte auf Maps hinzuzufügen.
# Aber dies funktioniert anders als die meisten anderen Skripte dieser Art.
# In der Regel werden Lichteffekte einfach durch Bilder dargestellt, jedoch
# wird das Licht bei Verdunkelung auch den Lichteffekt beeinflussen,
# da sie nicht auf einer Ebene mit der Schattenebene ist.
# Dieses Skript wirkt sich anders aus, indem Sie die Bilder des Lichteffekts
# auf die gleiche Ebene zeichnet wie die des Schattens. Dadurch bleibt das
# Licht von der Verdunkelung der Map unbeeinflusst und lässt fortgeschrittene
# Lichteffekte zu.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# BILDER FÜR DEN LICHTEFFEKT:
# Die Lichteffekte müssen in den Ordner Graphics/Lights. In der Demo sind
# dort Bilder als Beispiele gespeichert. Diese können auch farblich verändert
# werden um den Lichteffekt zu studieren.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# EINEN LICHTEFFEKT ERSTELLEN
# Zunächst einmal ist es nötig den Schatten als neue Ebene zu kreieren.
# Auf diesem werden dann die Lichter eingefügt.
# Dafür sollte man per Call Script Funktion folgendes aufrufen:
# create_shade(OPAZITÄT, ROT, GRÜN, BLAU, TYP)
# OPAZITÄT : Grad der Opazität des Schatten zwischen 0 und 255. Standard 160.
# ROT : Rotton zwischen 0 und 255. Standard 0.
# GRÜN : Grünton zwischen 0 und 255. Standard 0.
# BLAU : Blauton zwischen 0 und 255. Standard 0.
# TYP : Art des Effekts. 0 = normal, 1 = additiv, 2 = invertiert.
# Standard ist 2 (Farben umgekehrt)
#
# Ist die Schattenebene erstellt, gibt es mehrere Möglichkeiten
# das Licht zu definieren.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# LICHT DURCH KOMMENTARE
# Ein Lichteffekt kann in einem Kommentar eingesetzt werden.
# Diese Lichter sind solange aktiv, wie die Event-Seite, die das Kommentar
# enthält, ebenfalls aktiv ist.
# Als Kommntar geht das wie folgt:
# LIGHT (a) o v s x y z
# a : Name der Bilddatei, in Klammern.
# o : Opazität zwischen 0 und 255.
# v : Grad der Variation der Opazität zwischen 0 und 255.
# s : Geschwindigkeit der Änderung der Opazität zwischen 0 und 255.
# x : Einstellung der Position x
# y : Einstellung der Position y
# z : zoom
# Bsp.:
# LIGHT (licht weiß) 160 0 0 0 5 1
#
# Es gibt auch einige vordefinierte Werte für einen Kommentar.
# SIMPLE LIGHT Opazität
# SIMPLE LAMP Opazität
# SIMPLE TORCH Opazität
# SIMPLE WINDOW A Opazität
# SIMPLE WINDOW B Opazität
# FLASH LIGHT Opazität
# FLASH LAMP Opazität
# FLASH TORCH Opazität
# FLASH WINDOW A Opazität
# FLASH WINDOW B Opazität
# LANTERN Opazität
# Die Opazität ist die Deckkraft des Lichts und kann auch hier ausgelassen
# werden. Der Befehl "SIMPLE" erzeugt ein einfaches Licht, der Befehl
# "FLASH" erzeugt ein pulsierendes Licht. Und LANTERN aktiviert eine Lampe.
# (ein Licht direkt vor dem Charakter).
#
# Bsp.:
# SIMPLE LIGHT
# FLASH TORCH 200
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# LICHT PER SCRIPT
# Der Lichteffekt kann auch per Script Befehl aufgerufen werden. Der Effekt ist
# aber nur solange aktiv, bis ein Mapwechsel stattfindet. Auf jeder neuen Map
# muss das Licht durch einen neuen Scriptaufruf erzeugt werden.
#
# Es gibt dafür zwei Scriptbefehle, jeweils für Charaktere und für Events.
# player_light(img, id, index, o, x, y, v, s, z) # Für Charaktere
# event_light(img, id, index, o, x, y, v, s, z) # Für Events
# img : Name der Bilddatei
# id : ID des Lichteffekts um jedes Licht zu identifizieren, modifizieren
# oder zu entfernen. Verschiedene Lichter sollten auch unterschiedliche
# IDs haben.
# index : Dies ist die Index ID und nur nötig, wenn man das Hintereinander-
# Laufen Script der 'Legacy Engine' verwendet. Standardgemäß ist dies 0.
# o : Opazität zwischen 0 und 255.
# x : Einstellung der Position x
# y : Einstellung der Position y
# v : Grad der Variation der Opazität zwischen 0 und 255.
# s : Geschwindigkeit der Änderung der Opazität zwischen 0 und 255.
# z : zoom
# Alle Werte nach index können auch ausgelassen werden.
# Bsp.:
# player_light("Licht", 1, 0, 200)
# event_light("Fackel", 2, 5, 200, 0, 0, 50, 3)
#
# Es ist auch möglich ein Licht nur einem Tile zuzuordnen. Der Befehl dazu:
# map_light(img, id, mx, my, o, x, y, v, s, z)
# img : Name der Bilddatei
# id : ID des Lichteffekts um jedes Licht zu identifizieren, modifizieren
# oder zu entfernen. Verschiedene Lichter sollten auch unterschiedliche
# IDs haben.
# mx : X-Koordinate der Map
# my : Y-Koordinate der Map
# x : Einstellung der Position x
# y : Einstellung der Position y
# v : Grad der Variation der Opazität zwischen 0 und 255.
# s : Geschwindigkeit der Änderung der Opazität zwischen 0 und 255.
# z : zoom
# Alle Werte nach (index?) können auch ausgelassen werden.
# Bsp.:
# map_light("Lampe", 3, 5, 6, 225)
#
# TASCHENLAMPEN sind Lichter die sich automatisch vor dem Spieler/Event bewegen.
# Folgende Befehle sind zum (de)aktivieren der Taschnelampe:
# player_lantern_on(index, opacity) # Taschenlampe für Spieler aktivieren
# event_lantern_on(index, opacity) # Taschenlampe für Event aktivieren
# player_lantern_off(index) # Taschenlampe für Spieler deaktivieren
# event_lantern_off(index) # Taschenlampe für Event deaktivieren
# index : Dies ist die Index ID des Events. Für den Spieler nur nötig, wenn
# man das Hintereinander-Laufen Script der 'Legacy Engine' verwendet.
# Standardgemäß ist dies 0.
# opacity : Opazität zwischen 0 und 255.
#
# Der Lichteffekt kann durch einen einfachen Befehl deaktiviert werden:
# remove_light(id)
# id : Die ID des Lichteffekts der zuvor angegeben wurde.
#
#==============================================================================
$legacy_engine = {} if $legacy_engine.nil?
$legacy_engine["Light Effect"] = true
#==============================================================================
# ** RPG::Cache
#------------------------------------------------------------------------------
# Modul das Bitmaps lädt und speichert
#==============================================================================
module RPG::Cache
#--------------------------------------------------------------------------
# Lädt die Grafiken für den Lichteffekt
# filename : Dateiname
# hue : Information über den Farbton
#--------------------------------------------------------------------------
def self.lights(filename)
self.load_bitmap('Graphics/Lights/', filename)
end
end
#==============================================================================
# ** Sprite_Light
#------------------------------------------------------------------------------
# Klasse, das die Darstellung des Lichts auf dem Sprite verwaltet
#==============================================================================
class Sprite_Light < RPG::Sprite
#--------------------------------------------------------------------------
# Public Variablen
#--------------------------------------------------------------------------
attr_reader :lights
attr_reader :update_tone
#--------------------------------------------------------------------------
# Objekt-Initialisierung
# args : Einstellungswert
#--------------------------------------------------------------------------
def initialize(*args)
args.flatten!
super(args.last)
self.bitmap = Bitmap.new(640, 480)
self.blend_type = args[0]
self.opacity = args[4]
@new_opacity = $game_map.new_opacity.nil? ? args[4] : $game_map.new_opacity
@max_opacity = $game_map.max_opacity.nil? ? args[4] : $game_map.max_opacity
@change_speed = $game_map.change_speed.nil? ? 0 : $game_map.change_speed
self.z = 100
color(args[1], args[2], args[3])
@lights = {}
@update_list = []
end
#--------------------------------------------------------------------------
# Frames updaten
#--------------------------------------------------------------------------
def update
super
self.ox = $game_map.adjust_x($game_map.display_x) / 4
self.oy = $game_map.adjust_y($game_map.display_y) / 4
update_lights
update_opacity
end
#--------------------------------------------------------------------------
# Lichter updaten
#--------------------------------------------------------------------------
def update_lights
map_x = $game_map.adjust_x($game_map.display_x) / 4
map_y = $game_map.adjust_y($game_map.display_y) / 4
rect = Rect.new(map_x, map_y, 640, 480)
self.bitmap.fill_rect(rect, @color)
for light in @lights.values
light.update
next unless on_screen?(light, map_x, map_y)
draw_light(light, light.x, light.y)
end
end
#--------------------------------------------------------------------------
# Definition des Lichts auf der Map
# light : das Licht Sprite
# map_x : X-Position auf der Karte
# map_y : Y-Position auf der Karte
#--------------------------------------------------------------------------
def on_screen?(light, map_x, map_y)
return false unless (light.x.between?(map_x, map_x + 640) or
(light.x + light.width).between?(map_x, map_x + 640))
return false unless (light.y.between?(map_y, map_y + 480) or
(light.y + light.height).between?(map_y, map_y + 480))
return true
end
#--------------------------------------------------------------------------
# Zeichne Licht
# light : das Licht Sprite
# x : x-Position
# y : y-Position
#--------------------------------------------------------------------------
def draw_light(light, x, y)
img = light.bitmap
rect = Rect.new(x, y, light.width, light.height)
self.bitmap.stretch_blt(rect, img, img.rect, light.opacity)
end
#--------------------------------------------------------------------------
# Farben setzen
# red : rot färben
# green : grün färben
# blue : blau färben
#--------------------------------------------------------------------------
def color(red = 0, green = 0, blue = 0)
if self.blend_type == 2
@color = Color.new(255 - red, 255 - green, 255 - blue, 255)
else
@color = Color.new(red, green, blue, 255)
end
end
#--------------------------------------------------------------------------
# Neues Licht kreieren
# value : Einstellung
#--------------------------------------------------------------------------
def create_light(value)
args = value.dup
remove_light(args[0])
@lights[args[0]] = Light_Sprite.new(args)
end
#--------------------------------------------------------------------------
# Licht entfernen
# id : ID des Bildes
#--------------------------------------------------------------------------
def remove_light(id)
return if @lights[id].nil?
@lights.delete(id)
end
#--------------------------------------------------------------------------
# Opazität updaten
#--------------------------------------------------------------------------
def update_opacity
if @max_opacity != self.opacity
if @max_opacity > self.opacity
@new_opacity += @change_speed
self.opacity = [@new_opacity, @max_opacity].min.to_i
elsif @max_opacity < self.opacity
@new_opacity -= @change_speed
self.opacity = [@new_opacity, @max_opacity].max.to_i
end
end
$game_map.shade_opacity = self.opacity
$game_map.new_opacity = @new_opacity
$game_map.max_opacity = @max_opacity
$game_map.change_speed = @change_speed
end
#--------------------------------------------------------------------------
# Transparenz ändern
# args : Einstellung
#--------------------------------------------------------------------------
def opacity_change(*args)
args.flatten!
@max_opacity = args[0]
@new_opacity = self.opacity.to_f
@change_speed = args[1].to_f
end
#--------------------------------------------------------------------------
# Entsorgen
#--------------------------------------------------------------------------
def dispose
super
@lights.values {|light| light.dispose unless light.bitmap.disposed?}
end
end
#==============================================================================
# ** Light_Sprite
#------------------------------------------------------------------------------
# Klasse, die die einzelnen Sprites von jedem Lichtpunkt verwaltet
#==============================================================================
class Light_Sprite
#--------------------------------------------------------------------------
# Public Variablen
#--------------------------------------------------------------------------
attr_reader :values
attr_reader :bitmap
attr_reader :opacity
attr_reader :x
attr_reader :y
attr_reader :real_x
attr_reader :real_y
attr_reader :width
attr_reader :height
#--------------------------------------------------------------------------
# Objekt-Initialisierung
# args : Einstellungswert
#--------------------------------------------------------------------------
def initialize(*args)
args.flatten!
@values = args.dup
@bitmap = RPG::Cache.lights(args[1])
@target = set_target(args[2])
@opacity = args[3]
@plus_x = args[4]
@plus_y = args[5]
@width = @bitmap.width * args[8]
@height = @bitmap.height * args[8]
@base_opacity = args[3]
@base_variance = args[6]
@speed = args[7]
@variance = 0.0
update
end
#--------------------------------------------------------------------------
# Frames updaten
#--------------------------------------------------------------------------
def update
update_position
update_opacity
end
#--------------------------------------------------------------------------
# Positionen updaten
#--------------------------------------------------------------------------
def update_position
if @target.is_a?(Game_Character)
@x = $game_map.adjust_x(@target.real_x) / 4 - @width / 2 + @plus_x + 16
@y = $game_map.adjust_y(@target.real_y) / 4 - @height / 2 + @plus_y + 16
@real_x = (@target.real_x / 32).to_i
@real_y = (@target.real_y / 32).to_i
else
@x = $game_map.adjust_x(@target[:x] * 128) / 4 - @width / 2 + @plus_x + 16
@y = $game_map.adjust_y(@target[:y] * 128) / 4 - @height / 2 + @plus_y + 16
@real_x = @target[:x]
@real_y = @target[:y]
end
end
#--------------------------------------------------------------------------
# Opazität updaten
#--------------------------------------------------------------------------
def update_opacity
@variance += @speed
@speed *= -1 if (@speed > 0 and @variance > @base_variance) or
(@speed < 0 and @variance < -@base_variance)
@opacity = [[@base_opacity + @variance, 0].max, 255].min
end
#--------------------------------------------------------------------------
# Entsorgen
#--------------------------------------------------------------------------
def dispose
@bitmap.dispose
end
#--------------------------------------------------------------------------
# Das Ziel des Lichts definieren
# value
#--------------------------------------------------------------------------
def set_target(value)
if value.include?('actor')
return (($legacy_engine["Caterpillar"] and value['actor'] > 0) ?
$game_player.actors[value['actor'] - 1] : $game_player)
elsif value.include?('event')
return $game_map.events[value['event']]
else
return value
end
end
end
#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
# Diese Klasse verwaltet die Maps. Dies bestimmt das Scrollen und die
# Passierbarkeit. Bezieh dich auf $game_map für die Instanzen dieser Klasse.
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# Public Variablen
#--------------------------------------------------------------------------
attr_accessor :light_effect
attr_accessor :lights
attr_accessor :remove_lights
attr_accessor :shade_opacity
attr_accessor :opacity_change
attr_accessor :max_opacity
attr_accessor :new_opacity
attr_accessor :change_speed
#--------------------------------------------------------------------------
# Einstellung
# map_id : ID der Map
#--------------------------------------------------------------------------
alias setup_lighteffects setup
def setup(map_id)
clear_lights
setup_lighteffects(map_id)
end
#--------------------------------------------------------------------------
# Werte der Lichter zurücksetzen
#--------------------------------------------------------------------------
def clear_lights
@lights = {}
@remove_lights = []
@shade_opacity = 0
@light_effect = nil
@max_opacity = nil
@new_opacity = nil
@change_speed = nil
end
end
#==============================================================================
# ** Game_Character (Teil 1)
#------------------------------------------------------------------------------
# Diese Klasse beschäftigt sich mit den Helden. Dies wird als Superklasse für
# die Klassen Game_Player und Game_Event verwendet.
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
# Public Variablen
#--------------------------------------------------------------------------
attr_accessor :lantern
#--------------------------------------------------------------------------
# Objekt-Initialisierung
#--------------------------------------------------------------------------
alias initialize_lighteffects initialize
def initialize
initialize_lighteffects
@lantern = 0
end
#--------------------------------------------------------------------------
# Frames updaten
#--------------------------------------------------------------------------
alias update_lighteffects update
def update
update_lighteffects
dir = $legacy_engine["Rotational Move"] ? @new_direction : @direction
if @lantern != 0 and @lantern_direction != dir
@lantern_direction = dir
id = self.event? ? "EL#{@id}" : "AL#{@id}"
tp = self.event? ? 'event' : 'actor'
case @lantern_direction
when 1
img = 'lantern_downleft'
value = [id, img, {tp => @id}, @lantern, -48, 48, 0, 0, 1.0]
when 2
img = 'lantern_down'
value = [id, img, {tp => @id}, @lantern, 0, 64, 0, 0, 1.0]
when 3
img = 'lantern_downright'
value = [id, img, {tp => @id}, @lantern, 48, 48, 0, 0, 1.0]
when 4
img = 'lantern_left'
value = [id, img, {tp => @id}, @lantern, -64, 0, 0, 0, 1.0]
when 6
img = 'lantern_right'
value = [id, img, {tp => @id}, @lantern, 64, 0, 0, 0, 1.0]
when 7
img = 'lantern_upleft'
value = [id, img, {tp => @id}, @lantern, -48, -48, 0, 0, 1.0]
when 8
img = 'lantern_up'
value = [id, img, {tp => @id}, @lantern, 0, -64, 0, 0, 1.0]
when 9
img = 'lantern_upright'
value = [id, img, {tp => @id}, @lantern, 48, -48, 0, 0, 1.0]
end
$game_map.lights[id] = value
elsif @lantern == 0 and @lantern_direction != nil
id = self.event? ? "EL#{@id}" : "AL#{@id}"
$game_map.remove_lights << id if $game_map.remove_lights != nil
@lantern_direction = nil
end
end
end
#==============================================================================
# ** Game_Event
#------------------------------------------------------------------------------
# Diese Klasse verwaltet Events. Es steuert die Funktion der Eventseiten, den
# Wechsel, die Bedingungen, sowie parallele Prozesse. Es wird innerhalb der
# Game_Map Klasse verwendet.
#==============================================================================
class Game_Event < Game_Character
#--------------------------------------------------------------------------
# Entferne den Flag der Initialisierung
#--------------------------------------------------------------------------
alias clear_starting_lighteffects clear_starting
def clear_starting
clear_starting_lighteffects
@lantern = 0
$game_map.remove_lights << "EV#{@id}" if $game_map.remove_lights != nil
refresh_lights unless @page.nil?
end
#--------------------------------------------------------------------------
# Lichter updaten
#--------------------------------------------------------------------------
def refresh_lights
for comment in comments
if comment =~ /SIMPLE[ ]*LIGHT[ ]*(\d+)?/i
set_light("EV#{@id}", "light", $1)
elsif comment =~ /SIMPLE[ ]*LAMP[ ]*(\d+)?/i
set_light("EV#{@id}", "lamp", $1)
elsif comment =~ /SIMPLE[ ]*TORCH[ ]*(\d+)?/i
set_light("EV#{@id}", "torch", $1)
elsif comment =~ /SIMPLE[ ]*WINDOW[ ]*A[ ]*(\d+)?/i
set_light("EV#{@id}", "window", $1)
elsif comment =~ /SIMPLE[ ]*WINDOW[ ]*B[ ]*(\d+)?/i
set_light("EV#{@id}", "window", $1, 0, 0, 0, -14)
elsif comment =~ /FLASH[ ]*LIGHT[ ]*(\d+)?[ ]*(\d+)?[ ]*(\d+)?/i
set_light("EV#{@id}", "light", $1, $2, $3)
elsif comment =~ /FLASH[ ]*LAMP[ ]*(\d+)?[ ]*(\d+)?[ ]*(\d+)?/i
set_light("EV#{@id}", "lamp", $1, $2, $3)
elsif comment =~ /FLASH[ ]*TORCH[ ]*(\d+)?[ ]*(\d+)?[ ]*(\d+)?/i
set_light("EV#{@id}", "torch", $1, $2, $3, 0, 0, 2.0)
elsif comment =~ /FLASH[ ]*WINDOW[ ]*A[ ]*(\d+)?[ ]*(\d+)?[ ]*(\d+)?/i
set_light("EV#{@id}", "window", $1, $2, $3)
elsif comment =~ /FLASH[ ]*WINDOW[ ]*B[ ]*(\d+)?[ ]*(\d+)?[ ]*(\d+)?/i
set_light("EV#{@id}", "window", $1, $2, $3, 0, -14)
elsif comment =~ /LIGHT[ ]\((\w+)\)((?:[ ]*(?:[\+\-]?\d+))*)/i
v = []
name = $1.dup
$2.scan(/\d+/).each {|i| v << i}
set_light("EV#{@id}", name, v[0], v[1], v[1], v[3], v[4], v[5])
elsif comment =~ /LANTERN[ ]*(\d+)?/i
@lantern = ($1.nil? ? 255 : $1.to_i)
end
end
end
#--------------------------------------------------------------------------
# Lichter definieren
# id : ID des Lichts
# name : Name der Bilddatei
# op : Opazität
# vr : Grad der Variation
# sp : Geschwindigkeit der Variation
# x : Einstellung der Position x
# y : Einstellung der Position y
# zm : zoom
#--------------------------------------------------------------------------
def set_light(id, name, op, vr = 0, sp = 0, x = 0, y = 0, zm = 1.0)
op = op.nil? ? 255 : op.to_i
vr = vr.nil? ? 50 : vr.to_i
sp = sp.nil? ? 2 : sp.to_i
x = x.nil? ? 0 : x.to_i
y = y.nil? ? 0 : x.to_i
zm = zm.nil? ? 1.0 : zm.to_f
value = [id, name, {'event' => @id}, op, x, y, vr, sp, zm]
$game_map.lights[id] = value
$game_map.remove_lights.delete(id)
end
end
#==============================================================================
# ** Spriteset_Map
#------------------------------------------------------------------------------
# Zu dieser Klasse gehören alle Sprites auf dem Bildschirm, Tilesets, Helden, etc.
# Diese Klasse ist in der Klasse Scene_Map enthalten.
#==============================================================================
class Spriteset_Map
#--------------------------------------------------------------------------
# Public Variablen
#--------------------------------------------------------------------------
attr_reader :light_effects
#--------------------------------------------------------------------------
# Objekt-Initialisierung
#--------------------------------------------------------------------------
alias initialize_lighteffects initialize
def initialize
initialize_lighteffects
update_light
end
#--------------------------------------------------------------------------
# Frames updaten
#--------------------------------------------------------------------------
alias update_lighteffects update
def update
update_lighteffects
update_light
end
#--------------------------------------------------------------------------
# Entsorgen
#--------------------------------------------------------------------------
alias dispose_lighteffects dispose
def dispose
dispose_lighteffects
dispose_light unless $scene.is_a?(Scene_Map)
end
#--------------------------------------------------------------------------
# Lichter updaten
#--------------------------------------------------------------------------
def update_light
update_shade
update_effects
update_shade_opacity
end
#--------------------------------------------------------------------------
# Lichteffekt entfernen
#--------------------------------------------------------------------------
def dispose_light
if @light_effect != nil
@light_effect.dispose
@light_effect = nil
@light_values = nil
end
end
#--------------------------------------------------------------------------
# Schatten updaten
#--------------------------------------------------------------------------
def update_shade
if $game_map.light_effect != nil and (@light_effect.nil? or
$game_map.light_effect != @light_values)
@light_effect.dispose if @light_effect != nil
@light_values = $game_map.light_effect
@light_effect = Sprite_Light.new(@light_values, @viewport2)
$game_map.event_list.each {|ev| ev.refresh_lights}
elsif $game_map.light_effect != nil and @light_effect != nil
@light_effect.update
elsif $game_map.light_effect.nil? and @light_effect != nil
dispose_lights
end
end
#--------------------------------------------------------------------------
# Lichteffekte updaten
#--------------------------------------------------------------------------
def update_effects
return if @light_effect.nil? or $game_map.lights.empty?
for key in $game_map.lights.keys
if $game_map.remove_lights.include?(key)
@light_effect.remove_light(key)
$game_map.lights.delete(key)
next
end
next if @light_effect.lights[key] != nil and
@light_effect.lights[key].values == $game_map.lights[key]
@light_effect.create_light($game_map.lights[key])
end
$game_map.remove_lights.clear
end
#--------------------------------------------------------------------------
# Opazität des Schattens updaten
#--------------------------------------------------------------------------
def update_shade_opacity
if $game_map.opacity_change != nil
@light_effect.opacity_change($game_map.opacity_change)
$game_map.opacity_change = nil
end
end
end
#==============================================================================
# ** Interpreter
#------------------------------------------------------------------------------
# Es ist die Klasse, die die Befehle der In-Game Events interpretiert.
# Es wird innerhalb der Klasse Game_Event und Game_System verwendet.
#==============================================================================
class Interpreter
#--------------------------------------------------------------------------
# Schatten kreieren
# op : Opazität
# red : Rot färben
# green : Grün färben
# blue : Blau färben
# type : Art des Effekts
#--------------------------------------------------------------------------
def create_shade(op = 160, red = 0, green = 0, blue = 0, type = 2)
$game_map.light_effect = [type, red, green, blue, op, true]
end
#--------------------------------------------------------------------------
# Opazität des Schattens ändern
# op : Neuer Wert für die Opazität
# speed : Geschwindigkeit der Änderung
#--------------------------------------------------------------------------
def change_opacity(op = 160, speed = 1)
return if $game_map.light_effect.nil?
$game_map.opacity_change = [op, speed]
end
#--------------------------------------------------------------------------
# Licht kreieren für den Spieler
# img : Name der Bilddatei
# id : ID des Lichteffekts
# index : Index
# op : Opazität
# x : Einstellung der Position x
# y : Einstellung der Position y
# var : Variation des Lichts
# speed : Geschwindigkeit der Änderung des Lichts
# zoom : zoom des Lichteffektes
#--------------------------------------------------------------------------
def player_light(img, id, index = 0, op = 160, x = 0, y = 0,
var = 0, speed = 0, zoom = 1.0)
actor = ($legacy_engine["Caterpillar"] and index > 0) ?
$game_player.actors[index - 1] : $game_player
return if actor.nil?
actor = {'actor' => index}
$game_map.lights[id] = [id, img, actor, op, x, y, var, speed, zoom]
end
#--------------------------------------------------------------------------
# Licht kreieren für ein Event
# img : Name der Bilddatei
# id : ID des Lichteffekts
# index : ID des Events
# op : Opazität
# x : Einstellung der Position x
# y : Einstellung der Position y
# var : Variation des Lichts
# speed : Geschwindigkeit der Änderung des Lichts
# zoom : zoom des Lichteffektes
#--------------------------------------------------------------------------
def event_light(img, id, index = 0, op = 160, x = 0, y = 0,
var = 0, speed = 0, zoom = 1.0)
return if $game_map.events[index].nil?
event = {'event' => index}
$game_map.lights[id] = [id, img, event, op, x, y, var, speed, zoom]
end
#--------------------------------------------------------------------------
# Licht kreieren auf der Map
# img : Name der Bilddatei
# id : ID des Lichteffekts
# mx : x-Koordinate des Tiles, die Licht erhält
# my : y-Koordinate des Tiles, die Licht erhält
# op : Opazität
# x : Einstellung der Position x
# y : Einstellung der Position y
# var : Variation des Lichts
# speed : Geschwindigkeit der Änderung des Lichts
# zoom : zoom des Lichteffektes
#--------------------------------------------------------------------------
def map_light(img, id, mx = 0, my = 0, op = 160, x = 0, y = 0,
var = 0, speed = 0, zoom = 1.0)
pos = {:x => mx, :y => my}
$game_map.lights[id] = [id, img, pos, op, x, y, var, speed, zoom]
end
#--------------------------------------------------------------------------
# Lichter entfernen
# id : ID des Lichteffektes
#--------------------------------------------------------------------------
def remove_light(id)
$game_map.remove_lights << id if $game_map.remove_lights != nil
end
#--------------------------------------------------------------------------
# Opazität des Schattens ändern
#--------------------------------------------------------------------------
def shade_opacity
return $game_map.shade_opacity
end
#--------------------------------------------------------------------------
# Taschenlampe des Spielers aktivieren
# index : Index
# opacity : Opazität
#--------------------------------------------------------------------------
def player_lantern_on(index = 0, opacity = 255)
actor = ($legacy_engine["Caterpillar"] and index > 0) ?
$game_player.actors[index - 1] : $game_player
return if actor.nil?
actor.lantern = opacity
end
#--------------------------------------------------------------------------
# Taschenlampe des Spielers deaktivieren
# index : Index
#--------------------------------------------------------------------------
def player_lantern_off(index = 0)
actor = ($legacy_engine["Caterpillar"] and index > 0) ?
$game_player.actors[index - 1] : $game_player
return if actor.nil?
actor.lantern = 0
end
#--------------------------------------------------------------------------
# Taschenlampe des Events aktivieren
# index : Index
# opacity : Opazität
#--------------------------------------------------------------------------
def event_lantern_on(index = 0, opacity = 255)
return if $game_map.events[index].nil?
$game_map.events[index].lantern = opacity
end
#--------------------------------------------------------------------------
# Taschenlampe des Events deaktivieren
# index : Index
#--------------------------------------------------------------------------
def event_lantern_off(index = 0)
return if $game_map.events[index].nil?
$game_map.events[index].lantern = 0
end
end
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
# Diese Klasse verarbeitet die Maps.
#==============================================================================
class Scene_Map
#--------------------------------------------------------------------------
# Public Variablen
#--------------------------------------------------------------------------
attr_reader :spriteset
#--------------------------------------------------------------------------
# Teleport
#--------------------------------------------------------------------------
alias transfer_player_lighteffects transfer_player
def transfer_player
@spriteset.dispose_light
$game_map.clear_lights
transfer_player_lighteffects
end
end
Wichtig: Die Demo damit ihr das Ganze mal in Aktion sehen könnt. Download (http://wachowski.kauschinger.net/downloads/Legacy Engine - Lighting.zip)
Screen:
http://ascare.as.ohost.de/rgss/rgss_lichteffekt.png
PS: Würde mich freuen wenn ihr eure Erfahrungen mit dem Script hier teilt. Auch bin ich noch nicht hinter jede Funktion durchgestiegen. Was ist zB der Unterschied zwischen Simple Window A und B?
PPS: Opazität steht übrigens für Deckkraft.
Dann mal viel Spaß mit der Benutzung, ich zumindest kann's SEHR gut gebrauchen. :)