Class: Yuki::Particle_Object
- Defined in:
- scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00503 Particle_Object.rb,
scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00502 Yuki_Particles Action Handlers.rb
Overview
The object that describe a particle
Constant Summary collapse
- TILE_ZOOM =
Zoom of a tile to adjust coordinate
Configs.display.tilemap_settings.character_tile_zoom
- ACTION_HANDLERS =
{}
- ACTION_HANDLERS_ORDER =
[]
Instance Attribute Summary collapse
-
#disposed ⇒ Boolean
(also: #disposed?)
readonly
if the particle is disposed.
Class Method Summary collapse
-
.add_handler(name, before = nil, &block)
Add a new action handler.
Instance Method Summary collapse
-
#dispose
Dispose the particle.
-
#exectute_action(action)
Execute an animation instruction.
-
#initialize(character, data, on_tp = false, params = {}) ⇒ Particle_Object
constructor
Create a particle object.
-
#screen_z
Function that process screen z depending on original screen_y (without zoom).
-
#update
Update the particle animation.
-
#update_default_flow(data) ⇒ Boolean
Update the default particle state flow.
-
#update_particle_info(data) ⇒ Boolean
Update the particle info.
-
#update_radius_flow(data) ⇒ Boolean
Update the radius particle kind flow.
-
#update_sprite_position
Update the position of the particle sprite.
-
#x ⇒ Integer
Get the real x of the particle on the map.
-
#y ⇒ Integer
Get the real y of the particle on the map.
Constructor Details
#initialize(character, data, on_tp = false, params = {}) ⇒ Particle_Object
Create a particle object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00503 Particle_Object.rb', line 36 def initialize(character, data, on_tp = false, params = {}) @character = character init_map_data(character) @x = character.x + @map_data.offset_x @y = character.y + @map_data.offset_y @z = character.z @sprite = ::Sprite.new(Particles.) @data = data @counter = 0 @position_type = :center_pos @state = (on_tp ? :stay : :enter) @state = params[:state] if params.key?(:state) init_zoom @ox = 0 @oy = 0 @oy_off = 0 @ox_off = 0 @wait_count = 0 @params = params @flow = params[:flow] || :update_default_flow end |
Instance Attribute Details
#disposed ⇒ Boolean (readonly) Also known as: disposed?
if the particle is disposed
9 10 11 |
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00503 Particle_Object.rb', line 9 def disposed @disposed end |
Class Method Details
.add_handler(name, before = nil, &block)
Add a new action handler
9 10 11 12 13 14 15 16 |
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00502 Yuki_Particles Action Handlers.rb', line 9 def self.add_handler(name, before = nil, &block) unless ACTION_HANDLERS_ORDER.include?(name) index = before ? ACTION_HANDLERS_ORDER.index(before) : nil index ||= ACTION_HANDLERS_ORDER.size ACTION_HANDLERS_ORDER.insert(index, name) end ACTION_HANDLERS[name] = block end |
Instance Method Details
#dispose
Dispose the particle
183 184 185 186 187 188 189 190 |
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00503 Particle_Object.rb', line 183 def dispose return if disposed? @sprite.dispose unless @sprite.disposed? @sprite = nil @disposed = true Yuki::Particles.clean_stack end |
#exectute_action(action)
Execute an animation instruction
146 147 148 149 150 151 152 |
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00503 Particle_Object.rb', line 146 def exectute_action(action) ACTION_HANDLERS_ORDER.each do |name| if (data = action[name]) instance_exec(data, &ACTION_HANDLERS[name]) end end end |
#screen_z
Function that process screen z depending on original screen_y (without zoom)
178 179 180 |
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00503 Particle_Object.rb', line 178 def screen_z (y * 128 - $game_map.display_y + 3) / 4 + 32 * @z + 31 end |
#update
Update the particle animation
59 60 61 62 63 64 65 66 67 68 |
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00503 Particle_Object.rb', line 59 def update return if disposed? return dispose unless @map_linker.map_datas.include?(@map_data) if @wait_count > 0 @wait_count -= 1 return update_sprite_position end update_particle_info(@data[@state]) && update_sprite_position end |
#update_default_flow(data) ⇒ Boolean
Update the default particle state flow
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00503 Particle_Object.rb', line 103 def update_default_flow(data) if @state == :enter @state = :stay @counter = 0 elsif @state == :stay @state = :leave if x != @character.x || y != @character.y @counter = 0 else return false end return true end |
#update_particle_info(data) ⇒ Boolean
Update the particle info
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00503 Particle_Object.rb', line 85 def update_particle_info(data) if @counter < data[:max_counter] (action = data[:data][@counter]) && exectute_action(action) @counter += 1 elsif send(@flow, data) return true elsif !data[:loop] dispose return false else @counter = 0 end return true end |
#update_radius_flow(data) ⇒ Boolean
Update the radius particle kind flow
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00503 Particle_Object.rb', line 119 def update_radius_flow(data) radius = Math.sqrt(($game_player.x - @character.x)**2 + ($game_player.y - @character.y)**2) if @state == :enter @state = :stay @counter = 0 elsif @state == :stay return false if @map_data.map_id != $game_map.map_id if radius > @params[:radius] @state = :leave @counter = 0 end elsif @state == :leave return false if @map_data.map_id != $game_map.map_id if (@sprite.visible = (radius <= @params[:radius])) @state = :enter @counter = 0 end else return false end return true end |
#update_sprite_position
Update the position of the particle sprite
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00503 Particle_Object.rb', line 155 def update_sprite_position case @position_type when :center_pos, :grass_pos @sprite.x = (((x * 128 - $game_map.display_x + 3) / 4 + 16) * @tile_zoom).floor @sprite.y = ((y * 128 - $game_map.display_y + 3) / 4 + 32) if @position_type == :center_pos || @sprite.y >= @character.screen_y @sprite.z = (screen_z + @add_z) else @sprite.z = (screen_z - 1) end @sprite.y = (@sprite.y * @tile_zoom).floor @sprite.ox = @ox + @ox_off @sprite.oy = @oy + @oy_off when :character_pos @sprite.x = @character.screen_x * @tile_zoom @sprite.y = @character.screen_y * @tile_zoom @sprite.z = (@character.screen_z(0) + @add_z) @sprite.ox = @ox + @ox_off @sprite.oy = @oy + @oy_off end end |
#x ⇒ Integer
Get the real x of the particle on the map
72 73 74 |
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00503 Particle_Object.rb', line 72 def x return @x - @map_data.offset_x end |
#y ⇒ Integer
Get the real y of the particle on the map
78 79 80 |
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00503 Particle_Object.rb', line 78 def y return @y - @map_data.offset_y end |