Elekami Fondateur
Messages postés : 19071 Date d'inscription : 19/07/2008 Jauge LPC :
| Sujet: [XP] Sauter au dessus de terrains Ven 10 Fév 2012 - 0:54 | |
| Avec ce script, vous pouvez sauter par dessus une case de terrain, en appuyant sur [ESPACE]. Il est configurable, voir fin du post... Créez un script au dessus de Main apellé "walljump" avec : - Code:
-
#============================================================================== # ? WallJump Script #------------------------------------------------------------------------------ #==============================================================================
#============================================================================== # ? Customisation #============================================================================== JumpID = 1 # The terrain ID of the tiles which can be jumped over MaxJump = 2 # The longest jump that can be made by the player #============================================================================== # ? Game_Player #==============================================================================
class Game_Player < Game_Character # forces Game_Character's passable method to be used, so CTRL no longer makes # the hero able to walk through walls def passable?(x, y, d) super(x, y, d) end def leap # finds the increases to x & y for the current direction xdir = (@direction == 6 ? 1 : @direction == 4 ? -1 : 0) ydir = (@direction == 2 ? 1 : @direction == 8 ? -1 : 0) # Ow! unless $game_map.terrain_tag(@x + xdir, @y + ydir) == JumpID or $game_map.passable?(@x + xdir, @y + ydir, @direction, self) # make the player jump route = RPG::MoveRoute.new route.list.clear route.list.push(RPG::MoveCommand.new(37)) route.list.push(RPG::MoveCommand.new(14, [0, 0])) route.list.push(RPG::MoveCommand.new(38)) route.list.push(RPG::MoveCommand.new(0)) route.repeat = false $game_player.force_move_route(route) # shake the screen $game_screen.start_shake(7, 7, 5) # display an "Ouch!" message $game_temp.message_text = "Ouch!" return end # finds the jumpable distance dist = jumpable_distance # wall jump if dist.between?(1, MaxJump - 1) and !$game_map.passable?(@x + (dist + 1) * xdir, @y + (dist + 1) * ydir, @direction, self) and !($game_map.terrain_tag(@x + (dist + 1) * xdir, @y + (dist + 1) * ydir) == JumpID) # finds the reverse direction bounce_dir = @direction == 2 ? 8 : (@direction == 4 ? 6 : (@direction == 6 ? 4 : 2)) # finds the wall-jump distance b_dist = jumpable_distance(bounce_dir, MaxJump + 2, @x + dist * xdir, @y + dist * ydir) # finds the additions to x and y made by the reverse direction b_xdir = (bounce_dir == 6 ? 1 : bounce_dir == 4 ? -1 : 0) b_ydir = (bounce_dir == 2 ? 1 : bounce_dir == 8 ? -1 : 0) # create the move_route route = RPG::MoveRoute.new route.list.clear route.list.push(RPG::MoveCommand.new(37)) # add the normal jump route.list.push(RPG::MoveCommand.new(14, [xdir * dist, ydir * dist])) # add the wall jump route.list.push(RPG::MoveCommand.new(14, [b_xdir * b_dist, b_ydir * b_dist])) route.list.push(RPG::MoveCommand.new(38)) route.list.push(RPG::MoveCommand.new(0)) route.repeat = false $game_player.force_move_route(route) return end # creates a route for a normal jump and forces the player to follow it route = RPG::MoveRoute.new route.list.clear route.list.push(RPG::MoveCommand.new(37)) route.list.push(RPG::MoveCommand.new(14, [xdir * dist, ydir * dist])) route.list.push(RPG::MoveCommand.new(38)) route.list.push(RPG::MoveCommand.new(0)) route.repeat = false $game_player.force_move_route(route) end alias update_primary update def update # calls the normal update method update_primary # locks the facing if CTRL is pressed, else unlocks it @direction_fix = Input.press?(Input::CTRL) # leaps if Input::A is triggered leap if Input.trigger?(Input::A) && !moving? end def jumpable_distance(dir = @direction, max_dist = MaxJump, x = @x, y = @y) xdir = (dir == 6 ? 1 : dir == 4 ? -1 : 0) ydir = (dir == 2 ? 1 : dir == 8 ? -1 : 0) jumpable_tiles = [] for i in 0..max_dist check_x = x + i * xdir check_y = y + i * ydir e = $game_map.events[$game_map.check_event(check_x, check_y)] if e if e.list[0].parameters[0] =~ "\Tall" break end if not e.through next end end if $game_map.passable?(check_x, check_y, dir, self) or $game_map.terrain_tag(check_x, check_y) == JumpID jumpable_tiles.push(i) end end jumpable_tiles.reverse.each do |i| check_x = x + i * xdir check_y = y + i * ydir return i if $game_map.passable?(check_x, check_y, dir, self) end return 0 end end Paramètres du script : JumpID = 1 # Le numéro de terrain au-dessus du quel on peut sauter. MaxJump = 2 # Le maximum de cases que l'on peut sauter. Il faut en jeu appuyer sur [ESPACE] pour sauter. |
|
Jin Ancien staffeux
Messages postés : 8557 Date d'inscription : 08/12/2010 Jauge LPC :
| Sujet: Re: [XP] Sauter au dessus de terrains Ven 10 Fév 2012 - 13:06 | |
| C'est facilement faisable en event ca ... tiens ... bah je vais poster ca en event ^^ |
|