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.

Sized Events

Toby

Member

Sorry for taking so long to post a fix! This should do it:

Code:
#--------------------------------------------------------------------------
# *** Sized Events v0.2
#--------------------------------------------------------------------------
#   By Toby Zerner
#   Enables events to be sized; occupy more space than 1 tile.
#--------------------------------------------------------------------------
#   USAGE:
#   In a parallel process event, call this script:
#     $game_map.events[ID].size(SIZE_X, SIZE_Y)
#   If you would like a different size for horizontal/vertical directions,
#   call use this:
#     $game_map.events[ID].size(HORIZ_SIZE_X, HORIZ_SIZE_Y, VERT_SIZE_X, VERT_SIZE_Y)
#   Optionally, you can call the size inside a comment instead:
#     Comment: size(SIZE_X,SIZE_Y)
#   Or:
#     Comment: size(H_SIZE_X,H_SIZE_Y,V_SIZE_X,V_SIZE_Y)
#--------------------------------------------------------------------------

class Game_Character
  
  # New class sizing variables
  attr_accessor :vertical_size_x          # Size X when facing a vertical direction
  attr_accessor :vertical_size_y          # Size Y when facing a vertical direction
  attr_accessor :horizontal_size_x        # Size X when facing a horizontal direction
  attr_accessor :horizontal_size_y        # Size Y when facing a horizontal direction
  attr_accessor :size_x                   # Current size X
  attr_accessor :size_y                   # Current size Y
  attr_accessor :tiles_left               # Number of tiles spanning to the left
  attr_accessor :tiles_right              # Number of tiles spanning to the right
  
  # Initialize new variables
  def initialize
    @id = 0
    @x = 0
    @y = 0
    @real_x = 0
    @real_y = 0
    @tile_id = 0
    @character_name = ""
    @character_hue = 0
    @opacity = 255
    @blend_type = 0
    @direction = 2
    @pattern = 0
    @move_route_forcing = false
    @through = false
    @animation_id = 0
    @transparent = false
    @original_direction = 2
    @original_pattern = 0
    @move_type = 0
    @move_speed = 4
    @move_frequency = 6
    @move_route = nil
    @move_route_index = 0
    @original_move_route = nil
    @original_move_route_index = 0
    @walk_anime = true
    @step_anime = false
    @direction_fix = false
    @always_on_top = false
    @anime_count = 0
    @stop_count = 0
    @jump_count = 0
    @jump_peak = 0
    @wait_count = 0
    @locked = false
    @prelock_direction = 0
    @vertical_size_x = 1
    @vertical_size_y = 1
    @horizontal_size_x = 1
    @horizontal_size_y = 1
    @size_x = 1
    @size_y = 1
    @tiles_left = 0
    @tiles_right = 0
  end
  
  #--------------------------------------------------------------------------
  # * Change the size of an event
  #     x : x size (horizontally-facing x if vx/vy are defined)
  #     y : y size (horizontally-facing y if vx/vy are defined)
  #     vx : vertically-facing x size (optional)
  #     vy : vertically-facing y size (optional)
  #--------------------------------------------------------------------------
  def size(x, y, vx = false, vy = false)
    # If we have vertical sizes, then we also have separate horizontal sizes
    if vx and vy
      @vertical_size_x   = vx.to_i
      @vertical_size_y   = vy.to_i
      @horizontal_size_x = x.to_i
      @horizontal_size_y = y.to_i
    # Otherwise we've got the same size for both directions
    else
      @vertical_size_x = @horizontal_size_x = x
      @vertical_size_y = @horizontal_size_y = y
    end
    # Initialize the size variables
    set_size(@direction)
  end
  
  #--------------------------------------------------------------------------
  # * Change the size variables depending on the event direction
  #     d : event direction
  #--------------------------------------------------------------------------
  def set_size(d = 2)
    # Set the size variables depending on the direction
    # Up and down - vertical
    if d == 2 or d == 8
      @size_x = @vertical_size_x.to_i
      @size_y = @vertical_size_y.to_i
    # Left and right - horizontal
    else
      @size_x = @horizontal_size_x.to_i
      @size_y = @horizontal_size_y.to_i
    end
    # Work out the number of tiles either side of the event
    tiles_x      = (@size_x - 1) / 2
    @tiles_left  = tiles_x.floor
    @tiles_right = tiles_x.ceil
    if @tiles_left + @tiles_right + 1 < @size_x then @tiles_left += 1 end
  end
  
  #--------------------------------------------------------------------------
  # * Determine if Passable
  #     x : x-coordinate
  #     y : y-coordinate
  #     d : direction (0,2,4,6,8)
  #         * 0 = Determines if all directions are impassable (for jumping)
  #--------------------------------------------------------------------------
  def passable?(x, y, d)
    # Update the size variables
    if d != 0 then set_size(d) end
    # 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, passable
    return true if @through
    # If there is no character set, passable
    return true if @character_name == ""
    
    # Check map passability settings
    # Loop through each x tile
    for i in 0...@size_x
      # Loop through each y tile
      for j in 0...@size_y
        # If unable to leave first move tile in designated direction
        unless $game_map.passable?(x - @tiles_left + i, y - j, d, self) then return false end
        # If unable to enter move tile in designated direction
        unless $game_map.passable?(new_x - @tiles_left + i, new_y - j, 10 - d) then return false end
      end
    end
    
    # Loop through map events
    for event in $game_map.events.values
      # If self is in range of [event]'s sizing, we can't pass
      return false if event_collide?(self, event, new_x, new_y) and
        event.character_name != "" and not event.through
    end

    # If player coordinates are consistent with move destination
    if event_collide?(self, $game_player, new_x, new_y) and self != $game_player
      return false
    end

    # Passable
    return true
  end
  
  #--------------------------------------------------------------------------
  # * Check if two events collide
  #     event1 : the first event
  #     event2 : the second event
  #     new_x  : the new x coordinate of event 1
  #     new_y  : the new y coordinate of event 1
  #--------------------------------------------------------------------------
  def event_collide?(event1, event2, new_x, new_y)
    # Passable if the events are the same
    return false if event1.id == event2.id
    # Work out some coordinate variables for easy reference
    event1_left   = new_x - event1.tiles_left
    event1_right  = new_x + event1.tiles_right
    event1_top    = new_y - (event1.size_y - 1)
    event1_bottom = new_y
    event2_left   = event2.x - event2.tiles_left
    event2_right  = event2.x + event2.tiles_right
    event2_top    = event2.y - (event2.size_y - 1)
    event2_bottom = event2.y
    # Check if the events are in range of each other
    if event1_left <= event2_right and event2_left <= event1_right and
      event1_right >= event2_left and event2_right >= event1_left and
      event1_top <= event2_bottom and event2_top <= event2_bottom and
      event1_bottom >= event2_top and event2_bottom >= event1_top
      # They are - the events collide
      return true
    end
    # No collision
    return false
  end
  
end

# Game_Player edits - check various player collisions
class Game_Player
  
  #--------------------------------------------------------------------------
  # * Same Position Starting Determinant
  #--------------------------------------------------------------------------
  def check_event_trigger_here(triggers)
    result = false
    # If event is running
    if $game_system.map_interpreter.running?
      return result
    end
    # All event loops
    for event in $game_map.events.values
      # If event coordinates and triggers are consistent
      # If player's coordinates collide with the event and its sizing
      if event_collide?(self, event, @x, @y) and 
        triggers.include?(event.trigger)
        # If starting determinant is same position event (other than jumping)
        if not event.jumping? and event.over_trigger?
          event.start
          result = true
        end
      end
    end
    return result
  end
  #--------------------------------------------------------------------------
  # * Front Envent Starting Determinant
  #--------------------------------------------------------------------------
  def check_event_trigger_there(triggers)
    result = false
    # If event is running
    if $game_system.map_interpreter.running?
      return result
    end
    # Calculate front event coordinates
    new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
    new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
    # All event loops
    for event in $game_map.events.values
      # If event coordinates and triggers are consistent
      # If player's new coordinates collide with the event and its sizing
      if event_collide?(self, event, new_x, new_y) and
        triggers.include?(event.trigger)
        # If starting determinant is front event (other than jumping)
        if not event.jumping? and not event.over_trigger?
          event.start
          result = true
        end
      end
    end
    # If fitting event is not found
    if result == false
      # If front tile is a counter
      if $game_map.counter?(new_x, new_y)
        # Calculate 1 tile inside coordinates
        new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
        new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
        # All event loops
        for event in $game_map.events.values
          # If event coordinates and triggers are consistent
          # If player's new coordinates collide with the event and its sizing
          if event_collide?(self, event, new_x, new_y) and
             triggers.include?(event.trigger)
            # If starting determinant is front event (other than jumping)
            if not event.jumping? and not event.over_trigger?
              event.start
              result = true
            end
          end
        end
      end
    end
    return result
  end
  #--------------------------------------------------------------------------
  # * Touch Event Starting Determinant
  #--------------------------------------------------------------------------
  def check_event_trigger_touch(x, y)
    result = false
    # If event is running
    if $game_system.map_interpreter.running?
      return result
    end
    # All event loops
    for event in $game_map.events.values
      # If passed coordinates collide with the event and its sizing
      if event_collide?(self, event, x, y) and [1,2].include?(event.trigger)
        event.start
        result = true
      end
    end
    return result
  end
  
end

# Sprite_Character edit - check for sizing comment
class Sprite_Character
  def initialize(viewport, character = nil)
    super(viewport)
    @character = character
    if character.is_a?(Game_Event) and character.list != nil
      for i in 0...character.list.size
        if character.list[i].code == 108
          comment = character.list[i].parameters[0]
          # Format should be: size(hx, hy[, vx, vy])
          if values = /size\((([\d]+[,]?[ ]*){2,4})\)/i.match(comment)
            sizes = values[1].split(/,\s*/)
            if (sizes.size == 4)
              character.size(sizes[0], sizes[1], sizes[2], sizes[3])
            else
              character.size(sizes[0], sizes[1])
            end
          end
        end
      end
    end
    update
  end
end

@dams999: Yes, it is possible to resize the main character. Use this command:
Code:
$game_player.size(SIZE_X, SIZE_Y)
 
nice fix :) you might want to consider altering the version in the first post though lol it still contains the errors mentioned previous. tis a wicked script though compadre :)
will make a nice change to have more than two names on the credits lol
 

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