Advertisement
soulrpg

Event offset v2.0

Oct 3rd, 2020
1,532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.95 KB | None | 0 0
  1. #===============================================================
  2. # ● [VX Snippet] ◦ Sprite Mover ◦ □
  3. # * Move sprite in pixel to get right location~ *
  4. #--------------------------------------------------------------
  5. # ◦ by Woratana [woratana@hotmail.com]
  6. # ◦ Thaiware RPG Maker Community
  7. # ◦ Released on: 02/06/2008
  8. # ◦ Version: 1.0
  9. #--------------------------------------------------------------
  10.  
  11. #==================================================================
  12. # ** HOW TO USE **
  13. #-----------------------------------------------------------------
  14. # * In the event page that you want to move sprite, add comment:
  15. #  MOVE x_plus, y_plus
  16. # ** x_plus: how many pixel you want to move sprite horizontally
  17. # (- number: move left | + number: move right)
  18. # ** y_plus: how many pixel you want to move sprite vertically
  19. # (- number: move up | + number: move down)
  20.  
  21. # * For example, add comment:
  22. #  MOVE 0, -20
  23. # ** to move sprite up 20 pixel~
  24. #==================================================================
  25.  
  26.  
  27. class Game_Event < Game_Character
  28.   attr_accessor :spr_move
  29.   attr_accessor :event_mov_offset
  30.   attr_accessor :event_mov_current_offset
  31.   alias wora_mover_gameve_setup initialize
  32.  
  33.   def initialize(*args)
  34.         @event_mov_offset = []
  35.     wora_mover_gameve_setup(*args)
  36.     for i in 0...self.event.pages.size
  37.       tmp_offset = comment_in_list?('MOVE', self.event.pages[i].list)
  38.       if tmp_offset
  39.         tmp_offset.sub!('MOVE','').gsub!(/\s+/){''}
  40.         tmp_offset = tmp_offset.split(',')
  41.         tmp_offset.each_index {|i| tmp_offset[i] = tmp_offset[i].to_i }
  42.         @event_mov_offset.push(tmp_offset)
  43.       else
  44.         @event_mov_offset.push([0, 0])
  45.       end
  46.     end
  47.   end
  48.  
  49.   def comment_in_list?(comment, list)
  50.     if !list.nil?
  51.       for i in 0...list.size - 1
  52.                 next if list[i].code != 108
  53.                 if list[i].parameters[0].include?(comment)
  54.                   return list[i].parameters[0]
  55.                 end
  56.           end
  57.       return false
  58.     else
  59.       return false
  60.     end
  61.   end
  62.  
  63.   alias soul_update_game_event update
  64.   def update
  65.     soul_update_game_event
  66.     # pages to zwykła tablica, więc chyba trzeba po prostu porównywać czy
  67.     # jest tym samym elementem (event serio nie przechowuje nigdzie ID aktualnie
  68.     # wybranej strony XD?)
  69.     for i in 0...self.event.pages.size
  70.       if @list === self.event.pages[i].list
  71.         @event_mov_current_offset = @event_mov_offset[i]
  72.         break
  73.       end
  74.     end
  75.   end
  76. end
  77.  
  78. class Sprite_Character < Sprite_Base
  79.   alias wora_mover_sprcha_upd update
  80.  
  81.   def update
  82.         wora_mover_sprcha_upd
  83.     if @character.is_a?(Game_Event) and !@character.event_mov_current_offset.nil?
  84.         print("Offset: ", @character.event_mov_current_offset[0], " " , @character.event_mov_current_offset[1], "\n")
  85.         self.x = @character.screen_x + @character.event_mov_current_offset[0]
  86.         self.y = @character.screen_y + @character.event_mov_current_offset[1]
  87.     end
  88.   end
  89. end
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement