Class: RPG::Sprite
- Inherits:
-
Sprite
- Object
- LiteRGSS::Disposable
- LiteRGSS::Drawable
- LiteRGSS::Sprite
- LiteRGSS::ShaderedSprite
- Sprite
- RPG::Sprite
- Defined in:
- scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb,
scripts/01600 Alpha 25 Battle Engine/99999 Pokemon_Script_Project/00100 RPG__Sprite.rb
Direct Known Subclasses
Constant Summary collapse
- SHADER =
<<~EOSHADER uniform sampler2D texture; uniform float hue; // Source: https://gist.github.com/mairod/a75e7b44f68110e1576d77419d608786 vec3 hueShift( vec3 color, float hueAdjust ) { const vec3 kRGBToYPrime = vec3 (0.299, 0.587, 0.114); const vec3 kRGBToI = vec3 (0.596, -0.275, -0.321); const vec3 kRGBToQ = vec3 (0.212, -0.523, 0.311); const vec3 kYIQToR = vec3 (1.0, 0.956, 0.621); const vec3 kYIQToG = vec3 (1.0, -0.272, -0.647); const vec3 kYIQToB = vec3 (1.0, -1.107, 1.704); float YPrime = dot (color, kRGBToYPrime); float I = dot (color, kRGBToI); float Q = dot (color, kRGBToQ); float hue = atan (Q, I); float chroma = sqrt (I * I + Q * Q); hue += hueAdjust; Q = chroma * sin (hue); I = chroma * cos (hue); vec3 yIQ = vec3 (YPrime, I, Q); return vec3( dot (yIQ, kYIQToR), dot (yIQ, kYIQToG), dot (yIQ, kYIQToB) ); } void main() { vec4 color = texture2D(texture, gl_TexCoord[0].xy); color.rgb = hueShift(color.rgb, hue); gl_FragColor = color * gl_Color; } EOSHADER
- TARGET_SHADER =
<<~EOSHADER uniform vec4 color; uniform sampler2D texture; void main() { vec4 frag = texture2D(texture, gl_TexCoord[0].xy); // Tone&Color process frag.rgb = mix(frag.rgb, color.rgb, color.a); frag.a *= gl_Color.a; // Result gl_FragColor = frag; } EOSHADER
- @@_animations =
[]
- @@_reference_count =
{}
Instance Attribute Summary collapse
-
#blend_type
Returns the value of attribute blend_type.
-
#bush_depth
Returns the value of attribute bush_depth.
-
#color
Returns the value of attribute color.
-
#tone
Returns the value of attribute tone.
Attributes inherited from LiteRGSS::ShaderedSprite
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
Instance Method Summary collapse
- #animation(animation, hit, reverse = false)
- #animation_process_timing(timing, hit)
- #animation_set_sprites(sprites, cell_data, position)
- #appear
- #blink? ⇒ Boolean
- #blink_off
- #blink_on
- #collapse
- #damage(value, critical)
- #dispose
- #dispose_animation
- #dispose_damage
- #dispose_loop_animation
- #effect? ⇒ Boolean
- #escape
- #flash(color, duration)
- #handle_flash
-
#initialize(viewport = nil) ⇒ Sprite
constructor
A new instance of Sprite.
- #loop_animation(animation)
- #register_position
- #reset_position
- #update
- #update_animation
- #update_loop_animation
- #whiten
- #x=(x)
- #y=(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
Constructor Details
#initialize(viewport = nil) ⇒ Sprite
Returns a new instance of Sprite.
201 202 203 204 205 206 207 208 209 210 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 201 def initialize( = nil) super() @_whiten_duration = 0 @_appear_duration = 0 @_escape_duration = 0 @_collapse_duration = 0 @_damage_duration = 0 @_animation_duration = 0 @_blink = false end |
Instance Attribute Details
#blend_type
Returns the value of attribute blend_type.
187 188 189 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 187 def blend_type @blend_type end |
#bush_depth
Returns the value of attribute bush_depth.
188 189 190 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 188 def bush_depth @bush_depth end |
#color
Returns the value of attribute color.
190 191 192 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 190 def color @color end |
#tone
Returns the value of attribute tone.
189 190 191 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 189 def tone @tone end |
Instance Method Details
#animation(animation, hit, reverse = false)
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 293 def animation(animation, hit) dispose_animation @_animation = animation return if @_animation == nil @_animation_hit = hit @_animation_duration = @_animation.frame_max animation_name = @_animation.animation_name animation_hue = @_animation.animation_hue bitmap = RPG::Cache.animation(animation_name, animation_hue) if @@_reference_count.include?(bitmap) @@_reference_count[bitmap] += 1 else @@_reference_count[bitmap] = 1 end @_animation_sprites = [] if @_animation.position != 3 or not @@_animations.include?(animation) for i in 0..15 sprite = ::Sprite.new(self.) sprite.bitmap = bitmap sprite.visible = false @_animation_sprites.push(sprite) end unless @@_animations.include?(animation) @@_animations.push(animation) end end update_animation end |
#animation_process_timing(timing, hit)
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 525 def animation_process_timing(timing, hit) if (timing.condition == 0) or (timing.condition == 1 and hit == true) or (timing.condition == 2 and hit == false) if timing.se.name != "" se = timing.se Audio.se_play("Audio/SE/" + se.name, se.volume, se.pitch) end case timing.flash_scope when 1 self.flash(timing.flash_color, timing.flash_duration * 2) when 2 if self. != nil self..flash(timing.flash_color, timing.flash_duration * 2) end when 3 self.flash(nil, timing.flash_duration * 2) end end end |
#animation_set_sprites(sprites, cell_data, position)
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 488 def animation_set_sprites(sprites, cell_data, position) for i in 0..15 sprite = sprites[i] pattern = cell_data[i, 0] if sprite == nil or pattern == nil or pattern == -1 sprite.visible = false if sprite != nil next end sprite.visible = true sprite.src_rect.set(pattern % 5 * 192, pattern / 5 * 192, 192, 192) if position == 3 if self. != nil sprite.x = self..rect.width / 2 sprite.y = self..rect.height - 160 else sprite.x = 320 sprite.y = 240 end else sprite.x = self.x - self.ox + self.src_rect.width / 2 sprite.y = self.y - self.oy + self.src_rect.height / 2 sprite.y -= self.src_rect.height / 4 if position == 0 sprite.y += self.src_rect.height / 4 if position == 2 end sprite.x += cell_data[i, 1] sprite.y += cell_data[i, 2] sprite.z = 2000 sprite.ox = 96 sprite.oy = 96 sprite.zoom_x = cell_data[i, 3] / 100.0 sprite.zoom_y = cell_data[i, 3] / 100.0 sprite.angle = cell_data[i, 4] sprite.mirror = (cell_data[i, 5] == 1) sprite.opacity = cell_data[i, 6] * self.opacity / 255.0 sprite.blend_type = cell_data[i, 7] end end |
#appear
226 227 228 229 230 231 232 233 234 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 226 def appear self.blend_type = 0 self.color.set(0, 0, 0, 0) self.opacity = 0 @_appear_duration = 16 @_whiten_duration = 0 @_escape_duration = 0 @_collapse_duration = 0 end |
#blink? ⇒ Boolean
396 397 398 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 396 def blink? @_blink end |
#blink_off
390 391 392 393 394 395 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 390 def blink_off if @_blink @_blink = false self.color.set(0, 0, 0, 0) end end |
#blink_on
384 385 386 387 388 389 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 384 def blink_on unless @_blink @_blink = true @_blink_count = 0 end end |
#collapse
244 245 246 247 248 249 250 251 252 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 244 def collapse self.blend_type = 1 self.color.set(255, 64, 64, 255) self.opacity = 255 @_collapse_duration = 48 @_whiten_duration = 0 @_appear_duration = 0 @_escape_duration = 0 end |
#damage(value, critical)
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 253 def damage(value, critical) dispose_damage if value.is_a?(Numeric) damage_string = value.abs.to_s else damage_string = value.to_s end bitmap = Texture.new(160, 48) bitmap.font.name = "Arial Black" bitmap.font.size = 32 bitmap.font.color.set(0, 0, 0) bitmap.draw_text(-1, 12-1, 160, 36, damage_string, 1) bitmap.draw_text(+1, 12-1, 160, 36, damage_string, 1) bitmap.draw_text(-1, 12+1, 160, 36, damage_string, 1) bitmap.draw_text(+1, 12+1, 160, 36, damage_string, 1) if value.is_a?(Numeric) and value < 0 bitmap.font.color.set(176, 255, 144) else bitmap.font.color.set(255, 255, 255) end bitmap.draw_text(0, 12, 160, 36, damage_string, 1) if critical bitmap.font.size = 20 bitmap.font.color.set(0, 0, 0) bitmap.draw_text(-1, -1, 160, 20, "CRITICAL", 1) bitmap.draw_text(+1, -1, 160, 20, "CRITICAL", 1) bitmap.draw_text(-1, +1, 160, 20, "CRITICAL", 1) bitmap.draw_text(+1, +1, 160, 20, "CRITICAL", 1) bitmap.font.color.set(255, 255, 255) bitmap.draw_text(0, 0, 160, 20, "CRITICAL", 1) end @_damage_sprite = ::Sprite.new(self.) @_damage_sprite.bitmap = bitmap @_damage_sprite.ox = 80 @_damage_sprite.oy = 20 @_damage_sprite.x = self.x @_damage_sprite.y = self.y - self.oy / 2 @_damage_sprite.z = 3000 @_damage_duration = 40 end |
#dispose
211 212 213 214 215 216 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 211 def dispose dispose_damage dispose_animation dispose_loop_animation super end |
#dispose_animation
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 352 def dispose_animation if @_animation_sprites != nil sprite = @_animation_sprites[0] if sprite != nil @@_reference_count[sprite.bitmap] -= 1 if @@_reference_count[sprite.bitmap] == 0 sprite.bitmap.dispose end end for sprite in @_animation_sprites sprite.dispose end @_animation_sprites = nil @_animation = nil end end |
#dispose_damage
344 345 346 347 348 349 350 351 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 344 def dispose_damage if @_damage_sprite != nil @_damage_sprite.bitmap.dispose @_damage_sprite.dispose @_damage_sprite = nil @_damage_duration = 0 end end |
#dispose_loop_animation
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 368 def dispose_loop_animation if @_loop_animation_sprites != nil sprite = @_loop_animation_sprites[0] if sprite != nil @@_reference_count[sprite.bitmap] -= 1 if @@_reference_count[sprite.bitmap] == 0 sprite.bitmap.dispose end end for sprite in @_loop_animation_sprites sprite.dispose end @_loop_animation_sprites = nil @_loop_animation = nil end end |
#effect? ⇒ Boolean
399 400 401 402 403 404 405 406 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 399 def effect? @_whiten_duration > 0 or @_appear_duration > 0 or @_escape_duration > 0 or @_collapse_duration > 0 or @_damage_duration > 0 or @_animation_duration > 0 end |
#escape
235 236 237 238 239 240 241 242 243 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 235 def escape self.blend_type = 0 self.color.set(0, 0, 0, 0) self.opacity = 255 @_escape_duration = 32 @_whiten_duration = 0 @_appear_duration = 0 @_collapse_duration = 0 end |
#flash(color, duration)
191 192 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 191 def flash(*args) end |
#handle_flash
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'scripts/01600 Alpha 25 Battle Engine/99999 Pokemon_Script_Project/00100 RPG__Sprite.rb', line 218 def handle_flash return if @flash_duration == 0 @flash_duration -= 1 if @flash_color color.set( @flash_color.red, @flash_color.green, @flash_color.blue, @flash_color.alpha * @flash_duration / @flash_total_duration ) else self.visible = @flash_duration <= 0 end end |
#loop_animation(animation)
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 321 def loop_animation(animation) return if animation == @_loop_animation dispose_loop_animation @_loop_animation = animation return if @_loop_animation == nil @_loop_animation_index = 0 animation_name = @_loop_animation.animation_name animation_hue = @_loop_animation.animation_hue bitmap = RPG::Cache.animation(animation_name, animation_hue) if @@_reference_count.include?(bitmap) @@_reference_count[bitmap] += 1 else @@_reference_count[bitmap] = 1 end @_loop_animation_sprites = [] for i in 0..15 sprite = ::Sprite.new(self.) sprite.bitmap = bitmap sprite.visible = false @_loop_animation_sprites.push(sprite) end update_loop_animation end |
#register_position
83 84 85 86 87 88 |
# File 'scripts/01600 Alpha 25 Battle Engine/99999 Pokemon_Script_Project/00100 RPG__Sprite.rb', line 83 def register_position @_registered_x = x @_registered_ox = ox @_registered_y = y @_registered_oy = oy end |
#reset_position
90 91 92 93 94 95 |
# File 'scripts/01600 Alpha 25 Battle Engine/99999 Pokemon_Script_Project/00100 RPG__Sprite.rb', line 90 def reset_position self.x = @_registered_x self.ox = @_registered_ox self.y = @_registered_y self.oy = @_registered_oy end |
#update
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 407 def update super if @_whiten_duration > 0 @_whiten_duration -= 1 self.color.alpha = 128 - (16 - @_whiten_duration) * 10 end if @_appear_duration > 0 @_appear_duration -= 1 self.opacity = (16 - @_appear_duration) * 16 end if @_escape_duration > 0 @_escape_duration -= 1 self.opacity = 256 - (32 - @_escape_duration) * 10 end if @_collapse_duration > 0 @_collapse_duration -= 1 self.opacity = 256 - (48 - @_collapse_duration) * 6 end if @_damage_duration > 0 @_damage_duration -= 1 case @_damage_duration when 38..39 @_damage_sprite.y -= 4 when 36..37 @_damage_sprite.y -= 2 when 34..35 @_damage_sprite.y += 2 when 28..33 @_damage_sprite.y += 4 end @_damage_sprite.opacity = 256 - (12 - @_damage_duration) * 32 if @_damage_duration == 0 dispose_damage end end if @_animation != nil and (Graphics.frame_count % 2 == 0) @_animation_duration -= 1 update_animation end if @_loop_animation != nil and (Graphics.frame_count % 2 == 0) update_loop_animation @_loop_animation_index += 1 @_loop_animation_index %= @_loop_animation.frame_max end if @_blink @_blink_count = (@_blink_count + 1) % 32 if @_blink_count < 16 alpha = (16 - @_blink_count) * 6 else alpha = (@_blink_count - 16) * 6 end self.color.set(255, 255, 255, alpha) end @@_animations.clear end |
#update_animation
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 462 def update_animation if @_animation_duration > 0 frame_index = @_animation.frame_max - @_animation_duration cell_data = @_animation.frames[frame_index].cell_data position = @_animation.position animation_set_sprites(@_animation_sprites, cell_data, position) for timing in @_animation.timings if timing.frame == frame_index animation_process_timing(timing, @_animation_hit) end end else dispose_animation end end |
#update_loop_animation
477 478 479 480 481 482 483 484 485 486 487 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 477 def update_loop_animation frame_index = @_loop_animation_index cell_data = @_loop_animation.frames[frame_index].cell_data position = @_loop_animation.position animation_set_sprites(@_loop_animation_sprites, cell_data, position) for timing in @_loop_animation.timings if timing.frame == frame_index animation_process_timing(timing, true) end end end |
#whiten
217 218 219 220 221 222 223 224 225 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 217 def whiten self.blend_type = 0 self.color.set(255, 255, 255, 128) self.opacity = 255 @_whiten_duration = 16 @_appear_duration = 0 @_escape_duration = 0 @_collapse_duration = 0 end |
#x=(x)
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 545 def x=(x) sx = x - self.x if sx != 0 if @_animation_sprites != nil for i in 0..15 @_animation_sprites[i].x += sx end end if @_loop_animation_sprites != nil for i in 0..15 @_loop_animation_sprites[i].x += sx end end end super end |
#y=(y)
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/99999 RMXP_DATA.rb', line 561 def y=(y) sy = y - self.y if sy != 0 if @_animation_sprites != nil for i in 0..15 @_animation_sprites[i].y += sy end end if @_loop_animation_sprites != nil for i in 0..15 @_loop_animation_sprites[i].y += sy end end end super end |