Stairs Movement
Stairs Movement v1.0FenixFyreX
Introduction
This script allows movement on a diagonal line to emulate scaling staircases.
Features
- Easily designate a staircase via a region
- Change the speed at which steps are taken to match the pace of moving up/down the staircase
- Alter the y coordinate offset of the character sprite to match the tileset staircase center
Screenshots
Not really applicable as you'd need to see it in action. Just put it in your project, set up a staircase, and try it out.
How to Use
1> Install the script below the default scripts and above Main.
2> Edit the script config to change the staircase region id to your liking.
3> Create a staircase on the map with your tileset.
4> Along the path of the staircase, put that region down.
5> Playtest!
Demo
Mediafire - Stairs Movement
Script
Spoiler Code:
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=## Stairs Movement v 1.1#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=### FenixFyreX## Final Fantasy VI had stairs that the player actually walked up. Their direction# became two way on these stairs, left or right. This script replicates that# feature.##-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#StairsRegionID = 10 # The region ID to use for designating staircasesStairsOffset = 4 # The height of one tileset staircase plank (about 4px)CharAnimSpeed= 2 # The speed at which a sprite cycles through frames#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=## End of Config. Do not edit below.#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#class Game_Mapdef stairs?(x,y) region_id(x,y) == StairsRegionIDendendclass Game_CharacterBase # give other coders access to checking stairs statusattr_reader :on_stairs, :stairs_dalias on_stairs? on_stairs # check whether character is on stairsdef check_stairs @on_stairs = stairs?(0)end # Checks if there are any sets of stairs in the given directiondef stairs?(d) return case d when 0 $game_map.stairs?(@x,@y) when 2 $game_map.stairs?(@x-1,@y+1) || $game_map.stairs?(@x+1,@y+1) when 4 $game_map.stairs?(@x-1,@y-1) || $game_map.stairs?(@x-1,@y+1) when 6 $game_map.stairs?(@x+1,@y-1) || $game_map.stairs?(@x+1,@y+1) when 8 $game_map.stairs?(@x-1,@y-1) || $game_map.stairs?(@x+1,@y-1) else false endend # Checks passability in the given direction for stairsdef stairs_passable?(x, y, d) x2 = $game_map.round_x_with_direction(x, d) y2 = $game_map.round_y_with_direction(y, d) return false unless $game_map.valid?(x2, y2) return true if @through || debug_through? return false unless map_passable?(x, y, d) return false if collide_with_characters?(x2, y2) return trueend # Moves the character in the given direction diagonally up or down stairsdef move_diag_stairs(d, horz, vert, turn_ok) x,y = @x+horz,@y+vert horz = [[-1,1].index(horz)] vert = [[-1,1].index(vert)] @move_succeed = stairs_passable?(x,y,d) d = [[,,,].index()%2] set_direction(d) if turn_ok if @move_succeed @x = $game_map.round_x_with_direction(@x, horz) @y = $game_map.round_y_with_direction(@y, vert) @real_x = $game_map.x_with_direction(@x, reverse_dir(horz)) @real_y = $game_map.y_with_direction(@y, reverse_dir(vert)) increase_steps endend # Returns the stair vector for the given directiondef stair_vector(d) x,y = 0,0 case d when 4,6 x = [-1,1][.index(d)] y = $game_map.stairs?(@x+x,@y-1) ? -1 : 1 when 2,8 y = [-1,1][.index(d)] x = $game_map.stairs?(@x-1,@y+y) ? -1 : 1 end end # Checks whether or not the character is not getting on or off stairsdef midstairs? @on_stairs && stairs?(reverse_dir(@direction))end # Alters original move method to put stairs into effectalias move_straight_no_stairs move_straightdef move_straight(d, turn_ok = true) if on_stairs? && stairs?(d) @stairs_d = d move_diag_stairs(d, *stair_vector(d), turn_ok) else d = @direction if @on_stairs && .include?(d) move_straight_no_stairs(d, turn_ok) end check_stairsend alias move_diagonal_for_stairs move_diagonaldef move_diagonal(horz, vert) if self.is_a?(Game_Follower) && @preceding_character.on_stairs? check_stairs if on_stairs? && stairs?(@preceding_character.stairs_d) d = @preceding_character.stairs_d move_diag_stairs(d, *stair_vector(d), true) else move_diagonal_for_stairs(horz, vert) end else move_diagonal_for_stairs(horz, vert) endend # Shift the y coordinate of the character's sprite to compensate for stairsalias shift_y_for_stairs shift_ydef shift_y(*a,&bl) shift_y_for_stairs(*a,&bl) + (midstairs? ? StairsOffset : 0)end # Update the sprite more to create pace-per-step effect on stairsalias update_anime_count_for_stairs update_anime_countdef update_anime_count(*a,&bl) ac = @anime_count update_anime_count_for_stairs(*a,&bl) @anime_count += CharAnimSpeed if midstairs?endendclass Game_Player < Game_Characteralias move_straight_for_stairs move_straightdef move_straight(*a,&bl) @followers.move if stairs_passable?(@x,@y,a) if on_stairs? move_straight_for_stairs(*a,&bl)endend#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=## End of Script#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
Credit and Thanks
- FenixFyreX
Changelog & Bug Fixes
Version 1.1
- Fixed bug where followers wouldn't follow the player up or down stairs.
本贴来自国际rpgmaker官方论坛作者:FenixFyreX处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/stairs-movement.9216/
页:
[1]