赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 9 |
经验 | 0 |
最后登录 | 2025-4-1 |
在线时间 | 148 小时 |
Lv2.观梦者
- 梦石
- 0
- 星屑
- 852
- 在线时间
- 148 小时
- 注册时间
- 2019-9-17
- 帖子
- 19
|
50星屑
如图,本人在使用Theo防卡顿脚本时点击开始游戏后报错。为排除脚本冲突原因,特开了一个新建项目,只放了核心脚本与该脚本,结果还是报错。。。求助各位大佬帮忙指点一下QAQ
核心脚本:
- # =============================================================================
- # TheoAllen - 基础模块
- # 版本 : 1.5d
- # 联系方式 : www.rpgmakerid.com (or) http://theolized.blogspot.com
- # 作者 : TheoAllen (初始编写者)
- # 汉化:Nil2018(○┰○)、MireniamuYuki
- # =============================================================================
- $imported = {} if $imported.nil?
- # =============================================================================
- # 本脚本是我个人的模块,用于脚本/系统的开发.无论是小实验还是大系统都便于我编写
- # 脚本.
- #
- # 然而,我的脚本并不是全部都需要基础模块,大部分不需要,其他的则需要。
- # -----------------------------------------------------------------------------
- # 模块包括 :
- # =============================================================================
- $imported[:Theo_BasicFuntions] = true # 基础功能
- $imported[:Theo_BitmapAddons] = true # 位图额外插件
- $imported[:Theo_CoreDamage] = true # 核心伤害处理
- $imported[:Theo_CoreResult] = true # 核心伤害结果
- $imported[:Theo_Movement] = true # 对象核心移动
- $imported[:Theo_CoreFade] = true # 对象核心淡入淡出
- $imported[:Theo_Circular] = true # 对象循环移动
- $imported[:Theo_CloneImage] = true # 克隆图像. 残影的基础
- $imported[:Theo_RotateImage] = true # 转动精灵
- $imported[:Theo_SmoothMove] = true # 对象平滑移动
- # =============================================================================
- # 写给使用者:
- # -----------------------------------------------------------------------------
- # 本脚本作为基础脚本,意味着需要将本脚本放在其他自定义脚本之上.
- #
- # 我知道基础模块可能会与其他脚本不兼容,其实我的脚本并不是都需要基础模块.
- # 只要是需要基础模块的脚本我都会给予提示,为了提供更多的兼容性,你可以将需要禁
- # 用的功能设定为false.
- #
- # =============================================================================
- # 写给脚本师 :
- # -----------------------------------------------------------------------------
- # 下面就是脚本的各个部件.
- #
- # 如果你想要改善基础模块,可以任意编辑此脚本,请告诉我你编辑了哪些地方.
- # 我很乐意见到脚本师为基础模块做出改良.
- #
- # 如果你改良了基础模块,你可以在作者中署名。但请记住,基础模块不应该对默认脚本
- # 造成任何影响.仅为其他脚本提供可能需要的基础功能.
- # =============================================================================
- # 已知不兼容 :
- # >> Modern Algebra - Bitmap Addons (需要关闭"位图额外插件")
- # >> Tsukihime - Core Damage (需要关闭"核心伤害处理")
- # >> YEA - Lunatic Damage 疯狂的伤害 (需要关闭"核心伤害处理")
- # >> Enu - Tankentai (我只是听说的,还没真正试过)
- # =============================================================================
- # ChangeLogs :
- # =============================================================================
- # Version 1.0 : - Initial Release
- # Version 1.2 : - Add Bitmap Entire Fill
- # - Add Bitmap Border Fill
- # - Add To Center window position
- # - Add more description
- # Version 1.3 : - Added Clone Sprite function and afterimagebase
- # Version 1.3b : - Added TSBS basic function
- # - Greatly reduced lag for afterimage effect
- # Version 1.4 : - Added rotate image basic module
- # - Fixed bug at Object Core Fade
- # Version 1.5 : - Added Smooth movement
- # - Fixed bug on circle movement
- # - Fixed bug on movement module where float may causes endless
- # moving
- # - Fixed wrong parameter in drawing eclipse / circle
- # - Fixed color parameter on drawing arrow
- # - Added Plane_Mask on basic functions
- # - Added step parameter on draw circle
- # - Fixed wrong target opacity in object core fade for Window
- # - Dispose afterimages from Sprite_Base
- # Version 1.5b - Afterimage now followed by flashing sprite
- # Version 1.5c - Fixed bug on object core fade.
- # - Remove core fade from window since it's absurb :v
- # - Compatibility with nickle's core
- # Version 1.5d - Allow you to jump in same place
- # =============================================================================
- # RGSS3 ~ Bug Fixes (Taken from RMWeb.com)
- # forums.rpgmakerweb.com/index.php?/topic/1131-rgss3-unofficial-bugfix-snippets
- # =============================================================================
- # Screen shake bugfix
- # -----------------------------------------------------------------------------
- class Game_Interpreter
-
- def command_225
- screen.start_shake(@params[0], @params[1], @params[2])
- wait(@params[2]) if @params[3]
- end
-
- end
- # -----------------------------------------------------------------------------
- # Enemy targeting bugfix
- # -----------------------------------------------------------------------------
- class Game_Action
- def targets_for_friends
- if item.for_user?
- [subject]
- elsif item.for_dead_friend?
- if item.for_one?
- [friends_unit.smooth_dead_target(@target_index)]
- else
- friends_unit.dead_members
- end
- elsif item.for_friend?
- if item.for_one?
- if @target_index < 0
- [friends_unit.random_target]
- else
- [friends_unit.smooth_target(@target_index)]
- end
- else
- friends_unit.alive_members
- end
- end
- end
- end
- # -----------------------------------------------------------------------------
- # process normal char bugfix
- # -----------------------------------------------------------------------------
- class Window_Base < Window
- alias :process_normal_character_theolized :process_normal_character
- def process_normal_character(c, pos)
- return unless c >= ' '
- process_normal_character_theolized(c, pos)
- end
- end
- # -----------------------------------------------------------------------------
- # Disable Japanese input name
- # -----------------------------------------------------------------------------
- class Game_System
- def japanese?
- false
- end
- end
- #==============================================================================
- # ** Basic Functions ~
- #------------------------------------------------------------------------------
- # These are just basic functions. It will not do anything in script mechanics.
- # I only provide these functions to be used later in upcoming script or just
- # simply for experimental.
- #------------------------------------------------------------------------------
- if $imported[:Theo_BasicFuntions] # Activation flag
- #==============================================================================
- module Math
-
- # Convert degree to radian
- def self.radian(degree)
- return (degree.to_f/180) * Math::PI
- end
-
- # Convert radian to degree
- def self.degree(radian)
- return (radian.to_f/Math::PI) * 180
- end
-
- end
- class Object
-
- # Generate number with range from minimum to maximum
- unless method_defined?(:rand_range)
- def rand_range(min,max,float = false)
- range = max - min
- return float ? (min + (rand*range)) : min + rand(range)
- end
- end
- # ---------------------------------------------------------------------------
- # Iterate instance variables one by one.
- #
- # Example usage :
- # each_var do |ivar|
- # ivar.update if ivar.is_a?(Sprite)
- # end
- # ---------------------------------------------------------------------------
- def each_var
- instance_variables.each do |varsymb|
- yield instance_variable_get(varsymb)
- end
- end
-
- end
- #==============================================================================
- # ** Sprite_Screen
- #------------------------------------------------------------------------------
- # Sprite that same size as the screen. It can be used to draw anything on
- # screen. I believe sometime you need it
- #
- # Example usage :
- # - http://goo.gl/E88ufV ( Event Pointer )
- #==============================================================================
- class Sprite_Screen < Sprite
-
- def initialize(viewport = nil)
- super(viewport)
- self.bitmap = Bitmap.new(Graphics.width,Graphics.height)
- end
-
- def dispose
- self.bitmap.dispose
- super
- end
-
- end
- #==============================================================================
- # ** Plane_Mask
- #------------------------------------------------------------------------------
- # Sprite that same size as the map size. It's also scrolled alongside the map
- # if it's updated. It can be used to draw anything on map. Can be used as base
- # class of parallax lock actually
- #==============================================================================
- class Plane_Mask < Plane
-
- def initialize(vport)
- super(vport)
- @width = 1
- @height = 1
- end
-
- def update
- if $game_map
- if @width != $game_map.width || @height != $game_map.height
- @width = $game_map.width
- @height = $game_map.height
- update_bitmap
- end
- self.ox = $game_map.display_x * 32
- self.oy = $game_map.display_y * 32
- end
- end
-
- def update_bitmap
- bmp = Bitmap.new(@width * 32, @height * 32)
- self.bitmap = bmp
- end
-
- end
- #==============================================================================
- # ** Window_Confirmation
- #------------------------------------------------------------------------------
- # Window command class that holds yes and no command. Used to make
- # confirmation function. If you want some alteration of this class, just make
- # inheritance.
- #
- # This is for my personal development. I mean, if there is a simple script
- # that display window yes/no confirmation, it will not require this basic
- # module. I prefer to duplicate this class to my script instead. You know,
- # most people hates Core Script / Basic Modules
- #==============================================================================
- class Window_Confirmation < Window_Command
- def window_width
- return 100
- end
-
- def make_command_list
- add_command(ok_vocab, :ok, ok_condition)
- add_command(cancel_vocab, :cancel, cancel_condition)
- end
-
- # Vocab yes
- def ok_vocab
- return "确认"
- end
-
- # Vocab cancel
- def cancel_vocab
- return "取消"
- end
-
- # Overwrite this method in child class
- def ok_condition
- return true
- end
-
- # Overwrite this method in child class
- def cancel_condition
- return true
- end
-
- def alignment
- return 1
- end
-
- end
- #==============================================================================
- # ** Coordinate
- #------------------------------------------------------------------------------
- # Coordinate class that holds x dan y point. Can be used to calculate point
- # operation such as vector
- #
- # Example usage :
- # - http://goo.gl/E88ufV ( Event Pointer )
- #==============================================================================
- class Coordinate
- attr_accessor :x,:y
-
- def initialize(x,y)
- @x = x
- @y = y
- end
-
- def + (other)
- other = other.to_c unless other.is_a?(Coordinate)
- Coordinate.new(self.x + other.x, self.y + other.y)
- end
-
- def - (other)
- other = other.to_c unless other.is_a?(Coordinate)
- Coordinate.new(self.x - other.x, self.y - other.y)
- end
-
- def == (other)
- other = other.to_c unless other.is_a?(Coordinate)
- return self.x == other.x && self.y == other.y
- end
-
- # To String function
- def to_s
- return "(#{self.x},#{self.y})"
- end
-
- end
- #==============================================================================
- # ** Vector
- #------------------------------------------------------------------------------
- # Vector class that handles all vector functions. Note that some of these
- # methods and variable terms are named in Indonesian terms. Because I don't
- # really know what is in English terms
- #
- # Example usage :
- # - http://goo.gl/E88ufV ( Event Pointer )
- #==============================================================================
- class Vector
- attr_accessor :pangkal # Starting point
- attr_accessor :ujung # End point
-
- def initialize(pangkal,ujung,radius = 0)
- @pangkal = pangkal.is_a?(Coordinate) ? pangkal : pangkal.to_c
- if ujung.is_a?(Numeric)
- x_pos = @pangkal.x + (Math.cos(Math.radian(ujung)) * radius)
- y_pos = @pangkal.y + (Math.sin(Math.radian(ujung)) * radius)
- @ujung = Coordinate.new(x_pos,y_pos)
- return
- end
- @ujung = ujung.is_a?(Coordinate) ? ujung : ujung.to_c
- end
-
- # Get scalar value
- def skalar
- Math.sqrt(jarak_x**2 + jarak_y**2)
- end
-
- def + (other)
- if other.is_a?(Coordinate)
- return Vector.new(pangkal + other, ujung + other)
- end
- Vector.new(pangkal, ujung + other.satuan)
- end
-
- def - (other)
- if other.is_a?(Coordinate)
- return Vector.new(pangkal - other, ujung - other)
- end
- Vector.new(pangkal, ujung - other.satuan)
- end
-
- # Get degree upon two different point
- def degree
- Math.degree(Math.atan2(jarak_y,jarak_x)) rescue 0
- end
-
- # Get distance X
- def jarak_y
- ujung.y - pangkal.y
- end
-
- # Get distance Y
- def jarak_x
- ujung.x - pangkal.x
- end
-
- # Convert vector to coordinate
- def satuan
- Coordinate.new(jarak_x, jarak_y)
- end
-
- # To string format
- def to_s
- return @pangkal.to_s + " ---> " + @ujung.to_s
- end
-
- end
- #==============================================================================
- # ** VectorObject
- #------------------------------------------------------------------------------
- # This class handles two objects that their vector is later will be used.
- #
- # Example usage :
- # - http://goo.gl/E88ufV ( Event Pointer )
- #==============================================================================
- class VectorObject
- attr_accessor :pangkal # Starting object
- attr_accessor :ujung # End object
- attr_accessor :color # Color value (to draw lines)
- attr_accessor :offset_x # Offset value X
- attr_accessor :offset_y # Offset value Y
-
- # Basically, offset value is a increment value upon a new vector that created
- # using to_v vector. I don't really know if 'offset' is the right word. I'm
- # suck at english afterall
-
- def initialize(pangkal,ujung,color = Color.new(255,255,255))
- @pangkal = pangkal
- @ujung = ujung
- @color = color
- @offset_x = 0
- @offset_y = 0
- end
-
- # Two object converted into vector
- def to_v
- a = @pangkal.to_c
- b = @ujung.to_c
- a.x += @offset_x
- b.x += @offset_x
- a.y += @offset_y
- b.y += @offset_y
- Vector.new(a,b)
- end
-
- end
- #==============================================================================
- # ** Bitmap
- #------------------------------------------------------------------------------
- # Built in class that handles bitmap
- #==============================================================================
- class Bitmap
-
- # Fill entire bitmap with color
- def entire_fill(color = Color.new(0,0,0,150))
- fill_rect(self.rect,color)
- end
-
- # Fill bitmap edge only
- def border_fill(color = Color.new(255,255,255))
- fill_rect(0,0,width,1,color)
- fill_rect(0,0,1,height,color)
- fill_rect(width-1,0,1,height,color)
- fill_rect(0,height-1,width,1,color)
- end
-
- end
- #==============================================================================
- # ** Window_Base
- #------------------------------------------------------------------------------
- # This is a super class of all windows within the game.
- #==============================================================================
- class Window_Base < Window
-
- # Same as bitmap entire fill
- def entire_fill(color = Color.new(0,0,0,150))
- contents.entire_fill(color)
- end
-
- # Set window to center position of the screen
- def to_center
- self.x = Graphics.width/2 - self.width/2
- self.y = Graphics.height/2 - self.height/2
- end
-
- end
- #==============================================================================
- # ** Color
- #------------------------------------------------------------------------------
- # Built in class that handles color
- #==============================================================================
- class Color
-
- # Is color same as other?
- def same?(*args)
- args = args.select {|color| color.is_a?(Color)}
- return false if args.empty?
- return args.any?{|color| self.red == color.red &&
- self.green == color.green && self.blue == color.blue &&
- self.alpha == color.alpha}
- end
-
- # Is color empty?
- def empty?
- return self.alpha <= 0
- end
-
- end
- # -----------------------------------------------------------------------------
- # New Method : To Coordinate Conversion
- # -----------------------------------------------------------------------------
- class Object
-
- def to_c
- return Coordinate.new(0,0)
- end
- end
- class Numeric
-
- def to_c
- return Coordinate.new(self,self)
- end
-
- end
- class Sprite
-
- def to_c
- return Coordinate.new(self.x,self,y)
- end
-
- end
- class Window
-
- def to_c
- return Coordinate.new(self.x,self,y)
- end
-
- end
- class Game_Enemy < Game_Battler
-
- def to_c
- return Coordinate.new(self.screen_x,self,screen_y)
- end
-
- end
- class Game_CharacterBase
-
- def to_c(map = false)
- if map
- return Coordinate.new(self.real_x,self.real_y)
- end
- return Coordinate.new(self.screen_x,self.screen_y)
- end
-
- end
- # -----------------------------------------------------------------------------
- # Added TSBS basic function. To calculate sprite anim cell
- # -----------------------------------------------------------------------------
- module TSBS
- def self.cell(row, col)
- result = (MaxCol * (row - 1)) + (col - 1)
- return result
- end
- end
- end
- #==============================================================================
- # ** Bitmap Extra addons v2.1
- #------------------------------------------------------------------------------
- # This bitmap extra addons provide basic function of drawing shapes. It could
- # be drawing polygon, line, arrow, elipse or such.
- #
- # The code may look messy. Even myself forget how it works. To be note that
- # even this current version is 2.1, the draw filled polygon is imperfect. Do
- # not use at this moment.
- #
- # Some functions may need my Basic Functions to be activated. So I suggest you
- # to also activate it
- #
- # Example usage :
- # - http://goo.gl/E88ufV ( Event Pointer )
- # - http://goo.gl/DlrPuR ( Simple Polygon Status )
- #------------------------------------------------------------------------------
- if $imported[:Theo_BitmapAddons] # Activation flag
- # =============================================================================
- class Bitmap
- attr_accessor :start_degree
-
- # ------------------------------------------------------------------------
- # Static Members
- # ------------------------------------------------------------------------
- @@default_color = Color.new(255,255,255)
- @@arrow_degree = 30
-
- def self.default_color=(color)
- @@default_color = color
- end
-
- def self.arrow_degree=(degree)
- @@arrow_degree = degree
- end
-
- def self.default_color
- @@default_color
- end
-
- def self.arrow_degree
- @@arrow_degree
- end
-
- alias theo_bitmap_init initialize
- def initialize(*args)
- theo_bitmap_init(*args)
- @start_degree = 270
- end
- # ------------------------------------------------------------------------
- # Bitmap draw line. The avalaible arguments to put are
- # - draw_line(x1,x2,y1,y2,[color])
- # - draw_line(coordinate1, coordinate2, [color])
- # - draw_line(vector, [color])
- #
- # coordinate must be Coordinate object from this basic module.
- # So do the vector
- # ------------------------------------------------------------------------
- def draw_line(x1, y1=0, x2=0, y2=0, color=@@default_color.dup,
- color_set_skip = false)
- # ----------------------------------------------------------------------
- # If the argument is a vector
- # ----------------------------------------------------------------------
- if x1.is_a?(Vector)
- new_color = (y1.is_a?(Color) ? y1 : color)
- draw_line(x1.pangkal,x1.ujung,new_color) # Recursive
- return # Exit
- # ----------------------------------------------------------------------
- # If two arguments are coordinates
- # ----------------------------------------------------------------------
- elsif x1.is_a?(Coordinate) && y1.is_a?(Coordinate)
- pangkal = x1
- ujung = y1
- new_color = (x2.is_a?(Color) ? x2 : color)
- draw_line(pangkal.x,pangkal.y,ujung.x,ujung.y,new_color) # Recursive
- return # Exit
- end
- # ----------------------------------------------------------------------
- # If two coordinate is same
- # ----------------------------------------------------------------------
- if x1 == x2 && y1 == y2
- set_pixel(x1,y1,color)
- yield [x1,x2] if block_given?
- return # Exit
- end
- # ----------------------------------------------------------------------
- # Calculate distance X dan Y
- # ----------------------------------------------------------------------
- jarak_x = (x2-x1)
- jarak_y = (y2-y1)
- # ----------------------------------------------------------------------
- # If line is horz line or vert line
- # ----------------------------------------------------------------------
- if jarak_y == 0 || jarak_x == 0
-
- # Horizontal
- if jarak_y == 0
- draw_horz(x1,y1,jarak_x,color)
- for j in 0..jarak_x
- yield [x1,y1]
- x1 += 1
- end if block_given?
-
- # Vertikal
- elsif jarak_x == 0
- draw_vert(x1,y1,jarak_y,color)
- for k in 0..jarak_y
- yield [x1,y1]
- y1 += 1
- end if block_given?
- end
- return # Exit
-
- end
- # ----------------------------------------------------------------------
- # If line is diagonal
- # ----------------------------------------------------------------------
- maximum = [jarak_x.abs,jarak_y.abs].max
- rasio_x = jarak_x / maximum.to_f
- rasio_y = jarak_y / maximum.to_f
- real_x = x1.to_f
- real_y = y1.to_f
- for i in 0..maximum
- set_pixel(x1,y1,color) unless get_pixel(x1,y1).same?(color) ||
- color_set_skip ? !get_pixel(x1,y1).empty? : false
- real_x += rasio_x
- real_y += rasio_y
- yield [x1,y1] if block_given?
- x1 = real_x.round
- y1 = real_y.round
- end
- end
- # ------------------------------------------------------------------------
- # Gradient line
- # ------------------------------------------------------------------------
- def gradient_line(x1,y1=0,x2=0,y2=0,color1=@@default_color.dup,
- color2 = color1)
- if x1.is_a?(Vector)
- warna_pangkal = (y1.is_a?(Color) ? y1 : color1)
- warna_ujung = (x2.is_a?(Color) ? x2 : color2)
- gradient_line(x1.pangkal, x1.ujung, warna_pangkal, warna_ujung)
- return
- elsif x1.is_a?(Coordinate) && y1.is_a?(Coordinate)
- pangkal = x1
- ujung = y1
- warna_pangkal = (x2.is_a?(Color) ? x2 : color1)
- warna_ujung = (y2.is_a?(Color) ? y2 : color2)
- gradient_line(pangkal.x,pangkal.y,ujung.x,ujung.y,warna_pangkal,
- warna_ujung)
- return
- end
- jarak_x = (x2-x1)
- jarak_y = (y2-y1)
- radius = Math.sqrt((jarak_x**2) + (jarak_y**2))
- red_diff = (color2.red - color1.red) / radius
- green_diff = (color2.green - color1.green) / radius
- blue_diff = (color2.blue - color1.blue) / radius
- alpha_diff = (color2.alpha - color1.alpha) / radius
- red = color1.red
- green = color1.green
- blue = color1.blue
- alpha = color1.alpha
- if jarak_y.abs == 0 || jarak_x.abs == 0
- gradient_fill_rect(x1,y1,1,jarak_y,color1,color2,true) if jarak_y.abs == 0
- gradient_fill_rect(x1,y1,jarak_x,1,color1,color2) if jarak_x.abs == 0
- return
- end
- maximum = [jarak_x.abs,jarak_y.abs].max
- rasio_x = jarak_x / maximum.to_f
- rasio_y = jarak_y / maximum.to_f
- real_x = x1.to_f
- real_y = y1.to_f
- for i in 0..maximum
- new_color = Color.new(red,green,blue,alpha)
- set_pixel(x1,y1,new_color) unless get_pixel(x1,y1).same?(new_color)
- real_x += rasio_x
- real_y += rasio_y
- x1 = real_x.round
- y1 = real_y.round
- red += red_diff
- blue += blue_diff
- green += green_diff
- alpha += alpha_diff
- end
- end
-
- # Draw horizontal line
- def draw_horz(x,y,width,color = Color.new(255,255,255))
- if width < 0
- fill_rect(x+width+1,y,width.abs,1,color)
- return
- end
- fill_rect(x,y,width,1,color)
- end
-
- # Draw vertical line
- def draw_vert(x,y,height,color = Color.new(255,255,255))
- if height < 0
- fill_rect(x,y+height+1,1,height.abs,color)
- return
- end
- fill_rect(x,y,1,height,color)
- end
-
- # --------------------------------------------------------------------------
- # Drawing ellipse.
- #
- # The parameters are :
- # - x >> Center coordinate X
- # - y >> Center coordinate Y
- # - horz >> Horizontal Radius value
- # - vert >> Vertical Radius value
- # - color >> Line color
- # - thick >> Thickness of line
- # - step >> Dot step. Greater number may causes ellipse being drawn
- # imperfect. But may perform better
- # --------------------------------------------------------------------------
- def draw_ellipse(x,y=0,horz=1,vert=1,color=Color.new(255,255,255),thick=1,
- step=0.1)
- return if thick < 1
- ori_x = x
- ori_y = y
- x += horz
- degree = 0.0
- while degree <= 360
- yield [x,y] if block_given?
- set_pixel(x,y,color) unless get_pixel(x,y).same?(color)
- x = Math.cos(Math.radian(degree)) * horz + ori_x
- y = Math.sin(Math.radian(degree)) * vert + ori_y
- degree = [degree+step,361].min
- end
- if thick > 1
- draw_ellipse(ori_x+1,ori_y+1,horz,vert,color,thick-1,step)
- draw_ellipse(ori_x-1,ori_y-1,horz,vert,color,thick-1,step)
- draw_ellipse(ori_x+1,ori_y-1,horz,vert,color,thick-1,step)
- draw_ellipse(ori_x-1,ori_y+1,horz,vert,color,thick-1,step)
- end
- end
- # --------------------------------------------------------------------------
- # Draw circle. Similar of drawing ellipse. But only have one radius parameter
- # --------------------------------------------------------------------------
- def draw_circle(x,y,radius,color=Color.new(255,255,255),step=0.1,thick=1)
- draw_ellipse(x,y,radius,radius,color,thick,step) {|coordinate|
- yield coordinate if block_given?
- }
- end
-
- # Do not use ~ !
- def fill_circle(x,y,radius,color1,color2=color1,step=0.1)
- fill_ellipse(x,y,radius,radius,color1,color2,step)
- end
-
- # Do not use ~ !
- def fill_ellipse(x,y,horz,vert,color1,color2=color1,step=0.1)
- draw_ellipse(x,y,horz,vert,1,color1,0.5) {|cor|
- draw_line(x,y,cor[0],cor[1],color2,true)
- }
- for i in 0..1
- for baris in 0..horz*2
- for kolom in 0..vert*2
- pos_x = baris-horz+x
- pos_y = kolom-vert+y
- syarat = (get_pixel(pos_x+1,pos_y).same?(color1,color2) &&
- get_pixel(pos_x-1,pos_y).same?(color1,color2)) ||
- (get_pixel(pos_x,pos_y-1).same?(color1,color2) &&
- get_pixel(pos_x,pos_y+1).same?(color1,color2)) ||
- (get_pixel(pos_x+1,pos_y+1).same?(color1,color2) &&
- get_pixel(pos_x-1,pos_y-1).same?(color1,color2)) ||
- (get_pixel(pos_x-1,pos_y+1).same?(color1,color2) &&
- get_pixel(pos_x+1,pos_y-1).same?(color1,color2))
- if syarat && !get_pixel(pos_x,pos_y).same?(color1,color2)
- set_pixel(pos_x,pos_y,color2)
- end
- end
- end
- end
- end
- # ---------------------------------------------------------------------------
- # Drawing polygon
- #
- # The parameters are :
- # - x >> Center coordinate X
- # - y >> Center coordinate Y
- # - corner >> Number of corner. The mininmal value is 3 (Triangle)
- # - length >> Radius range from center
- # - color1 >> Edge line color
- # - bone >> Drawing bone? (true/false)
- # - color2 >> Bone Color
- # ---------------------------------------------------------------------------
- def draw_polygon(x,y,corner,length,color1,bone=true,color2=color1)
- return unless corner.is_a?(Numeric)
- draw_shape(x,y,Array.new(corner){1},length,color1,bone,false,color2)
- end
-
- # Do not use ~ !
- def fill_polygon(x,y,corner,length,color1,color2=color1)
- return unless corner.is_a?(Numeric)
- draw_shape(x,y,Array.new(corner),length,color1,false,true,color2)
- end
-
- # Draw polygon parameter
- def draw_shape_params(x,y,params,length,color1,bone=true,color2=color1)
- draw_shape(x,y,params,length,color1,bone,false,color2)
- end
-
- # Do not use ~ !
- def fill_shape_params(x,y,params,length,color1,color2=color1)
- draw_shape(x,y,params,length,color1,false,true,color2)
- end
-
- # Core function of drawing shape
- def draw_shape(x,y,params,length,color1 = Color.new(255,255,255),
- include_bone = true ,fill=false,color2 = color1)
- return unless params.is_a?(Array) # Corner lenght should be array
- return unless params.size >= 3 # At the size should have min 3
- degree_plus = 360 / params.size
- degree = @start_degree
- coordinate = []
- edge = []
- params.each do |i|
- x_des = x + Math.cos(Math.radian(degree)) * (length*(i.to_f/params.max))
- y_des = y + Math.sin(Math.radian(degree)) * (length*(i.to_f/params.max))
- draw_line(x,y,x_des,y_des,color2) if include_bone
- degree += degree_plus
- coordinate.push(Coordinate.new(x_des,y_des))
- end
- for i in -1..coordinate.size-2
- c = coordinate
- draw_line(c[i].x,c[i].y,c[i+1].x,c[i+1].y,color1) {|cor| edge.push(cor)}
- end
- return unless fill
- # -------------------------------------------------------------------------
- # Yes, it should return. Because the code below this point is sooo much
- # messy.
- # -------------------------------------------------------------------------
- edge.each do |line|
- draw_line(x,y,line[0],line[1],color2,true)
- end
- for i in 0..1
- for baris in 0..length*2
- for kolom in 0..length*2
- pos_x = baris-length+x
- pos_y = kolom-length+y
- syarat = (get_pixel(pos_x+1,pos_y).same?(color1,color2) &&
- get_pixel(pos_x-1,pos_y).same?(color1,color2)) ||
- (get_pixel(pos_x,pos_y-1).same?(color1,color2) &&
- get_pixel(pos_x,pos_y+1).same?(color1,color2)) ||
- (get_pixel(pos_x+1,pos_y+1).same?(color1,color2) &&
- get_pixel(pos_x-1,pos_y-1).same?(color1,color2)) ||
- (get_pixel(pos_x-1,pos_y+1).same?(color1,color2) &&
- get_pixel(pos_x+1,pos_y-1).same?(color1,color2))
- if syarat && !get_pixel(pos_x,pos_y).same?(color1,color2)
- set_pixel(pos_x,pos_y,color2)
- end
- end
- end
- end
- end
-
- # ---------------------------------------------------------------------------
- # Bitmap drawing arrows. It's similar as draw line actually
- # - draw_arrow(x1,x2,y1,y2,[color])
- # - draw_arrow(coordinate1, coordinate2, [color])
- # - draw_arrow(vector, [color])
- #
- # coordinate must be Coordinate object from this basic module.
- # So do the vector
- # ---------------------------------------------------------------------------
- def draw_arrow(x1,y1=0,x2=0,y2=0,color=@@default_color.dup)
- if x1.is_a?(Vector)
- new_color = (y1.is_a?(Color) ? y1 : color)
-
- # Recursive call. Split a vector to two coordinate.
- draw_arrow(x1.pangkal,x1.ujung,new_color)
- # Return
- return
- elsif x1.is_a?(Coordinate) && y1.is_a?(Coordinate)
- pangkal = x1
- ujung = y1
- new_color = (x2.is_a?(Color) ? x2 : color)
-
- # Recursive call. Split each coordinate into two primitive x,y value
- draw_arrow(pangkal.x,pangkal.y,ujung.x,ujung.y,new_color)
- # Return
- return
- end
- # Draw basic line
- draw_line(x1,y1,x2,y2,color)
- # Get reversed degree
- degree = Vector.new(Coordinate.new(x1,y1),Coordinate.new(x2,y2)).degree-180
- # Draw arrow
- draw_line(Vector.new(Coordinate.new(x2,y2),degree + @@arrow_degree,10),
- color)
- draw_line(Vector.new(Coordinate.new(x2,y2),degree - @@arrow_degree,10),
- color)
- end
-
- end
- # -----------------------------------------------------------------------------
- # Draw Polygon status
- # -----------------------------------------------------------------------------
- class Game_Battler < Game_BattlerBase
-
- def params_array
- return [self.atk,self.def,self.mat,self.mdf,self.agi,self.luk]
- end
-
- end
- class Window_Base < Window
-
- def draw_polygon_params(x,y,actor,inner,outer,color1,color2)
- contents.draw_shape_params(x,y,actor.params_array,inner,color1)
- contents.draw_polygon(x,y,actor.params_array.size,outer,color2)
- end
-
- end
- end
- #==============================================================================
- # ** Core Damage Processing
- # -----------------------------------------------------------------------------
- # I altered the way how damage calculation to provide more flexibility. Any
- # scripts that also overwrite make_damage_value will highly incompatible.
- #
- # However, I don't have any script implements this module right now. So you
- # may disable it
- # -----------------------------------------------------------------------------
- if $imported[:Theo_CoreDamage] # Activation flag
- #==============================================================================
- class Game_Battler < Game_BattlerBase
- # ---------------------------------------------------------------------------
- # *) Overwrite make damage value
- # ---------------------------------------------------------------------------
- def make_damage_value(user, item)
- value = base_damage(user, item)
- value = apply_element_rate(user, item, value)
- value = process_damage_rate(user, item, value)
- value = apply_damage_modifiers(user, item, value)
- @result.make_damage(value.to_i, item)
- end
- # ---------------------------------------------------------------------------
- # *) Make base damage. Evaling damage formula
- # ---------------------------------------------------------------------------
- def base_damage(user, item)
- value = item.damage.eval(user, self, $game_variables)
- value
- end
- # ---------------------------------------------------------------------------
- # *) Apply element rate
- # ---------------------------------------------------------------------------
- def apply_element_rate(user, item, value)
- value *= item_element_rate(user, item)
- value
- end
- # ---------------------------------------------------------------------------
- # *) Apply damage rate. Such as physical, magical, recovery
- # ---------------------------------------------------------------------------
- def process_damage_rate(user, item, value)
- value *= pdr if item.physical?
- value *= mdr if item.magical?
- value *= rec if item.damage.recover?
- value
- end
- # ---------------------------------------------------------------------------
- # *) Apply damage modifier. Such as guard, critical, variance
- # ---------------------------------------------------------------------------
- def apply_damage_modifiers(user, item, value)
- value = apply_critical(value, user) if @result.critical
- value = apply_variance(value, item.damage.variance)
- value = apply_guard(value)
- value
- end
- # ---------------------------------------------------------------------------
- # *) Applying critical
- # ---------------------------------------------------------------------------
- def apply_critical(damage, user)
- damage * 3
- end
-
- end
- end
- #=============================================================================
- # ** Core Damage Result ~
- #-----------------------------------------------------------------------------
- # I altered how action result is being handled. It's used within my sideview
- # battle system.
- #-----------------------------------------------------------------------------
- if $imported[:Theo_CoreResult] # Activation flag
- #=============================================================================
- class Game_Battler < Game_BattlerBase
-
- def item_apply(user, item)
- make_base_result(user, item)
- apply_hit(user, item) if @result.hit?
- end
-
- def make_base_result(user, item)
- @result.clear
- @result.used = item_test(user, item)
- @result.missed = (@result.used && rand >= item_hit(user, item))
- @result.evaded = ([email protected] && rand < item_eva(user, item))
- end
-
- def apply_hit(user, item)
- unless item.damage.none?
- determine_critical(user, item)
- make_damage_value(user, item)
- execute_damage(user)
- end
- apply_item_effects(user, item)
- end
-
- def determine_critical(user, item)
- @result.critical = (rand < item_cri(user, item))
- end
-
- def apply_item_effects(user, item)
- item.effects.each {|effect| item_effect_apply(user, item, effect) }
- item_user_effect(user, item)
- end
-
- end
- end
- #==============================================================================
- # ** Object Core Movement
- #------------------------------------------------------------------------------
- # This basic module allow you to move objects like Window or Sprite to a
- # certain position in a given time duration. The object must be updated in each
- # frame. It could also applied to any classes that contains x,y and allow it to
- # be modified
- #
- # Avalaible methods :
- # - goto(x, y, duration, [jump])
- # Tells the object to move to specified x,y coordinate in a given time
- # duration in frame. By default, the jump value is zero.
- #
- # - slide(x, y, duration, jump)
- # Tells the object to slide in x,y coordinate from original position in a
- # given time duration in frame. By default, the jump value is zero.
- #
- # I use this module within my sideview battle system movement sequences
- #------------------------------------------------------------------------------
- if $imported[:Theo_Movement] # Activation flag
- #==============================================================================
- module THEO
- module Movement
- # =========================================================================
- # Exclusive class move object. To prevent adding to many instance variable
- # in object that implements this module
- # -------------------------------------------------------------------------
- class Move_Object
- attr_reader :obj # Reference object
- # -----------------------------------------------------------------------
- # *) Initialize
- # -----------------------------------------------------------------------
- def initialize(obj)
- @obj = obj
- clear_move_info
- end
- # -----------------------------------------------------------------------
- # *) Clear move info
- # -----------------------------------------------------------------------
- def clear_move_info
- @to_x = -1
- @to_y = -1
- @real_x = 0.0
- @real_y = 0.0
- @x_speed = 0.0
- @y_speed = 0.0
- @jump = 0.0
- @jump_interval = 0.0
- @offset = 0
- @duration = 0
- end
- # -----------------------------------------------------------------------
- # *) Tells the object to move
- # -----------------------------------------------------------------------
- def move_to(x,y=0,jump=0,duration=0)
- # You can also put the coordinate
- if x.is_a?(Coordinate)
- target = x
- move_to(target.x, target.y, y, jump)
- return
- end
- @to_x = x.to_i
- @to_y = y.to_i
- @real_x = @obj.x.to_f
- @real_y = @obj.y.to_f
- determine_speed(duration,jump)
- end
- # -----------------------------------------------------------------------
- # *) Determine traveling speed
- # -----------------------------------------------------------------------
- def determine_speed(duration,jump)
- @x_speed = (@to_x - @obj.x) / duration.to_f
- @y_speed = (@to_y - @obj.y) / duration.to_f
- @jump = jump.to_f
- @jump_interval = @jump/(duration/2.0)
- @duration = duration
- end
- # -----------------------------------------------------------------------
- # *) Is object currently moving?
- # -----------------------------------------------------------------------
- def moving?
- return false if @to_x == -1 && @to_y == -1
- result = @obj.x != @to_x || @obj.y != @to_y
- return result || @duration > 0
- end
- # -----------------------------------------------------------------------
- # *) Update movement
- # -----------------------------------------------------------------------
- def update_move
- @duration -= 1
- @real_x += @x_speed
- @real_y += @y_speed
- @obj.x = @real_x.round
- @obj.y = @real_y.round + @offset.round
- @jump -= @jump_interval
- @offset -= @jump
- clear_move_info unless moving?
- end
- end
- #==========================================================================
- # -------------------------------------------------------------------------
- # *) Set the movement object
- # -------------------------------------------------------------------------
- def set_obj(obj)
- # I just added only one instance variable
- @move_obj = Move_Object.new(obj)
- end
- # -------------------------------------------------------------------------
- # *) Tells the object to move
- # -------------------------------------------------------------------------
- def goto(x,y,duration = Graphics.frame_rate,jump = 0.0)
- @move_obj.move_to(x,y,jump,duration)
- end
- # -------------------------------------------------------------------------
- # *) Tells the object to slide
- # -------------------------------------------------------------------------
- def slide(x,y,duration = Graphics.frame_rate,jump = 0.0)
- slide_x = 0
- slide_y = 0
- if x.is_a?(Coordinate)
- target = x
- slide_x = @move_obj.obj.x + target.x
- slide_y = @move_obj.obj.y + target.y
- else
- slide_x = @move_obj.obj.x + x
- slide_y = @move_obj.obj.y + y
- end
- goto(slide_x,slide_y,duration,jump) unless moving?
- end
- # -------------------------------------------------------------------------
- # *) Update movement
- # -------------------------------------------------------------------------
- def update_move
- @move_obj.update_move if moving?
- end
- # -------------------------------------------------------------------------
- # *) Is object moving?
- # -------------------------------------------------------------------------
- def moving?
- @move_obj.moving?
- end
- # -------------------------------------------------------------------------
- # *) Slide up
- # -------------------------------------------------------------------------
- def up(range,duration = Graphics.frame_rate,jump = 0.0)
- slide(0,-range,duration,jump)
- end
- # -------------------------------------------------------------------------
- # *) Slide down
- # -------------------------------------------------------------------------
- def down(range,duration = Graphics.frame_rate,jump = 0.0)
- slide(0,range,duration,jump)
- end
- # -------------------------------------------------------------------------
- # *) Slide to right
- # -------------------------------------------------------------------------
- def right(range,duration = Graphics.frame_rate,jump = 0.0)
- slide(range,0,duration,jump)
- end
- # -------------------------------------------------------------------------
- # *) Slide to left
- # -------------------------------------------------------------------------
- def left(range,duration = Graphics.frame_rate,jump = 0.0)
- slide(-range,0,duration,jump)
- end
- # -------------------------------------------------------------------------
- # *) Slide to upright
- # -------------------------------------------------------------------------
- def upright(range,duration = Graphics.frame_rate,jump = 0.0)
- slide(range,-range,duration,jump)
- end
- # -------------------------------------------------------------------------
- # *) Slide to upleft
- # -------------------------------------------------------------------------
- def upleft(range,duration = Graphics.frame_rate,jump = 0.0)
- slide(-range,-range,duration,jump)
- end
- # -------------------------------------------------------------------------
- # *) Slide to downright
- # -------------------------------------------------------------------------
- def downright(range,duration = Graphics.frame_rate,jump = 0.0)
- slide(range,-range,duration,jump)
- end
- # -------------------------------------------------------------------------
- # *) Slide to downleft
- # -------------------------------------------------------------------------
- def downleft(range,duration = Graphics.frame_rate,jump = 0.0)
- slide(-range,range,duration,jump)
- end
- end
- end
- # -----------------------------------------------------------------------------
- # Implemented to Sprite
- # -----------------------------------------------------------------------------
- class Sprite
- include THEO::Movement
-
- alias theolized_sprite_init initialize
- def initialize(*args)
- theolized_sprite_init(*args)
- set_obj(self)
- end
-
- alias theolized_move_update update
- def update
- theolized_move_update
- update_move
- end
- end
- # -----------------------------------------------------------------------------
- # Implemented to Window
- # -----------------------------------------------------------------------------
- class Window
- include THEO::Movement
-
- alias theolized_move_window_init initialize
- def initialize(x, y, width, height)
- theolized_move_window_init(x, y, width, height)
- set_obj(self)
- end
-
- alias theolized_move_update update
- def update
- theolized_move_update
- update_move
- end
-
- end
- end
- #==============================================================================
- # ** Object Core Fade
- #------------------------------------------------------------------------------
- # Same as core movement. But this one is dealing with opacity. It can be
- # implemented to any object that has opacity value. Such as Window or Sprite
- #
- # Avalaible methods :
- # - fade(target_opacity, duration)
- # - fadeout(duration)
- # - fadein(duration)
- #
- # I use this module within my sideview battle system
- #------------------------------------------------------------------------------
- if $imported[:Theo_CoreFade] # Activation flag
- #==============================================================================
- module THEO
- module FADE
- # Default duration of fading
- DEFAULT_DURATION = 60
- # -------------------------------------------------------------------------
- # *) Init core fade instance variables
- # -------------------------------------------------------------------------
- def init_fade_members
- @obj = nil
- @target_opacity = -1
- @fade_speed = 0.0
- @pseudo_opacity = 0
- end
- # -------------------------------------------------------------------------
- # *) Set object
- # -------------------------------------------------------------------------
- def setfade_obj(obj)
- @obj = obj
- @pseudo_opacity = @obj.opacity
- end
- # -------------------------------------------------------------------------
- # *) Fade function
- # -------------------------------------------------------------------------
- def fade(opacity, duration = DEFAULT_DURATION)
- @target_opacity = opacity
- make_fade_speed(duration)
- end
- # -------------------------------------------------------------------------
- # *) Determine fade speed
- # -------------------------------------------------------------------------
- def make_fade_speed(duration)
- @fade_speed = (@target_opacity - @obj.opacity)/duration.to_f
- @pseudo_opacity = @obj.opacity.to_f
- end
- # -------------------------------------------------------------------------
- # *) Fadeout function
- # -------------------------------------------------------------------------
- def fadeout(duration = DEFAULT_DURATION)
- fade(0, duration)
- end
- # -------------------------------------------------------------------------
- # *) Fadein function
- # -------------------------------------------------------------------------
- def fadein(duration = DEFAULT_DURATION)
- fade(255, duration)
- end
- # -------------------------------------------------------------------------
- # *) Update fade
- # -------------------------------------------------------------------------
- def update_fade
- if fade?
- @pseudo_opacity += @fade_speed
- @obj.opacity = @pseudo_opacity
- else
- @target_opacity = -1
- end
- end
- # -------------------------------------------------------------------------
- # *) Is performing fade?
- # -------------------------------------------------------------------------
- def fade?
- return false if @target_opacity == -1
- @target_opacity != @pseudo_opacity.round
- end
-
- end
- end
- # -----------------------------------------------------------------------------
- # Implements to Sprite
- # -----------------------------------------------------------------------------
- class Sprite
-
- include THEO::FADE
-
- alias pre_fade_init initialize
- def initialize(*args)
- pre_fade_init(*args)
- init_fade_members
- setfade_obj(self)
- end
-
- alias pre_fade_update update
- def update
- pre_fade_update
- update_fade
- end
-
- end
- end
- #==============================================================================
- # ** Object Circular Movement
- #------------------------------------------------------------------------------
- # This is the most troublesome basic module I have ever made. I wrote this
- # documentation after I made this modules months ago. So I little bit forgot
- # how it works, why I did this, why I did that.
- #
- # Well, this basic module is deal with circular movement of object. Like our
- # Moon and Earth. You can set which coordinate/object that will be the center
- # rotation. Then tells the object to surround. I'm aware this module is far
- # from perfect. I'm open mind if anyone want to edit to make it better
- #
- # Avalaible Methods :
- # - circle_move(degree, duration)
- # - center_coordinate(x,y)
- # - center_object(obj)
- # - endless_circle(speed)
- #------------------------------------------------------------------------------
- if $imported[:Theo_Circular] # Activation flag
- #==============================================================================
- module THEO
- module Circular
- class Circular_Obj
- attr_reader :ox # Center coordinate X
- attr_reader :oy # Center coordinate Y
- attr_reader :center_obj # Center object
- attr_reader :obj # Object
- # -----------------------------------------------------------------------
- # *) Initialize
- # -----------------------------------------------------------------------
- def initialize(obj,ox,oy,center_obj)
- @obj = obj
- @center_obj = center_obj if can_move?(center_obj)
- @ox = ox
- @oy = oy
- @speed = 0
- @endless = false
- @freeze = false
- refresh_info
- end
- # -----------------------------------------------------------------------
- # *) Refresh information
- # -----------------------------------------------------------------------
- def refresh_info
- @radius = radius
- @degree_dest = @current_degree = get_degree
- end
- # -----------------------------------------------------------------------
- # *) Set center object
- # -----------------------------------------------------------------------
- def center_obj=(center)
- return unless can_move?(center)
- @center_obj = center
- refresh_info
- end
- # -----------------------------------------------------------------------
- # *) Set center coordinate X
- # -----------------------------------------------------------------------
- def ox=(ox)
- @ox = ox
- refresh_info
- end
- # -----------------------------------------------------------------------
- # *) Set center coordinate Y
- # -----------------------------------------------------------------------
- def oy=(oy)
- @oy = oy
- refresh_info
- end
- # -----------------------------------------------------------------------
- # *) Is object can move?
- # -----------------------------------------------------------------------
- def can_move?(obj)
- obj.respond_to?("x") && obj.respond_to?("y")
- end
- # -----------------------------------------------------------------------
- # *) Circle move
- # -----------------------------------------------------------------------
- def circle_move(degree,duration)
- return if endless?
- @degree_dest = (@current_degree + degree)
- @speed = (@degree_dest - @current_degree) / duration.to_f
- end
- # -----------------------------------------------------------------------
- # *) Go to specified degree
- # -----------------------------------------------------------------------
- def circle_goto(degree,duration)
- return if endless?
- @degree_dest = degree
- @speed = (@degree_dest - @current_degree) / duration.to_f
- end
- # -----------------------------------------------------------------------
- # *) Endless circle movement
- # -----------------------------------------------------------------------
- def endless_circle(speed)
- @speed = speed
- @endless = true
- end
- # -----------------------------------------------------------------------
- # *) Get current degree from center point
- # -----------------------------------------------------------------------
- def get_degree
- Math.degree(Math.atan2(range_y,range_x)) rescue 0
- end
- # -----------------------------------------------------------------------
- # *) Get distance X from center point
- # -----------------------------------------------------------------------
- def range_x
- @obj.x - center_x
- end
- # -----------------------------------------------------------------------
- # *) Get distance Y from center point
- # -----------------------------------------------------------------------
- def range_y
- @obj.y - center_y
- end
- # -----------------------------------------------------------------------
- # *) Get coordinate X from center point
- # -----------------------------------------------------------------------
- def center_x
- @center_obj.nil? ? @ox : @center_obj.x
- end
- # -----------------------------------------------------------------------
- # *) Get coordinate Y from center point
- # -----------------------------------------------------------------------
- def center_y
- @center_obj.nil? ? @oy : @center_obj.y
- end
- # -----------------------------------------------------------------------
- # *) Get radius value from center point
- # -----------------------------------------------------------------------
- def radius
- Math.sqrt((range_x**2) + (range_y**2))
- end
- # -----------------------------------------------------------------------
- # *) Update circle movement
- # -----------------------------------------------------------------------
- def update_circle
- return if circle_frozen?
- return unless rotate? || @endless
- @current_degree += @speed
- update_x
- update_y
- @degree_dest = @current_degree if @endless
- end
- # -----------------------------------------------------------------------
- # *) Object is moving?
- # -----------------------------------------------------------------------
- def rotate?
- return @current_degree.round != @degree_dest.round
- end
- # -----------------------------------------------------------------------
- # *) Update X position
- # -----------------------------------------------------------------------
- def update_x
- @obj.x = center_x + (@radius *
- Math.cos(Math.radian(@current_degree))).round
- end
- # -----------------------------------------------------------------------
- # *) Update Y position
- # -----------------------------------------------------------------------
- def update_y
- @obj.y = center_y + (@radius *
- Math.sin(Math.radian(@current_degree))).round
- end
- # -----------------------------------------------------------------------
- # *) Freeze circle
- # -----------------------------------------------------------------------
- def circle_freeze
- @freeze = true
- end
- # -----------------------------------------------------------------------
- # *) Unfreeze circle
- # -----------------------------------------------------------------------
- def circle_unfreeze
- @freeze = false
- end
- # -----------------------------------------------------------------------
- # *) Is frozen?
- # -----------------------------------------------------------------------
- def circle_frozen?
- @freeze
- end
- # -----------------------------------------------------------------------
- # *) Stop circling
- # -----------------------------------------------------------------------
- def stop
- @endless = false
- end
- # -----------------------------------------------------------------------
- # *) Continue circling
- # -----------------------------------------------------------------------
- def continue
- @endless = true
- end
- # -----------------------------------------------------------------------
- # *) Endless circle?
- # -----------------------------------------------------------------------
- def endless?
- @endless
- end
- end
- # =========================================================================
- # These methods below aren't necessary to comment
- # -------------------------------------------------------------------------
- def set_circle(obj,ox = 0,oy = 0,center_obj = nil)
- @circle = Circular_Obj.new(obj,ox,oy,center_obj)
- end
-
- def stop
- @circle.stop
- end
-
- def continue
- @circle.continue
- end
-
- def endless?
- @circle.endless?
- end
-
- def circle_move(degree, dur = Graphics.frame_rate)
- @circle.circle_move(degree,dur)
- end
-
- def endless_circle(speed)
- @circle.endless_circle(speed)
- end
-
- def circle_freeze
- @circle.circle_freeze
- end
-
- def circle_unfreeze
- @circle.circle_unfreeze
- end
-
- def circle_frozed?
- @circle.circle_frozen?
- end
-
- def update_circle
- @circle.update_circle
- end
-
- def rotating?
- @circle.rotate?
- end
-
- def center_coordinate(ox,oy)
- @circle.ox = ox
- @circle.oy = oy
- end
-
- def center_distance(ox,oy)
- @circle.ox = @circle.obj.x + ox
- @circle.oy = @circle.obj.y + oy
- end
-
- def center_obj(obj)
- @circle.center_obj = obj
- end
-
- def refresh_info
- @circle.refresh_info
- end
-
- end
- end
- # -----------------------------------------------------------------------------
- # Implements to window
- # -----------------------------------------------------------------------------
- class Window
-
- include THEO::Circular
-
- alias theolized_circle_window_init initialize
- def initialize(*args)
- theolized_circle_window_init(*args)
- set_circle(self,x,y)
- end
-
- alias window_circle_update update
- def update
- window_circle_update
- update_circle
- end
-
- end
- # -----------------------------------------------------------------------------
- # Implements to sprite
- # -----------------------------------------------------------------------------
- class Sprite
-
- include THEO::Circular
-
- alias theolized_circle_init initialize
- def initialize(*args)
- theolized_circle_init(*args)
- set_circle(self,x,y)
- end
-
- alias sprite_circle_update update
- def update
- sprite_circle_update
- update_circle
- end
-
- end
- end
- #==============================================================================
- # ** Clone Image / Afterimage Base
- #------------------------------------------------------------------------------
- # This basic modules is purposely to make sprite can be cloned / duplicated.
- # In more complex concept, it could be used as base of afterimage. It's used
- # within my sideview battle system
- #------------------------------------------------------------------------------
- if $imported[:Theo_CloneImage] # Activation flag
- #==============================================================================
- class Sprite
- attr_reader :clone_bitmap
- # ---------------------------------------------------------------------------
- # *) Aliased Initialize
- # ---------------------------------------------------------------------------
- alias theo_clonesprites_init initialize
- def initialize(*args)
- @cloned_sprites = []
- @color_flash = Color.new(0,0,0,0)
- @alpha_val = 0.0
- @alpha_ease = 0.0
- @dur_flash = 0
- theo_clonesprites_init(*args)
- end
- # ---------------------------------------------------------------------------
- # *) Base function to clone sprite
- # ---------------------------------------------------------------------------
- def clone(z_pos = 0, clone_bitmap = false)
- @cloned_sprites.delete_if {|spr| spr.disposed? }
- cloned = clone_class.new(viewport)
- cloned.x = x
- cloned.y = y
- cloned.bitmap = bitmap
- cloned.bitmap = bitmap.clone if clone_bitmap
- if z_pos != 0
- cloned.z = z + z_pos
- else
- @cloned_sprites.each do |spr|
- spr.z -= 1
- end
- cloned.z = z - 1
- end
- cloned.src_rect.set(src_rect)
- cloned.zoom_x = zoom_x
- cloned.zoom_y = zoom_y
- cloned.angle = angle
- cloned.mirror = mirror
- cloned.opacity = opacity
- cloned.blend_type = blend_type
- cloned.color.set(color)
- cloned.tone.set(tone)
- cloned.visible = visible
- cloned.bush_depth = bush_depth
- cloned.bush_opacity = bush_opacity
- cloned.ox = ox
- cloned.oy = oy
- on_after_cloning(cloned)
- @cloned_sprites.push(cloned)
- cloned
- end
-
- def on_after_cloning(cloned)
- cloned.theo_clonesprites_flash(@color_flash, @dur_flash)
- # Abstract method. Overwrite it as you want
- end
-
- # Sprite class for cloned sprite
- def clone_class
- Sprite
- end
-
- alias theo_clonesprites_flash flash
- def flash(color, duration)
- theo_clonesprites_flash(color, duration)
- @dur_flash = duration
- @color_flash = color.clone
- @alpha_val = color.alpha.to_f
- @alpha_ease = @alpha_val / duration
- end
-
- alias theo_clonesprites_update update
- def update
- theo_clonesprites_update
- @dur_flash = [@dur_flash - 1,0].max
- @alpha_val = [@alpha_val - @alpha_ease,0.0].max
- @color_flash.alpha = @alpha_val
- end
-
- end
- # =============================================================================
- # Afterimages basic module for all sprite base instance object. Any classes
- # that inherited from Sprite_Base will highly possible to make afterimage
- # effect.
- #
- # How to setup :
- # - Make sure "def afterimage" should return to true
- # - Set rate and opacity easing
- # - Higher rate means the higher delay between displayed afterimage
- # - Higher opac means the faster afterimage will fadeout
- # =============================================================================
- class Sprite_Base < Sprite
- attr_accessor :afterimage # Afterimage flag
- attr_accessor :afterimage_opac # Afterimage opacity easing
- attr_accessor :afterimage_rate # Afterimage thick rate
- # ---------------------------------------------------------------------------
- # *) Aliased initialize
- # ---------------------------------------------------------------------------
- alias theo_afterimagebase_init initialize
- def initialize(*args)
- init_afterimage_base
- theo_afterimagebase_init(*args)
- end
- # ---------------------------------------------------------------------------
- # *) Initialize afterimage variables
- # ---------------------------------------------------------------------------
- def init_afterimage_base
- @afterimage = false
- @afterimage_count = 0
- @afterimage_rate = 3
- @afterimage_opac = 5
- @afterimages = []
- end
- # ---------------------------------------------------------------------------
- # *) Aliased update method
- # ---------------------------------------------------------------------------
- alias theo_afterimagebase_update update
- def update
- theo_afterimagebase_update
- update_afterimage_effect
- end
- # ---------------------------------------------------------------------------
- # *) Update afterimage
- # ---------------------------------------------------------------------------
- def update_afterimage_effect
- # Update and delete afterimage once its opacity has reached zero
- @afterimages.delete_if do |image|
- image.opacity -= afterimage_opac
- image.update if updating_afterimages?
- if image.opacity == 0
- image.dispose
- end
- image.disposed?
- end
- return unless afterimage
- @afterimage_count += 1
- if @afterimage_count % afterimage_rate == 0
- @afterimages.push(clone)
- end
- end
- # ---------------------------------------------------------------------------
- # *) Is afterimages are need to be updated?
- # ---------------------------------------------------------------------------
- def updating_afterimages?
- return false
- end
- # ---------------------------------------------------------------------------
- # *) Disposes sprite alongside the afterimage to prevent RGSS3 crash
- # ---------------------------------------------------------------------------
- alias theo_afterimagebase_dispose dispose
- def dispose
- theo_afterimagebase_dispose
- @afterimages.each do |afimg|
- afimg.dispose
- end
- end
-
- end
- end
- #==============================================================================
- # ** Sprite Rotate Basic module
- #------------------------------------------------------------------------------
- # This basic module only dealing with sprite angle. It's used within my
- # sideview battle system to rotate weapon icon.
- #------------------------------------------------------------------------------
- if $imported[:Theo_RotateImage]
- #==============================================================================
- module Theo
- module Rotation
- # -------------------------------------------------------------------------
- # *) Init rotate function
- # -------------------------------------------------------------------------
- def init_rotate
- @degree = self.angle.to_f
- @target_degree = 0
- @rotating = false
- @rotate_speed = 0.0
- end
- # -------------------------------------------------------------------------
- # *) Change to specific angle
- # -------------------------------------------------------------------------
- def change_angle(target_degree, duration)
- @degree = self.angle.to_f
- @target_degree = target_degree.to_f
- if duration == 0
- @rotate_speed = target_degree
- else
- @rotate_speed = (target_degree - @degree) / duration
- end
- @rotating = true
- end
- # -------------------------------------------------------------------------
- # *) Update rotation
- # -------------------------------------------------------------------------
- def update_rotation
- return unless @rotating
- @degree += @rotate_speed
- new_angle = @degree.round
- self.angle = new_angle
- if new_angle == @target_degree
- init_rotate
- end
- end
- # -------------------------------------------------------------------------
- # *) Start rotate to additional degree
- # -------------------------------------------------------------------------
- def start_rotate(degree_plus, duration)
- change_angle(@degree + degree_plus, duration)
- end
-
- end
- end
- # -----------------------------------------------------------------------------
- # Implements on sprite
- # -----------------------------------------------------------------------------
- class Sprite
- include Theo::Rotation
-
- alias theo_spr_rotate_init initialize
- def initialize(viewport = nil)
- theo_spr_rotate_init(viewport)
- init_rotate
- end
-
- alias theo_spr_rotate_update update
- def update
- theo_spr_rotate_update
- update_rotation
- end
-
- end
- end
- #==============================================================================
- # ** Smooth_Slide
- #------------------------------------------------------------------------------
- # This module provides basic module for smooth sliding. It can be implemented
- # to any classes as long as they have x and y.
- #
- # Avalaible methods :
- # - smooth_move(x,y,dur,[reverse])
- # Tells the object to move to specific x,y coordinate in given time duration
- # in frame. If reverse set to true, object will start with maximum speed
- #
- # - smooth_slide(x,y,dur,[reverse])
- # Tells the object to slide to specific x,y coordinate from original position
- # in given time duration in frame. If reverse set to true, object will start
- # with maximum speed
- #------------------------------------------------------------------------------
- if $imported[:Theo_SmoothMove] # Activation Flag
- #==============================================================================
- module Smooth_Slide
- # ---------------------------------------------------------------------------
- # Initialize smooth movement data
- # ---------------------------------------------------------------------------
- def init_smove
- @smooth_dur = 0 # Travel duration
- @accel_x = 0.0 # Acceleration X
- @accel_y = 0.0 # Acceleration Y
- @vel_x = 0.0 # Velocity X
- @vel_y = 0.0 # Velocity Y
- @sreal_x = self.x # Real position X
- @sreal_y = self.y # Real Position Y
- @starget_x = 0.0 # Target X
- @starget_y = 0.0 # Target Y
- @srev = false # Reverse Flag
- @smove = false # Moving Flag
-
- # The reason why I give 's' in front of most instance variables is for
- # uniqueness. Well, if there is any basic module / script out there that
- # also use same instance name, it may causes incompatibility
-
- end
- # ---------------------------------------------------------------------------
- # Do smooth movement
- # ---------------------------------------------------------------------------
- def smooth_move(x,y,dur,reverse = false)
- init_smove
- @srev = reverse
- @smove = true
- @smooth_dur = dur
- @sreal_x = self.x.to_f
- @sreal_y = self.y.to_f
- @starget_x = x.to_i
- @starget_y = y.to_i
- calc_accel
- end
- # ---------------------------------------------------------------------------
- # Do smooth slide
- # ---------------------------------------------------------------------------
- def smooth_slide(x,y,dur,reverse = false)
- tx = x + self.x
- ty = y + self.y
- smooth_move(tx,ty,dur,reverse)
- end
- # ---------------------------------------------------------------------------
- # Calculate acceleration
- # ---------------------------------------------------------------------------
- def calc_accel
- # Get travel distance
- dist_x = @starget_x - @sreal_x
- dist_y = @starget_y - @sreal_y
-
- # Calculate acceleration
- @accel_x = (dist_x/((@smooth_dur**2)/2.0))
- @accel_y = (dist_y/((@smooth_dur**2)/2.0))
-
- # If reverse, velocity started on max speed
- if @srev
- @vel_x = (@accel_x * (@smooth_dur.to_f - 0.5))
- @vel_y = (@accel_y * (@smooth_dur.to_f - 0.5))
- end
- end
- # ---------------------------------------------------------------------------
- # Execute end smooth
- # ---------------------------------------------------------------------------
- def end_smooth_slide
- init_smove
- end
- # ---------------------------------------------------------------------------
- # Update Smooth movement
- # ---------------------------------------------------------------------------
- def update_smove
- if @smove
- # If not reversed. Increase velocity on the first time executed
- if !@srev
- @vel_x += @accel_x
- @vel_y += @accel_y
- end
-
- # Give increment / decrement upon real position
- @sreal_x = (@starget_x > @sreal_x ?
- [@sreal_x + @vel_x, @starget_x].min :
- [@sreal_x + @vel_x, @starget_x].max)
- @sreal_y = (@starget_y > @sreal_y ?
- [@sreal_y + @vel_y, @starget_y].min :
- [@sreal_y + @vel_y, @starget_y].max)
-
- # Rounded real position
- self.x = @sreal_x.round
- self.y = @sreal_y.round
-
- # If reversed, decrease velocity after make a change to real position
- if @srev
- @vel_x -= @accel_x
- @vel_y -= @accel_y
- end
-
- # If target has reach it's destination, call end execution
- if (self.x == @starget_x && self.y == @starget_y)
- end_smooth_slide
- end
- end
- end
- # ---------------------------------------------------------------------------
- # Get smooth moving flag
- # ---------------------------------------------------------------------------
- def smoving?
- @smove
- end
-
- end
- # -----------------------------------------------------------------------------
- # Implemented on sprite
- # -----------------------------------------------------------------------------
- class Sprite
- include Smooth_Slide
-
- alias smooth_init initialize
- def initialize(v=nil)
- smooth_init(v)
- init_smove
- end
-
- alias smooth_update update
- def update
- smooth_update
- update_smove
- end
-
- end
- # -----------------------------------------------------------------------------
- # Implemented on window
- # -----------------------------------------------------------------------------
- class Window
- include Smooth_Slide
-
- alias smooth_init initialize
- def initialize(*args)
- smooth_init(*args)
- init_smove
- end
-
- alias smooth_update update
- def update
- smooth_update
- update_smove
- end
-
- end
- end
- # =============================================================================
- # Below this line are just miscellaneous functions
- # -----------------------------------------------------------------------------
- # Debug print line
- # -----------------------------------------------------------------------------
- def debug
- puts "这一行已被执行"
- end
- # -----------------------------------------------------------------------------
- # Debug print frame
- # -----------------------------------------------------------------------------
- def debugc
- puts Graphics.frame_count
- end
- # -----------------------------------------------------------------------------
- # Copy object. Because calling clone/dup sometimes is not enough
- # -----------------------------------------------------------------------------
- def copy(object)
- Marshal.load(Marshal.dump(object))
- end
复制代码
防卡顿脚本:
- #===============================================================================
- # TheoAllen - 终极防止卡顿
- # Version : 1.1
- # Language : English
- #-------------------------------------------------------------------------------
- # 帮助编写此脚本的人 :
- # - Tsukihime
- # - KilloZapit
- # - Galv
- #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- # Contact :
- #-------------------------------------------------------------------------------
- # *> http://www.rpgmakerid.com
- # *> http://www.rpgmakervxace.net
- # *> http://www.theolized.com
- #===============================================================================
- ($imported ||= {})[:Theo_AntiLag] = true
- #===============================================================================
- # Change Logs:
- # ------------------------------------------------------------------------------
- # 2015.02.20 - Added page check enhancer to work with parallel process
- # 2015.01.25 - Compatibility with Shaz's Mouse Script. def events_xy now should
- # always return array,
- # - Avoid error 'undefined method delete_sprite for nilClass'
- # 2015.01.01 - Avoid unexpected error 'undefined method spriteset for scene'
- # 2014.12.05 - Finished
- #===============================================================================
- =begin
- ------------------------------------------
- *) 介绍 :
- ------------------------------------------
- 如你所知, RPG Maker 游戏中出现卡顿是个常见问题.
- 你开始猜想会不会是因为在地图上设定了过多的事件,因此,为了防卡,你将地图拆分
- 为小块,同时减少事件的使用.
-
- 这也不全错,因为过多事件的确会让程序花更多时间去检查。可是,减少事件并不能
- 极大地优化游戏速度。
- 本脚本将提升游戏运行效率,阻止一些不必要的更新以提升游戏速度。
-
- 注意,因为我改了许多地方,因此不能完全保证其可以较高的兼容其他脚本。
- 相比于兼容其他人的脚本,我很可能会优先兼容我自己的脚本。
-
- ------------------------------------------
- *) 使用方法 :
- ------------------------------------------
- 将本脚本防在插件脚本之下,Main之上。建议尽可能放在其他自定义脚本之上.
-
- 如果发生兼容性的问题,在设定部分根据自己的需要进行修改。
-
- ------------------------------------------
- *) 使用条款 :
- 署名脚本作者, TheoAllen. 你可以自由编辑此脚本,只要你不声明你是脚本的原作者
- 如果你想用此脚本于商业游戏,请和我共享收益.别忘了给我一份免费的游戏拷贝.
-
- 在标题部分还写有帮助编写此脚本的人,如果要使用本脚本于商业游戏,记得也给他们
- 发一个免费的游戏拷贝 ;)
-
- =end
- #==============================================================================
- # 设定 :
- #==============================================================================
- module Theo
- module AntiLag
-
- #=============================================================================
- # *) 普通优化
- #-----------------------------------------------------------------------------
- # 较为普通的优化方式,在地图中的总事件数为200 - 300之间时效果明显.
- #=============================================================================
-
- #-----------------------------------------------------------------------------
- Optimize_XY = true
- #-----------------------------------------------------------------------------
- # 默认下,检查事件位置会检查同一地图中的全部事件的位置。如果你要检查事件的x,y
- # 坐标,系统会确认全部事件是否匹配。启用此优化后,全部事件会登记到某一个table上。
- # 检查时不会检查全部地图的事件,而是会检查某一个table内的事件。
- #
- # 建议将此优化设定为 true. 注意,此优化可能与“按像素移动”的脚本不兼容,
- # 因为其使用的是新的碰撞接触系统,而不是默认的图块网格.
- #-----------------------------------------------------------------------------
-
- #-----------------------------------------------------------------------------
- Optimize_Event = true
- #-----------------------------------------------------------------------------
- # 默认下,如果系统引擎想要检查是否有事件被触发,其会检查地图中的全部事件。
- # 且每一帧都会检查。如果你在地图中设定了200个事件,则每秒会检查60 x 200次.
- #
- # 启用此优化后,如果某事件被触发,其会登记到一个记录列表中。
- # 之后引擎只会在这个记录列表中检查是否有事件被触发,而不会检查地图中的全部事件。
- #-----------------------------------------------------------------------------
-
- #-----------------------------------------------------------------------------
- Optimize_Sprite = true
- #-----------------------------------------------------------------------------
- # 默认下,系统引擎会更新画面外的全部精灵。有时,不必要的画面外更新会浪费时间. By
- # 启用此优化后,将会无视画面外精灵的更新。
- #-----------------------------------------------------------------------------
-
- #=============================================================================
- # *) 终极优化
- #-----------------------------------------------------------------------------
- # 此优化可以解决在同一地图中事件数大于230时发生卡顿的问题。
- # 使用了一些像按table搜索和随时处理任何不必要精灵的方式。
- #=============================================================================
-
- #-----------------------------------------------------------------------------
- Table_Limit_Search = 230
- #-----------------------------------------------------------------------------
- # 按Table搜索是一种从地图table中拾取事件来读取的自定义算法。
- # 区别于迭代所有事件并检查它们是否在画面中,此优化方式会先检查事件是否处于
- # 玩家可见的地图table中。所以,离玩家画面很远的事件不会被更新。
- # 但是,所并行处理和自动执行的事件,和事件中的移动路线设定仍然会正常更新。
- #
- # 当地图中的总事件数超过限制,脚本会使用table搜索的算法。当事件数为999 ,或
- # 10.000 时你就不用担心了.
- #
- # Table搜索需要将 Optimize_XY 设定为 true.
- #
- # 如果你不想使用table搜索的算法,将其设定为nil即可.
- #-----------------------------------------------------------------------------
-
- #-----------------------------------------------------------------------------
- Table_Range_Search = 2
- #-----------------------------------------------------------------------------
- # 确定table搜索会检查的范围. 设定为 3 则意为会更新到画面外3图块的区域。
- #
- # 注意,范围大小会影响游戏表现效果。
- # 建议设定为 2 - 4
- #-----------------------------------------------------------------------------
-
- #-----------------------------------------------------------------------------
- Dispose_Sprite = true
- #-----------------------------------------------------------------------------
- # 有时,限制事件的更新远远不够。精灵对象也是个游戏表现杀手。
- # 无视画面外精灵会击打提升游戏顺畅度。此优化仅在启用table搜索时有效。
- #
- # 即时无视精灵有时会出现一些问题,可以设定为false来禁用此功能.
- #-----------------------------------------------------------------------------
-
- #-----------------------------------------------------------------------------
- PageCheck_Enchancer = true
- #-----------------------------------------------------------------------------
- # 在同一地图中存在事件页有20页的事件,且有一大堆并行处理改变变量或开关时,你会
- # 见到明显的卡顿。
- #
- # 此优化仅会刷新画面内事件的事件页。
- # 刷新地图外的事件有时是愚蠢的,因为就算是画面内,玩家也永远都不会知道暗中发生
- # 了什么。
- #
- # 可是,此优化可能会毁了某些系统,其仅为实验性功能。
- #-----------------------------------------------------------------------------
-
- end
- end
- #===============================================================================
- # *) 最后的注释 :
- #-------------------------------------------------------------------------------
- # 最后说一下,以上是我对优化游戏速度的一些考量。游戏表现效果受到各种因素的影响:
- #
- # - 你电脑的 CPU 速度
- # - 你的笔记本电脑 / PC 的温度
- # - 你的电脑的 CPU 功率
- # - 任务数量
- # - 别人的脚本
- #
- # 以前我都是在旧电脑中使用 RM . 当我换更高级的笔记本后,发现60FPS真的是很顺滑.
- #
- # 如果你的 CPU 太热了, 关掉你的笔记本/ PC 使其冷却.
- # 因为风扇故障,有次我的笔记本过热了.玩我的游戏时仅10 FPS.
- # 我使用了自己的防卡脚本,但是没有一个起作用,直到我发现原来是笔记本过热了。
- #
- # 节能模式也会影响游戏体验. 为了防止卡顿,你可以试着切换到高性能模式.
- # 有一次我的朋友在节能模式下玩我的游戏,才得 15 FPS.
- #
- # 一次性执行多个进程,在RM游戏中也会出现一些卡顿。
- # 类似于画面在一段时间内不更新。
- #
- # 一些不完备的脚本也可能会影响显示效果。本防卡脚本仅在使用默认脚本的情况下进行
- # 测试。
- #
- #-------------------------------------------------------------------------------
- # *) 以下部分,除非你会写脚本,否则请勿改动。
- #===============================================================================
- #===============================================================================
- # ** MapTable
- #-------------------------------------------------------------------------------
- # This class used to register the event into 2D table to increase performance
- #===============================================================================
- class MapTable
- #-----------------------------------------------------------------------------
- # * Initialize
- #-----------------------------------------------------------------------------
- def initialize
- @table = []
- ($game_map.width + 1).times do |x|
- @table[x] = []
- ($game_map.height + 1).times do |y|
- @table[x][y] = []
- end
- end
- end
- #-----------------------------------------------------------------------------
- # * Set value
- #-----------------------------------------------------------------------------
- def set(x,y,val)
- @table[x][y] << val
- end
- #-----------------------------------------------------------------------------
- # * Get array
- #-----------------------------------------------------------------------------
- def get(x,y)
- @table[x][y]
- end
-
- end
- #===============================================================================
- # ** Array
- #===============================================================================
- class Array
-
- # Just a fool proof
- def values
- return self
- end
-
- end
- #===============================================================================
- # ** Game_Map
- #===============================================================================
- class Game_Map
- #-----------------------------------------------------------------------------
- # * Public attributes
- #-----------------------------------------------------------------------------
- attr_accessor :event_redirect # Redirect events
- attr_reader :forced_update_events # To keep force move route updated
- attr_reader :keep_update_events # To keep parallel process updated
- attr_reader :cached_events # To store event that need to be updated
- attr_reader :starting_events # To store activated event
- attr_reader :table # 2D Map table
- #-----------------------------------------------------------------------------
- # * Constant
- #-----------------------------------------------------------------------------
- EVENT_LIMIT = Theo::AntiLag::Table_Limit_Search
- RANGE = Theo::AntiLag::Table_Range_Search
- #-----------------------------------------------------------------------------
- # * Alias method : Setup Events
- #-----------------------------------------------------------------------------
- alias theo_antilag_setup_events setup_events
- def setup_events
- @table = MapTable.new
- @forced_update_events = []
- @keep_update_events = []
- @starting_events = []
- @refreshed_events = []
- theo_antilag_setup_events
- select_on_screen_events
- end
- #-----------------------------------------------------------------------------
- # * Overwrite method : Events
- #-----------------------------------------------------------------------------
- def events
- @event_redirect ? @cached_events : @events
- end
- #///////////////////////////////////////////////////////////////////////////////
- if Theo::AntiLag::Optimize_XY
- #///////////////////////////////////////////////////////////////////////////////
- #-----------------------------------------------------------------------------
- # * Overwrite method : Event XY
- #-----------------------------------------------------------------------------
- def events_xy(x, y)
- @table.get(x,y) || []
- end
- #-----------------------------------------------------------------------------
- # * Overwrite method : Event XY nt
- #-----------------------------------------------------------------------------
- def events_xy_nt(x, y)
- @table.get(x,y).select do |event|
- event.pos_nt?(x, y)
- end
- end
- #///////////////////////////////////////////////////////////////////////////////
- end
- #///////////////////////////////////////////////////////////////////////////////
- if Theo::AntiLag::Optimize_Event
- #///////////////////////////////////////////////////////////////////////////////
- #-----------------------------------------------------------------------------
- # * Overwrite method : Setup starting event
- #-----------------------------------------------------------------------------
- def setup_starting_map_event
- event = @starting_events[0]
- event.clear_starting_flag if event
- @interpreter.setup(event.list, event.id) if event
- event
- end
- #-----------------------------------------------------------------------------
- # * Overwrite method : Any event starting?
- #-----------------------------------------------------------------------------
- def any_event_starting?
- !@starting_events.empty?
- end
- #///////////////////////////////////////////////////////////////////////////////
- end
- #///////////////////////////////////////////////////////////////////////////////
- #-----------------------------------------------------------------------------
- # * Overwrite method : Refresh
- #-----------------------------------------------------------------------------
- def refresh
- return table_refresh if table_update? && Theo::AntiLag::PageCheck_Enchancer
- @events.each_value {|event| next if event.never_refresh; event.refresh }
- @common_events.each {|event| event.refresh }
- refresh_tile_events
- @need_refresh = false
- end
- #-----------------------------------------------------------------------------
- # * New method : Refresh event by table search
- #-----------------------------------------------------------------------------
- def table_refresh
- @refreshed_events = []
- @tile_events = []
- @common_events.each {|event| event.refresh }
- @need_refresh = false
- end
- #-----------------------------------------------------------------------------
- # * Overwrite method : Update events
- #-----------------------------------------------------------------------------
- def update_events
- last_events = (@cached_events.dup rescue @events.values)
- select_on_screen_events
- events = @cached_events | @keep_update_events | @forced_update_events
- if Theo::AntiLag::Dispose_Sprite
- offscreen_events = last_events - events
- offscreen_events.each {|event| event.delete_sprite}
- end
- events.each {|event| event.update}
- @common_events.each {|event| event.update}
- end
- #-----------------------------------------------------------------------------
- # * New method : Select on screen events
- #-----------------------------------------------------------------------------
- def select_on_screen_events
- unless table_update?
- @cached_events = @events.values
- return
- end
- #---------------------------------------------------------------------------
- # * Table search algorithm
- #---------------------------------------------------------------------------
- new_dpx = display_x.to_i
- new_dpy = display_y.to_i
- dpx = loop_horizontal? ? new_dpx - RANGE : [new_dpx - RANGE, 0].max
- dpy = loop_vertical? ? new_dpy - RANGE : [new_dpy - RANGE, 0].max
- sw = (Graphics.width >> 5) + RANGE * 2
- sh = (Graphics.height >> 5) + RANGE * 2
- @cached_events = []
- sw.times do |x|
- sh.times do |y|
- xpos = loop_horizontal? ? (x + dpx) % width : x + dpx
- ypos = loop_vertical? ? (y + dpy) % height : y + dpy
- next if xpos >= width || ypos >= height
- ary = @table.get(xpos, ypos)
- ary.each do |ev|
- unless @refreshed_events.include?(ev.id)
- ev.refresh
- @tile_events << ev if ev.tile?
- @refreshed_events << ev.id
- end
- end if Theo::AntiLag::PageCheck_Enchancer
- @cached_events += ary
- end
- end
- @cached_events.uniq!
- end
- #-----------------------------------------------------------------------------
- # * Check if table search need to be performed or not
- #-----------------------------------------------------------------------------
- def table_update?
- EVENT_LIMIT && @events.size > EVENT_LIMIT && Theo::AntiLag::Optimize_XY
- end
-
- end
- #===============================================================================
- # ** Game_Temp
- #===============================================================================
- class Game_Temp
- attr_reader :event_sprites
- #-----------------------------------------------------------------------------
- # * Alias method : Initialize
- #-----------------------------------------------------------------------------
- alias theo_antilag_init initialize
- def initialize
- theo_antilag_init
- @event_sprites = {}
- end
-
- end
- #===============================================================================
- # ** Game_CharacterBase
- #===============================================================================
- class Game_CharacterBase
- #-----------------------------------------------------------------------------
- # * Empty method : Sprite
- #-----------------------------------------------------------------------------
- def sprite
- return nil
- end
- #-----------------------------------------------------------------------------
- # * Empty method : Sprite =
- #-----------------------------------------------------------------------------
- def sprite=(spr)
- end
-
- end
- #===============================================================================
- # ** Game_Event
- #===============================================================================
- class Game_Event
- #-----------------------------------------------------------------------------
- # * Never refesh flag
- #-----------------------------------------------------------------------------
- attr_reader :never_refresh
- #-----------------------------------------------------------------------------
- # * Alias method : Initialize
- #-----------------------------------------------------------------------------
- alias theo_antilag_init initialize
- def initialize(map_id, event)
- theo_antilag_init(map_id, event)
- $game_map.table.set(x,y,self)
- @last_x = @x
- @last_y = @y
- end
- #-----------------------------------------------------------------------------
- # * Alias method : Update
- #-----------------------------------------------------------------------------
- alias theo_antilag_update update
- def update
- if (sprite && sprite.disposed?) || sprite.nil?
- spriteset = SceneManager.scene.spriteset
- return unless spriteset
- spriteset.add_sprite(self)
- end
- theo_antilag_update
- if Theo::AntiLag::Optimize_XY && (@last_x != @x || @last_y != @y)
- $game_map.table.get(@last_x, @last_y).delete(self)
- $game_map.table.set(@x,@y,self)
- @last_x = @x
- @last_y = @y
- end
- end
- #-----------------------------------------------------------------------------
- # * Alias method : Start
- #-----------------------------------------------------------------------------
- alias theo_antilag_start start
- def start
- theo_antilag_start
- return unless Theo::AntiLag::Optimize_Event
- $game_map.starting_events << self if @starting
- end
- #-----------------------------------------------------------------------------
- # * Alias method : Clear starting flag
- #-----------------------------------------------------------------------------
- alias theo_antilag_clear_start clear_starting_flag
- def clear_starting_flag
- theo_antilag_clear_start
- return unless Theo::AntiLag::Optimize_Event
- $game_map.starting_events.delete(self)
- end
- #-----------------------------------------------------------------------------
- # * Alias method : Setup page setting
- #-----------------------------------------------------------------------------
- alias theo_antilag_setup_page_settings setup_page_settings
- def setup_page_settings
- theo_antilag_setup_page_settings
- if @event.pages.size == 1 && no_condition?(@event.pages[0].condition)
- @never_refresh = true
- end
- if @trigger == 3 || @interpreter
- $game_map.keep_update_events << self
- $game_map.keep_update_events.uniq!
- else
- $game_map.keep_update_events.delete(self)
- end
- end
- #-----------------------------------------------------------------------------
- # * Check if the events has no page condition
- #-----------------------------------------------------------------------------
- def no_condition?(page)
- !page.switch1_valid && !page.switch2_valid && !page.variable_valid &&
- !page.self_switch_valid && !page.item_valid && !page.actor_valid
- end
- #-----------------------------------------------------------------------------
- # * Delete sprite
- #-----------------------------------------------------------------------------
- def delete_sprite
- sprset = SceneManager.scene.spriteset
- return unless sprset
- SceneManager.scene.spriteset.delete_sprite(sprite)
- end
- #-----------------------------------------------------------------------------
- # * Overwrite method : Force move route
- #-----------------------------------------------------------------------------
- def force_move_route(move_route)
- super
- $game_map.forced_update_events << self
- $game_map.forced_update_events.uniq!
- end
- #-----------------------------------------------------------------------------
- # * Overwrite method : Restore move route
- #-----------------------------------------------------------------------------
- def restore_move_route
- super
- $game_map.forced_update_events.delete(self)
- end
- #-----------------------------------------------------------------------------
- # * Overwrite method : Sprite
- #-----------------------------------------------------------------------------
- def sprite
- $game_temp.event_sprites[@id]
- end
- #-----------------------------------------------------------------------------
- # * Overwrite method : Sprite =
- #-----------------------------------------------------------------------------
- def sprite=(spr)
- $game_temp.event_sprites[@id] = spr
- end
-
- end
- #===============================================================================
- # ** Sprite Character
- #===============================================================================
- class Sprite_Character
- #-----------------------------------------------------------------------------
- # * Alias method : Initialize
- #-----------------------------------------------------------------------------
- alias theo_antilag_init initialize
- def initialize(viewport, character = nil)
- character.sprite = self if character
- theo_antilag_init(viewport, character)
- end
- #-----------------------------------------------------------------------------
- # * Alias method : Update
- #-----------------------------------------------------------------------------
- alias theo_antilag_update update
- def update
- @sx = @character.screen_x
- @sy = @character.screen_y
- if Theo::AntiLag::Optimize_Sprite && !need_update?
- self.visible = false
- return
- end
- theo_antilag_update
- end
- #-----------------------------------------------------------------------------
- # * New method : Determine if on screen
- #-----------------------------------------------------------------------------
- def need_update?
- return true if graphic_changed?
- return true if @character.animation_id > 0
- return true if @balloon_sprite
- return true if @character.balloon_id != 0
- w = Graphics.width
- h = Graphics.height
- cw = @cw || 32
- ch = @ch || 32
- @sx.between?(-cw,w+cw) && @sy.between?(0,h+ch)
- end
- #-----------------------------------------------------------------------------
- # * Overwrite update position.
- # To limit screen_x and screen_y to be called many times
- #-----------------------------------------------------------------------------
- def update_position
- move_animation(@sx - x, @sy - y)
- self.x = @sx
- self.y = @sy
- self.z = @character.screen_z
- end
- #-----------------------------------------------------------------------------
- # * Overwrite animation origin
- # Since X and Y axis of sprite is not updated when off screen
- #-----------------------------------------------------------------------------
- def set_animation_origin
- if @animation.position == 3
- if viewport == nil
- @ani_ox = Graphics.width / 2
- @ani_oy = Graphics.height / 2
- else
- @ani_ox = viewport.rect.width / 2
- @ani_oy = viewport.rect.height / 2
- end
- else
- @ani_ox = @sx - ox + width / 2
- @ani_oy = @sy - oy + height / 2
- if @animation.position == 0
- @ani_oy -= height / 2
- elsif @animation.position == 2
- @ani_oy += height / 2
- end
- end
- end
-
- end
- #===============================================================================
- # ** Spriteset_Map
- #===============================================================================
- class Spriteset_Map
- #-----------------------------------------------------------------------------
- # * Alias method : create character
- #-----------------------------------------------------------------------------
- alias theo_antilag_create_characters create_characters
- def create_characters
- $game_map.event_redirect = Theo::AntiLag::Dispose_Sprite
- theo_antilag_create_characters
- $game_map.event_redirect = false
- end
- #-----------------------------------------------------------------------------
- # * New method : delete sprite
- #-----------------------------------------------------------------------------
- def delete_sprite(spr)
- return unless spr
- return if spr.disposed?
- @character_sprites.delete(spr)
- spr.dispose
- end
- #-----------------------------------------------------------------------------
- # * New method : add sprite
- #-----------------------------------------------------------------------------
- def add_sprite(char)
- spr = Sprite_Character.new(@viewport1, char)
- @character_sprites.push(spr)
- end
-
- end
- #===============================================================================
- # ** Scene_Base
- #===============================================================================
- class Scene_Base
- attr_reader :spriteset
- end
复制代码
|
最佳答案
查看完整内容
https://rpg.blue/thread-350955-1-1.html
把这个脚本插入到Theo的脚本之上
|