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.

Relection Script: Reworked

Hey,

I was wondering if anyone could quickly edit the reflection script for use with rounded water autotiles, so that the corners do not show the relection over the area of land. This would solve alot of peoples qualms with the script and would benefit my game at the same time.

The other thing, whilst not essential, but would be nice if possible is the relection itself. When facing side on to a reflectable surface, the characters right side will reflect in the mirror when the player is facing right. It should be the left side and vice-versa, is there any way to show the opposite side and flip the image easily?

Here's the reflection script to help:

Code:
#==============================================================================
# â–  Sprite_Reflection
# Based on Sprite_Mirror, Modified By: JmsPlDnl, rewritten entirely by Rataime
#==============================================================================
CATERPILLAR_COMPATIBLE = true

class Game_Party
  attr_reader :characters
end

class Sprite_Reflection < RPG::Sprite

 attr_accessor :character

 def initialize(viewport=nil, character=nil,self_angle = 180)
   super(viewport)
   @character = character
   @self_angle=self_angle
   self.opacity=0
   @reflected=false
   @former=false
   @moving=false
   if $game_map.terrain_tag(@character.real_x/128,@character.real_y/128+1)==7
     @reflected=true
     @former=true
   end
   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== 6
           sy = ( 4- 2) / 2 * @ch
     end
     if @character.direction== 4
           sy = ( 6- 2) / 2 * @ch
    end
    if @character.direction != 4 and @character.direction != 6
          sy = (@character.direction - 2) / 2 * @ch
    end
   end
   
   self.x = @character.screen_x
   self.y = @character.screen_y-5
   @moving=!(@character.real_x%128==0 and @character.real_y%128==0)
   @d=@character.direction
   @rect=[sx, sy, @cw, @ch]
   if !(@moving)
     if $game_map.terrain_tag(@character.real_x/128,@character.real_y/128+1)==7 
       @reflected=true
       @former=true
     else
       @reflected=false  
       @former=false
     end
     
   else
       case @d
       
       when 2
       if $game_map.terrain_tag(@character.real_x/128,@character.real_y/128+2)==7
         @reflected=true
         if @former==false
           @offset = (@character.screen_y%32)*@ch/32
           @rect=[sx, sy, @cw, @offset]
           self.y=@character.screen_y-5
         end
       else
         @reflected=false  
       end
       
       when 4
       if $game_map.terrain_tag(@character.real_x/128,@character.real_y/128+1)!=7
         @offset = ((@character.screen_x-@cw/2)%32)*@cw/32
         @rect=[sx, sy, @offset, @ch]
         self.x=@character.screen_x
       else
         @reflected=true
         if @former==false
           @offset = ((@character.screen_x-@cw/2)%32)*@cw/32
           @rect=[sx+@offset, sy, @cw-@offset, @ch]
           self.x=@character.screen_x-@offset
         end
       end
       
       when 6
       if $game_map.terrain_tag(@character.real_x/128+1,@character.real_y/128+1)!=7
         @offset = ((@character.screen_x-@cw/2)%32)*@cw/32
         @rect=[sx+@offset, sy, @cw-@offset, @ch]
         self.x=@character.screen_x-@offset
       else
         @reflected=true
         if @former==false
           @offset = ((@character.screen_x-@cw/2)%32)*@cw/32
           @rect=[sx, sy, @offset, @ch]
           self.x=@character.screen_x
         end
       end
       
       when 8
       if $game_map.terrain_tag(@character.real_x/128,@character.real_y/128+2)==7
         @reflected=true
         if $game_map.terrain_tag(@character.real_x/128,@character.real_y/128+1)!=7
           @offset = (@character.screen_y%32)*@ch/32
           @rect=[sx, sy, @cw, @offset]
           self.y=@character.screen_y-5
         end
       else
         @reflected=false  
       end
       
       end

   end
   if @reflected
     self.opacity=128
   else
    @rect=[sx, sy, @cw, @ch]
    self.opacity=0
   end
   
   if $game_map.terrain_tag((@character.real_x+64)/128,@character.real_y/128+2)!=7
     if $game_map.terrain_tag((@character.real_x+64)/128,@character.real_y/128+2)!=7
       @rect[1]= @rect[1]+@ch/2
       @rect[3]= @rect[3]/2
       self.y = self.y - @ch/2
     else
       @reflected=false
     end
   end
     
   self.src_rect.set(@rect[0],@rect[1],@rect[2],@rect[3])
   
   @character.is_a?(Game_Player) ? self.z = 9 : self.z = 5
   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

   self.angle = @self_angle
 end
end

#===================================================
# â–¼ CLASS Sprite_Character edit
#===================================================

class Sprite_Character < RPG::Sprite
  alias reflect_initialize initialize
  
  def initialize(viewport, character = nil)
    @character = character
    @reflection = []
    super(viewport)
    if (character.is_a?(Game_Event) and character.list!=nil and character.list[0].code == 108 and character.list[0].parameters == ["r"])
     @reflection.push(Sprite_Reflection.new(viewport,@character))
    end
    if (character.is_a?(Game_Event) and character.list!=nil and character.list[0].code == 108 and character.list[0].parameters == ["hero_r"])
     @reflection.push(Sprite_Reflection.new(viewport,$game_player))
#===================================================
# ● Compatibility with fukuyama's caterpillar script
#===================================================
if CATERPILLAR_COMPATIBLE and $game_party.characters!=nil

  for member in $game_party.characters
    @reflection.push(Sprite_Reflection.new(viewport,member))
  end

end
#===================================================
# ● End of the compatibility
#===================================================
    end
    reflect_initialize(viewport, @character)
  end
  
  alias reflect_update update
  
  def update
   reflect_update
   if @reflection!=nil
     for reflect in @reflection
       reflect.update
     end
   end
  end
  
end
 
Actually, Rataime does have a workaround...

If you have a matching set of tiles to the 'autotiles' that draw the water (minus the water / only showing the grass/shoreline), then you can draw these tiles on layer 2. They should be exact copies of the autotiles, except that you'd have the water replaced with the 'transparent color', so when they're drawn in layer 2, the layer 1 water shows through. As the layer1 tiles are set up to reflect the hero's image, the layer2 tiles block all land visible on the map... so only the water reflects.

This is subject to you making the matching tiles with the 'transparent' color in place of the water... of course. :D
 
I see what you mean... It's a very good idea.

I happen to personally use a rounded water autotile with a transparent shoreline though, so that it can be used atop of every environment as opposed to grass. I assume I would have to make the edges for every type of terrain that I use throughout the game.

So is there no quicker "scripted" fix to just not show a reflection in the corner pieces at all? I'm assuming it wouldn't be too noticeable. Otherwise I guess I'll persevere with making the blocking terrain pieces.

Also, any idea's on a fix to the second problem on reflecting the opposite side rather than the same side?

Thanks
 
Nah, and either this or his mirror script won't show 'trailing' characters... don't remember which. Think it was mirror. Glad they both work with his Visual Equipment script though.

Maybe we should check fotz's Pixelmovement script. He's added almost everything else into it, eh?
 
I'm not bothered by trailing character issues, I used to use them in past projects but found them to be a pain in general.

I'm not familiar with fotz's features in the pixel script, I don't need it so I haven't paid any attention to it really. You're suggesting there may be a new method for reflections within his script that fixes the aforementioned issue?
 
DerVVulfman said:
Well, if he doesn't have one now... maybe we should ask him. He added mapwrap when I asked him for it.

^^By saying that, does that mean you have already asked him?

Once it was added to the pixel movement script, I wouldn't know how to make it a standalone script though by extracting the right section + adding any new coding that would be needed. And of course it isn't just necessary to just fit in ratiames version, but to make a new version addressing the initial drawbacks of raitaimes.
 
Heh. I told him of the problem I had getting a mapwrap feature (either Dirtie's script or KGC's script) to work properly with SBABS caterpillar system or fukuyama's Train Actor script. As the hero crossed the border with his following party, the party disappeared until he got far enough away so the rest of the party showed up.

Fotz' got it RIGHT. Even crossing these mapwrap/worldmap-like borders, the rest of the party stays visible and DOESN'T disappear.

Just took a look at what he's implemented:
- Pixelmovement
- Collision Maps (optional!)
- Variable Event-Sizes (optional!)
- individual RGSS-Move-Commands
- New Global Methods: (load bitmap, char_sprite, in_range?)
- 8-Directions (required) / more frames (optional!)
- Isometric Script (optional!)
- Caterpillar Script (optional!)
- Sprint/Sneak Script (optional!)
- Pathfinding
- Anti-Lag-Script
- Minimap Script (optional!)
- Looping Maps (optional!)
- Sliding Script (optional!)
- Maps are saved after teleporting
- Jump Script (optional!)
- Surface Script (optional!)
- Pixel Event Setting


What is not implemented yet?
- Improvement of Height/Swamp
- general Obstacles when no Collision Map exists
- Ice floor (two different forms)
- Fog of War


What's the harm in asking for Rataime's system? He'll probably see the request and say... "Damn, I actually missed something?" :D

Go for it... give it a shot.
 
Okay, thanks I'll ask in his thread, but what I meant was that will it cause me problems having the pixel movement script with all my existing scripts - by the looks of the amount of things in there I was guessing it would. But then again, seeing as this is becoming the ultimate of scripts, I guess many of it's other features could prove beneficial too and I should try and fit it in.
 

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