dsiver144

Dark's Free Jumping System

Mar 15th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.55 KB | None | 0 0
  1. #===============================================================================
  2. #                     ╔══════════════════════════════════╗
  3. #                     ║ ▼ Dark's Free Jumping System     ║  
  4. #                     ║ ▼ Author: Nhat Nguyen (Dark Sky) ║
  5. #                     ║ ▼ Release Date: March 16th 2016  ║
  6. #                     ║ ▼ Forum: TaoTroChoi.com          ║
  7. #                     ╚══════════════════════════════════╝
  8. #-------------------------------------------------------------------------------
  9. #                           Version 1.0: Release!
  10. #-------------------------------------------------------------------------------
  11. #                            Free to everyone!
  12. #-------------------------------------------------------------------------------
  13. # Yêu cầu: None
  14. #-------------------------------------------------------------------------------
  15. # Chức năng:
  16. #      + Có thể điều chỉnh cự ly nhảy của nhân vật.
  17. #      + Không thể nhảy vào các khu vực không cho phép cũng như ra khỏi map.
  18. #-------------------------------------------------------------------------------
  19. # Script call: None
  20. #===============================================================================
  21. module DarkSky_Jumping
  22.   NORMAL_JUMP_DISTANNCE = 3 # Số ô nhảy qua được
  23.   DASH_JUMP_DISTANNCE   = 3 # Số ô nhảy qua được khi chạy
  24.   JUMP_KEY              = :Z # Phím D.
  25. end
  26. class Spriteset_Map
  27.   include DarkSky_Jumping
  28.   #-----------------------------------------------------------------------------
  29.   # * Aliasing methods
  30.   #-----------------------------------------------------------------------------
  31.   alias :darksky_spriteset_map_abs_update :update
  32.   alias :darksky_spriteset_map_abs_init :initialize
  33.   #-----------------------------------------------------------------------------
  34.   # * Initialize
  35.   #-----------------------------------------------------------------------------
  36.   def initialize
  37.     darksky_spriteset_map_abs_init()
  38.     create_player_shadow
  39.     @curr_y = $game_player.screen_y
  40.   end
  41.   #-----------------------------------------------------------------------------
  42.   # * Create Shadow
  43.   #-----------------------------------------------------------------------------
  44.   def create_player_shadow
  45.     @p_shadow = Sprite.new()
  46.     @p_shadow.bitmap = Cache.system("Shadow")
  47.     @p_shadow.visible = false
  48.     @p_shadow.ox += 16
  49.     @p_shadow.oy += 10
  50.   end
  51.   #-----------------------------------------------------------------------------
  52.   # * Update Shadow
  53.   #-----------------------------------------------------------------------------
  54.   def update_player_jump_shadow
  55.     @p_shadow.visible = $game_player.jumping?
  56.     @p_shadow.x = $game_player.screen_x
  57.     if $game_player.direction == 2 or $game_player.direction == 8
  58.       @p_shadow.y = $game_player.screen_y
  59.     end
  60.   end
  61.   #-----------------------------------------------------------------------------
  62.   # * Check Event Collison
  63.   #-----------------------------------------------------------------------------
  64.   def check_event_collison(x,y,d)
  65.     return false if !$game_player.map_passable?(x,y,d)
  66.     events = $game_map.events.values
  67.     events.each do |event|
  68.       if event.x == x && event.y == y
  69.         return false
  70.       end
  71.     end
  72.     return true
  73.   end
  74.   #-----------------------------------------------------------------------------
  75.   # * Player Jump
  76.   #-----------------------------------------------------------------------------
  77.   def player_jump(xp,yp,d)
  78.     c_x = xp
  79.     c_y = yp
  80.     case d
  81.       when 4,6
  82.         while c_x.abs > 0
  83.           if $game_player.map_passable?($game_player.x+c_x,$game_player.y+c_y,d) && check_event_collison($game_player.x+c_x,$game_player.y+c_y,d)
  84.             j_se = RPG::SE.new("Jump1")
  85.             j_se.play
  86.             @p_shadow.y = $game_player.screen_y
  87.             $game_player.jump(c_x,c_y)
  88.             c_x = 0
  89.             return
  90.           else
  91.             c_x -= 1 if xp > 0
  92.             c_x += 1 if xp < 0
  93.           end
  94.         end
  95.       when 2,8
  96.         while c_y.abs > 0
  97.           if $game_player.map_passable?($game_player.x+c_x,$game_player.y+c_y,d) && check_event_collison($game_player.x+c_x,$game_player.y+c_y,d)
  98.             j_se = RPG::SE.new("Jump1")
  99.             j_se.play
  100.             $game_player.jump(c_x,c_y)
  101.             c_y = 0
  102.             return
  103.           else
  104.             c_y -= 1 if yp > 0
  105.             c_y += 1 if yp < 0
  106.           end
  107.         end
  108.       end
  109.       j_se = RPG::SE.new("Jump1")
  110.       j_se.play
  111.       $game_player.jump(0,0)
  112.   end
  113.   #-----------------------------------------------------------------------------
  114.   # * Update
  115.   #-----------------------------------------------------------------------------
  116.   def update
  117.     darksky_spriteset_map_abs_update()
  118.     update_player_jump_shadow if @p_shadow
  119.     if $game_player.dash? && $game_player.moving?
  120.       @jump_speed = DASH_JUMP_DISTANNCE
  121.     else
  122.       @jump_speed = NORMAL_JUMP_DISTANNCE
  123.     end
  124.     if Input.trigger?(JUMP_KEY) && !$game_player.jumping?
  125.       case $game_player.direction
  126.         when 2
  127.           player_jump(0,@jump_speed,$game_player.direction)
  128.         when 4
  129.           player_jump(-@jump_speed,0,$game_player.direction)
  130.         when 6
  131.           player_jump(@jump_speed,0,$game_player.direction)
  132.         when 8
  133.           player_jump(0,-@jump_speed,$game_player.direction)
  134.       end
  135.     end
  136.   end
  137. end
Add Comment
Please, Sign In to add comment