Mirror Script?

Started by Ryex, January 27, 2008, 08:56:17 am

Previous topic - Next topic

Ryex

IS it possible to make a script the duplacates a mirror? like you stand in frount of it and your reflection appears?
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Calintz

I think that would be cool, but I think it's do-able...I'm not advanced enuff to try this, but I've seen this done in rivers and lakes in other ppls games, so I'd say it's possible...

Blizzard

I should actually be fairly simple. But the lag factor could be pretty high if not made well. It's a bit tricky to set up the viewpoint when I now think of it.
Check out our game brands:

Daygames
Game Night Games
Chugnar Games

Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Punn

Look for Retaime's script, in his script bed, theres some. Unless you want me to post it..I do it later

Blizzard

Didn't he only have a water reflection script? O_o
Check out our game brands:

Daygames
Game Night Games
Chugnar Games

Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Punn


Nortos

Water reflection script would be just alike mirrors practically but ripply

Calintz

Haha, that would be funny...
- But useful if you had a Nemesis like looking into his cauldron and seeing the hero or something...

Punn

January 27, 2008, 06:47:35 pm #8 Last Edit: January 27, 2008, 06:57:52 pm by Blizzard
On a event, put in comments

Like this

Comment: m
Comment: 120

Spoiler: ShowHide

#==============================================================================
# ? Sprite_Mirror
# Based on Sprite_Shadow, modified by Rataime
#==============================================================================

class Sprite_Mirror < RPG::Sprite

attr_accessor :character
attr_accessor :events
attr_accessor :event_y

def initialize(viewport=nil)
   super(viewport)
   @character = $game_player
   @events=0
   @event_y=0
   self.opacity=0
   update
end

def update
   super
   if @tile_id != @character.tile_id or
      @character_name != @character.character_name or
      @character_hue != @character.character_hue
     @tile_id = @character.tile_id
     @character_name = @character.character_name
     @character_hue = @character.character_hue
     if @tile_id >= 384
       self.bitmap = RPG::Cache.tile($game_map.tileset_name,
         @tile_id, @character.character_hue)
       self.src_rect.set(0, 0, 32, 32)
       self.ox = 16
       self.oy = 32
     else
       self.bitmap = RPG::Cache.character(@character.character_name,
         @character.character_hue)
       @cw = bitmap.width / 4
       @ch = bitmap.height / 4
       self.ox = @cw / 2
       self.oy = @ch
     end
   end
   self.visible = (not @character.transparent)
   if @tile_id == 0
     sx = (@character.pattern) * @cw
     sy = (@character.direction - 2) / 2 * @ch
     if @character.direction==8
       sy = 0 * @ch
     end
     if @character.direction==2
       sy = 3 * @ch
     end
     self.src_rect.set(sx, sy, @cw, @ch)
   end
   self.x = @character.screen_x
   self.y = self.event_y-($game_player.screen_y-self.event_y).abs+30
   self.z = 10
   self.blend_type = @character.blend_type
   self.bush_depth = @character.bush_depth
   if @character.animation_id != 0
     animation = $data_animations[@character.animation_id]
     animation(animation, true)
     @character.animation_id = 0
   end
end
end

#===================================================
# ? CLASS Sprite_Character edit
#===================================================

class Sprite_Character < RPG::Sprite
  alias mirror_initialize initialize
 
  def initialize(viewport, character = nil)
    @character = character
    super(viewport)
    if character.is_a?(Game_Player)
     $game_map.mirror=Sprite_Mirror.new(viewport)
    end
    mirror_initialize(viewport, @character)
  end
 
  alias mirror_update update
 
  def update
   mirror_update
   if (@mirror!=nil and character.is_a?(Game_Event) and character.list!=nil and character.list[0].code == 108 and character.list[0].parameters == ["m"])
     if $game_player.screen_y-self.y<80 and self.y<$game_player.screen_y and ($game_player.screen_x-self.x).abs<17
       if (character.list[1]!=nil and character.list[1].code == 108)
         @mirror.opacity=character.list[1].parameters[0].to_f
       else
         @mirror.opacity=$game_player.opacity
       end
       @mirror.events=self.id
       @mirror.event_y=self.y
     else
       if @mirror.events==self.id
         @mirror.events=0
       else
         if @mirror.events==0
           @mirror.opacity=0
         end
       end
     end
   end
   @mirror=$game_map.mirror
   if character.is_a?(Game_Player)
     @mirror.update
   end
  end
 
end

#===================================================
# ? CLASS Scene_Save edit
#===================================================
class Scene_Save < Scene_File
 
  alias mirror_write_save_data write_save_data
 
  def write_save_data(file)
    $game_map.mirror = nil
    mirror_write_save_data(file)
  end
end

#===================================================
# ? CLASS Game_Map edit
#===================================================
class Game_Map
  attr_accessor :mirror
end

#===================================================
# ? CLASS Scene_Map edit
#===================================================
class Spriteset_Map
 
  alias mirror_map_initialize initialize
 
  def initialize
    $game_map.mirror=nil
    mirror_map_initialize
  end
end

alexthemusicdude

Quote from: mumerus on January 27, 2008, 06:47:35 pm
On a event, put in comments

Like this

Comment: m
Comment: 120

Spoiler: ShowHide

#==============================================================================
# ? Sprite_Mirror
# Based on Sprite_Shadow, modified by Rataime
#==============================================================================

class Sprite_Mirror < RPG::Sprite

attr_accessor :character
attr_accessor :events
attr_accessor :event_y

def initialize(viewport=nil)
   super(viewport)
   @character = $game_player
   @events=0
   @event_y=0
   self.opacity=0
   update
end

def update
   super
   if @tile_id != @character.tile_id or
      @character_name != @character.character_name or
      @character_hue != @character.character_hue
     @tile_id = @character.tile_id
     @character_name = @character.character_name
     @character_hue = @character.character_hue
     if @tile_id >= 384
       self.bitmap = RPG::Cache.tile($game_map.tileset_name,
         @tile_id, @character.character_hue)
       self.src_rect.set(0, 0, 32, 32)
       self.ox = 16
       self.oy = 32
     else
       self.bitmap = RPG::Cache.character(@character.character_name,
         @character.character_hue)
       @cw = bitmap.width / 4
       @ch = bitmap.height / 4
       self.ox = @cw / 2
       self.oy = @ch
     end
   end
   self.visible = (not @character.transparent)
   if @tile_id == 0
     sx = (@character.pattern) * @cw
     sy = (@character.direction - 2) / 2 * @ch
     if @character.direction==8
       sy = 0 * @ch
     end
     if @character.direction==2
       sy = 3 * @ch
     end
     self.src_rect.set(sx, sy, @cw, @ch)
   end
   self.x = @character.screen_x
   self.y = self.event_y-($game_player.screen_y-self.event_y).abs+30
   self.z = 10
   self.blend_type = @character.blend_type
   self.bush_depth = @character.bush_depth
   if @character.animation_id != 0
     animation = $data_animations[@character.animation_id]
     animation(animation, true)
     @character.animation_id = 0
   end
end
end

#===================================================
# ? CLASS Sprite_Character edit
#===================================================

class Sprite_Character < RPG::Sprite
  alias mirror_initialize initialize
 
  def initialize(viewport, character = nil)
    @character = character
    super(viewport)
    if character.is_a?(Game_Player)
     $game_map.mirror=Sprite_Mirror.new(viewport)
    end
    mirror_initialize(viewport, @character)
  end
 
  alias mirror_update update
 
  def update
   mirror_update
   if (@mirror!=nil and character.is_a?(Game_Event) and character.list!=nil and character.list[0].code == 108 and character.list[0].parameters == ["m"])
     if $game_player.screen_y-self.y<80 and self.y<$game_player.screen_y and ($game_player.screen_x-self.x).abs<17
       if (character.list[1]!=nil and character.list[1].code == 108)
         @mirror.opacity=character.list[1].parameters[0].to_f
       else
         @mirror.opacity=$game_player.opacity
       end
       @mirror.events=self.id
       @mirror.event_y=self.y
     else
       if @mirror.events==self.id
         @mirror.events=0
       else
         if @mirror.events==0
           @mirror.opacity=0
         end
       end
     end
   end
   @mirror=$game_map.mirror
   if character.is_a?(Game_Player)
     @mirror.update
   end
  end
 
end

#===================================================
# ? CLASS Scene_Save edit
#===================================================
class Scene_Save < Scene_File
 
  alias mirror_write_save_data write_save_data
 
  def write_save_data(file)
    $game_map.mirror = nil
    mirror_write_save_data(file)
  end
end

#===================================================
# ? CLASS Game_Map edit
#===================================================
class Game_Map
  attr_accessor :mirror
end

#===================================================
# ? CLASS Scene_Map edit
#===================================================
class Spriteset_Map
 
  alias mirror_map_initialize initialize
 
  def initialize
    $game_map.mirror=nil
    mirror_map_initialize
  end
end



Is there a way to:

1. add a reflection when you approach the event from the top? right now it only works if you're below it and walk "up" towards it.

2. add in additional characters in a catepillar script? right now I'm only seeing a reflection of the main character, even if i have 3 reflections side to side and walk from one end to the other

thx

alexthemusicdude