Advertisement
Zeriab

[RGSS3]Float event sprite (crude)

Apr 8th, 2015
488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.35 KB | None | 0 0
  1. #------------------------------------------------------------------------------
  2. # * License :
  3. #
  4. # Copyright (C) 2015   Zeriab
  5. #
  6. # This software is provided 'as-is', without any express or implied warranty.
  7. # In no event will the authors be held liable for any damages arising from
  8. # the use of this software.
  9. # Permission is granted to anyone to use this software for any purpose,
  10. # including commercial applications, and to alter it and redistribute it
  11. # freely, subject to the following restrictions:
  12. #
  13. # 1. The origin of this software must not be misrepresented; you must not
  14. #    claim that you wrote the original software. If you use this software
  15. #    in a product, an acknowledgment in the product documentation would
  16. #    be appreciated but is not required.
  17. # 2. Altered source versions must be plainly marked as such, and must not
  18. #    be misrepresented as being the original software.
  19. # 3. This notice may not be removed or altered from any source distribution.
  20. #
  21.  
  22. def float_event_to(event_id, x, y)
  23.   event = $game_map.events[event_id]
  24.   event.float_to(x, y)
  25. end
  26.  
  27. def float_event(event_id, x, y)
  28.   event = $game_map.events[event_id]
  29.   absolut_x = event.x + x
  30.   absolut_y = event.y + y
  31.   event.float_to(absolut_x, absolut_y)
  32. end
  33.  
  34. class Game_Event < Game_Character
  35.   def float_to(x, y)
  36.     @x_dist = (x - @x).abs.to_f
  37.     @y_dist = (y - @y).abs.to_f
  38.     @x = x % $game_map.width
  39.     @y = y % $game_map.height
  40.     @floating = true
  41.   end
  42.  
  43.   ##
  44.   # Update While Moving
  45.   #
  46.   def update_move
  47.     distance = distance_per_frame
  48.     # During float the distance travelled may be different between the axis
  49.     if @floating && (@x_dist + @y_dist > 0)
  50.       @x_dist ||= 1
  51.       @y_dist ||= 1
  52.       total_distance = @x_dist + @y_dist
  53.       x_distance = ((distance * @x_dist) / total_distance)
  54.       y_distance = ((distance * @y_dist) / total_distance)
  55.     else
  56.       x_distance = distance
  57.       y_distance = distance
  58.     end
  59.     # Coordinate dependent distance
  60.     @real_x = [@real_x - x_distance, @x].max if @x < @real_x
  61.     @real_x = [@real_x + x_distance, @x].min if @x > @real_x
  62.     @real_y = [@real_y - y_distance, @y].max if @y < @real_y
  63.     @real_y = [@real_y + y_distance, @y].min if @y > @real_y
  64.     update_bush_depth unless moving?
  65.     # Remove float status
  66.     if @floating && !moving?
  67.       @floating = false
  68.     end
  69.   end
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement