Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Event passage through other event, but not impassable tiles

Culex

Member

I would like for the events to be configured so that when they're set to "Through," they can pass through other events or the player but NOT impassable tiles.

Example: There's a room full of rats and you have to wade through them. Rather than waiting for them to move or get stuck in a narrow hallway with them, they can just pass through the player or vice-versa (they're small enough for it not to look too silly). If they're set to "Through" normally, they'll obviously pass right through the walls. ;D

I thought about setting variables to each rat's coordinates and then make a parallel process that moves them to another space when their coordinates get too close to where a wall would be...but for each rat in the room...aye, that would be cumbersome... :P

Thank you for looking into this!  :)
 

poccil

Sponsor

That involves modifying the _passable?_ method of Game_Character.  Put the following code in a new script section.  The changed method works as normal but grants a special passability exception to events named "Rat".

Code:
class Game_Character
  def passable?(x, y, d)
    # Get new coordinates
    new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
    new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
    # If coordinates are outside of map
    unless $game_map.valid?(new_x, new_y)
      # impassable
      return false
    end
    # If through is ON
    if @through
      # passable if the event isn't a Rat
      if !@event || @event.name!="Rat"
        return true
      end
    end
    # If unable to leave first move tile in designated direction
    unless $game_map.passable?(x, y, d, self)
      # impassable
      return false
    end
    # If unable to enter move tile in designated direction
    unless $game_map.passable?(new_x, new_y, 10 - d)
      # impassable
      return false
    end
    # If through is ON (second check)
    if @through
      # passable
      return true
    end
    # Loop all events
    for event in $game_map.events.values
      # 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
    # If player coordinates are consistent with move destination
    if $game_player.x == new_x and $game_player.y == new_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
    # passable
    return true
  end
end
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top