Já viram qual a arte dessa semana?Exposição dos Artistas #8
3 Respostas   107 Visualizações
0 Membros e 1 Visitante estão vendo este tópico.
#-------------------------------------------------------------------------------# * Por Khas Arcthunder - arcthunder.site40.net# * Versão: 1.0 BR# * Lançada em: 12/01/2012##-------------------------------------------------------------------------------# * Termos de uso#-------------------------------------------------------------------------------# Ao utilizar qualquer script feito por Khas, você concorda com os termos abaixo# 1. Você deve dar crédito a Khas se estiver usando algum script Khas;# 2. Todos os scripts Khas estão sob licença Creative Commons;# 3. Todos os scripts Khas são para projetos não comerciais, se você precisar de # algum script Khas em seu projeto comercial (aceito pedidos para esse tipo # de projeto), envie um email para nilokruch@live.com com o pedido;# 4. Todos os scripts Khas são para uso pessoal, você pode usar e editar para uso# no seu projeto, porém você não pode postar nenhuma versão modificada;# 5. Você não pode dar créditos a si próprio por postar algum script Khas;# 6. Caso queira compartilhar um script Khas, não poste o link direto de # download, apenas redirecione o usuário para arcthunder.site40.net ##-------------------------------------------------------------------------------# * Características#-------------------------------------------------------------------------------# - Efeitos de luz realista# - Luz real (não passa paredes!)# - Fontes de luz estática (que não se move)# - Fonte de luz dinâmica (uma lanterna para o jogador, por exemplo)# - Efeitos multiplos podem se juntar# - Fácil configuração# - Uso por comentário##-------------------------------------------------------------------------------# * IMPORTANTE - Desempenho#-------------------------------------------------------------------------------# Esse script pode vir a ser pesado para processadores muito antigos! O Awesome# Light Effects foi testado em um Core 2 Duo E4500 e em um Core i5, sem lag.# Porém, além do processador, há vários fatores que influenciam no desempenho # do script:# # 1. Tamanho do mapa# Este script analiza o mapa em busca de superfícies para cortar a luz. Em um# mapa muito grande, esse número de superfícies pode aumentar muito, afetando # o desempenho da LUZ DINÂMICA. O tamanho do mapa não influência nas luzes # estáticas.## 2. Quantidade de efeitos# Este script desenha os efeitos na tela, conforme sua posição. Antes de # atualizá-los, a sua posição é verificada. Portanto, em mapas muito grandes# com excesso de efeitos pode a vir ocorrer lag. Note que isso é apenas uma # previsão, pois nos testes atuais não foi detectado lag.## 3. Tamanho da imagem# O tamanho da imagem da luz dinâmica influencia diretamente no desempenho. # O corte de luz é feito linha a linha, quanto maior a resolução da imagem,# mais tempo será gasto para cortá-la. A recomendação é até 200x200 pixels.# #-------------------------------------------------------------------------------# * IMPORTANTE - Imagens de luz#-------------------------------------------------------------------------------# Para o funcionamento correto do script, as imagens de luz DEVEM obedecer# os seguintes critérios:## 1. O tamanho da imagem DEVE ser par. Exemplo: 150x150# 2. A imagem DEVE ser quadrada, com dimensões IGUAIS. Exemplo: 156x156# 3. A imagem DEVE estar com as cores invertidas! Isso é nescessário, pois o# script inverte as cores para desenhar o efeito na superfície de efeitos.# Lembre-se que a cor preta ficará transparente!##-------------------------------------------------------------------------------# * Instruções - 1. Configurando efeitos estáticos#-------------------------------------------------------------------------------# Para configurar efeitos estáticos, vá até a configuração (logo abaixo) e # defina os efeitos dentro da hash Effects. Faça do seguinte modo:## X => [imagem, opacidade, variação, corte], <= Lembre dessa vírgula no final!# # Onde:# Imagem => Nome da imagem na pasta "Graphics/Lights";# Opacidade => Opacidade da imagem;# Variação => Variação POSITIVA da opacidade;# Corte => Coloque true para cortar a imagem e false para não cortar;# X => É o ID do efeito, para ser usado nos eventos. Use um ID para cada efeito.## Veja os efeitos pré configurados para entender como funciona.##-------------------------------------------------------------------------------# * Instruções - 2. Usando o efeitos em eventos:#-------------------------------------------------------------------------------# Para usar o efeito definido em um evento, coloque o seguinte comentário:# # [light x]## Onde x deve ser o ID do efeito configurado.# #-------------------------------------------------------------------------------# * Instruções - 3. Utilizando a luz dinâmica (lanterna)#-------------------------------------------------------------------------------# A lanterna é automaticamente inicializada como invisível. Você pode usar os# seguintes métodos com o comando "Chamar Script":# # l = $game_map.lantern# Adiquire a lanterna em uma variável.# Você pode usar todos os comandos abaixo com "$game_map.lantern" ao # invés de adiquirir a lanterna em uma variável, porém tome cuidado, pois# o comando "Chamar Script" corta o código e pode gerar erros.# # l.set_graphic(i)# Muda o gráfico da lanterna para i, onde i deve ser o nome, entre aspas,# da imagem na pasta Graphics/Lights## l.set_multiple_graphics(h)# Muda os gráficos da lanterna para h, onde h deve ser uma Hash com o seguinte# formato:## h = {2=>"ld",4=>"ll",6=>"lr",8=>"lu"}# # Onde: # "ld" é o nome da imagem quando o portador está virado para baixo;# "ll" é o nome da imagem quando o portador está virado para esquerda;# "lr" é o nome da imagem quando o portador está virado para direita;# "lu" é o nome da imagem quando o portador está virado para cima.## l.change_owner(char)# Muda o portador da lanterna para char, onde char pode ser:# $game_player <= O jogador;# self_event <= O evento em que o comando é chamado;# $game_map.events[x] <= O evento de ID x do mapa.## l.set_opacity(o,p)# Ajusta a opacidade da lanterna, onde:# o é a opacidade padrão;# p é a variação POSITIVA da opacidade.## l.show# Depois de configurar a lanterna com os comandos acima, use este comando para# tornar a lanterna visível.## l.hide# Use este comando para esconder a lanterna.##-------------------------------------------------------------------------------# * Instruções - 4. Utilizando a superfície de efeitos (Chamar Script)#-------------------------------------------------------------------------------# O Awesome Light Effects desenha os efeitos sobre uma superfície. Para que# os efeitos estejam visíveis, a superfície de efeitos deve estar visível.# Para utilizar a superfície de efeitos, utilize os comandos abaixo:## s = $game_map.effect_surface# Adiquire a superfície em uma variável.# Você pode usar todos os comandos abaixo com "$game_map.effect_surface" ao # invés de adiquirir a superfície em uma variável, porém tome cuidado, pois# o comando "Chamar Script" corta o código e pode gerar erros.## s.set_color(r,g,b)# Muda a cor da superfície instantâneamente para a cor fornecida:# r => valor da cor vermelha;# g => valor da cor verde;# b => valor da cor azul.## s.set_alpha(a)# Muda a opacidade da superfície instantâneamente para a.## s.change_color(time,r,g,b)# Muda SOMENTE a cor da superfície em um certo tempo, onde:# time => tempo para a mudança (em frames);# r => valor da cor vermelha;# g => valor da cor verde;# b => valor da cor azul.## s.change_color(time,r,g,b,a)# Muda a cor da superfície e a opacidade em um certo tempo, onde:# time => tempo para a mudança (em frames);# r => valor da cor vermelha;# g => valor da cor verde;# b => valor da cor azul;# a => opacidade.## s.change_alpha(time,a)# Muda a opacidade da superfície em um certo tempo, onde:# time => tempo para a mudança (em frames);# a => opacidade.##-------------------------------------------------------------------------------# * Instruções - 5. Utilizando a superfície de efeitos (Evento)#-------------------------------------------------------------------------------# Você pode acessar a superfície de efeitos pelo comando "Tonalidade de Tela",# para isso, coloque a opção "Surface_UE" (nas configurações) como true. Caso# queria desabilitar essa opção e ter controle sobre o tom da tela, coloque a# opção "Surface_UE" como false. ## Observe os seguintes detalhes, se for usar esta opção:# 1. Os valores de cor devem estar entre 0 e 255;# 2. O tempo é em frames;# 3. O valor "Cinza" será enviado como a opacidade da superfície.##-------------------------------------------------------------------------------# * Instruções - 6. Configurando as Tags do mapa#-------------------------------------------------------------------------------# Afim de que as luzes sejam cortadas de forma precisa e realista, há 3 tipos# de comportamento para um tile: telhado, parede e bloco. Pense de maneira # lógica: um telhado gera sombras como telhado, uma parede como uma parede, e# assim por diante.## Para isso, as tags do tileset DEVEM ser configuradas. Por padrão, são # configuradas para 6,7 e 8. Veja a demo para ter noção de como isso funciona.## Note que o script só irá analizar a primeira camada (camada A) do mapa. Certos# tilesets não irão funcionar caso os tiles não estejam configurados de modo # correto. Note ainda que este script depende do bom mapeamento para funcionar,# preste atenção aos detalhes do seu mapa.##-------------------------------------------------------------------------------# * Configuração#-------------------------------------------------------------------------------module Light_Core Effects = { # Não mude isto!#-------------------------------------------------------------------------------# ADICIONE ABAIXO OS SEUS EFEITOS!#------------------------------------------------------------------------------- 0 => ["light",255,0,true], 1 => ["torch",200,20,true], 2 => ["torch_m",180,30,true], 3 => ["light_s",255,0,true], #-------------------------------------------------------------------------------# Fim da configuração de efeitos#------------------------------------------------------------------------------- } # Não mude isto! # Coordenada Z da superfície de efeitos: Surface_Z = 180 # Habilitar controle da superfície por "Tonalidade da Tela"? Surface_UE = true # Tag para a superfície se comportar como "telhado" Roof_Tag = 5 # Tag para a superfície se comportar como "parede" Wall_Tag = 6 # Tag para a superfície se comportar como "bloco" (semelhante ao telhado) Block_Tag = 7 # Constante de correção de ângulo (não altere) ACC = Math.tan(Math::PI/26)end#-------------------------------------------------------------------------------# Fim da configuração - Início do script#-------------------------------------------------------------------------------module Cache def self.light(filename) load_bitmap("Graphics/Lights/", filename) endendmodule Light_Bitcore include Light_Core def self.initialize @@buffer = {} Effects.values.each { |effect| Light_Bitcore.push(effect[0])} end def self::[](key) return @@buffer[key] end def self.push(key) return if @@buffer.keys.include?(key) @@buffer[key] = Cache.light(key) endendLight_Bitcore.initializeclass Light_SSource attr_reader :real_x attr_reader :real_y attr_reader :range attr_accessor :bitmap attr_reader :w attr_reader :h attr_reader :hs def initialize(char,bitmap,opacity,plus,hs) sync(char) @key = bitmap @bitmap = Light_Bitcore[@key].clone @range = @bitmap.width/2 @w = @bitmap.width @h = @bitmap.height @mr = @range - 16 @opacity = opacity @plus = plus @hs = hs render if @hs end def render tx = x ty = y tsx = x + @range tsy = y + @range dr = @range*2 for s in $game_map.surfaces next if !s.visible?(tsx,tsy) || !s.within?(tx,tx+dr,ty,ty+dr) s.render_shadow(tx,ty,tsx,tsy,@range,@bitmap) end end def restore return unless @bitmap.nil? @bitmap = Light_Bitcore[@key].clone render if @hs end def opacity @plus == 0 ? @opacity : (@opacity + rand(@plus)) end def sx return $game_map.adjust_x(@real_x)*32-@mr end def sy return $game_map.adjust_y(@real_y)*32-@mr end def sync(char) @real_x = char.real_x @real_y = char.real_y end def x return (@real_x*32 - @mr).to_f end def y return (@real_y*32 - @mr).to_f end def dispose return if @bitmap.nil? @bitmap.dispose @bitmap = nil endendclass Light_DSource < Light_SSource attr_reader :bitmap attr_reader :visible def initialize @key = nil @bitmap = nil @opacity = 255 @plus = 0 @char = $game_player @visible = false end def set_opacity(o,p) @opacity = o @plus = p end def set_graphic(sb) dispose @key = {2=>sb,4=>sb,6=>sb,8=>sb} Light_Bitcore.push(sb) @bitmap = {2=>Light_Bitcore[@key[2]].clone,4=>Light_Bitcore[@key[4]].clone,6=>Light_Bitcore[@key[6]].clone,8=>Light_Bitcore[@key[8]].clone} @range = @bitmap[2].width/2 @w = @bitmap[2].width @h = @bitmap[2].height @mr = @range - 16 end def set_multiple_graphics(ba) dispose @key = ba @key.values.each {|key| Light_Bitcore.push(key)} @bitmap = {2=>Light_Bitcore[@key[2]].clone,4=>Light_Bitcore[@key[4]].clone,6=>Light_Bitcore[@key[6]].clone,8=>Light_Bitcore[@key[8]].clone} @range = @bitmap[2].width/2 @w = @bitmap[2].width @h = @bitmap[2].height @mr = @range - 16 end def get_graphic return @bitmap[@char.direction].clone end def show return if @bitmap.nil? @visible = true end def hide @visible = false end def restore return if @key.nil? @key.values.each {|key| Light_Bitcore.push(key)} @bitmap = {2=>Light_Bitcore[@key[2]].clone,4=>Light_Bitcore[@key[4]].clone,6=>Light_Bitcore[@key[6]].clone,8=>Light_Bitcore[@key[8]].clone} end def dispose return if @bitmap.nil? @bitmap.values.each { |b| b.dispose } @bitmap = nil end def change_owner(char) @char = char end def render end def sx return $game_map.adjust_x(@char.real_x)*32-@mr end def sy return $game_map.adjust_y(@char.real_y)*32-@mr end def x return (@char.real_x*32 - @mr).to_f end def y return (@char.real_y*32 - @mr).to_f endendclass Light_Surface def initialize @ta = @a = 0 @tr = @r = 255 @tg = @g = 255 @tb = @b = 255 @va = @vr = @vg = @vb = 0.0 @timer = 0 end def refresh return if @timer == 0 @a += @va @r += @vr @g += @vg @b += @vb $game_map.light_surface.opacity = @a @timer -= 1 end def change_color(time,r,g,b,a=nil) r = 0 if r < 0; r = 255 if r > 255 g = 0 if g < 0; g = 255 if g > 255 b = 0 if b < 0; b = 255 if b > 255 unless a.nil? a = 0 if a < 0; a = 255 if a > 255 end @timer = time @tr = 255-r @tg = 255-g @tb = 255-b @va = (a.nil? ? 0 : (a-@a).to_f/@timer) @vr = (@tr - @r).to_f/@timer @vg = (@tg - @g).to_f/@timer @vb = (@tb - @b).to_f/@timer end def change_alpha(time,a) a = 0 if a < 0; a = 255 if a > 255 @timer = time @ta = a @vr = @vg = @vb = 0.0 @va = (a-@a).to_f/@timer end def set_color(r,g,b) r = 0 if r < 0; r = 255 if r > 255 g = 0 if g < 0; g = 255 if g > 255 b = 0 if b < 0; b = 255 if b > 255 @tr = @r = 255-r @tg = @g = 255-g @tb = @b = 255-b @va = @vr = @vg = @vb = 0.0 @timer = 0 end def set_alpha(a) a = 0 if a < 0; a = 255 if a > 255 @ta = @a = a $game_map.light_surface.opacity = @a @va = @vr = @vg = @vb = 0.0 @timer = 0 end def alpha return @a end def color return Color.new(@r,@g,@b) endendclass Game_Map include Light_Core attr_accessor :light_surface attr_accessor :light_sources attr_accessor :surfaces attr_accessor :effect_surface attr_accessor :lantern alias kbl_setup_events setup_events alias kbl_initialize initialize alias kbl_update update def initialize kbl_initialize @effect_surface = Light_Surface.new @lantern = Light_DSource.new end def update(arg) @effect_surface.refresh if arg kbl_update(arg) end def first_tag(x,y) tag = tileset.flags[tile_id(x,y,0)] >> 12 return tag > 0 ? tag : 0 end def setup_events @light_sources.nil? ? @light_sources = [] : @light_sources.clear setup_surfaces merge_surfaces kbl_setup_events end def setup_surfaces @surfaces = [] for x in 0..(width-1) for y in 0..(height-1) tag = first_tag(x,y) if tag == Wall_Tag i = tile_id(x,y,0) if i & 0x02 == 0x02 @surfaces << Block_SD.new(x*32,y*32,x*32+32,y*32) end if i & 0x04 == 0x04 @surfaces << Block_WR.new(x*32+31,y*32,x*32+31,y*32+32) @surfaces << Block_IL.new(x*32+32,y*32,x*32+32,y*32+32) end if i & 0x01 == 0x01 @surfaces << Block_IR.new(x*32-1,y*32,x*32-1,y*32+32) @surfaces << Block_WL.new(x*32,y*32,x*32,y*32+32) end elsif tag == Roof_Tag i = tile_id(x,y,0) @surfaces << Block_SU.new(x*32,y*32,x*32+32,y*32) if i & 0x02 == 0x02 @surfaces << Block_SR.new(x*32+31,y*32,x*32+31,y*32+32) if i & 0x04 == 0x04 @surfaces << Block_SL.new(x*32,y*32,x*32,y*32+32) if i & 0x01 == 0x01 elsif tag == Block_Tag f = tileset.flags[tile_id(x,y,0)] @surfaces << Block_SL.new(x*32,y*32,x*32,y*32+32) if f & 0x02 == 0x02 @surfaces << Block_SR.new(x*32+31,y*32,x*32+31,y*32+32) if f & 0x04 == 0x04 @surfaces << Block_SU.new(x*32,y*32,x*32+32,y*32) if f & 0x08 == 0x08 end end end end def merge_surfaces new_surfaces = [] hs = []; vs = [] ws = []; is = [] for surface in @surfaces if surface.type & 0x05 == 0 hs << surface else if surface.type & 0x010 == 0 vs << surface else if surface.type & 0x08 == 0 ws << surface else is << surface end end end end for surface in hs surface.ready ? next : surface.ready = true for s in hs next if s.ready || s.y1 != surface.y1 || surface.type != s.type if s.x2 == surface.x1 surface.x1 = s.x1 s.trash = true s.ready = true surface.ready = false elsif s.x1 == surface.x2 surface.x2 = s.x2 s.trash = true s.ready = true surface.ready = false end end end hs.each { |s| @surfaces.delete(s) if s.trash} for surface in vs surface.ready ? next : surface.ready for s in vs next if s.ready || s.x1 != surface.x1 if s.y2 == surface.y1 surface.y1 = s.y1 s.trash = true s.ready = true surface.ready = false elsif s.y1 == surface.y2 surface.y2 = s.y2 s.trash = true s.ready = true surface.ready = false end end end vs.each { |s| @surfaces.delete(s) if s.trash} for surface in ws surface.ready ? next : surface.ready for s in ws next if s.ready || s.x1 != surface.x1 if s.y2 == surface.y1 surface.y1 = s.y1 s.trash = true s.ready = true surface.ready = false elsif s.y1 == surface.y2 surface.y2 = s.y2 s.trash = true s.ready = true surface.ready = false end end end ws.each { |s| @surfaces.delete(s) if s.trash} for surface in is surface.ready ? next : surface.ready for s in is next if s.ready || s.x1 != surface.x1 if s.y2 == surface.y1 surface.y1 = s.y1 s.trash = true s.ready = true surface.ready = false elsif s.y1 == surface.y2 surface.y2 = s.y2 s.trash = true s.ready = true surface.ready = false end end end is.each { |s| @surfaces.delete(s) if s.trash} endendclass Game_Event < Game_Character alias kbl_initialize initialize alias kbl_setup_page setup_page def initialize(m,e) @light = nil kbl_initialize(m,e) end def setup_page(np) kbl_setup_page(np) setup_light(np.nil?) end def setup_light(dispose) unless @light.nil? $game_map.light_sources.delete(self) @light.dispose @light = nil end unless dispose && @list.nil? for command in @list if command.code == 108 && command.parameters[0].include?("[light") command.parameters[0].scan(/\[light ([0.0-9.9]+)\]/) effect = Light_Core::Effects[$1.to_i] @light = Light_SSource.new(self,effect[0],effect[1],effect[2],effect[3]) $game_map.light_sources << self return end end end end def draw_light sx = @light.sx sy = @light.sy w = @light.w h = @light.h return if sx > 544 && sy > 416 && sx + w < 0 && sy + h < 0 $game_map.light_surface.bitmap.blt(sx,sy,@light.bitmap,Rect.new(0,0,w,h),@light.opacity) end def dispose_light @light.dispose end def restore_light @light.restore endendif Light_Core::Surface_UE class Game_Interpreter def command_223 $game_map.effect_surface.change_color(@params[1],@params[0].red,@params[0].green,@params[0].blue,@params[0].gray) wait(@params[1]) if @params[2] end endendclass Game_Interpreter def self_event return $game_map.events[@event_id] endendclass Block_Surface include Light_Core attr_accessor :x1 attr_accessor :y1 attr_accessor :x2 attr_accessor :y2 attr_accessor :ready attr_accessor :trash def initialize(x1,y1,x2,y2) @x1 = x1 @y1 = y1 @x2 = x2 @y2 = y2 @ready = false @trash = false end def within?(min_x,max_x,min_y,max_y) return @x2 > min_x && @x1 < max_x && @y2 > min_y && @y1 < max_y endendclass Block_SL < Block_Surface attr_reader :type def initialize(x1,y1,x2,y2) super(x1,y1,x2,y2) @type = 0x01 end def visible?(sx,sy) return sx < @x1 end def render_shadow(phx,phy,sx,sy,range,bitmap) @m1 = (@y1-sy)/(@x1-sx) @n1 = sy - @m1*sx @m2 = (@y2-sy)/(@x2-sx) @n2 = sy - @m2*sx for x in @x1..(sx+range) init = shadow_iy(x) bitmap.clear_rect(x-phx,init-phy,1,shadow_fy(x)-init+3) end end def shadow_iy(x) return @m1*x+@n1 end def shadow_fy(x) return @m2*x+@n2 endendclass Block_SR < Block_Surface attr_reader :type def initialize(x1,y1,x2,y2) super(x1,y1,x2,y2) @type = 0x04 end def visible?(sx,sy) return sx > @x1 end def render_shadow(phx,phy,sx,sy,range,bitmap) @m1 = (@y1-sy)/(@x1-sx) @n1 = sy - @m1*sx @m2 = (@y2-sy)/(@x2-sx) @n2 = sy - @m2*sx for x in (sx-range).to_i..@x1 init = shadow_iy(x) bitmap.clear_rect(x-phx,init-phy,1,shadow_fy(x)-init+3) end end def shadow_iy(x) return @m1*x+@n1 end def shadow_fy(x) return @m2*x+@n2 endendclass Block_IL < Block_Surface attr_reader :type def initialize(x1,y1,x2,y2) super(x1,y1,x2,y2) @type = 0x019 end def visible?(sx,sy) return sx < @x1 && sy > @y1 end def render_shadow(phx,phy,sx,sy,range,bitmap) @m1 = (@y1-sy)/(@x1-sx) @n1 = @y1 - @m1*@x1 @m2 = (@y2-sy)/(@x2-sx) @m2 = 0 if @m2 > 0 @n2 = @y2 - @m2*@x2 for x in @x1..(sx+range) init = shadow_iy(x).floor bitmap.clear_rect(x-phx,init-3-phy,1,shadow_fy(x)-init+3) end end def shadow_iy(x) return @m1*x+@n1 end def shadow_fy(x) return @m2*x+@n2 endendclass Block_IR < Block_Surface attr_reader :type def initialize(x1,y1,x2,y2) super(x1,y1,x2,y2) @type = 0x01c end def visible?(sx,sy) return sx > @x1 && sy > @y1 end def render_shadow(phx,phy,sx,sy,range,bitmap) @m1 = (@y1-sy)/(@x1-sx) @n1 = @y1 - @m1*@x1 @m2 = (@y2-sy)/(@x2-sx) @m2 = 0 if @m2 < 0 @n2 = @y2 - @m2*@x2 for x in (sx-range).to_i..@x1 init = shadow_iy(x).floor bitmap.clear_rect(x-phx,init-3-phy,1,shadow_fy(x)-init+3) end end def shadow_iy(x) return @m1*x+@n1 end def shadow_fy(x) return @m2*x+@n2 endendclass Block_WL < Block_Surface attr_reader :type def initialize(x1,y1,x2,y2) super(x1,y1,x2,y2) @type = 0x011 end def visible?(sx,sy) return sx < @x1 && sy < @y2 end def render_shadow(phx,phy,sx,sy,range,bitmap) @m1 = (@y1-sy)/(@x1-sx) @n1 = sy - @m1*sx @m2 = (@y2-sy)/(@x2-sx) @n2 = sy - @m2*sx for x in @x1..(sx+range) init = shadow_iy(x) bitmap.clear_rect(x-phx,init-phy,1,shadow_fy(x)-init+2) end end def shadow_iy(x) return @m1*x+@n1 end def shadow_fy(x) return @m2*x+@n2 endendclass Block_WR < Block_Surface attr_reader :type def initialize(x1,y1,x2,y2) super(x1,y1,x2,y2) @type = 0x014 end def visible?(sx,sy) return sx > @x1 && sy < @y2 end def render_shadow(phx,phy,sx,sy,range,bitmap) @m1 = (@y1-sy)/(@x1-sx) @n1 = sy - @m1*sx @m2 = (@y2-sy)/(@x2-sx) @n2 = sy - @m2*sx for x in (sx-range).to_i..@x1 init = shadow_iy(x) bitmap.clear_rect(x-phx,init-phy,1,shadow_fy(x)-init+2) end end def shadow_iy(x) return @m1*x+@n1 end def shadow_fy(x) return @m2*x+@n2 endendclass Block_SU < Block_Surface attr_reader :type def initialize(x1,y1,x2,y2) super(x1,y1,x2,y2) @type = 0x02 end def visible?(sx,sy) return sy < @y1 end def render_shadow(phx,phy,sx,sy,range,bitmap) if @x1 == sx @m1 = nil else @m1 = (@y1-sy)/(@x1-sx) @m1 += ACC if @m1 < -ACC @n1 = @y1 - @m1*@x1 end if @x2 == sx @m2 = nil else @m2 = (@y2-sy)/(@x2-sx) @n2 = sy - @m2*sx end for y in @y1..(sy+range) init = shadow_ix(y) bitmap.clear_rect(init-phx,y-phy,shadow_fx(y)-init+1,1) end end def shadow_ix(y) return @m1.nil? ? @x1 : (y-@n1)/@m1 end def shadow_fx(y) return @m2.nil? ? @x2 : (y-@n2)/@m2 endendclass Block_SD < Block_Surface attr_reader :type def initialize(x1,y1,x2,y2) super(x1,y1,x2,y2) @type = 0x08 end def visible?(sx,sy) return sy > @y1 end def render_shadow(phx,phy,sx,sy,range,bitmap) if @x1 == sx @m1 = nil else @m1 = (@y1-sy)/(@x1-sx) @m1 -= ACC if @m1 > ACC @n1 = sy - @m1*sx end if x2 == sx @m2 = nil else @m2 = (@y2-sy)/(@x2-sx) @n2 = sy - @m2*sx end for y in (sy-range).to_i..@y1 init = shadow_ix(y) bitmap.clear_rect(init-phx,y-phy,shadow_fx(y)-init+1,1) end end def shadow_ix(y) return @m1.nil? ? @x1 : (y-@n1)/@m1 end def shadow_fx(y) return @m2.nil? ? @x2 : (y-@n2)/@m2 endendclass Spriteset_Map include Light_Core alias kbl_initialize initialize alias kbl_update update alias kbl_dispose dispose def initialize setup_lights kbl_initialize end def update kbl_update update_lights end def dispose kbl_dispose dispose_lights end def dispose_lights $game_map.lantern.dispose $game_map.light_sources.each { |source| source.dispose_light } $game_map.light_surface.bitmap.dispose $game_map.light_surface.dispose $game_map.light_surface = nil end def update_lights $game_map.light_surface.bitmap.clear $game_map.light_surface.bitmap.fill_rect(0,0,544,416,$game_map.effect_surface.color) $game_map.light_sources.each { |source| source.draw_light } return unless $game_map.lantern.visible @btr = $game_map.lantern.get_graphic x = $game_map.lantern.x y = $game_map.lantern.y r = $game_map.lantern.range sx = x + r sy = y + r dr = r*2 $game_map.surfaces.each { |s| s.render_shadow(x,y,sx,sy,r,@btr) if s.visible?(sx,sy) && s.within?(x,x+dr,y,y+dr) } $game_map.light_surface.bitmap.blt($game_map.lantern.sx,$game_map.lantern.sy,@btr,Rect.new(0,0,dr,dr),$game_map.lantern.opacity) end def setup_lights @btr = nil $game_map.lantern.restore $game_map.light_sources.each { |source| source.restore_light } $game_map.light_surface = Sprite.new $game_map.light_surface.bitmap = Bitmap.new(544,416) $game_map.light_surface.bitmap.fill_rect(0,0,544,416,$game_map.effect_surface.color) $game_map.light_surface.blend_type = 2 $game_map.light_surface.opacity = $game_map.effect_surface.alpha $game_map.light_surface.z = Surface_Z endend
#==============================================================================# VXAce Star Passability Bug Fix# by NeonBlack# -- Level: Easy, Normal# -- Requires: n/a# -- This simply checks if the tile is a star before checking passability. # If the tile is a star and it is passable, it then checks the tile UNDER it. # If not, it returns falseas always. This prevents everything that is a star # tile from being passable.## -- Original Topic:# http://forums.rpgmakerweb.com/index.php?/topic/7625-vxace-passabilities-bug/#==============================================================================class Game_Map def check_passage(x, y, bit) all_tiles(x, y).each do |tile_id| flag = tileset.flags[tile_id] if flag & 0x10 != 0 # [☆]: No effect on passage next if flag & bit == 0 # [○] : Passable but star return false if flag & bit == bit # [×] : Impassable else return true if flag & bit == 0 # [○] : Passable return false if flag & bit == bit # [×] : Impassable end end return false # Impassable endend
##------## Display rounding error fix created by Neon Black.#### When certain slow display panning speeds are used, events will improperly## round floating values to determine their position on screen. This causes## them to appear off from the tilemap by a single pixel. Though minor this is## noticable. This snippet fixes this behaviour.#### This snippet may be used in any project.#### -- Original Topic:## http://forums.rpgmakerweb.com/index.php?/topic/17448-event-jitter-fix-display-rounding-error-fix##------class Game_Map ## Rounds X and Y display values DOWN so the nearest 32 is found. def display_x (@display_x * 32).floor.to_f / 32 end def display_y (@display_y * 32).floor.to_f / 32 end def adjust_x(x) if loop_horizontal? && x < display_x - (width - screen_tile_x) / 2 x - display_x + @map.width else x - display_x end end def adjust_y(y) if loop_vertical? && y < display_y - (height - screen_tile_y) / 2 y - display_y + @map.height else y - display_y end endend
# starts the game in 1024x640 resolution it will look for a title image in # "Graphics/1024x640/Title1/filename" instead of "Graphics/Title1/filename"# # If it doesn't find a file in the resolution folder, it will look in the normal # spot for the file. So name your files consistantly :)# # This is a plug and play script. Place this script in the script editor towards# the bottom of the list in the section labeled "▼ Materials"##===============================================================================# ★☆★☆★☆★☆★☆★☆★☆★ TERMS AND CONDITIONS: ☆★☆★☆★☆★☆★☆★☆★☆★☆#===============================================================================# This script can be use in both commercial and non-commercial games.# Credit must be given to Dekita and Venka.#===============================================================================module SelRes #----------------------------------------------------------------------------- # Set up resoltion settings # You can add or take away from this list. It's best to use multiples of 32 # because tileset are 32 pixels. #----------------------------------------------------------------------------- Sizes = [ # [ "Name Text", Width, Height], # [ "Normal1" , 544, 416 ], # [ "Normal2" , 640, 480 ], # [ "Normal3" , 736, 576 ], # [ "Normal4" , 928, 704 ], # [ "Wide1" , 640, 416 ], [ "Máxima1" , 832, 544 ], [ "Máxima2" , 1024, 640 ], ] # <- Don't remove #----------------------------------------------------------------------------- # Pick the default resolution for when the game starts up for the first time. # The next time the game starts, the resolution will be whatever the player # picks. #----------------------------------------------------------------------------- Default_Size = [ "Máxima2" , 1024, 640 ] #----------------------------------------------------------------------------- # Select the first scene to show after the player picks their resolution. In # most cases this is "Scene_Title" unless you are using some custom start up. #----------------------------------------------------------------------------- First_Scene = Scene_Title Options_Text = "Resolução"end#===============================================================================module SceneManager#=============================================================================== #---------------------------------------------------------------------------- # ● overwrite method: first_scene_class #---------------------------------------------------------------------------- def self.first_scene_class if Graphics.initialize_resolution[1] size = Graphics.initialize_resolution[0] Graphics.resize_screen(size[1],size[2]) $BTEST ? Scene_Battle : SelRes::First_Scene else Scene_ResSel end endend#===============================================================================module Cache#=============================================================================== #---------------------------------------------------------------------------- # ● overwrite method: normal_bitmap #---------------------------------------------------------------------------- def self.normal_bitmap(path) if path[0..8] == "Graphics/" begin reso_path = path.clone reso_path.insert(9, "#{Graphics.width}x#{Graphics.height}/") @cache[reso_path] = Bitmap.new(reso_path) unless include?(reso_path) @cache[reso_path] rescue @cache[path] = Bitmap.new(path) unless include?(path) @cache[path] end end endend#===============================================================================class Window_ResSel < Window_Command#=============================================================================== #---------------------------------------------------------------------------- # ● upgraded method: initialize #---------------------------------------------------------------------------- def initialize(reso_size) super(0, 0) select(get_index(reso_size)) @reso = reso_size hide move_window end #---------------------------------------------------------------------------- # ○ new method: get_index #---------------------------------------------------------------------------- def get_index(reso_size) item_max.times do |i| return i if @list[i][:name] == "#{reso_size[1]}x#{reso_size[2]}" end end #---------------------------------------------------------------------------- # ○ new method: move_window #---------------------------------------------------------------------------- def move_window self.x = (Graphics.width - window_width) * 0.5 self.y = (Graphics.height - height) / 2 show end #---------------------------------------------------------------------------- # ● window settings #---------------------------------------------------------------------------- def window_width; return 220; end #---------------------------------------------------------------------------- # ● upgraded method: make_command_list #---------------------------------------------------------------------------- def make_command_list SelRes::Sizes.compact.each do |data| add_command("#{data[1]}x#{data[2]}", :reso) end end #---------------------------------------------------------------------------- # ● upgraded method: draw_item #---------------------------------------------------------------------------- def draw_item(index) rect = item_rect_for_text(index) rect.width = item_rect_for_text(index).width * 0.5 draw_text(rect, SelRes::Sizes[index][0], 1) rect.x += rect.width draw_text(rect, command_name(index), 1) endend#===============================================================================class Scene_ResSel < Scene_Base#=============================================================================== #---------------------------------------------------------------------------- # ● upgraded method: start #---------------------------------------------------------------------------- def start size = Graphics.initialize_resolution[0] Graphics.resize_screen(size[1],size[2]) super @command = Window_ResSel.new(size) @command.set_handler(:reso, method(:fix_reso)) end #---------------------------------------------------------------------------- # ○ new method: fix_reso #---------------------------------------------------------------------------- def fix_reso @command.hide size = SelRes::Sizes.compact[@command.index] Graphics.resize_screen(size[1], size[2]) Graphics.save_resolution(size) SceneManager.goto($BTEST ? Scene_Battle : SelRes::First_Scene) endend#===============================================================================class << Graphics#=============================================================================== #---------------------------------------------------------------------------- # ♦ Private Instance Variables #---------------------------------------------------------------------------- ReadIni = Win32API.new('kernel32', 'GetPrivateProfileString' , 'ppppip', 'i') WriteIni = Win32API.new('kernel32', 'WritePrivateProfileString', 'pppp' , 'i') #---------------------------------------------------------------------------- # ○ new method: initialize_resolution #---------------------------------------------------------------------------- def initialize_resolution @reso_setting = [] load_resolution set_up = (@reso_setting[1] == 0 ? false : true) @reso_setting = SelRes::Default_Size if @reso_setting[1] == 0 return [@reso_setting, set_up] end #---------------------------------------------------------------------------- # ○ new method: load_resolution #---------------------------------------------------------------------------- def load_resolution buffer = [].pack('x256') get_option = Proc.new do |key| l = ReadIni.call('Resolution', key, '0', buffer, buffer.size, './Game.ini') buffer[0, l] end @reso_setting[1] = get_option.call('Width', '0').to_i @reso_setting[2] = get_option.call('Height', '0').to_i end #---------------------------------------------------------------------------- # ○ new method: save_resolution #---------------------------------------------------------------------------- def save_resolution(setting) @reso_setting = setting set_option = Proc.new do |key, value| WriteIni.call('Resolution', key, value.to_s, './Game.ini') end set_option.call('Width', @reso_setting[1]) set_option.call('Height', @reso_setting[2]) endend#===============================================================================class Window_TitleCommand < Window_Command#=============================================================================== #---------------------------------------------------------------------------- # ● overwrite method: make_command_list #---------------------------------------------------------------------------- def make_command_list add_command(Vocab::new_game, :new_game) add_command(Vocab::continue, :continue, continue_enabled) add_command(SelRes::Options_Text, :settings) add_command(Vocab::shutdown, :shutdown) endend#===============================================================================class Scene_Title < Scene_Base#=============================================================================== #---------------------------------------------------------------------------- # ● alias method: create_command_window #---------------------------------------------------------------------------- alias :reso_settings_ccw :create_command_window def create_command_window reso_settings_ccw @command_window.set_handler(:settings, method(:command_settings)) end #---------------------------------------------------------------------------- # ○ new method: command_settings #---------------------------------------------------------------------------- def command_settings SceneManager.goto(Scene_ResSel) endend
$scrn_size = [X, Y]
#-------------------------------------------------------------------------------# * Por Khas Arcthunder - arcthunder.site40.net# * Versão: 1.0 BR# * Lançada em: 12/01/2012##-------------------------------------------------------------------------------# * Termos de uso#-------------------------------------------------------------------------------# Ao utilizar qualquer script feito por Khas, você concorda com os termos abaixo# 1. Você deve dar crédito a Khas se estiver usando algum script Khas;# 2. Todos os scripts Khas estão sob licença Creative Commons;# 3. Todos os scripts Khas são para projetos não comerciais, se você precisar de # algum script Khas em seu projeto comercial (aceito pedidos para esse tipo # de projeto), envie um email para nilokruch@live.com com o pedido;# 4. Todos os scripts Khas são para uso pessoal, você pode usar e editar para uso# no seu projeto, porém você não pode postar nenhuma versão modificada;# 5. Você não pode dar créditos a si próprio por postar algum script Khas;# 6. Caso queira compartilhar um script Khas, não poste o link direto de # download, apenas redirecione o usuário para arcthunder.site40.net ##-------------------------------------------------------------------------------# * Características#-------------------------------------------------------------------------------# - Efeitos de luz realista# - Luz real (não passa paredes!)# - Fontes de luz estática (que não se move)# - Fonte de luz dinâmica (uma lanterna para o jogador, por exemplo)# - Efeitos multiplos podem se juntar# - Fácil configuração# - Uso por comentário##-------------------------------------------------------------------------------# * IMPORTANTE - Desempenho#-------------------------------------------------------------------------------# Esse script pode vir a ser pesado para processadores muito antigos! O Awesome# Light Effects foi testado em um Core 2 Duo E4500 e em um Core i5, sem lag.# Porém, além do processador, há vários fatores que influenciam no desempenho # do script:# # 1. Tamanho do mapa# Este script analiza o mapa em busca de superfícies para cortar a luz. Em um# mapa muito grande, esse número de superfícies pode aumentar muito, afetando # o desempenho da LUZ DINÂMICA. O tamanho do mapa não influência nas luzes # estáticas.## 2. Quantidade de efeitos# Este script desenha os efeitos na tela, conforme sua posição. Antes de # atualizá-los, a sua posição é verificada. Portanto, em mapas muito grandes# com excesso de efeitos pode a vir ocorrer lag. Note que isso é apenas uma # previsão, pois nos testes atuais não foi detectado lag.## 3. Tamanho da imagem# O tamanho da imagem da luz dinâmica influencia diretamente no desempenho. # O corte de luz é feito linha a linha, quanto maior a resolução da imagem,# mais tempo será gasto para cortá-la. A recomendação é até 200x200 pixels.# #-------------------------------------------------------------------------------# * IMPORTANTE - Imagens de luz#-------------------------------------------------------------------------------# Para o funcionamento correto do script, as imagens de luz DEVEM obedecer# os seguintes critérios:## 1. O tamanho da imagem DEVE ser par. Exemplo: 150x150# 2. A imagem DEVE ser quadrada, com dimensões IGUAIS. Exemplo: 156x156# 3. A imagem DEVE estar com as cores invertidas! Isso é nescessário, pois o# script inverte as cores para desenhar o efeito na superfície de efeitos.# Lembre-se que a cor preta ficará transparente!##-------------------------------------------------------------------------------# * Instruções - 1. Configurando efeitos estáticos#-------------------------------------------------------------------------------# Para configurar efeitos estáticos, vá até a configuração (logo abaixo) e # defina os efeitos dentro da hash Effects. Faça do seguinte modo:## X => [imagem, opacidade, variação, corte], <= Lembre dessa vírgula no final!# # Onde:# Imagem => Nome da imagem na pasta "Graphics/Lights";# Opacidade => Opacidade da imagem;# Variação => Variação POSITIVA da opacidade;# Corte => Coloque true para cortar a imagem e false para não cortar;# X => É o ID do efeito, para ser usado nos eventos. Use um ID para cada efeito.## Veja os efeitos pré configurados para entender como funciona.##-------------------------------------------------------------------------------# * Instruções - 2. Usando o efeitos em eventos:#-------------------------------------------------------------------------------# Para usar o efeito definido em um evento, coloque o seguinte comentário:# # [light x]## Onde x deve ser o ID do efeito configurado.# #-------------------------------------------------------------------------------# * Instruções - 3. Utilizando a luz dinâmica (lanterna)#-------------------------------------------------------------------------------# A lanterna é automaticamente inicializada como invisível. Você pode usar os# seguintes métodos com o comando "Chamar Script":# # l = $game_map.lantern# Adiquire a lanterna em uma variável.# Você pode usar todos os comandos abaixo com "$game_map.lantern" ao # invés de adiquirir a lanterna em uma variável, porém tome cuidado, pois# o comando "Chamar Script" corta o código e pode gerar erros.# # l.set_graphic(i)# Muda o gráfico da lanterna para i, onde i deve ser o nome, entre aspas,# da imagem na pasta Graphics/Lights## l.set_multiple_graphics(h)# Muda os gráficos da lanterna para h, onde h deve ser uma Hash com o seguinte# formato:## h = {2=>"ld",4=>"ll",6=>"lr",8=>"lu"}# # Onde: # "ld" é o nome da imagem quando o portador está virado para baixo;# "ll" é o nome da imagem quando o portador está virado para esquerda;# "lr" é o nome da imagem quando o portador está virado para direita;# "lu" é o nome da imagem quando o portador está virado para cima.## l.change_owner(char)# Muda o portador da lanterna para char, onde char pode ser:# $game_player <= O jogador;# self_event <= O evento em que o comando é chamado;# $game_map.events[x] <= O evento de ID x do mapa.## l.set_opacity(o,p)# Ajusta a opacidade da lanterna, onde:# o é a opacidade padrão;# p é a variação POSITIVA da opacidade.## l.show# Depois de configurar a lanterna com os comandos acima, use este comando para# tornar a lanterna visível.## l.hide# Use este comando para esconder a lanterna.##-------------------------------------------------------------------------------# * Instruções - 4. Utilizando a superfície de efeitos (Chamar Script)#-------------------------------------------------------------------------------# O Awesome Light Effects desenha os efeitos sobre uma superfície. Para que# os efeitos estejam visíveis, a superfície de efeitos deve estar visível.# Para utilizar a superfície de efeitos, utilize os comandos abaixo:## s = $game_map.effect_surface# Adiquire a superfície em uma variável.# Você pode usar todos os comandos abaixo com "$game_map.effect_surface" ao # invés de adiquirir a superfície em uma variável, porém tome cuidado, pois# o comando "Chamar Script" corta o código e pode gerar erros.## s.set_color(r,g,b)# Muda a cor da superfície instantâneamente para a cor fornecida:# r => valor da cor vermelha;# g => valor da cor verde;# b => valor da cor azul.## s.set_alpha(a)# Muda a opacidade da superfície instantâneamente para a.## s.change_color(time,r,g,b)# Muda SOMENTE a cor da superfície em um certo tempo, onde:# time => tempo para a mudança (em frames);# r => valor da cor vermelha;# g => valor da cor verde;# b => valor da cor azul.## s.change_color(time,r,g,b,a)# Muda a cor da superfície e a opacidade em um certo tempo, onde:# time => tempo para a mudança (em frames);# r => valor da cor vermelha;# g => valor da cor verde;# b => valor da cor azul;# a => opacidade.## s.change_alpha(time,a)# Muda a opacidade da superfície em um certo tempo, onde:# time => tempo para a mudança (em frames);# a => opacidade.##-------------------------------------------------------------------------------# * Instruções - 5. Utilizando a superfície de efeitos (Evento)#-------------------------------------------------------------------------------# Você pode acessar a superfície de efeitos pelo comando "Tonalidade de Tela",# para isso, coloque a opção "Surface_UE" (nas configurações) como true. Caso# queria desabilitar essa opção e ter controle sobre o tom da tela, coloque a# opção "Surface_UE" como false. ## Observe os seguintes detalhes, se for usar esta opção:# 1. Os valores de cor devem estar entre 0 e 255;# 2. O tempo é em frames;# 3. O valor "Cinza" será enviado como a opacidade da superfície.##-------------------------------------------------------------------------------# * Instruções - 6. Configurando as Tags do mapa#-------------------------------------------------------------------------------# Afim de que as luzes sejam cortadas de forma precisa e realista, há 3 tipos# de comportamento para um tile: telhado, parede e bloco. Pense de maneira # lógica: um telhado gera sombras como telhado, uma parede como uma parede, e# assim por diante.## Para isso, as tags do tileset DEVEM ser configuradas. Por padrão, são # configuradas para 6,7 e 8. Veja a demo para ter noção de como isso funciona.## Note que o script só irá analizar a primeira camada (camada A) do mapa. Certos# tilesets não irão funcionar caso os tiles não estejam configurados de modo # correto. Note ainda que este script depende do bom mapeamento para funcionar,# preste atenção aos detalhes do seu mapa.##-------------------------------------------------------------------------------# * Configuração#-------------------------------------------------------------------------------module Light_Core Effects = { # Não mude isto!#-------------------------------------------------------------------------------# ADICIONE ABAIXO OS SEUS EFEITOS!#------------------------------------------------------------------------------- 0 => ["light",255,0,true], 1 => ["torch",200,20,true], 2 => ["torch_m",180,30,true], 3 => ["light_s",255,0,true], #-------------------------------------------------------------------------------# Fim da configuração de efeitos#------------------------------------------------------------------------------- } # Não mude isto! # Coordenada Z da superfície de efeitos: Surface_Z = 180 # Resolução $scrn_size = [1024, 640] # Habilitar controle da superfície por "Tonalidade da Tela"? Surface_UE = true # Tag para a superfície se comportar como "telhado" Roof_Tag = 5 # Tag para a superfície se comportar como "parede" Wall_Tag = 6 # Tag para a superfície se comportar como "bloco" (semelhante ao telhado) Block_Tag = 7 # Constante de correção de ângulo (não altere) ACC = Math.tan(Math::PI/26)end#-------------------------------------------------------------------------------# Fim da configuração - Início do script#-------------------------------------------------------------------------------module Cache def self.light(filename) load_bitmap("Graphics/Lights/", filename) endendmodule Light_Bitcore include Light_Core def self.initialize @@buffer = {} Effects.values.each { |effect| Light_Bitcore.push(effect[0])} end def self::[](key) return @@buffer[key] end def self.push(key) return if @@buffer.keys.include?(key) @@buffer[key] = Cache.light(key) endendLight_Bitcore.initializeclass Light_SSource attr_reader :real_x attr_reader :real_y attr_reader :range attr_accessor :bitmap attr_reader :w attr_reader :h attr_reader :hs def initialize(char,bitmap,opacity,plus,hs) sync(char) @key = bitmap @bitmap = Light_Bitcore[@key].clone @range = @bitmap.width/2 @w = @bitmap.width @h = @bitmap.height @mr = @range - 16 @opacity = opacity @plus = plus @hs = hs render if @hs end def render tx = x ty = y tsx = x + @range tsy = y + @range dr = @range*2 for s in $game_map.surfaces next if !s.visible?(tsx,tsy) || !s.within?(tx,tx+dr,ty,ty+dr) s.render_shadow(tx,ty,tsx,tsy,@range,@bitmap) end end def restore return unless @bitmap.nil? @bitmap = Light_Bitcore[@key].clone render if @hs end def opacity @plus == 0 ? @opacity : (@opacity + rand(@plus)) end def sx return $game_map.adjust_x(@real_x)*32-@mr end def sy return $game_map.adjust_y(@real_y)*32-@mr end def sync(char) @real_x = char.real_x @real_y = char.real_y end def x return (@real_x*32 - @mr).to_f end def y return (@real_y*32 - @mr).to_f end def dispose return if @bitmap.nil? @bitmap.dispose @bitmap = nil endendclass Light_DSource < Light_SSource attr_reader :bitmap attr_reader :visible def initialize @key = nil @bitmap = nil @opacity = 255 @plus = 0 @char = $game_player @visible = false end def set_opacity(o,p) @opacity = o @plus = p end def set_graphic(sb) dispose @key = {2=>sb,4=>sb,6=>sb,8=>sb} Light_Bitcore.push(sb) @bitmap = {2=>Light_Bitcore[@key[2]].clone,4=>Light_Bitcore[@key[4]].clone,6=>Light_Bitcore[@key[6]].clone,8=>Light_Bitcore[@key[8]].clone} @range = @bitmap[2].width/2 @w = @bitmap[2].width @h = @bitmap[2].height @mr = @range - 16 end def set_multiple_graphics(ba) dispose @key = ba @key.values.each {|key| Light_Bitcore.push(key)} @bitmap = {2=>Light_Bitcore[@key[2]].clone,4=>Light_Bitcore[@key[4]].clone,6=>Light_Bitcore[@key[6]].clone,8=>Light_Bitcore[@key[8]].clone} @range = @bitmap[2].width/2 @w = @bitmap[2].width @h = @bitmap[2].height @mr = @range - 16 end def get_graphic return @bitmap[@char.direction].clone end def show return if @bitmap.nil? @visible = true end def hide @visible = false end def restore return if @key.nil? @key.values.each {|key| Light_Bitcore.push(key)} @bitmap = {2=>Light_Bitcore[@key[2]].clone,4=>Light_Bitcore[@key[4]].clone,6=>Light_Bitcore[@key[6]].clone,8=>Light_Bitcore[@key[8]].clone} end def dispose return if @bitmap.nil? @bitmap.values.each { |b| b.dispose } @bitmap = nil end def change_owner(char) @char = char end def render end def sx return $game_map.adjust_x(@char.real_x)*32-@mr end def sy return $game_map.adjust_y(@char.real_y)*32-@mr end def x return (@char.real_x*32 - @mr).to_f end def y return (@char.real_y*32 - @mr).to_f endendclass Light_Surface def initialize @ta = @a = 0 @tr = @r = 255 @tg = @g = 255 @tb = @b = 255 @va = @vr = @vg = @vb = 0.0 @timer = 0 end def refresh return if @timer == 0 @a += @va @r += @vr @g += @vg @b += @vb $game_map.light_surface.opacity = @a @timer -= 1 end def change_color(time,r,g,b,a=nil) r = 0 if r < 0; r = 255 if r > 255 g = 0 if g < 0; g = 255 if g > 255 b = 0 if b < 0; b = 255 if b > 255 unless a.nil? a = 0 if a < 0; a = 255 if a > 255 end @timer = time @tr = 255-r @tg = 255-g @tb = 255-b @va = (a.nil? ? 0 : (a-@a).to_f/@timer) @vr = (@tr - @r).to_f/@timer @vg = (@tg - @g).to_f/@timer @vb = (@tb - @b).to_f/@timer end def change_alpha(time,a) a = 0 if a < 0; a = 255 if a > 255 @timer = time @ta = a @vr = @vg = @vb = 0.0 @va = (a-@a).to_f/@timer end def set_color(r,g,b) r = 0 if r < 0; r = 255 if r > 255 g = 0 if g < 0; g = 255 if g > 255 b = 0 if b < 0; b = 255 if b > 255 @tr = @r = 255-r @tg = @g = 255-g @tb = @b = 255-b @va = @vr = @vg = @vb = 0.0 @timer = 0 end def set_alpha(a) a = 0 if a < 0; a = 255 if a > 255 @ta = @a = a $game_map.light_surface.opacity = @a @va = @vr = @vg = @vb = 0.0 @timer = 0 end def alpha return @a end def color return Color.new(@r,@g,@b) endendclass Game_Map include Light_Core attr_accessor :light_surface attr_accessor :light_sources attr_accessor :surfaces attr_accessor :effect_surface attr_accessor :lantern alias kbl_setup_events setup_events alias kbl_initialize initialize alias kbl_update update def initialize kbl_initialize @effect_surface = Light_Surface.new @lantern = Light_DSource.new end def update(arg) @effect_surface.refresh if arg kbl_update(arg) end def first_tag(x,y) tag = tileset.flags[tile_id(x,y,0)] >> 12 return tag > 0 ? tag : 0 end def setup_events @light_sources.nil? ? @light_sources = [] : @light_sources.clear setup_surfaces merge_surfaces kbl_setup_events end def setup_surfaces @surfaces = [] for x in 0..(width-1) for y in 0..(height-1) tag = first_tag(x,y) if tag == Wall_Tag i = tile_id(x,y,0) if i & 0x02 == 0x02 @surfaces << Block_SD.new(x*32,y*32,x*32+32,y*32) end if i & 0x04 == 0x04 @surfaces << Block_WR.new(x*32+31,y*32,x*32+31,y*32+32) @surfaces << Block_IL.new(x*32+32,y*32,x*32+32,y*32+32) end if i & 0x01 == 0x01 @surfaces << Block_IR.new(x*32-1,y*32,x*32-1,y*32+32) @surfaces << Block_WL.new(x*32,y*32,x*32,y*32+32) end elsif tag == Roof_Tag i = tile_id(x,y,0) @surfaces << Block_SU.new(x*32,y*32,x*32+32,y*32) if i & 0x02 == 0x02 @surfaces << Block_SR.new(x*32+31,y*32,x*32+31,y*32+32) if i & 0x04 == 0x04 @surfaces << Block_SL.new(x*32,y*32,x*32,y*32+32) if i & 0x01 == 0x01 elsif tag == Block_Tag f = tileset.flags[tile_id(x,y,0)] @surfaces << Block_SL.new(x*32,y*32,x*32,y*32+32) if f & 0x02 == 0x02 @surfaces << Block_SR.new(x*32+31,y*32,x*32+31,y*32+32) if f & 0x04 == 0x04 @surfaces << Block_SU.new(x*32,y*32,x*32+32,y*32) if f & 0x08 == 0x08 end end end end def merge_surfaces new_surfaces = [] hs = []; vs = [] ws = []; is = [] for surface in @surfaces if surface.type & 0x05 == 0 hs << surface else if surface.type & 0x010 == 0 vs << surface else if surface.type & 0x08 == 0 ws << surface else is << surface end end end end for surface in hs surface.ready ? next : surface.ready = true for s in hs next if s.ready || s.y1 != surface.y1 || surface.type != s.type if s.x2 == surface.x1 surface.x1 = s.x1 s.trash = true s.ready = true surface.ready = false elsif s.x1 == surface.x2 surface.x2 = s.x2 s.trash = true s.ready = true surface.ready = false end end end hs.each { |s| @surfaces.delete(s) if s.trash} for surface in vs surface.ready ? next : surface.ready for s in vs next if s.ready || s.x1 != surface.x1 if s.y2 == surface.y1 surface.y1 = s.y1 s.trash = true s.ready = true surface.ready = false elsif s.y1 == surface.y2 surface.y2 = s.y2 s.trash = true s.ready = true surface.ready = false end end end vs.each { |s| @surfaces.delete(s) if s.trash} for surface in ws surface.ready ? next : surface.ready for s in ws next if s.ready || s.x1 != surface.x1 if s.y2 == surface.y1 surface.y1 = s.y1 s.trash = true s.ready = true surface.ready = false elsif s.y1 == surface.y2 surface.y2 = s.y2 s.trash = true s.ready = true surface.ready = false end end end ws.each { |s| @surfaces.delete(s) if s.trash} for surface in is surface.ready ? next : surface.ready for s in is next if s.ready || s.x1 != surface.x1 if s.y2 == surface.y1 surface.y1 = s.y1 s.trash = true s.ready = true surface.ready = false elsif s.y1 == surface.y2 surface.y2 = s.y2 s.trash = true s.ready = true surface.ready = false end end end is.each { |s| @surfaces.delete(s) if s.trash} endendclass Game_Event < Game_Character alias kbl_initialize initialize alias kbl_setup_page setup_page def initialize(m,e) @light = nil kbl_initialize(m,e) end def setup_page(np) kbl_setup_page(np) setup_light(np.nil?) end def setup_light(dispose) unless @light.nil? $game_map.light_sources.delete(self) @light.dispose @light = nil end unless dispose && @list.nil? for command in @list if command.code == 108 && command.parameters[0].include?("[light") command.parameters[0].scan(/\[light ([0.0-9.9]+)\]/) effect = Light_Core::Effects[$1.to_i] @light = Light_SSource.new(self,effect[0],effect[1],effect[2],effect[3]) $game_map.light_sources << self return end end end end def draw_light sx = @light.sx sy = @light.sy w = @light.w h = @light.h return if sx > $scrn_size[0] && sy > $scrn_size[1] && sx + w < 0 && sy + h < 0 $game_map.light_surface.bitmap.blt(sx,sy,@light.bitmap,Rect.new(0,0,w,h),@light.opacity) end def dispose_light @light.dispose end def restore_light @light.restore endendif Light_Core::Surface_UE class Game_Interpreter def command_223 $game_map.effect_surface.change_color(@params[1],@params[0].red,@params[0].green,@params[0].blue,@params[0].gray) wait(@params[1]) if @params[2] end endendclass Game_Interpreter def self_event return $game_map.events[@event_id] endendclass Block_Surface include Light_Core attr_accessor :x1 attr_accessor :y1 attr_accessor :x2 attr_accessor :y2 attr_accessor :ready attr_accessor :trash def initialize(x1,y1,x2,y2) @x1 = x1 @y1 = y1 @x2 = x2 @y2 = y2 @ready = false @trash = false end def within?(min_x,max_x,min_y,max_y) return @x2 > min_x && @x1 < max_x && @y2 > min_y && @y1 < max_y endendclass Block_SL < Block_Surface attr_reader :type def initialize(x1,y1,x2,y2) super(x1,y1,x2,y2) @type = 0x01 end def visible?(sx,sy) return sx < @x1 end def render_shadow(phx,phy,sx,sy,range,bitmap) @m1 = (@y1-sy)/(@x1-sx) @n1 = sy - @m1*sx @m2 = (@y2-sy)/(@x2-sx) @n2 = sy - @m2*sx for x in @x1..(sx+range) init = shadow_iy(x) bitmap.clear_rect(x-phx,init-phy,1,shadow_fy(x)-init+3) end end def shadow_iy(x) return @m1*x+@n1 end def shadow_fy(x) return @m2*x+@n2 endendclass Block_SR < Block_Surface attr_reader :type def initialize(x1,y1,x2,y2) super(x1,y1,x2,y2) @type = 0x04 end def visible?(sx,sy) return sx > @x1 end def render_shadow(phx,phy,sx,sy,range,bitmap) @m1 = (@y1-sy)/(@x1-sx) @n1 = sy - @m1*sx @m2 = (@y2-sy)/(@x2-sx) @n2 = sy - @m2*sx for x in (sx-range).to_i..@x1 init = shadow_iy(x) bitmap.clear_rect(x-phx,init-phy,1,shadow_fy(x)-init+3) end end def shadow_iy(x) return @m1*x+@n1 end def shadow_fy(x) return @m2*x+@n2 endendclass Block_IL < Block_Surface attr_reader :type def initialize(x1,y1,x2,y2) super(x1,y1,x2,y2) @type = 0x019 end def visible?(sx,sy) return sx < @x1 && sy > @y1 end def render_shadow(phx,phy,sx,sy,range,bitmap) @m1 = (@y1-sy)/(@x1-sx) @n1 = @y1 - @m1*@x1 @m2 = (@y2-sy)/(@x2-sx) @m2 = 0 if @m2 > 0 @n2 = @y2 - @m2*@x2 for x in @x1..(sx+range) init = shadow_iy(x).floor bitmap.clear_rect(x-phx,init-3-phy,1,shadow_fy(x)-init+3) end end def shadow_iy(x) return @m1*x+@n1 end def shadow_fy(x) return @m2*x+@n2 endendclass Block_IR < Block_Surface attr_reader :type def initialize(x1,y1,x2,y2) super(x1,y1,x2,y2) @type = 0x01c end def visible?(sx,sy) return sx > @x1 && sy > @y1 end def render_shadow(phx,phy,sx,sy,range,bitmap) @m1 = (@y1-sy)/(@x1-sx) @n1 = @y1 - @m1*@x1 @m2 = (@y2-sy)/(@x2-sx) @m2 = 0 if @m2 < 0 @n2 = @y2 - @m2*@x2 for x in (sx-range).to_i..@x1 init = shadow_iy(x).floor bitmap.clear_rect(x-phx,init-3-phy,1,shadow_fy(x)-init+3) end end def shadow_iy(x) return @m1*x+@n1 end def shadow_fy(x) return @m2*x+@n2 endendclass Block_WL < Block_Surface attr_reader :type def initialize(x1,y1,x2,y2) super(x1,y1,x2,y2) @type = 0x011 end def visible?(sx,sy) return sx < @x1 && sy < @y2 end def render_shadow(phx,phy,sx,sy,range,bitmap) @m1 = (@y1-sy)/(@x1-sx) @n1 = sy - @m1*sx @m2 = (@y2-sy)/(@x2-sx) @n2 = sy - @m2*sx for x in @x1..(sx+range) init = shadow_iy(x) bitmap.clear_rect(x-phx,init-phy,1,shadow_fy(x)-init+2) end end def shadow_iy(x) return @m1*x+@n1 end def shadow_fy(x) return @m2*x+@n2 endendclass Block_WR < Block_Surface attr_reader :type def initialize(x1,y1,x2,y2) super(x1,y1,x2,y2) @type = 0x014 end def visible?(sx,sy) return sx > @x1 && sy < @y2 end def render_shadow(phx,phy,sx,sy,range,bitmap) @m1 = (@y1-sy)/(@x1-sx) @n1 = sy - @m1*sx @m2 = (@y2-sy)/(@x2-sx) @n2 = sy - @m2*sx for x in (sx-range).to_i..@x1 init = shadow_iy(x) bitmap.clear_rect(x-phx,init-phy,1,shadow_fy(x)-init+2) end end def shadow_iy(x) return @m1*x+@n1 end def shadow_fy(x) return @m2*x+@n2 endendclass Block_SU < Block_Surface attr_reader :type def initialize(x1,y1,x2,y2) super(x1,y1,x2,y2) @type = 0x02 end def visible?(sx,sy) return sy < @y1 end def render_shadow(phx,phy,sx,sy,range,bitmap) if @x1 == sx @m1 = nil else @m1 = (@y1-sy)/(@x1-sx) @m1 += ACC if @m1 < -ACC @n1 = @y1 - @m1*@x1 end if @x2 == sx @m2 = nil else @m2 = (@y2-sy)/(@x2-sx) @n2 = sy - @m2*sx end for y in @y1..(sy+range) init = shadow_ix(y) bitmap.clear_rect(init-phx,y-phy,shadow_fx(y)-init+1,1) end end def shadow_ix(y) return @m1.nil? ? @x1 : (y-@n1)/@m1 end def shadow_fx(y) return @m2.nil? ? @x2 : (y-@n2)/@m2 endendclass Block_SD < Block_Surface attr_reader :type def initialize(x1,y1,x2,y2) super(x1,y1,x2,y2) @type = 0x08 end def visible?(sx,sy) return sy > @y1 end def render_shadow(phx,phy,sx,sy,range,bitmap) if @x1 == sx @m1 = nil else @m1 = (@y1-sy)/(@x1-sx) @m1 -= ACC if @m1 > ACC @n1 = sy - @m1*sx end if x2 == sx @m2 = nil else @m2 = (@y2-sy)/(@x2-sx) @n2 = sy - @m2*sx end for y in (sy-range).to_i..@y1 init = shadow_ix(y) bitmap.clear_rect(init-phx,y-phy,shadow_fx(y)-init+1,1) end end def shadow_ix(y) return @m1.nil? ? @x1 : (y-@n1)/@m1 end def shadow_fx(y) return @m2.nil? ? @x2 : (y-@n2)/@m2 endendclass Spriteset_Map include Light_Core alias kbl_initialize initialize alias kbl_update update alias kbl_dispose dispose def initialize setup_lights kbl_initialize end def update kbl_update update_lights end def dispose kbl_dispose dispose_lights end def dispose_lights $game_map.lantern.dispose $game_map.light_sources.each { |source| source.dispose_light } $game_map.light_surface.bitmap.dispose $game_map.light_surface.dispose $game_map.light_surface = nil end def update_lights $game_map.light_surface.bitmap.clear $game_map.light_surface.bitmap.fill_rect(0,0,$scrn_size[0],$scrn_size[1],$game_map.effect_surface.color) $game_map.light_sources.each { |source| source.draw_light } return unless $game_map.lantern.visible @btr = $game_map.lantern.get_graphic x = $game_map.lantern.x y = $game_map.lantern.y r = $game_map.lantern.range sx = x + r sy = y + r dr = r*2 $game_map.surfaces.each { |s| s.render_shadow(x,y,sx,sy,r,@btr) if s.visible?(sx,sy) && s.within?(x,x+dr,y,y+dr) } $game_map.light_surface.bitmap.blt($game_map.lantern.sx,$game_map.lantern.sy,@btr,Rect.new(0,0,dr,dr),$game_map.lantern.opacity) end def setup_lights @btr = nil $game_map.lantern.restore $game_map.light_sources.each { |source| source.restore_light } $game_map.light_surface = Sprite.new $game_map.light_surface.bitmap = Bitmap.new($scrn_size[0],$scrn_size[1]) $game_map.light_surface.bitmap.fill_rect(0,0,$scrn_size[0],$scrn_size[1],$game_map.effect_surface.color) $game_map.light_surface.blend_type = 2 $game_map.light_surface.opacity = $game_map.effect_surface.alpha $game_map.light_surface.z = Surface_Z endend
Então, o script do Khas foi criado com base na resolução padrão. Logo, a causa do erro é essa mesma. O problema é, pelo que olhei aqui, ele não criou os valores da resolução de modo configurável, só espalhou um monte de valores fixos pelo script inteiro. Editei aqui, mas não testei - e nem sei se vai funcionar, pra falar a verdade. A configuração da resolução está no início do código:Código: [Selecionar]$scrn_size = [X, Y]X e Y são largura e altura, respectivamente.Código: [Selecionar]#-------------------------------------------------------------------------------# * Por Khas Arcthunder - arcthunder.site40.net# * Versão: 1.0 BR# * Lançada em: 12/01/2012##-------------------------------------------------------------------------------# * Termos de uso#-------------------------------------------------------------------------------# Ao utilizar qualquer script feito por Khas, você concorda com os termos abaixo# 1. Você deve dar crédito a Khas se estiver usando algum script Khas;# 2. Todos os scripts Khas estão sob licença Creative Commons;# 3. Todos os scripts Khas são para projetos não comerciais, se você precisar de # algum script Khas em seu projeto comercial (aceito pedidos para esse tipo # de projeto), envie um email para nilokruch@live.com com o pedido;# 4. Todos os scripts Khas são para uso pessoal, você pode usar e editar para uso# no seu projeto, porém você não pode postar nenhuma versão modificada;# 5. Você não pode dar créditos a si próprio por postar algum script Khas;# 6. Caso queira compartilhar um script Khas, não poste o link direto de # download, apenas redirecione o usuário para arcthunder.site40.net ##-------------------------------------------------------------------------------# * Características#-------------------------------------------------------------------------------# - Efeitos de luz realista# - Luz real (não passa paredes!)# - Fontes de luz estática (que não se move)# - Fonte de luz dinâmica (uma lanterna para o jogador, por exemplo)# - Efeitos multiplos podem se juntar# - Fácil configuração# - Uso por comentário##-------------------------------------------------------------------------------# * IMPORTANTE - Desempenho#-------------------------------------------------------------------------------# Esse script pode vir a ser pesado para processadores muito antigos! O Awesome# Light Effects foi testado em um Core 2 Duo E4500 e em um Core i5, sem lag.# Porém, além do processador, há vários fatores que influenciam no desempenho # do script:# # 1. Tamanho do mapa# Este script analiza o mapa em busca de superfícies para cortar a luz. Em um# mapa muito grande, esse número de superfícies pode aumentar muito, afetando # o desempenho da LUZ DINÂMICA. O tamanho do mapa não influência nas luzes # estáticas.## 2. Quantidade de efeitos# Este script desenha os efeitos na tela, conforme sua posição. Antes de # atualizá-los, a sua posição é verificada. Portanto, em mapas muito grandes# com excesso de efeitos pode a vir ocorrer lag. Note que isso é apenas uma # previsão, pois nos testes atuais não foi detectado lag.## 3. Tamanho da imagem# O tamanho da imagem da luz dinâmica influencia diretamente no desempenho. # O corte de luz é feito linha a linha, quanto maior a resolução da imagem,# mais tempo será gasto para cortá-la. A recomendação é até 200x200 pixels.# #-------------------------------------------------------------------------------# * IMPORTANTE - Imagens de luz#-------------------------------------------------------------------------------# Para o funcionamento correto do script, as imagens de luz DEVEM obedecer# os seguintes critérios:## 1. O tamanho da imagem DEVE ser par. Exemplo: 150x150# 2. A imagem DEVE ser quadrada, com dimensões IGUAIS. Exemplo: 156x156# 3. A imagem DEVE estar com as cores invertidas! Isso é nescessário, pois o# script inverte as cores para desenhar o efeito na superfície de efeitos.# Lembre-se que a cor preta ficará transparente!##-------------------------------------------------------------------------------# * Instruções - 1. Configurando efeitos estáticos#-------------------------------------------------------------------------------# Para configurar efeitos estáticos, vá até a configuração (logo abaixo) e # defina os efeitos dentro da hash Effects. Faça do seguinte modo:## X => [imagem, opacidade, variação, corte], <= Lembre dessa vírgula no final!# # Onde:# Imagem => Nome da imagem na pasta "Graphics/Lights";# Opacidade => Opacidade da imagem;# Variação => Variação POSITIVA da opacidade;# Corte => Coloque true para cortar a imagem e false para não cortar;# X => É o ID do efeito, para ser usado nos eventos. Use um ID para cada efeito.## Veja os efeitos pré configurados para entender como funciona.##-------------------------------------------------------------------------------# * Instruções - 2. Usando o efeitos em eventos:#-------------------------------------------------------------------------------# Para usar o efeito definido em um evento, coloque o seguinte comentário:# # [light x]## Onde x deve ser o ID do efeito configurado.# #-------------------------------------------------------------------------------# * Instruções - 3. Utilizando a luz dinâmica (lanterna)#-------------------------------------------------------------------------------# A lanterna é automaticamente inicializada como invisível. Você pode usar os# seguintes métodos com o comando "Chamar Script":# # l = $game_map.lantern# Adiquire a lanterna em uma variável.# Você pode usar todos os comandos abaixo com "$game_map.lantern" ao # invés de adiquirir a lanterna em uma variável, porém tome cuidado, pois# o comando "Chamar Script" corta o código e pode gerar erros.# # l.set_graphic(i)# Muda o gráfico da lanterna para i, onde i deve ser o nome, entre aspas,# da imagem na pasta Graphics/Lights## l.set_multiple_graphics(h)# Muda os gráficos da lanterna para h, onde h deve ser uma Hash com o seguinte# formato:## h = {2=>"ld",4=>"ll",6=>"lr",8=>"lu"}# # Onde: # "ld" é o nome da imagem quando o portador está virado para baixo;# "ll" é o nome da imagem quando o portador está virado para esquerda;# "lr" é o nome da imagem quando o portador está virado para direita;# "lu" é o nome da imagem quando o portador está virado para cima.## l.change_owner(char)# Muda o portador da lanterna para char, onde char pode ser:# $game_player <= O jogador;# self_event <= O evento em que o comando é chamado;# $game_map.events[x] <= O evento de ID x do mapa.## l.set_opacity(o,p)# Ajusta a opacidade da lanterna, onde:# o é a opacidade padrão;# p é a variação POSITIVA da opacidade.## l.show# Depois de configurar a lanterna com os comandos acima, use este comando para# tornar a lanterna visível.## l.hide# Use este comando para esconder a lanterna.##-------------------------------------------------------------------------------# * Instruções - 4. Utilizando a superfície de efeitos (Chamar Script)#-------------------------------------------------------------------------------# O Awesome Light Effects desenha os efeitos sobre uma superfície. Para que# os efeitos estejam visíveis, a superfície de efeitos deve estar visível.# Para utilizar a superfície de efeitos, utilize os comandos abaixo:## s = $game_map.effect_surface# Adiquire a superfície em uma variável.# Você pode usar todos os comandos abaixo com "$game_map.effect_surface" ao # invés de adiquirir a superfície em uma variável, porém tome cuidado, pois# o comando "Chamar Script" corta o código e pode gerar erros.## s.set_color(r,g,b)# Muda a cor da superfície instantâneamente para a cor fornecida:# r => valor da cor vermelha;# g => valor da cor verde;# b => valor da cor azul.## s.set_alpha(a)# Muda a opacidade da superfície instantâneamente para a.## s.change_color(time,r,g,b)# Muda SOMENTE a cor da superfície em um certo tempo, onde:# time => tempo para a mudança (em frames);# r => valor da cor vermelha;# g => valor da cor verde;# b => valor da cor azul.## s.change_color(time,r,g,b,a)# Muda a cor da superfície e a opacidade em um certo tempo, onde:# time => tempo para a mudança (em frames);# r => valor da cor vermelha;# g => valor da cor verde;# b => valor da cor azul;# a => opacidade.## s.change_alpha(time,a)# Muda a opacidade da superfície em um certo tempo, onde:# time => tempo para a mudança (em frames);# a => opacidade.##-------------------------------------------------------------------------------# * Instruções - 5. Utilizando a superfície de efeitos (Evento)#-------------------------------------------------------------------------------# Você pode acessar a superfície de efeitos pelo comando "Tonalidade de Tela",# para isso, coloque a opção "Surface_UE" (nas configurações) como true. Caso# queria desabilitar essa opção e ter controle sobre o tom da tela, coloque a# opção "Surface_UE" como false. ## Observe os seguintes detalhes, se for usar esta opção:# 1. Os valores de cor devem estar entre 0 e 255;# 2. O tempo é em frames;# 3. O valor "Cinza" será enviado como a opacidade da superfície.##-------------------------------------------------------------------------------# * Instruções - 6. Configurando as Tags do mapa#-------------------------------------------------------------------------------# Afim de que as luzes sejam cortadas de forma precisa e realista, há 3 tipos# de comportamento para um tile: telhado, parede e bloco. Pense de maneira # lógica: um telhado gera sombras como telhado, uma parede como uma parede, e# assim por diante.## Para isso, as tags do tileset DEVEM ser configuradas. Por padrão, são # configuradas para 6,7 e 8. Veja a demo para ter noção de como isso funciona.## Note que o script só irá analizar a primeira camada (camada A) do mapa. Certos# tilesets não irão funcionar caso os tiles não estejam configurados de modo # correto. Note ainda que este script depende do bom mapeamento para funcionar,# preste atenção aos detalhes do seu mapa.##-------------------------------------------------------------------------------# * Configuração#-------------------------------------------------------------------------------module Light_Core Effects = { # Não mude isto!#-------------------------------------------------------------------------------# ADICIONE ABAIXO OS SEUS EFEITOS!#------------------------------------------------------------------------------- 0 => ["light",255,0,true], 1 => ["torch",200,20,true], 2 => ["torch_m",180,30,true], 3 => ["light_s",255,0,true], #-------------------------------------------------------------------------------# Fim da configuração de efeitos#------------------------------------------------------------------------------- } # Não mude isto! # Coordenada Z da superfície de efeitos: Surface_Z = 180 # Resolução $scrn_size = [1024, 640] # Habilitar controle da superfície por "Tonalidade da Tela"? Surface_UE = true # Tag para a superfície se comportar como "telhado" Roof_Tag = 5 # Tag para a superfície se comportar como "parede" Wall_Tag = 6 # Tag para a superfície se comportar como "bloco" (semelhante ao telhado) Block_Tag = 7 # Constante de correção de ângulo (não altere) ACC = Math.tan(Math::PI/26)end#-------------------------------------------------------------------------------# Fim da configuração - Início do script#-------------------------------------------------------------------------------module Cache def self.light(filename) load_bitmap("Graphics/Lights/", filename) endendmodule Light_Bitcore include Light_Core def self.initialize @@buffer = {} Effects.values.each { |effect| Light_Bitcore.push(effect[0])} end def self::[](key) return @@buffer[key] end def self.push(key) return if @@buffer.keys.include?(key) @@buffer[key] = Cache.light(key) endendLight_Bitcore.initializeclass Light_SSource attr_reader :real_x attr_reader :real_y attr_reader :range attr_accessor :bitmap attr_reader :w attr_reader :h attr_reader :hs def initialize(char,bitmap,opacity,plus,hs) sync(char) @key = bitmap @bitmap = Light_Bitcore[@key].clone @range = @bitmap.width/2 @w = @bitmap.width @h = @bitmap.height @mr = @range - 16 @opacity = opacity @plus = plus @hs = hs render if @hs end def render tx = x ty = y tsx = x + @range tsy = y + @range dr = @range*2 for s in $game_map.surfaces next if !s.visible?(tsx,tsy) || !s.within?(tx,tx+dr,ty,ty+dr) s.render_shadow(tx,ty,tsx,tsy,@range,@bitmap) end end def restore return unless @bitmap.nil? @bitmap = Light_Bitcore[@key].clone render if @hs end def opacity @plus == 0 ? @opacity : (@opacity + rand(@plus)) end def sx return $game_map.adjust_x(@real_x)*32-@mr end def sy return $game_map.adjust_y(@real_y)*32-@mr end def sync(char) @real_x = char.real_x @real_y = char.real_y end def x return (@real_x*32 - @mr).to_f end def y return (@real_y*32 - @mr).to_f end def dispose return if @bitmap.nil? @bitmap.dispose @bitmap = nil endendclass Light_DSource < Light_SSource attr_reader :bitmap attr_reader :visible def initialize @key = nil @bitmap = nil @opacity = 255 @plus = 0 @char = $game_player @visible = false end def set_opacity(o,p) @opacity = o @plus = p end def set_graphic(sb) dispose @key = {2=>sb,4=>sb,6=>sb,8=>sb} Light_Bitcore.push(sb) @bitmap = {2=>Light_Bitcore[@key[2]].clone,4=>Light_Bitcore[@key[4]].clone,6=>Light_Bitcore[@key[6]].clone,8=>Light_Bitcore[@key[8]].clone} @range = @bitmap[2].width/2 @w = @bitmap[2].width @h = @bitmap[2].height @mr = @range - 16 end def set_multiple_graphics(ba) dispose @key = ba @key.values.each {|key| Light_Bitcore.push(key)} @bitmap = {2=>Light_Bitcore[@key[2]].clone,4=>Light_Bitcore[@key[4]].clone,6=>Light_Bitcore[@key[6]].clone,8=>Light_Bitcore[@key[8]].clone} @range = @bitmap[2].width/2 @w = @bitmap[2].width @h = @bitmap[2].height @mr = @range - 16 end def get_graphic return @bitmap[@char.direction].clone end def show return if @bitmap.nil? @visible = true end def hide @visible = false end def restore return if @key.nil? @key.values.each {|key| Light_Bitcore.push(key)} @bitmap = {2=>Light_Bitcore[@key[2]].clone,4=>Light_Bitcore[@key[4]].clone,6=>Light_Bitcore[@key[6]].clone,8=>Light_Bitcore[@key[8]].clone} end def dispose return if @bitmap.nil? @bitmap.values.each { |b| b.dispose } @bitmap = nil end def change_owner(char) @char = char end def render end def sx return $game_map.adjust_x(@char.real_x)*32-@mr end def sy return $game_map.adjust_y(@char.real_y)*32-@mr end def x return (@char.real_x*32 - @mr).to_f end def y return (@char.real_y*32 - @mr).to_f endendclass Light_Surface def initialize @ta = @a = 0 @tr = @r = 255 @tg = @g = 255 @tb = @b = 255 @va = @vr = @vg = @vb = 0.0 @timer = 0 end def refresh return if @timer == 0 @a += @va @r += @vr @g += @vg @b += @vb $game_map.light_surface.opacity = @a @timer -= 1 end def change_color(time,r,g,b,a=nil) r = 0 if r < 0; r = 255 if r > 255 g = 0 if g < 0; g = 255 if g > 255 b = 0 if b < 0; b = 255 if b > 255 unless a.nil? a = 0 if a < 0; a = 255 if a > 255 end @timer = time @tr = 255-r @tg = 255-g @tb = 255-b @va = (a.nil? ? 0 : (a-@a).to_f/@timer) @vr = (@tr - @r).to_f/@timer @vg = (@tg - @g).to_f/@timer @vb = (@tb - @b).to_f/@timer end def change_alpha(time,a) a = 0 if a < 0; a = 255 if a > 255 @timer = time @ta = a @vr = @vg = @vb = 0.0 @va = (a-@a).to_f/@timer end def set_color(r,g,b) r = 0 if r < 0; r = 255 if r > 255 g = 0 if g < 0; g = 255 if g > 255 b = 0 if b < 0; b = 255 if b > 255 @tr = @r = 255-r @tg = @g = 255-g @tb = @b = 255-b @va = @vr = @vg = @vb = 0.0 @timer = 0 end def set_alpha(a) a = 0 if a < 0; a = 255 if a > 255 @ta = @a = a $game_map.light_surface.opacity = @a @va = @vr = @vg = @vb = 0.0 @timer = 0 end def alpha return @a end def color return Color.new(@r,@g,@b) endendclass Game_Map include Light_Core attr_accessor :light_surface attr_accessor :light_sources attr_accessor :surfaces attr_accessor :effect_surface attr_accessor :lantern alias kbl_setup_events setup_events alias kbl_initialize initialize alias kbl_update update def initialize kbl_initialize @effect_surface = Light_Surface.new @lantern = Light_DSource.new end def update(arg) @effect_surface.refresh if arg kbl_update(arg) end def first_tag(x,y) tag = tileset.flags[tile_id(x,y,0)] >> 12 return tag > 0 ? tag : 0 end def setup_events @light_sources.nil? ? @light_sources = [] : @light_sources.clear setup_surfaces merge_surfaces kbl_setup_events end def setup_surfaces @surfaces = [] for x in 0..(width-1) for y in 0..(height-1) tag = first_tag(x,y) if tag == Wall_Tag i = tile_id(x,y,0) if i & 0x02 == 0x02 @surfaces << Block_SD.new(x*32,y*32,x*32+32,y*32) end if i & 0x04 == 0x04 @surfaces << Block_WR.new(x*32+31,y*32,x*32+31,y*32+32) @surfaces << Block_IL.new(x*32+32,y*32,x*32+32,y*32+32) end if i & 0x01 == 0x01 @surfaces << Block_IR.new(x*32-1,y*32,x*32-1,y*32+32) @surfaces << Block_WL.new(x*32,y*32,x*32,y*32+32) end elsif tag == Roof_Tag i = tile_id(x,y,0) @surfaces << Block_SU.new(x*32,y*32,x*32+32,y*32) if i & 0x02 == 0x02 @surfaces << Block_SR.new(x*32+31,y*32,x*32+31,y*32+32) if i & 0x04 == 0x04 @surfaces << Block_SL.new(x*32,y*32,x*32,y*32+32) if i & 0x01 == 0x01 elsif tag == Block_Tag f = tileset.flags[tile_id(x,y,0)] @surfaces << Block_SL.new(x*32,y*32,x*32,y*32+32) if f & 0x02 == 0x02 @surfaces << Block_SR.new(x*32+31,y*32,x*32+31,y*32+32) if f & 0x04 == 0x04 @surfaces << Block_SU.new(x*32,y*32,x*32+32,y*32) if f & 0x08 == 0x08 end end end end def merge_surfaces new_surfaces = [] hs = []; vs = [] ws = []; is = [] for surface in @surfaces if surface.type & 0x05 == 0 hs << surface else if surface.type & 0x010 == 0 vs << surface else if surface.type & 0x08 == 0 ws << surface else is << surface end end end end for surface in hs surface.ready ? next : surface.ready = true for s in hs next if s.ready || s.y1 != surface.y1 || surface.type != s.type if s.x2 == surface.x1 surface.x1 = s.x1 s.trash = true s.ready = true surface.ready = false elsif s.x1 == surface.x2 surface.x2 = s.x2 s.trash = true s.ready = true surface.ready = false end end end hs.each { |s| @surfaces.delete(s) if s.trash} for surface in vs surface.ready ? next : surface.ready for s in vs next if s.ready || s.x1 != surface.x1 if s.y2 == surface.y1 surface.y1 = s.y1 s.trash = true s.ready = true surface.ready = false elsif s.y1 == surface.y2 surface.y2 = s.y2 s.trash = true s.ready = true surface.ready = false end end end vs.each { |s| @surfaces.delete(s) if s.trash} for surface in ws surface.ready ? next : surface.ready for s in ws next if s.ready || s.x1 != surface.x1 if s.y2 == surface.y1 surface.y1 = s.y1 s.trash = true s.ready = true surface.ready = false elsif s.y1 == surface.y2 surface.y2 = s.y2 s.trash = true s.ready = true surface.ready = false end end end ws.each { |s| @surfaces.delete(s) if s.trash} for surface in is surface.ready ? next : surface.ready for s in is next if s.ready || s.x1 != surface.x1 if s.y2 == surface.y1 surface.y1 = s.y1 s.trash = true s.ready = true surface.ready = false elsif s.y1 == surface.y2 surface.y2 = s.y2 s.trash = true s.ready = true surface.ready = false end end end is.each { |s| @surfaces.delete(s) if s.trash} endendclass Game_Event < Game_Character alias kbl_initialize initialize alias kbl_setup_page setup_page def initialize(m,e) @light = nil kbl_initialize(m,e) end def setup_page(np) kbl_setup_page(np) setup_light(np.nil?) end def setup_light(dispose) unless @light.nil? $game_map.light_sources.delete(self) @light.dispose @light = nil end unless dispose && @list.nil? for command in @list if command.code == 108 && command.parameters[0].include?("[light") command.parameters[0].scan(/\[light ([0.0-9.9]+)\]/) effect = Light_Core::Effects[$1.to_i] @light = Light_SSource.new(self,effect[0],effect[1],effect[2],effect[3]) $game_map.light_sources << self return end end end end def draw_light sx = @light.sx sy = @light.sy w = @light.w h = @light.h return if sx > $scrn_size[0] && sy > $scrn_size[1] && sx + w < 0 && sy + h < 0 $game_map.light_surface.bitmap.blt(sx,sy,@light.bitmap,Rect.new(0,0,w,h),@light.opacity) end def dispose_light @light.dispose end def restore_light @light.restore endendif Light_Core::Surface_UE class Game_Interpreter def command_223 $game_map.effect_surface.change_color(@params[1],@params[0].red,@params[0].green,@params[0].blue,@params[0].gray) wait(@params[1]) if @params[2] end endendclass Game_Interpreter def self_event return $game_map.events[@event_id] endendclass Block_Surface include Light_Core attr_accessor :x1 attr_accessor :y1 attr_accessor :x2 attr_accessor :y2 attr_accessor :ready attr_accessor :trash def initialize(x1,y1,x2,y2) @x1 = x1 @y1 = y1 @x2 = x2 @y2 = y2 @ready = false @trash = false end def within?(min_x,max_x,min_y,max_y) return @x2 > min_x && @x1 < max_x && @y2 > min_y && @y1 < max_y endendclass Block_SL < Block_Surface attr_reader :type def initialize(x1,y1,x2,y2) super(x1,y1,x2,y2) @type = 0x01 end def visible?(sx,sy) return sx < @x1 end def render_shadow(phx,phy,sx,sy,range,bitmap) @m1 = (@y1-sy)/(@x1-sx) @n1 = sy - @m1*sx @m2 = (@y2-sy)/(@x2-sx) @n2 = sy - @m2*sx for x in @x1..(sx+range) init = shadow_iy(x) bitmap.clear_rect(x-phx,init-phy,1,shadow_fy(x)-init+3) end end def shadow_iy(x) return @m1*x+@n1 end def shadow_fy(x) return @m2*x+@n2 endendclass Block_SR < Block_Surface attr_reader :type def initialize(x1,y1,x2,y2) super(x1,y1,x2,y2) @type = 0x04 end def visible?(sx,sy) return sx > @x1 end def render_shadow(phx,phy,sx,sy,range,bitmap) @m1 = (@y1-sy)/(@x1-sx) @n1 = sy - @m1*sx @m2 = (@y2-sy)/(@x2-sx) @n2 = sy - @m2*sx for x in (sx-range).to_i..@x1 init = shadow_iy(x) bitmap.clear_rect(x-phx,init-phy,1,shadow_fy(x)-init+3) end end def shadow_iy(x) return @m1*x+@n1 end def shadow_fy(x) return @m2*x+@n2 endendclass Block_IL < Block_Surface attr_reader :type def initialize(x1,y1,x2,y2) super(x1,y1,x2,y2) @type = 0x019 end def visible?(sx,sy) return sx < @x1 && sy > @y1 end def render_shadow(phx,phy,sx,sy,range,bitmap) @m1 = (@y1-sy)/(@x1-sx) @n1 = @y1 - @m1*@x1 @m2 = (@y2-sy)/(@x2-sx) @m2 = 0 if @m2 > 0 @n2 = @y2 - @m2*@x2 for x in @x1..(sx+range) init = shadow_iy(x).floor bitmap.clear_rect(x-phx,init-3-phy,1,shadow_fy(x)-init+3) end end def shadow_iy(x) return @m1*x+@n1 end def shadow_fy(x) return @m2*x+@n2 endendclass Block_IR < Block_Surface attr_reader :type def initialize(x1,y1,x2,y2) super(x1,y1,x2,y2) @type = 0x01c end def visible?(sx,sy) return sx > @x1 && sy > @y1 end def render_shadow(phx,phy,sx,sy,range,bitmap) @m1 = (@y1-sy)/(@x1-sx) @n1 = @y1 - @m1*@x1 @m2 = (@y2-sy)/(@x2-sx) @m2 = 0 if @m2 < 0 @n2 = @y2 - @m2*@x2 for x in (sx-range).to_i..@x1 init = shadow_iy(x).floor bitmap.clear_rect(x-phx,init-3-phy,1,shadow_fy(x)-init+3) end end def shadow_iy(x) return @m1*x+@n1 end def shadow_fy(x) return @m2*x+@n2 endendclass Block_WL < Block_Surface attr_reader :type def initialize(x1,y1,x2,y2) super(x1,y1,x2,y2) @type = 0x011 end def visible?(sx,sy) return sx < @x1 && sy < @y2 end def render_shadow(phx,phy,sx,sy,range,bitmap) @m1 = (@y1-sy)/(@x1-sx) @n1 = sy - @m1*sx @m2 = (@y2-sy)/(@x2-sx) @n2 = sy - @m2*sx for x in @x1..(sx+range) init = shadow_iy(x) bitmap.clear_rect(x-phx,init-phy,1,shadow_fy(x)-init+2) end end def shadow_iy(x) return @m1*x+@n1 end def shadow_fy(x) return @m2*x+@n2 endendclass Block_WR < Block_Surface attr_reader :type def initialize(x1,y1,x2,y2) super(x1,y1,x2,y2) @type = 0x014 end def visible?(sx,sy) return sx > @x1 && sy < @y2 end def render_shadow(phx,phy,sx,sy,range,bitmap) @m1 = (@y1-sy)/(@x1-sx) @n1 = sy - @m1*sx @m2 = (@y2-sy)/(@x2-sx) @n2 = sy - @m2*sx for x in (sx-range).to_i..@x1 init = shadow_iy(x) bitmap.clear_rect(x-phx,init-phy,1,shadow_fy(x)-init+2) end end def shadow_iy(x) return @m1*x+@n1 end def shadow_fy(x) return @m2*x+@n2 endendclass Block_SU < Block_Surface attr_reader :type def initialize(x1,y1,x2,y2) super(x1,y1,x2,y2) @type = 0x02 end def visible?(sx,sy) return sy < @y1 end def render_shadow(phx,phy,sx,sy,range,bitmap) if @x1 == sx @m1 = nil else @m1 = (@y1-sy)/(@x1-sx) @m1 += ACC if @m1 < -ACC @n1 = @y1 - @m1*@x1 end if @x2 == sx @m2 = nil else @m2 = (@y2-sy)/(@x2-sx) @n2 = sy - @m2*sx end for y in @y1..(sy+range) init = shadow_ix(y) bitmap.clear_rect(init-phx,y-phy,shadow_fx(y)-init+1,1) end end def shadow_ix(y) return @m1.nil? ? @x1 : (y-@n1)/@m1 end def shadow_fx(y) return @m2.nil? ? @x2 : (y-@n2)/@m2 endendclass Block_SD < Block_Surface attr_reader :type def initialize(x1,y1,x2,y2) super(x1,y1,x2,y2) @type = 0x08 end def visible?(sx,sy) return sy > @y1 end def render_shadow(phx,phy,sx,sy,range,bitmap) if @x1 == sx @m1 = nil else @m1 = (@y1-sy)/(@x1-sx) @m1 -= ACC if @m1 > ACC @n1 = sy - @m1*sx end if x2 == sx @m2 = nil else @m2 = (@y2-sy)/(@x2-sx) @n2 = sy - @m2*sx end for y in (sy-range).to_i..@y1 init = shadow_ix(y) bitmap.clear_rect(init-phx,y-phy,shadow_fx(y)-init+1,1) end end def shadow_ix(y) return @m1.nil? ? @x1 : (y-@n1)/@m1 end def shadow_fx(y) return @m2.nil? ? @x2 : (y-@n2)/@m2 endendclass Spriteset_Map include Light_Core alias kbl_initialize initialize alias kbl_update update alias kbl_dispose dispose def initialize setup_lights kbl_initialize end def update kbl_update update_lights end def dispose kbl_dispose dispose_lights end def dispose_lights $game_map.lantern.dispose $game_map.light_sources.each { |source| source.dispose_light } $game_map.light_surface.bitmap.dispose $game_map.light_surface.dispose $game_map.light_surface = nil end def update_lights $game_map.light_surface.bitmap.clear $game_map.light_surface.bitmap.fill_rect(0,0,$scrn_size[0],$scrn_size[1],$game_map.effect_surface.color) $game_map.light_sources.each { |source| source.draw_light } return unless $game_map.lantern.visible @btr = $game_map.lantern.get_graphic x = $game_map.lantern.x y = $game_map.lantern.y r = $game_map.lantern.range sx = x + r sy = y + r dr = r*2 $game_map.surfaces.each { |s| s.render_shadow(x,y,sx,sy,r,@btr) if s.visible?(sx,sy) && s.within?(x,x+dr,y,y+dr) } $game_map.light_surface.bitmap.blt($game_map.lantern.sx,$game_map.lantern.sy,@btr,Rect.new(0,0,dr,dr),$game_map.lantern.opacity) end def setup_lights @btr = nil $game_map.lantern.restore $game_map.light_sources.each { |source| source.restore_light } $game_map.light_surface = Sprite.new $game_map.light_surface.bitmap = Bitmap.new($scrn_size[0],$scrn_size[1]) $game_map.light_surface.bitmap.fill_rect(0,0,$scrn_size[0],$scrn_size[1],$game_map.effect_surface.color) $game_map.light_surface.blend_type = 2 $game_map.light_surface.opacity = $game_map.effect_surface.alpha $game_map.light_surface.z = Surface_Z endend