Class: Sprite_Character

Inherits:
RPG::Sprite show all
Defined in:
scripts/01450 Systems/00003 Map Engine/00001 Graphics/03200 Sprite_Character.rb

Overview

Class that describe a Character Sprite on the Map

Constant Summary collapse

TILE_ZOOM =

Zoom of a tile and factor used to fix coordinate

Configs.display.tilemap_settings.character_tile_zoom
SPRITE_ZOOM =

Zoom of a Sprite

Configs.display.tilemap_settings.character_sprite_zoom
SHADOW_TAG =

Tag that disable shadow

'§'
SHADOW_FILE =

Name of the shadow file

'0 Ombre Translucide'
REALISTIC_SHADOW =

Enable or disable realistic shadow

true
SUP_TAG =

Tag that add 1 to the superiority of the Sprite_Character

'¤'
REFLECTION_BLEND_MODE =

Blend mode for Reflection

BlendMode.new

Constants inherited from RPG::Sprite

RPG::Sprite::SHADER, RPG::Sprite::TARGET_SHADER

Instance Attribute Summary collapse

Attributes inherited from RPG::Sprite

#blend_type, #color, #tone

Attributes inherited from LiteRGSS::ShaderedSprite

#blendmode, #shader

Attributes inherited from LiteRGSS::Sprite

#__index__, #angle, #bitmap, #height, #mirror, #opacity, #ox, #oy, #src_rect, #viewport, #visible, #width, #x, #y, #z, #zoom, #zoom_x, #zoom_y

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RPG::Sprite

#animation, #animation_process_timing, #animation_set_sprites, #appear, #blink?, #blink_off, #blink_on, #collapse, #damage, #dispose_animation, #dispose_damage, #dispose_loop_animation, #effect?, #escape, #flash, #handle_flash, #loop_animation, #register_position, #reset_position, #update_animation, #update_loop_animation, #whiten, #x=, #y=

Methods inherited from Sprite

#load, #mouse_in?, #set_origin_div, #set_rect, #set_rect_div, #set_z, #simple_mouse_in?, #translate_mouse_coords

Methods inherited from LiteRGSS::Sprite

new, #set_origin, #set_position

Methods inherited from LiteRGSS::Disposable

#disposed?

Constructor Details

#initialize(viewport, character = nil) ⇒ Sprite_Character

Initialize a new Sprite_Character

Parameters:



28
29
30
31
32
33
34
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03200 Sprite_Character.rb', line 28

def initialize(viewport, character = nil)
  super(viewport)
  @bush_depth_sprite = Sprite.new(viewport)
  @bush_depth_sprite.opacity = 128
  @height = 0
  init(character)
end

Instance Attribute Details

#bush_depthInteger

Return the Sprite bush_depth

Returns:



24
25
26
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03200 Sprite_Character.rb', line 24

def bush_depth
  @bush_depth
end

#characterGame_Character

Character displayed by the Sprite_Character

Returns:



21
22
23
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03200 Sprite_Character.rb', line 21

def character
  @character
end

Class Method Details

.fix_rmxp_animations

Fix the animation file



260
261
262
263
264
265
266
267
268
269
270
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03200 Sprite_Character.rb', line 260

def self.fix_rmxp_animations
  if File.exist?('Data/Animations.rxdata')
    if !File.exist?('Data/Animations.psdk') ||
       File.size('Data/Animations.rxdata') != File.size('Data/Animations.psdk')
      save_data($data_animations, 'Data/Animations.rxdata')
      log_info('Re-Saving animations, it\'ll take 2 second...')
      sleep(2)
      save_data($data_animations, 'Data/Animations.psdk')
    end
  end
end

Instance Method Details

#dispose

Dispose the Sprite_Character and its shadow



188
189
190
191
192
193
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03200 Sprite_Character.rb', line 188

def dispose
  super
  dispose_shadow
  dispose_reflection
  @bush_depth_sprite.dispose
end

#dispose_reflection

Dispose the reflection sprite



254
255
256
257
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03200 Sprite_Character.rb', line 254

def dispose_reflection
  @reflection&.dispose
  @reflection = nil
end

#dispose_shadow

Dispose the shadow sprite



226
227
228
229
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03200 Sprite_Character.rb', line 226

def dispose_shadow
  @shadow&.dispose
  @shadow = nil
end

#init(character)

Initialize the specific parameters of the Sprite_Character (shadow, add_z etc…)

Parameters:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03200 Sprite_Character.rb', line 38

def init(character)
  @character = character
  dispose_shadow
  dispose_reflection
  @bush_depth_sprite.visible = false
  @bush_depth = 0
  init_reflection
  init_add_z_shadow
  @tile_zoom = TILE_ZOOM
  @tile_id = 0
  @character_name = nil
  @pattern = 0
  @direction = 0
  update
end

#init_add_z_shadow

Initialize the add_z info & the shadow sprite of the Sprite_Character



55
56
57
58
59
60
61
62
63
64
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03200 Sprite_Character.rb', line 55

def init_add_z_shadow
  event = character.instance_variable_get(:@event)
  return @add_z = 2 if event && event.name.index(SUP_TAG) == 0

  @add_z = 0
  return unless $game_switches[::Yuki::Sw::CharaShadow]
  return if character.shadow_disabled && event && event.pages.size == 1

  init_shadow if !event || event.name.index(SHADOW_TAG) != 0
end

#init_reflection

Init the reflection sprite



232
233
234
235
236
237
238
239
240
241
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03200 Sprite_Character.rb', line 232

def init_reflection
  return if $game_switches[Yuki::Sw::WATER_REFLECTION_DISABLED]
  return unless @character.reflection_enabled

  @reflection = ShaderedSprite.new(viewport)
  @reflection.z = -1000
  @reflection.angle = 180
  @reflection.mirror = true
  @reflection.shader = REFLECTION_BLEND_MODE
end

#init_shadow

Initialize the shadow display



196
197
198
199
200
201
202
203
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03200 Sprite_Character.rb', line 196

def init_shadow
  @shadow = Sprite.new(viewport)
  @shadow.bitmap = bmp = RPG::Cache.character(SHADOW_FILE)
  @shadow.src_rect.set(0, 0, bmp.width / 4, bmp.height / 4)
  @shadow.ox = bmp.width / 8
  @shadow.oy = bmp.height / 4
  @shadow.zoom = SPRITE_ZOOM
end

#update

Update every informations about the Sprite_Character



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03200 Sprite_Character.rb', line 67

def update
  super if @_animation || @_loop_animation
  # Check if the graphic info where updated
  update_graphics if @character_name != @character.character_name || @tile_id != @character.tile_id

  return unless update_position

  update_pattern if @tile_id == 0

  self.bush_depth = @character.bush_depth
  self.opacity = (@character.transparent ? 0 : @character.opacity)

  update_load_animation if @character.animation_id != 0
  update_bush_depth if @bush_depth > 0
  update_shadow if @shadow
end

#update_bush_depth

Update the bush depth effect



163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03200 Sprite_Character.rb', line 163

def update_bush_depth
  bsp = @bush_depth_sprite
  bsp.z = z
  bsp.set_position(x, y)
  bsp.zoom = zoom_x
  bsp.bitmap = bitmap if bsp.bitmap != bitmap
  rc = bsp.src_rect
  h = @height
  bd = @bush_depth / 2
  (rc2 = src_rect).height = h - bd
  bsp.set_origin(ox, bd)
  rc.set(rc2.x, rc2.y + rc2.height, rc2.width, bd)
end

#update_graphics

Update the graphics of the Sprite_Character



85
86
87
88
89
90
91
92
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03200 Sprite_Character.rb', line 85

def update_graphics
  @tile_id = @character.tile_id
  @character_name = @character.character_name
  self.visible = !@character_name.empty? || @tile_id > 0
  # Update graphics depending on if it's a tile or a sprite
  @tile_id >= 384 ? update_tile_graphic : update_sprite_graphic
  update_reflection_graphics
end

#update_load_animation

Load the animation when there's one on the character



154
155
156
157
158
159
160
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03200 Sprite_Character.rb', line 154

def update_load_animation
  $data_animations ||= load_data('Data/Animations.rxdata')
  Sprite_Character.fix_rmxp_animations
  animation = $data_animations[@character.animation_id]
  animation(animation, true)
  @character.animation_id = 0
end

#update_pattern

Update the pattern animation



138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03200 Sprite_Character.rb', line 138

def update_pattern
  pattern = @character.pattern
  if @pattern != pattern
    src_rect.x = pattern * @cw
    @pattern = pattern
    @reflection&.src_rect&.x = src_rect.x
  end
  direction = @character.direction
  if @direction != direction
    src_rect.y = (direction - 2) / 2 * @ch
    @direction = direction
    @reflection&.src_rect&.y = src_rect.y
  end
end

#update_positionBoolean

Update the position of the Sprite_Character on the screen

Returns:

  • (Boolean)

    if the update can continue after the call of this function or not



130
131
132
133
134
135
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03200 Sprite_Character.rb', line 130

def update_position
  set_position(@character.screen_x * @tile_zoom, @character.screen_y * @tile_zoom)
  @reflection&.set_position(x, y + ((@character.z - 1) * 32 * @tile_zoom).floor)
  self.z = @character.screen_z(@ch) + @add_z
  return true
end

#update_reflection_graphics

Update the reflection graphics



244
245
246
247
248
249
250
251
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03200 Sprite_Character.rb', line 244

def update_reflection_graphics
  return unless @reflection

  @reflection.bitmap = bitmap
  @reflection.set_origin(ox, oy)
  @reflection.zoom = zoom_x
  @reflection.src_rect = src_rect
end

#update_shadow

Update the shadow



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03200 Sprite_Character.rb', line 206

def update_shadow
  @shadow.opacity = opacity
  @shadow.x = @character.shadow_screen_x * @tile_zoom
  @shadow.y = @character.shadow_screen_y * @tile_zoom
  @shadow.z = z - 1
  @shadow.visible = (!@character.jumping? || REALISTIC_SHADOW) && !@character.shadow_disabled && @character.activated?

  if REALISTIC_SHADOW
    character_offset_y_on_tiles = (@character.shadow_screen_y - @character.screen_y - 2) / 32
    if character_offset_y_on_tiles < 4
      @shadow.zoom_x = SPRITE_ZOOM - 0.25 * character_offset_y_on_tiles
      @shadow.zoom_y = SPRITE_ZOOM - 0.25 * character_offset_y_on_tiles
    else
      @shadow.zoom_x = 0
      @shadow.zoom_y = 0
    end
  end
end

#update_sprite_graphic

Update the sprite graphics



95
96
97
98
99
100
101
102
103
104
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03200 Sprite_Character.rb', line 95

def update_sprite_graphic
  self.bitmap = RPG::Cache.character(@character_name, 0)
  @cw = bitmap.width / 4
  @height = @ch = bitmap.height / 4
  set_origin(@cw / 2, @ch)
  self.zoom = SPRITE_ZOOM
  src_rect.set(@character.pattern * @cw, (@character.direction - 2) / 2 * @ch, @cw, @ch)
  @pattern = @character.pattern
  @direction = @character.direction
end

#update_tile_graphic

Update the tile graphic of the sprite



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03200 Sprite_Character.rb', line 107

def update_tile_graphic
  map_data = Yuki::MapLinker.map_datas
  if !map_data || map_data.empty?
    self.bitmap = RPG::Cache.tileset($game_map.tileset_name)
    tile_id = @tile_id - 384
    tlsy = tile_id / 8 * 32
    max_size = 4096 # Graphics::MAX_TEXTURE_SIZE
    src_rect.set((tile_id % 8 + tlsy / max_size * 8) * 32, tlsy % max_size, 32, @height = 32)
  else
    x = @character.x
    y = @character.y
    # @type [Yuki::Tilemap::MapData]
    event_map = map_data.find { |map| map.x_range.include?(x) && map.y_range.include?(y) } || map_data.first
    event_map.assign_tile_to_sprite(self, @tile_id)
    @height = 32
  end
  self.zoom = TILE_ZOOM
  set_origin(16, 32)
  @ch = 32
end