NamKazt's Flatform Move Systems : New Version 1.4.4

NamKazt's Platform Move Systems Version: 1.4.4
By: NamKazt (Me)
(" i'm Vietnamese and my english not good, sr all about that :shades: ")

Introduction

This script used to make a platform move 2 direction, e.g : Maplestory,patapon,...
This not like XRXS's Script.. this better then... :box:

Features
    Flatform Movement ( suck as Maplestory, Patapon ,...)
    Pixel per pixel movement

Update in 1.4.4
  1. #      +, Add Ladder ^^~
  2. #         you can add [Ladder] into name of event and set it through
  3. #         e.g : EV001[W100][H200][Ladder]
  4. #      +, Add Fly obj like a bird ^^~
  5. #         you can add [Fly] into name of event
  6. #         e.g : EV001[W100][H200][Fly]
  7. #         only event is fly obj, in move random mode is can move 8 directionr
  8. #      +, remove game crash if event dont have width or height or ...
  9.  
Expand to see the code.


Update in 1.4.3
  1. #      +, Add height of event
  2. #         e.g : EV001[W380][H200]
  3. #         for obj and for a gate ^^~
  4. #      +, fixbug event blow another event or player
Expand to see the code.


Update in 1.4.2
  1. #      +, Add width of event
  2. #          like : Event id 1 have name is EV001 and width of it's 380
  3. #                 you must named it to EV001[W380]
  4. #                 without it, game will crash!
  5. #         -> it'll improve smooth when you touch events with other size
  6. #         -> suck as a chest have width is 35, a dragon have width is 600
  7. #      +, Improve smooth by use real_x ( old is using x )
  8. #      +, Add block player if event not through ( problem is distance too long )
  9. #      +, fix bug distance too long
  10.  
Expand to see the code.


Future
    Add Action suck as throw or push event

Screenshots (in version 1.4.4)

Image

Demo All Version



Script

  1. #==============================================================================
  2. # ** NamKazt's Platform Move Systems
  3. #------------------------------------------------------------------------------
  4. #  Version : 1.4.4
  5. #   * Features :
  6. #     +, Flatform Movement ( suck as Maplestory, Patapon ,...)
  7. #     +, Pixel per pixel movement
  8. #------------------------------------------------------------------------------
  9. #  Future :
  10. #     +, Add action suck as throw or push event
  11. #------------------------------------------------------------------------------
  12. #  Update 1.4.4 :
  13. #      +, Add Ladder ^^~
  14. #         you can add [Ladder] into name of event and set it through
  15. #         e.g : EV001[W100][H200][Ladder]
  16. #      +, Add Fly obj like a bird ^^~
  17. #         you can add [Fly] into name of event
  18. #         e.g : EV001[W100][H200][Fly]
  19. #         only event is fly obj, in move random mode is can move 8 direction
  20. #------------------------------------------------------------------------------
  21. #  Update 1.4.3 :
  22. #      +, Add height of event
  23. #         e.g : EV001[W380][H200]
  24. #         for obj and for a gate ^^~
  25. #      +, fixbug event blow another event or player
  26. #------------------------------------------------------------------------------
  27. #  Update 1.4.2 :
  28. #      +, Add width of event
  29. #          like : Event id 1 have name is EV001 and width of it's 380
  30. #                 you must named it to EV001[W380]
  31. #                 without it, game will crash!
  32. #         -> it'll improve smooth when you touch events with other size
  33. #         -> suck as a chest have width is 35, a dragon have width is 600
  34. #      +, Improve smooth by use real_x ( old is using x )
  35. #      +, Fixbug distance too long
  36. #------------------------------------------------------------------------------
  37. #  Update 1.4.1 :
  38. #      +, Add block player if event not through
  39. #------------------------------------------------------------------------------
  40. #  Thanks :
  41. #   HikiMoKi for the idea and base
  42. #   I just was developing the idea for XP
  43. #==============================================================================
  44.  
  45. class Game_Character
  46.   attr_reader   :xv                       # Trục x
  47.   attr_reader   :yv                       # Trục y
  48.   attr_accessor :gravity                  # Nặng
  49.   #--------------------------------------------------------------------------
  50.   # * Object Initialization
  51.   #--------------------------------------------------------------------------
  52.   alias pms_initialize initialize
  53.   def initialize
  54.     pms_initialize
  55.     @xv = 0
  56.     @yv = 0
  57.     @move_count = 0
  58.     @gravity = 5
  59.     @jump_flag = false
  60.   end
  61.   #--------------------------------------------------------------------------
  62.   # * Determine if Moving
  63.   #--------------------------------------------------------------------------
  64.   def moving?
  65.     # If logical coordinates differ from real coordinates,
  66.     # movement is occurring.
  67.     return @move_count > 0
  68.   end
  69.   #--------------------------------------------------------------------------
  70.   # * Determine if player on ladder
  71.   #--------------------------------------------------------------------------
  72.   def ladder?
  73.     # If logical coordinates differ from real coordinates,
  74.     # movement is occurring.
  75.     if self == $game_player and check_event_ladder_here([0])
  76.       return true
  77.     end
  78.     return false
  79.   end
  80.   #--------------------------------------------------------------------------
  81.   # * Check if on ladder
  82.   #--------------------------------------------------------------------------
  83.   def check_event_ladder_here(triggers)
  84.     # All event loops
  85.     for event in $game_map.events.values
  86.       @size = /\d+/.match(/\[W\d+\]/.match(event.get_name)[0])[0].to_i / 2 if event.get_name.include? "[W"
  87.       if event.get_name.include? "[Ladder]"
  88.         # If event coordinates and triggers are consistent
  89.         if self.real_x >= (event.real_x - @size) and self.real_x <= (event.real_x + @size) and self.real_y > event.real_y - @height - 30 and self.real_y <= event.real_y + 5 and triggers.include?(event.trigger)
  90.             return true
  91.         end
  92.       end
  93.     end
  94.     return false
  95.   end
  96.   #--------------------------------------------------------------------------
  97.   # * Determine if event is fly obj
  98.   #--------------------------------------------------------------------------
  99.   def isfly?
  100.     # If logical coordinates differ from real coordinates,
  101.     # movement is occurring.
  102.     if self != $game_player and self.get_name.include? "[Fly]"
  103.       return true
  104.     end
  105.     return false
  106.   end
  107.   #--------------------------------------------------------------------------
  108.   # * Tocch
  109.   #     mode :
  110.   #     * 0 : Left or Right
  111.   #     * 1 : Up or Down
  112.   #--------------------------------------------------------------------------
  113.   def touch?(mode = 0)
  114.     if mode == 0
  115.       if @xv > 0
  116.         check_event_trigger_touch(@x+1, @y)
  117.       else
  118.         check_event_trigger_touch(@x-1, @y)
  119.       end
  120.     else
  121.       if @xv > 0
  122.         check_event_trigger_touch(@x, @y+1)
  123.       else
  124.         check_event_trigger_touch(@x, @y-1)
  125.       end
  126.     end
  127.   end
  128.  
  129.   def distance_x_from_player
  130.     sx = @x - $game_player.x
  131.     return sx
  132.   end
  133.  
  134.   def passable?(mode = 0)
  135.    
  136.     if self != $game_player and self.get_name.include? "[Ladder]"
  137.       return false
  138.     end
  139.    
  140.     left_x = @real_x >> 7    # 4 << 3
  141.     right_x = @real_x >> 7  # 28 << 3
  142.     up_y = @real_y>> 7      # 2 << 3
  143.     down_y = @real_y + 40>> 7   # 28 << 3
  144.       # Get new coordinates
  145.     if self != $game_player
  146.       if mode == 0
  147.         if @xv > 0
  148.           return false unless $game_map.passable?(right_x, up_y,6)
  149.           return false unless $game_map.passable?(right_x, down_y,6)
  150.         else
  151.           return false unless $game_map.passable?(left_x, up_y,4)
  152.           return false unless $game_map.passable?(left_x, down_y,4)
  153.         end
  154.       else
  155.         if @yv > 0
  156.           return false unless $game_map.passable?(left_x, down_y,2)
  157.           return false unless $game_map.passable?(right_x, down_y,2)
  158.         else
  159.           return false unless $game_map.passable?(left_x, up_y,8)
  160.           return false unless $game_map.passable?(right_x, up_y,8)
  161.         end
  162.       end
  163.     else
  164.       if ladder? && Input.press?(Input::DOWN)
  165.         return true
  166.       else
  167.         if mode == 0
  168.         if @xv > 0
  169.           return false unless $game_map.passable?(right_x, up_y,6)
  170.           return false unless $game_map.passable?(right_x, down_y,6)
  171.         else
  172.           return false unless $game_map.passable?(left_x, up_y,4)
  173.           return false unless $game_map.passable?(left_x, down_y,4)
  174.         end
  175.       else
  176.         if @yv > 0
  177.           return false unless $game_map.passable?(left_x, down_y,2)
  178.           return false unless $game_map.passable?(right_x, down_y,2)
  179.         else
  180.           return false unless $game_map.passable?(left_x, up_y,8)
  181.           return false unless $game_map.passable?(right_x, up_y,8)
  182.         end
  183.       end
  184.       end
  185.     end
  186.    
  187.     if @through
  188.       return true
  189.     end
  190.    
  191.    
  192.     # Loop all events
  193.     for event in $game_map.events.values
  194.        new_x = (event.direction == 6 ? ((@real_x + 32 >> 7) + 1) :  event.direction == 4 ? ((@real_x + 110 >> 7) + 1) : 0)
  195.        new_y = (event.direction == 2 ? ((@real_y + 16 >> 7) + 1) :  event.direction == 8 ? ((@real_y + 110 >> 7) + 1) : 0)
  196.       # If event coordinates are consistent with move destination
  197.       if event.x == new_x and event.y == new_y
  198.         #If through is OFF
  199.         unless event.through
  200.           # If self is event
  201.           if self != $game_player
  202.             # impassable
  203.             return false
  204.           end
  205.           # With self as the player and partner graphic as character
  206.           if event.character_name != ""
  207.             # impassable
  208.             return false
  209.           end
  210.         end
  211.       end
  212.      
  213.       if(self != $game_player)
  214.       @width = /\d+/.match(/\[W\d+\]/.match(event.get_name)[0])[0].to_i / 2 if event.get_name.include? "[W"
  215.       @height = /\d+/.match(/\[H\d+\]/.match(event.get_name)[0])[0].to_i if event.get_name.include? "[H"
  216.        
  217.         if self.real_y >= event.real_y - @height and
  218.            self.real_y <= event.real_y + 5 and
  219.            self.real_x >= event.real_x - @width and
  220.            self.real_x <= event.real_x + @width and
  221.            self != event
  222.            
  223.           unless event.through and self.through
  224.             return false
  225.           end
  226.          
  227.         end
  228.       end
  229.       @width = /\d+/.match(/\[W\d+\]/.match(event.get_name)[0])[0].to_i / 2 if event.get_name.include? "[W"
  230.        @height = /\d+/.match(/\[H\d+\]/.match(event.get_name)[0])[0].to_i if event.get_name.include? "[H"
  231.         if $game_player.real_y >= event.real_y - @height and
  232.            $game_player.real_y <= event.real_y + 125 and # height of player
  233.            $game_player.real_x >= event.real_x - @width and
  234.            $game_player.real_x <= event.real_x + @width
  235.              unless event.through
  236.                return false
  237.              end
  238.         end
  239.       end
  240.       new1_x = ($game_player.direction == 6 ? ((@real_x + 32 >> 7) +  1) : $game_player.direction == 4 ? ((@real_x + 110 >> 7) + 1) : 0)
  241.     new1_y = ($game_player.direction == 2 ? ((@real_y + 16 >> 7) +  1) : $game_player.direction == 8 ? ((@real_y + 110 >> 7) + 1) : 0)
  242.    if $game_player.x == new1_x and $game_player.y == new1_y
  243.       # If through is OFF
  244.       unless $game_player.through
  245.         # If your own graphic is the character
  246.         if @character_name != ""
  247.           # impassable
  248.           return false
  249.         end
  250.       end
  251.     end
  252.    
  253.     return true
  254.   end
  255.   #--------------------------------------------------------------------------
  256.   # * Frame Update
  257.   #--------------------------------------------------------------------------
  258.   def update
  259.     update_x
  260.     update_y
  261.     # Branch with jumping, moving, and stopping
  262.     if jumping?
  263.       update_jump
  264.     elsif moving?
  265.       @move_count -= 1
  266.       if @walk_anime
  267.         @anime_count += 1.5
  268.       elsif @step_anime
  269.         @anime_count += 1
  270.       end
  271.     elsif ladder?
  272.       if @walk_anime
  273.         @anime_count += 1.5
  274.       elsif @step_anime
  275.         @anime_count += 1
  276.       end
  277.     else
  278.       update_stop
  279.     end
  280.     # If animation count exceeds maximum value
  281.     # * Maximum value is move speed * 1 taken from basic value 18
  282.     if @anime_count > 18 - @move_speed * 2
  283.       # If stop animation is OFF when stopping
  284.       if not @step_anime and @stop_count > 0
  285.         # Return to original pattern
  286.         @pattern = @original_pattern
  287.       # If stop animation is ON when moving
  288.       else
  289.         # Update pattern
  290.         @pattern = (@pattern + 1) % 4
  291.       end
  292.       # Clear animation count
  293.       @anime_count = 0
  294.     end
  295.     # If waiting
  296.     if @wait_count > 0
  297.       # Reduce wait count
  298.       @wait_count -= 1
  299.       return
  300.     end
  301.     # If move route is forced
  302.     if @move_route_forcing
  303.       # Custom move
  304.       move_type_custom
  305.       return
  306.     end
  307.     # When waiting for event execution or locked
  308.     if @starting or lock?
  309.       # Not moving by self
  310.       return
  311.     end
  312.     # If stop count exceeds a certain value (computed from move frequency)
  313.     if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency)
  314.       # Branch by move type
  315.       case @move_type
  316.       when 1  # Random
  317.         move_type_random
  318.       when 2  # Approach
  319.         move_type_toward_player
  320.       when 3  # Custom
  321.         move_type_custom
  322.       end
  323.     end
  324.   end
  325.   #--------------------------------------------------------------------------
  326.   # ● Update X
  327.   #--------------------------------------------------------------------------
  328.   def update_x
  329.     if !@jump_flag && !moving?
  330.       @xv = 0
  331.       return
  332.     end
  333.       last_x = @real_x
  334.       @real_x += @xv
  335.       @x = @real_x >> 7
  336.       unless passable?(0)
  337.         @real_x = last_x
  338.         @x = @real_x>> 7
  339.         @xv = 0
  340.         touch?(0)
  341.       end
  342.   end
  343.   #--------------------------------------------------------------------------
  344.   # ● Update Y
  345.   #--------------------------------------------------------------------------
  346.   def update_y
  347.     if !ladder?
  348.       if !isfly?
  349.         if  @gravity > 0
  350.           @yv += @gravity
  351.           @yv = 64 if @yv > 64
  352.         elsif !moving?
  353.           @yv = 0
  354.           return
  355.         end
  356.         last_y = @real_y
  357.         @real_y += @yv
  358.         @y = @real_y >> 7
  359.         unless passable?(1)
  360.           @real_y = last_y
  361.           @y = @real_y >> 7
  362.           @jump_flag = false if @yv > 0
  363.           @yv = 0
  364.           touch?(1)
  365.         end
  366.       else
  367.         last_y = @real_y
  368.         @real_y += @yv
  369.         @y = @real_y >> 7
  370.         unless passable?(1)
  371.           @real_y = last_y
  372.           @y = @real_y >> 7
  373.           @jump_flag = false if @yv > 0
  374.           @yv = 0
  375.           touch?(1)
  376.         end
  377.       end
  378.     else
  379.       if Input.press?(Input::UP)
  380.         #last_y = @real_y
  381.         @real_y -= 5;
  382.         @y = @real_y >> 7
  383.       elsif Input.press?(Input::DOWN)
  384.         turn_down
  385.         #last_y = @real_y
  386.         @real_y += 5;
  387.         @y = @real_y >> 7
  388.       else
  389.         if  @gravity > 0
  390.           @yv += @gravity
  391.           @yv = 64 if @yv > 64
  392.         elsif !moving?
  393.           @yv = 0
  394.           return
  395.         end
  396.         last_y = @real_y
  397.         @real_y += @yv
  398.         @y = @real_y >> 7
  399.         unless passable?(1)
  400.           @real_y = last_y
  401.           @y = @real_y >> 7
  402.           @jump_flag = false if @yv > 0
  403.           @yv = 0
  404.           touch?(1)
  405.         end
  406.       end
  407.     end
  408.   end
  409.   #--------------------------------------------------------------------------
  410.   # * Move Down
  411.   #     turn_enabled : a flag permits direction change on that spot
  412.   #--------------------------------------------------------------------------
  413.   def move_down(turn_enabled = true)
  414.     @stop_count = 0
  415.     d = 2 ** @move_speed
  416.     @yv = d
  417.     @move_count =128 / d
  418.   end
  419.  
  420.   #--------------------------------------------------------------------------
  421.   # * Move Left
  422.   #     turn_enabled : a flag permits direction change on that spot
  423.   #--------------------------------------------------------------------------
  424.   def move_left(turn_enabled = true)
  425.     turn_left
  426.     d = 2 ** @move_speed
  427.     @xv = 0 - d
  428.     @move_count = 128 / d
  429.     increase_steps
  430.   end
  431.   #--------------------------------------------------------------------------
  432.   # * Move Right
  433.   #     turn_enabled : a flag permits direction change on that spot
  434.   #--------------------------------------------------------------------------
  435.   def move_right(turn_enabled = true)
  436.     turn_right
  437.     d = 2 ** @move_speed
  438.     @xv = d
  439.     @move_count = 128 / d
  440.     increase_steps
  441.   end
  442.   #--------------------------------------------------------------------------
  443.   # * Move up
  444.   #     turn_enabled : a flag permits direction change on that spot
  445.   #--------------------------------------------------------------------------
  446.   def move_up(turn_enabled = true)
  447.     @stop_count = 0
  448.     d = 2 ** @move_speed
  449.     @yv = 0 - d
  450.     @move_count = 128 / d
  451.   end
  452.   #--------------------------------------------------------------------------
  453.   # * Move Lower Left
  454.   #--------------------------------------------------------------------------
  455.   def move_lower_left
  456.     # If no direction fix
  457.     unless @direction_fix
  458.       # Face down is facing right or up
  459.       @direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
  460.     end
  461.       # Update coordinates
  462.       d = 2 ** @move_speed
  463.       @xv = 0 - d
  464.       @yv = d
  465.       @move_count = 128/ d
  466.       # Increase steps
  467.       increase_steps
  468.   end
  469.   #--------------------------------------------------------------------------
  470.   # * Move Lower Right
  471.   #--------------------------------------------------------------------------
  472.   def move_lower_right
  473.     # If no direction fix
  474.     unless @direction_fix
  475.       # Face right if facing left, and face down if facing up
  476.       @direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
  477.     end
  478.       d = 2 ** @move_speed
  479.       @xv = d
  480.       @yv = d
  481.       @move_count = 128 / d
  482.       # Increase steps
  483.       increase_steps
  484.   end
  485.   #--------------------------------------------------------------------------
  486.   # * Move Upper Left
  487.   #--------------------------------------------------------------------------
  488.   def move_upper_left
  489.     # If no direction fix
  490.     unless @direction_fix
  491.       # Face left if facing right, and face up if facing down
  492.       @direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
  493.     end
  494.       # Update coordinates
  495.       d = 2 ** @move_speed
  496.       @xv = 0 - d
  497.       @yv = 0 - d
  498.       @move_count = 128 / d
  499.       # Increase steps
  500.       increase_steps
  501.   end
  502.   #--------------------------------------------------------------------------
  503.   # * Move Upper Right
  504.   #--------------------------------------------------------------------------
  505.   def move_upper_right
  506.     # If no direction fix
  507.     unless @direction_fix
  508.       # Face right if facing left, and face up if facing down
  509.       @direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
  510.     end
  511.       d = 2 ** @move_speed
  512.       @xv = d
  513.       @yv = 0 - d
  514.       @move_count = 128 / d
  515.       # Increase steps
  516.       increase_steps
  517.   end
  518.   #--------------------------------------------------------------------------
  519.   # * Move at Random
  520.   #--------------------------------------------------------------------------
  521.   def move_random
  522.     if !isfly?
  523.       @a = rand(1000)
  524.       if @a % 2 == 0
  525.         move_left(false)
  526.       else
  527.         move_right(false)
  528.       end
  529.     else
  530.       case rand(8)
  531.         when 0;  move_left(false)
  532.         when 1;  move_right(false)
  533.         when 2;  move_up(false)
  534.         when 3;  move_down(false)
  535.         when 4;  move_lower_left
  536.         when 5;  move_lower_right
  537.         when 6;  move_upper_left
  538.         when 7;  move_upper_right
  539.       end
  540.     end
  541.   end
  542.   #--------------------------------------------------------------------------
  543.   # * Move toward Player
  544.   #--------------------------------------------------------------------------
  545.   def move_toward_player
  546.     sx = distance_x_from_player
  547.     sx > 0 ? move_left : move_right
  548.   end
  549.   #--------------------------------------------------------------------------
  550.   # * Move away from Player
  551.   #--------------------------------------------------------------------------
  552.   def move_away_from_player
  553.     sx = distance_x_from_player
  554.     sx > 0 ? move_right : move_left
  555.   end
  556.   #--------------------------------------------------------------------------
  557.   # * Jump
  558.   #  Không cần nhập giá trị x và y ở RMXP
  559.   #--------------------------------------------------------------------------
  560.   def jump(x_plus, y_plus)
  561.     return if @jump_flag
  562.     @yv = -48
  563.     @jump_flag = true
  564.     @stop_count = 0
  565.   end
  566.   #--------------------------------------------------------------------------
  567.   # * Turn Towards Player
  568.   #--------------------------------------------------------------------------
  569.   def turn_toward_player
  570.     if @real_x < $game_player.real_x
  571.       turn_right
  572.     else
  573.       turn_left
  574.     end
  575.   end
  576. end
  577.  
  578. class Game_Player < Game_Character
  579.   #--------------------------------------------------------------------------
  580.   # * Passable Determinants
  581.   #--------------------------------------------------------------------------
  582.   def passable?(mode)
  583.     super(mode)
  584.   end
  585.  
  586.   def move_left(turn_ok = true)
  587.     turn_left
  588.     max_speed = -8
  589.     @xv = [@xv + 1, max_speed].min if @xv < max_speed and !@jump_flag
  590.     @xv = [@xv - 1, max_speed].max if @xv > max_speed
  591.     @move_count = 1
  592.   end
  593.  
  594.   def move_right(turn_ok = true)
  595.     turn_right
  596.     max_speed = 8
  597.     @xv = [@xv + 1, max_speed].min if @xv < max_speed
  598.     @xv = [@xv - 1, max_speed].max if @xv > max_speed and !@jump_flag
  599.     @move_count = 1
  600.   end
  601.  
  602.   def update_x
  603.     if !@jump_flag && !moving?
  604.       @xv = [@xv + 1, 0].min if @xv < 0
  605.       @xv = [@xv - 1, 0].max if @xv > 0
  606.     end
  607.     if !ladder?
  608.       last_x = @real_x
  609.       @real_x += @xv
  610.       @x = @real_x >> 7
  611.       unless passable?(0)
  612.         @real_x = last_x
  613.         @x = @real_x>> 7
  614.         @xv = 0
  615.         touch?(0)
  616.       end
  617.     else
  618.       if Input.press?(Input::UP) || Input.press?(Input::DOWN)
  619.         turn_up
  620.         last_x = @real_x
  621.         @x = @real_x >> 7
  622.       else
  623.         last_x = @real_x
  624.         @real_x += @xv
  625.         @x = @real_x >> 7
  626.         unless passable?(0)
  627.           @real_x = last_x
  628.           @x = @real_x>> 7
  629.           @xv = 0
  630.           touch?(0)
  631.         end
  632.       end
  633.     end
  634.   end
  635.  
  636.   def move_jump(yv)
  637.     @yv = yv
  638.     @jump_flag = true
  639.   end
  640.   #--------------------------------------------------------------------------
  641.   # * Frame Update
  642.   #--------------------------------------------------------------------------
  643.   def update
  644.     # Remember whether or not moving in local variables
  645.     last_moving = moving?
  646.     # If moving, event running, move route forcing, and message window
  647.     # display are all not occurring
  648.     unless moving? or $game_system.map_interpreter.running? or
  649.            @move_route_forcing or $game_temp.message_window_showing
  650.       # Move player in the direction the directional button is being pressed
  651.       if Input.press?(Input::LEFT)
  652.         move_left
  653.       elsif Input.press?(Input::RIGHT)
  654.         move_right
  655.       end
  656.     end
  657.     if Input.trigger?(Input::UP) && @jump_flag == false    # Jump
  658.       move_jump(-48)
  659.     end
  660.     # Remember coordinates in local variables
  661.     last_real_x = @real_x
  662.     last_real_y = @real_y
  663.     super
  664.     # If character moves down and is positioned lower than the center
  665.     # of the screen
  666.     if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
  667.       # Scroll map down
  668.       $game_map.scroll_down(@real_y - last_real_y)
  669.     end
  670.     # If character moves left and is positioned more let on-screen than
  671.     # center
  672.     if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
  673.       # Scroll map left
  674.       $game_map.scroll_left(last_real_x - @real_x)
  675.     end
  676.     # If character moves right and is positioned more right on-screen than
  677.     # center
  678.     if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
  679.       # Scroll map right
  680.       $game_map.scroll_right(@real_x - last_real_x)
  681.     end
  682.     # If character moves up and is positioned higher than the center
  683.     # of the screen
  684.     if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
  685.       # Scroll map up
  686.       $game_map.scroll_up(last_real_y - @real_y)
  687.     end
  688.     # If not moving
  689.     unless moving?
  690.       # If player was moving last time
  691.       if last_moving
  692.         # Event determinant is via touch of same position event
  693.         result = check_event_trigger_here([1,2])
  694.         # If event which started does not exist
  695.         if result == false
  696.           # Disregard if debug mode is ON and ctrl key was pressed
  697.           unless $DEBUG and Input.press?(Input::CTRL)
  698.             # Encounter countdown
  699.             if @encounter_count > 0
  700.               @encounter_count -= 1
  701.             end
  702.           end
  703.         end
  704.       end
  705.       # If C button was pressed
  706.       if Input.trigger?(Input::C)
  707.         # Same position and front event determinant
  708.         check_event_trigger_here([0])
  709.         check_event_trigger_there([0,1,2])
  710.       end
  711.     end
  712.   end
  713.   #--------------------------------------------------------------------------
  714.   # * Same Position Starting Determinant
  715.   #--------------------------------------------------------------------------
  716.   def check_event_trigger_here(triggers)
  717.     result = false
  718.     # If event is running
  719.     if $game_system.map_interpreter.running?
  720.       return result
  721.     end
  722.     # All event loops
  723.     for event in $game_map.events.values
  724.       @size = /\d+/.match(/\[W\d+\]/.match(event.get_name)[0])[0].to_i / 2 if event.get_name.include? "[W"
  725.       # If event coordinates and triggers are consistent
  726.       if @real_x >= (event.real_x - @size) - 36 and @real_x <= (event.real_x + @size) + 36 and $game_player.real_y > event.real_y - @height and $game_player.real_y <= event.real_y + 5 and triggers.include?(event.trigger)
  727.         # If starting determinant is same position event (other than jumping)
  728.         if not event.jumping? and event.over_trigger?
  729.           event.start
  730.           result = true
  731.           return result
  732.         end
  733.       end
  734.     end
  735.     return result
  736.   end
  737.  
  738.   #--------------------------------------------------------------------------
  739.   # * Front Envent Starting Determinant
  740.   #--------------------------------------------------------------------------
  741.   def check_event_trigger_there(triggers)
  742.     result = false
  743.     # If event is running
  744.     if $game_system.map_interpreter.running?
  745.       return result
  746.     end
  747.     # Calculate front event coordinates
  748.     new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
  749.     new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
  750.     # All event loops
  751.     for event in $game_map.events.values
  752.       @size = /\d+/.match(/\[W\d+\]/.match(event.get_name)[0])[0].to_i / 2 if event.get_name.include? "[W"
  753.       # If event coordinates and triggers are consistent
  754.       if @real_x >= (event.real_x - @size) - 36 and @real_x <= (event.real_x + @size) + 36 and $game_player.real_y > event.real_y - @height and $game_player.real_y <= event.real_y + 5 and triggers.include?(event.trigger)
  755.         # If starting determinant is front event (other than jumping)
  756.         if not event.jumping? and not event.over_trigger?
  757.           event.start
  758.           result = true
  759.           return result
  760.         end
  761.       end
  762.     end
  763.     # If fitting event is not found
  764.     if result == false
  765.       # If front tile is a counter
  766.       if $game_map.counter?(new_x, new_y)
  767.         # Calculate 1 tile inside coordinates
  768.         new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
  769.         new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
  770.         # All event loops
  771.         for event in $game_map.events.values
  772.           @size = /\d+/.match(/\[W\d+\]/.match(event.get_name)[0])[0].to_i / 2 if event.get_name.include? "[W"
  773.           # If event coordinates and triggers are consistent
  774.           if @real_x >= (event.real_x - @size) - 36 and @real_x <= (event.real_x + @size) + 36  and $game_player.real_y > event.real_y - @height and $game_player.real_y <= event.real_y + 5 and
  775.              triggers.include?(event.trigger)
  776.             # If starting determinant is front event (other than jumping)
  777.             if not event.jumping? and not event.over_trigger?
  778.               event.start
  779.               result = true
  780.               return result
  781.             end
  782.           end
  783.         end
  784.       end
  785.     end
  786.     return result
  787.   end
  788.   #--------------------------------------------------------------------------
  789.   # * Touch Event Starting Determinant
  790.   #--------------------------------------------------------------------------
  791.   def check_event_trigger_touch(x, y)
  792.     result = false
  793.     # If event is running
  794.     if $game_system.map_interpreter.running?
  795.       return result
  796.     end
  797.     # All event loops
  798.     for event in $game_map.events.values
  799.       @size = /\d+/.match(/\[W\d+\]/.match(event.get_name)[0])[0].to_i / 2 if event.get_name.include? "[W"
  800.       @height = /\d+/.match(/\[H\d+\]/.match(event.get_name)[0])[0].to_i if event.get_name.include? "[H"
  801.       # If event coordinates and triggers are consistent
  802.       if @real_x >= (event.real_x - @size) - 36 and @real_x <= (event.real_x + @size) + 36  and $game_player.real_y > event.real_y - @height and $game_player.real_y <= event.real_y + 5 and [1,2].include?(event.trigger)
  803.         # If starting determinant is front event (other than jumping)
  804.         if not event.jumping? and not event.over_trigger?
  805.           event.start
  806.           result = true
  807.           return result
  808.         end
  809.       end
  810.     end
  811.     return result
  812.   end
  813. end
  814.  
  815. class Game_Event < Game_Character
  816.   def get_name
  817.     return @event.name
  818.   end
  819.  
  820. end
Expand to see the code.


How to use
you can see all in the newest demo version

Credits and Thanks
NamKazt
HikiMoKi

Author's Notes

if you have a bug, plz pm me

Terms and Conditions

if you use this script, plz give me and HikiMoKi credit
Woaw, nice one, works really smooth!
The pixelperpixel movement and the little slide when you turn round while going are cool eyecandy, good work!

Still testing it-
    How can you change jump heigh?
    Content Hidden Spoiler
    460 move_jump(-75) #def 48

    *Could you add that I can change it by a callscript?
    like: jump_heigh=xx pixel
    *Could you implent doubel jump plz (:?
    *Could the distance you jump when being in motion for a while being increas
ed?
... i'm Vietnamese and i am not clear about your question. ... :o:
but some thing i can :D

How can you change jump heigh?
Player :
  1. Class Game_Player
  2.   #--------------------------------------------------------------------------
  3.   # * Jump
  4.   #  Không cần nhập giá trị x và y ở RMXP
  5.   #--------------------------------------------------------------------------
  6.   def jump(x_plus, y_plus)
  7.     return if @jump_flag
  8.     @yv = -48
  9.     @jump_flag = true
  10.     @stop_count = 0
  11.   end
Expand to see the code.

this can change jump height

and def jump in class game_character : change jump height for event or move route

Could you implent doubel jump plz (:?
i will try it :) now thanks for your ideas...
Could you add that I can change it by a callscript?
like: jump_heigh=xx pixel

ya.! it can do so but must be revised :D

sr about my english , tell me if I misunderstand your comments
I like you more and more :3
You udnerstood it perfectly, the last thing I'm looking forward to is the following:

If the player runs for x amount of time. Let's say 1second
Than he should jump x higher, and run x faster.
Thanks a lot in advance (:

~Ragnai
Holy shit this is actually really good and works great, AND it clears up the up and down buttons so they can be used for other things...

Y'see, I've been making a platforming game myself but with events for the platforming system, and with this, my frame rate won't drop due to all the conditional branches etc, AND it's easier than learning in Game Maker, lol.

I've just got one question, is there a way to make it so you can't walk through event characters ?

Or maybe, you can only walk past them if they have a $ in their name or something ?

So you can't walk past boy (He's a solid object), but you can walk past $man

Because if so, that'd be great for me.

Also, just a little something you could add, if a tiles priority is 5*, then it shows above the player, and can't be jumped onto,

For example, walking along a path with a fence, but the fence shows above the player (So it's like he's stood behind and not on top of it), and when he jumps he doesn't land on it.

Do you think you could add that maybe ?
sorry for the delay, i'm very busy in this time
ah Jbrist i'm fixing it, sr , it've some error with passable? >> event
This is a great script!!!! I've been waiting for something like this for along time :D Great job!!
could you maybe add ladders? And can you make it where events dont have gravity unless we put @ in the name.
Sounds interesting, but I think I will wait for the demo.
Great script, can you make one for VX ^^
I'm enjoying it more and more, but could you please implant a function that would make the Player jump?
Something like a trampoline.
Using it somehow like: player_extrajump= -xx

Thanks in advance
~Ragnai

Edit: Could you implant extra graphics for jumping etc? : player_jump[x=numberofframes]
Because it looks like he would be standing in the air on screenshots and it doesn't look much better in the running game :l
Image
This is great, grats on making a good platorm system, the others... suck. :box:
How do i make a step...
i mean somthing that he can walk beside the ground...


_X_-x--
like he jump to a higher flor...
and how to chenge Keys and stuff like that why you cant add a tutorail if you makeing a script!!!

how i make the defult X.Y be a little higher not at 0,0 but like to 5,5........

.... thx ....
I think there is a big need for a demo here.
I will make one for tomorrow, just say what you want to see in it.
I already explained how to make a step, change gravity and jump heigh.

~Ragnai
Holy crap this is really smooth.

Really nice work. I'll be interested to see any more features you add.
The script is really good! Just wondering how do i make a ladder event? Like go up and down
sr for my work is very slow, i'm busy for now... more more exam... and i cant complete my platform script :-S.
sr u, i'll done it when my exam finish.
Everything works but the jumping, can somebody help?
EDIT: And i cant activate my transfer events. Nice script though.
just make an event for jumping..

I made one ..

Awesome script, Anyway.. I'd recommend it to the others..
but I have a problem,

when I set an event to event touch or player touch, and tested it,
the event won't trigger!!
Please help!..

in the ladder, I tried using jump and putting a block for going down..
(now it acts like stairs..)

anyway,
for those who are kinda tired of pasting it to one rmxp project just to test it,
here it is!

It's not just pasted, or something, it would seem like a minigame..

It inlcudes the jumping system I just made..

the instruction is inside the game..
Edit:I also made the jump higher..
Please, Enjoy..
thank you everyone for your interest in my script
I will continue to complete it at this time.

~NamKazt
i just update a feature :

* block if event not through
- it have a problem is distance too long but i think i will edit some think but not here to fix it.

def passable in Game_Character Class
  1. def passable?(mode = 0)
  2.     left_x = @real_x + 32 >> 7    # 4 << 3
  3.     right_x = @real_x + 110 >> 7  # 28 << 3
  4.     up_y = @real_y + 16>> 7      # 2 << 3
  5.     down_y = @real_y + 110 >> 7   # 28 << 3
  6.     # Get new coordinates
  7.     if mode == 0
  8.       if @xv > 0
  9.         return false unless $game_map.passable?(right_x, up_y,6)
  10.         return false unless $game_map.passable?(right_x, down_y,6)
  11.       else
  12.         return false unless $game_map.passable?(left_x, up_y,4)
  13.         return false unless $game_map.passable?(left_x, down_y,4)
  14.       end
  15.     else
  16.       if @yv > 0
  17.         return false unless $game_map.passable?(left_x, down_y,2)
  18.         return false unless $game_map.passable?(right_x, down_y,2)
  19.       else
  20.         return false unless $game_map.passable?(left_x, up_y,8)
  21.         return false unless $game_map.passable?(right_x, up_y,8)
  22.       end
  23.     end
  24.    
  25.     if @through
  26.       return true
  27.     end
  28.     # Loop all events
  29.     for event in $game_map.events.values
  30.        new_x = (event.direction == 6 ? ((@real_x + 32 >> 7) + 1) :  event.direction == 4 ? ((@real_x + 110 >> 7) + 1) : 0)
  31.        new_y = (event.direction == 2 ? ((@real_y + 16 >> 7) + 1) :  event.direction == 8 ? ((@real_y + 110 >> 7) + 1) : 0)
  32.       # If event coordinates are consistent with move destination
  33.       if event.x == new_x and event.y == new_y
  34.         #If through is OFF
  35.         unless event.through
  36.           # If self is event
  37.           if self != $game_player
  38.             # impassable
  39.             return false
  40.           end
  41.           # With self as the player and partner graphic as character
  42.           if event.character_name != ""
  43.             # impassable
  44.             return false
  45.           end
  46.         end
  47.       end
  48.     end
  49.    
  50.     new1_x = ($game_player.direction == 6 ? ((@real_x + 32 >> 7) +  1) : $game_player.direction == 4 ? ((@real_x + 110 >> 7) + 1) : 0)
  51.     new1_y = ($game_player.direction == 2 ? ((@real_y + 16 >> 7) +  1) : $game_player.direction == 8 ? ((@real_y + 110 >> 7) + 1) : 0)
  52.     #if is player
  53.     if(self == $game_player)
  54.     #Loop all events
  55.     for event in $game_map.events.values
  56.       if $game_player.x < event.x
  57.           if(event.x - $game_player.x) < 2
  58.             unless event.through
  59.               return false
  60.             end
  61.           end
  62.       end
  63.      
  64.       if $game_player.x > event.x
  65.           if($game_player.x - event.x) < 2
  66.             unless event.through
  67.               return false
  68.             end
  69.           end
  70.       end
  71.      
  72.     end
  73.     end
  74.    
  75.     if $game_player.x == new1_x and $game_player.y == new1_y
  76.       # If through is OFF
  77.       unless $game_player.through
  78.         # If your own graphic is the character
  79.         if @character_name != ""
  80.           # impassable
  81.           return false
  82.         end
  83.       end
  84.     end
  85.    
  86.    
  87.     return true
  88.   end
Expand to see the code.



change in :
  1. #if is player
  2.     if(self == $game_player)
  3.     #Loop all events
  4.     for event in $game_map.events.values
  5.      #case 1 : position of player small than event
  6.       if $game_player.x < event.x
  7.           if(event.x - $game_player.x) < 2
  8.             unless event.through # if through
  9.               return false
  10.             end
  11.           end
  12.       end
  13.       #case 1 : position of player lager than event
  14.       if $game_player.x > event.x
  15.           if($game_player.x - event.x) < 2
  16.             unless event.through # if through
  17.               return false
  18.             end
  19.           end
  20.       end
  21.      
  22.     end
  23.     end
Expand to see the code.
Jeea wrote:
just make an event for jumping..

I made one ..

Awesome script, Anyway.. I'd recommend it to the others..
but I have a problem,

when I set an event to event touch or player touch, and tested it,
the event won't trigger!!
Please help!..

in the ladder, I tried using jump and putting a block for going down..
(now it acts like stairs..)

anyway,
for those who are kinda tired of pasting it to one rmxp project just to test it,
here it is!

It's not just pasted, or something, it would seem like a minigame..

It inlcudes the jumping system I just made..

the instruction is inside the game..
Edit:I also made the jump higher..
Please, Enjoy..



i'll see your problems ^^~
and it included jump system :D u just press up button
This is excellent, just what I was looking for. One small thing, could you add support for slopes (as in, a 45 degree slope marked by an event with a comment in it)?
Naridar wrote:
This is excellent, just what I was looking for. One small thing, could you add support for slopes (as in, a 45 degree slope marked by an event with a comment in it)?


i'll try
add it to todolist
Great platform system. I love the mechanics. It still needs tons of work, though. To start with, I think when on top of a moving event, the player should move with the event. Hope to see it finished someday.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=68686