Spanciai Posted August 16, 2010 Share Posted August 16, 2010 (edited) NamKazt's Platform Move SystemsVersion: 1.04 AutoreNamKaztDescrizioneUno script che permette di simulare un platform...Molto funzionale ma che posto per risolvere alcuni bugScript: #============================================================================== # ** NamKazt's Platform Move Systems #------------------------------------------------------------------------------ # Phiên Bản : 1.04 # * Cải tiến : # +, Thêm Jump ( Nhảy ) # +, Thêm Passable? >> Event # +, Sửa một vài lỗi nhỏ ( Move route ) # +, Sửa lỗi handing float x # +, Sửa lỗi passable? # +, Thêm X distance # +, Gộp chung vào thành 1 script, xoá bỏ những phần thừa #------------------------------------------------------------------------------ # Hiện tại vẫn còn mắc lỗi đi xuyên qua event, chưa có fly event và nâng event # thực ra thì cái đi xuyên event mình cảm thấy dùng cũng đc, tại game thì đi xuyên event sẽ tốt hơn, nhưng sẽ có vài event cản đương # vì thế sửa vẫn tốt hơn =.=" # sẽ update vào phiên bản sau #------------------------------------------------------------------------------ # Công Dụng : # * Di chuyển mặp phẳng 2D # * Di chuyển Pixel #------------------------------------------------------------------------------ # Thanks : # HikiMoKi vì script tuyệt vời của họ trên nền VX # [url="http://hikimoki.hp.infoseek.co.jp/"]http://hikimoki.hp.infoseek.co.jp/[/url] # Script này đc phát triển trên nền đó, dựa vào ý tưởng của họ #============================================================================== class Game_Character attr_reader :xv # Trục x attr_reader :yv # Trục y attr_accessor :gravity # Độ cao #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- alias pms_initialize initialize def initialize pms_initialize @xv = 0 @yv = 0 @move_count = 0 @gravity = 5 @jump_flag = false end #-------------------------------------------------------------------------- # * Determine if Moving #-------------------------------------------------------------------------- def moving? # If logical coordinates differ from real coordinates, # movement is occurring. return @move_count > 0 end #-------------------------------------------------------------------------- # * Tocch # mode : # * 0 : Left or Right # * 1 : Up or Down #-------------------------------------------------------------------------- def touch?(mode = 0) if mode == 0 if @xv > 0 check_event_trigger_touch(@x+1, @y) else check_event_trigger_touch(@x-1, @y) end else if @xv > 0 check_event_trigger_touch(@x, @y+1) else check_event_trigger_touch(@x, @y-1) end end end def distance_x_from_player sx = @x - $game_player.x return sx end def passable?(mode = 0) left_x = @real_x + 32 >> 7 # 4 << 3 right_x = @real_x + 110 >> 7 # 28 << 3 up_y = @real_y + 16>> 7 # 2 << 3 down_y = @real_y + 110 >> 7 # 28 << 3 # Get new coordinates if mode == 0 if @xv > 0 return false unless $game_map.passable?(right_x, up_y,6) return false unless $game_map.passable?(right_x, down_y,6) else return false unless $game_map.passable?(left_x, up_y,4) return false unless $game_map.passable?(left_x, down_y,4) end else if @yv > 0 return false unless $game_map.passable?(left_x, down_y,2) return false unless $game_map.passable?(right_x, down_y,2) else return false unless $game_map.passable?(left_x, up_y,8) return false unless $game_map.passable?(right_x, up_y,8) end end return true if @through # Loop all events for event in $game_map.events.values new_x = (event.direction == 6 ? ((@real_x + 32 >> 7) + 1) : event.direction == 4 ? ((@real_x + 110 >> 7) + 1) : 0) new_y = (event.direction == 2 ? ((@real_y + 16 >> 7) + 1) : event.direction == 8 ? ((@real_y + 110 >> 7) + 1) : 0) # If event coordinates are consistent with move destination if event.x == new_x and event.y == new_y # If through is OFF unless event.through # If self is event if self != $game_player # impassable return false end # With self as the player and partner graphic as character if event.character_name != "" # impassable return false end end end end new1_x = ($game_player.direction == 6 ? ((@real_x + 32 >> 7) + 1) : $game_player.direction == 4 ? ((@real_x + 110 >> 7) + 1) : 0) new1_y = ($game_player.direction == 2 ? ((@real_y + 16 >> 7) + 1) : $game_player.direction == 8 ? ((@real_y + 110 >> 7) + 1) : 0) if $game_player.x == new1_x and $game_player.y == new1_y # If through is OFF unless $game_player.through # If your own graphic is the character if @character_name != "" # impassable return false end end end return true end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update update_x update_y # Branch with jumping, moving, and stopping if jumping? update_jump elsif moving? @move_count -= 1 if @walk_anime @anime_count += 1.5 elsif @step_anime @anime_count += 1 end else update_stop end # If animation count exceeds maximum value # * Maximum value is move speed * 1 taken from basic value 18 if @anime_count > 18 - @move_speed * 2 # If stop animation is OFF when stopping if not @step_anime and @stop_count > 0 # Return to original pattern @pattern = @original_pattern # If stop animation is ON when moving else # Update pattern @pattern = (@pattern + 1) % 4 end # Clear animation count @anime_count = 0 end # If waiting if @wait_count > 0 # Reduce wait count @wait_count -= 1 return end # If move route is forced if @move_route_forcing # Custom move move_type_custom return end # When waiting for event execution or locked if @starting or lock? # Not moving by self return end # If stop count exceeds a certain value (computed from move frequency) if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency) # Branch by move type case @move_type when 1 # Random move_type_random when 2 # Approach move_type_toward_player when 3 # Custom move_type_custom end end end #-------------------------------------------------------------------------- # ● Update X #-------------------------------------------------------------------------- def update_x if !@jump_flag && !moving? @xv = 0 return end last_x = @real_x @real_x += @xv @x = @real_x >> 7 unless passable?(0) @real_x = last_x @x = @real_x >> 7 @xv = 0 touch?(0) end end #-------------------------------------------------------------------------- # ● Update Y #-------------------------------------------------------------------------- def update_y if @gravity > 0 @yv += @gravity @yv = 64 if @yv > 64 elsif !moving? @yv = 0 return end last_y = @real_y @real_y += @yv @y = @real_y >> 7 unless passable?(1) @real_y = last_y @y = @real_y >> 7 @jump_flag = false if @yv > 0 @yv = 0 touch?(1) end end #-------------------------------------------------------------------------- # * Move Down # turn_enabled : a flag permits direction change on that spot #-------------------------------------------------------------------------- def move_down(turn_enabled = true) @stop_count = 0 d = 2 ** @move_speed @yv = d @move_count = 128 / d end #-------------------------------------------------------------------------- # * Move Left # turn_enabled : a flag permits direction change on that spot #-------------------------------------------------------------------------- def move_left(turn_enabled = true) turn_left d = 2 ** @move_speed @xv = 0 - d @move_count = 128 / d increase_steps end #-------------------------------------------------------------------------- # * Move Right # turn_enabled : a flag permits direction change on that spot #-------------------------------------------------------------------------- def move_right(turn_enabled = true) turn_right d = 2 ** @move_speed @xv = d @move_count = 128 / d increase_steps end #-------------------------------------------------------------------------- # * Move up # turn_enabled : a flag permits direction change on that spot #-------------------------------------------------------------------------- def move_up(turn_enabled = true) @stop_count = 0 d = 2 ** @move_speed @yv = 0 - d @move_count = 128 / d end #-------------------------------------------------------------------------- # * Move Lower Left #-------------------------------------------------------------------------- def move_lower_left # If no direction fix unless @direction_fix # Face down is facing right or up @direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction) end # Update coordinates d = 2 ** @move_speed @xv = 0 - d @yv = d @move_count = 128 / d # Increase steps increase_steps end #-------------------------------------------------------------------------- # * Move Lower Right #-------------------------------------------------------------------------- def move_lower_right # If no direction fix unless @direction_fix # Face right if facing left, and face down if facing up @direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction) end d = 2 ** @move_speed @xv = d @yv = d @move_count = 128 / d # Increase steps increase_steps end #-------------------------------------------------------------------------- # * Move Upper Left #-------------------------------------------------------------------------- def move_upper_left # If no direction fix unless @direction_fix # Face left if facing right, and face up if facing down @direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction) end # Update coordinates d = 2 ** @move_speed @xv = 0 - d @yv = 0 - d @move_count = 128 / d # Increase steps increase_steps end #-------------------------------------------------------------------------- # * Move Upper Right #-------------------------------------------------------------------------- def move_upper_right # If no direction fix unless @direction_fix # Face right if facing left, and face up if facing down @direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction) end d = 2 ** @move_speed @xv = d @yv = 0 - d @move_count = 128 / d # Increase steps increase_steps end #-------------------------------------------------------------------------- # * Move at Random #-------------------------------------------------------------------------- def move_random case rand(@gravity == 0 ? 4 : 2) when 0; move_left(false) when 1; move_right(false) when 2; move_up(false) when 3; move_down(false) end end #-------------------------------------------------------------------------- # * Move toward Player #-------------------------------------------------------------------------- def move_toward_player sx = distance_x_from_player sx > 0 ? move_left : move_right end #-------------------------------------------------------------------------- # * Move away from Player #-------------------------------------------------------------------------- def move_away_from_player sx = distance_x_from_player sx > 0 ? move_right : move_left end #-------------------------------------------------------------------------- # * Jump # Không cần nhập giá trị x và y ở RMXP #-------------------------------------------------------------------------- def jump(x_plus, y_plus) return if @jump_flag @yv = -48 @jump_flag = true @stop_count = 0 end #-------------------------------------------------------------------------- # * Turn Towards Player #-------------------------------------------------------------------------- def turn_toward_player if @real_x < $game_player.real_x turn_right else turn_left end end end class Game_Player < Game_Character #-------------------------------------------------------------------------- # * Passable Determinants #-------------------------------------------------------------------------- def passable?(mode) super(mode) end def move_left(turn_ok = true) turn_left max_speed = -16 @xv = [@xv + 2, max_speed].min if @xv < max_speed and !@jump_flag @xv = [@xv - 2, max_speed].max if @xv > max_speed @move_count = 1 end def move_right(turn_ok = true) turn_right max_speed = 16 @xv = [@xv + 2, max_speed].min if @xv < max_speed @xv = [@xv - 2, max_speed].max if @xv > max_speed and !@jump_flag @move_count = 1 end def update_x if !@jump_flag && !moving? @xv = [@xv + 2, 0].min if @xv < 0 @xv = [@xv - 2, 0].max if @xv > 0 end last_x = @real_x @real_x += @xv @x = @real_x >> 7 unless passable?(0) @real_x = last_x @x = @real_x >> 7 @xv = 0 touch?(0) end end def move_jump(yv) @yv = yv @jump_flag = true end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update # Remember whether or not moving in local variables last_moving = moving? # If moving, event running, move route forcing, and message window # display are all not occurring unless moving? or $game_system.map_interpreter.running? or @move_route_forcing or $game_temp.message_window_showing # Move player in the direction the directional button is being pressed if Input.press?(Input::LEFT) move_left elsif Input.press?(Input::RIGHT) move_right end end if Input.trigger?(Input::Y) && @jump_flag == false # Jump move_jump(-48) end # Remember coordinates in local variables last_real_x = @real_x last_real_y = @real_y super # If character moves down and is positioned lower than the center # of the screen if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y # Scroll map down $game_map.scroll_down(@real_y - last_real_y) end # If character moves left and is positioned more let on-screen than # center if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X # Scroll map left $game_map.scroll_left(last_real_x - @real_x) end # If character moves right and is positioned more right on-screen than # center if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X # Scroll map right $game_map.scroll_right(@real_x - last_real_x) end # If character moves up and is positioned higher than the center # of the screen if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y # Scroll map up $game_map.scroll_up(last_real_y - @real_y) end # If not moving unless moving? # If player was moving last time if last_moving # Event determinant is via touch of same position event result = check_event_trigger_here([1,2]) # If event which started does not exist if result == false # Disregard if debug mode is ON and ctrl key was pressed unless $DEBUG and Input.press?(Input::CTRL) # Encounter countdown if @encounter_count > 0 @encounter_count -= 1 end end end end # If C button was pressed if Input.trigger?(Input::C) # Same position and front event determinant check_event_trigger_here([0]) check_event_trigger_there([0,1,2]) end end end end class Game_Event < Game_Character def get_name return @event.name end end IstruzioniPer cambiare la lunghezza del salto cambiare il valore della stringa 42 @gravity = 3 Questo script rileva qualche bug...Due in particolare...I pg cadono...cioè non rimangono fermi nella posione scelta e questo non permette di creare monete o oggetti da raccogliere saltando come succede spesso nei platform...E non funziona tanto bene la collisione con gli altri pg...Chi è in grado di modificare lo script se può aiutare=) Edited April 27, 2013 by Dilos Script monoriga sistemato. http://i74.servimg.com/u/f74/13/12/87/37/spanci10.png http://i86.servimg.com/u/f86/18/56/59/72/banner10.pnghttp://i39.servimg.com/u/f39/18/56/59/72/banner10.png Il rippaggio è il miglior amico del makeratore! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now