Chaos Project

RPG Maker => RPG Maker Scripts => Script Requests => Topic started by: Parkman202 on April 11, 2015, 03:53:44 pm

Title: [XP] Pixel Movement and Collision Maps
Post by: Parkman202 on April 11, 2015, 03:53:44 pm
Hello, everyone! I've been trying to figure out how to do this for some time now; and I keep running into things that either don't work or run in RPG Maker VX\Ace.

What I've been trying to do is to modify a simple pixel movement script to allow the player to collide with the objects by, instead of a 32 x 32 tile, the pixel itself using a black and white color map. The reason why is because I am attempting to make isometric-ish maps with both Blender and pixel-by-pixel tracing and tiling.

I don't know if RGSS1 can do this, but I have seen it in RGSS2/3A. I've also seen similar black and white tiling done with H-Mode 7, a limited (but very awesome) third-dimensional script for RPG Maker XP. However, H-Mode 7 used them for a different aspect, but it's kid of the same.

If anyone can find a script for me anywhere, that would be great! Thanks!

P.S. If it's needed, here's my pixel movement script:

#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
# DRG - Pixel Movement
# Version: 1.03
# Author : LiTTleDRAgo
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
($imported ||= {})[:drg_pixel_movement] = 1.03
#==============================================================================
#
# Introduction :
#
#   This script makes player's movement became pixel movement
#
#==============================================================================
#==============================================================================
# ** Game_Character
#------------------------------------------------------------------------------
#  This class deals with characters. It's used as a superclass for the
#  Game_Player and Game_Event classes.
#==============================================================================

class Game_Character
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :pixel_movement
  #--------------------------------------------------------------------------
  # * Constant
  #--------------------------------------------------------------------------
  ALIASING_PIXEL = lambda do |x|
    [:move_down,:move_left,:move_right,:move_up].each do |meth|
      $@ || alias_method(:"#{meth}_unpixel_#{x}", :"#{meth}")
      define_method(:"#{meth}") do |*a|
        pixel_disable ? reset_pixel &&
        send(:"#{meth}_unpixel_#{x}",*a) : send(:"#{meth}_pixel",*a)
      end
    end
    [:move_lower_left,:move_lower_right,:move_upper_left,
     :move_upper_right].each do |meth|
      $@ || alias_method(:"#{meth}_unpixel_#{x}", :"#{meth}")
      define_method(:"#{meth}") do |*a|
        reset_pixel && send(:"#{meth}_unpixel_#{x}",*a)
      end
    end
  end
  #--------------------------------------------------------------------------
  # * xy_pixel_correction
  #--------------------------------------------------------------------------
  def xy_pixel_correction(direction)
    case direction
    when 2
      unless passable?(@x.ceil, @y.ceil, 2)
        @x = @x.floor if passable?(@x.floor, @y.ceil, 2)
      end
      unless passable?(@x.floor, @y.ceil, 2)
        @x = @x.ceil  if passable?(@x.ceil, @y.ceil, 2)
      end
    when 4
      unless passable?(@x.floor, @y.ceil, 4)
        @y = @y.floor if passable?(@x.floor, @y.floor, 4)
      end
      unless passable?(@x.floor, @y.floor, 4)
        @y = @y.ceil  if passable?(@x.floor, @y.ceil, 4)
      end
    when 6
      unless passable?(@x.floor, @y.ceil, 6)
        @y = @y.floor if passable?(@x.floor, @y.floor, 6)
      end
      unless passable?(@x.ceil, @y.floor, 6)
        @y = @y.ceil  if passable?(@x.ceil, @y.ceil, 6)
      end
    when 8
      unless passable?(@x.ceil, @y.floor, 8)
        @x = @x.floor if passable?(@x.floor, @y.floor, 8)
      end
      unless passable?(@x.floor, @y.floor, 8)
        @x = @x.ceil  if passable?(@x.ceil, @y.floor, 8)
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Pixel Disable
  #--------------------------------------------------------------------------
  def pixel_disable
    return true unless self.pixel_movement 
    return true if @move_route_forcing
    return false
  end
  #--------------------------------------------------------------------------
  # * reset_pixel
  #--------------------------------------------------------------------------
  def reset_pixel
    @x,@y = @x.floor,@y.floor
  end
  #--------------------------------------------------------------------------
  # * Move Down
  #     turn_enabled : a flag permits direction change on that spot
  #--------------------------------------------------------------------------
  def move_down_pixel(turn_enabled = true)
    @quarter = false
    turn_enabled && turn_down
    if passable?(@x, @y.floor, 2)
      turn_down
      xy_pixel_correction(2)
      @y += 0.5 if passable?(@x.floor, @y.floor, 2)
      increase_steps
    else
      check_event_trigger_touch(@x, @y+1)
    end
  end
  #--------------------------------------------------------------------------
  # * Move Left
  #     turn_enabled : a flag permits direction change on that spot
  #--------------------------------------------------------------------------
  def move_left_pixel(turn_enabled = true)
    @quarter = false
    turn_enabled && turn_left
    if passable?(@x.ceil, @y, 4)
      turn_left
      xy_pixel_correction(4)
      @x -= 0.5 if passable?(@x.ceil, @y.floor, 4)
      increase_steps
    else
      check_event_trigger_touch(@x-1, @y)
    end
  end
  #--------------------------------------------------------------------------
  # * Move Right
  #     turn_enabled : a flag permits direction change on that spot
  #--------------------------------------------------------------------------
  def move_right_pixel(turn_enabled = true)
    @quarter = false
    turn_enabled && turn_right
    if passable?(@x.floor, @y, 6)
      turn_right
      xy_pixel_correction(6)
      @x += 0.5 if passable?(@x.floor, @y.floor, 6)
      increase_steps
    else
      check_event_trigger_touch(@x+1, @y)
    end
  end
  #--------------------------------------------------------------------------
  # * Move up
  #     turn_enabled : a flag permits direction change on that spot
  #--------------------------------------------------------------------------
  def move_up_pixel(turn_enabled = true)
    @quarter = false
    turn_enabled && turn_up
    if passable?(@x, @y.ceil, 8)
      turn_up
      xy_pixel_correction(8)
      @y -= 0.5 if passable?(@x.floor, @y.ceil, 8)
      increase_steps
    else
      check_event_trigger_touch(@x, @y-1)
    end
  end
end

#==============================================================================
# ** Game_Player
#------------------------------------------------------------------------------
#  This class handles the player. Its functions include event starting
#  determinants and map scrolling. Refer to "$game_player" for the one
#  instance of this class.
#==============================================================================
class Game_Player
  #--------------------------------------------------------------------------
  # * Constant
  #--------------------------------------------------------------------------
  ALIASING_PIXEL.call(0)
  #--------------------------------------------------------------------------
  # * Alias Method
  #--------------------------------------------------------------------------
  unless method_defined?(:pixel_check_touch)
    alias_method :pixel_initialize,   :initialize
    alias_method :pixel_check_here,   :check_event_trigger_here
    alias_method :pixel_check_there,  :check_event_trigger_there
    alias_method :pixel_check_touch,  :check_event_trigger_touch
  end
  #--------------------------------------------------------------------------
  # * Pixel Movement
  #--------------------------------------------------------------------------
  def initialize(*args)
    pixel_initialize(*args)
    @pixel_movement = true
  end
  #--------------------------------------------------------------------------
  # * Touch Event Starting Determinant
  #--------------------------------------------------------------------------
  def check_event_trigger_touch(x, y)
    result = pixel_check_touch(x, y)
    return result if $game_system.map_interpreter.running?
    event = $game_map.events.values.select do |e| 
      (x-e.x).abs < 1 && (y-e.y).abs < 1 &&
      [1,2].include?(e.trigger) && !e.jumping? && e.over_trigger?
    end
    (result = true) && event.first.start unless event.empty?
    return result
  end
  #--------------------------------------------------------------------------
  # * Same Position Starting Determinant
  #--------------------------------------------------------------------------
  def check_event_trigger_here(t)
    result = pixel_check_here(t)
    return result if $game_system.map_interpreter.running?
    event = $game_map.events.values.select do |e|
      (@x-e.x).abs < 1&& (@y-e.y).abs < 1 &&
      t.include?(e.trigger) && !e.jumping? && e.over_trigger?
    end
    (result = true) && event.first.start unless event.empty?
    return result
  end
  #--------------------------------------------------------------------------
  # * Front Envent Starting Determinant
  #--------------------------------------------------------------------------
  def check_event_trigger_there(t)
    result = pixel_check_there(t)
    return result if $game_system.map_interpreter.running?
    x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
    y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
    event = $game_map.events.values.select do |e|
      (x-e.x).abs < 1 && (y-e.y).abs < 1 &&
      t.include?(e.trigger) && !e.jumping? && e.over_trigger?
    end
    (result = true) && event.first.start unless event.empty?
    if result == false && $game_map.counter?(x.round, y.round)
      x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
      y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
      event = $game_map.events.values.select do |e|
        (x-e.x).abs < 1 && (y-e.y).abs < 1 &&
        t.include?(e.trigger) && !e.jumping? && e.over_trigger?
      end
      (result = true) && event.first.start unless event.empty?
    end
    return result
  end
end
Title: Re: [XP] Pixel Movement and Collision Maps
Post by: ForeverZer0 on April 11, 2015, 04:11:13 pm
I don't remember who wrote it, but I remember clearly seeing a pixel movement script for rmxp that used collision maps just as you are talking about. I don't know if it is on this site, though.
Title: Re: [XP] Pixel Movement and Collision Maps
Post by: Parkman202 on April 11, 2015, 04:14:03 pm
QuoteI don't remember who wrote it, but I remember clearly seeing a pixel movement script for rmxp that used collision maps just as you are talking about. I don't know if it is on this site, though.


I think that was someone asking for something with an ABS. I actually think I ran into that one, but there wasn't any script there. I could be wrong, though.
Title: Re: [XP] Pixel Movement and Collision Maps
Post by: ForeverZer0 on April 11, 2015, 09:23:39 pm
No, it was a full script, I am 100% sure, and it was not for an ABS. I will see if I can find it and provide a link.

EDIT:
Google for Cogwheel's pixel movement. If I remember correctly, he was the author.
Title: Re: [XP] Pixel Movement and Collision Maps
Post by: Parkman202 on April 11, 2015, 11:35:22 pm
QuoteEDIT:
Google for Cogwheel's pixel movement. If I remember correctly, he was the author.


I found it, but it still limits passability. I need a script that does something kind of like this, but for XP and not VX:

https://www.youtube.com/watch?v=8RUANqmxQ2k (https://www.youtube.com/watch?v=8RUANqmxQ2k)

From what I know, it uses a black and white copy of the tileset for collision (e.g. black is what you walk on, white is what you collide with, or vice-versa, ect.)
Title: Re: [XP] Pixel Movement and Collision Maps
Post by: G_G on April 11, 2015, 11:59:30 pm
I wanna say this was it.

http://www.hbgames.org/forums/viewtopic.php?f=156&t=624

I remember a long time ago I played the demo and almost clearly remember there being collision maps.

EDIT: Here's the script download, the first link in that topic is broke.
http://www.rpg-palace.com/mewsterus/Pixelmovement-1.6.zip
Title: Re: [XP] Pixel Movement and Collision Maps
Post by: ForeverZer0 on April 12, 2015, 12:50:04 am
Yep, that is the one I was thinking about. I had the author wrong, but that is the script. It has been years, but I clearly remember checking it out when I was first learning RMXP. :)
Title: Re: [XP] Pixel Movement and Collision Maps
Post by: Parkman202 on April 12, 2015, 12:54:42 am
QuoteEDIT: Here's the script download, the first link in that topic is broke.
http://www.rpg-palace.com/mewsterus/Pixelmovement-1.6.zip


Thank you, it works like a charm!