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.

[Resolved] Fog Priority Layers?

Basically, i was wondering if it is possible to create a fog script somehow so that any tiles with a priority of 5 or something are drawn above the fog. while all tiles without the priority of 5 are affected by the fog.

Here's the default screen of when you add a fog:
http://i61.photobucket.com/albums/h72/R ... ithfog.png[/img]


Here's a mock-up of what i'm trying to do (the fog is still on the level, but not on the roof):
http://i61.photobucket.com/albums/h72/R ... ithout.png[/img]

Any suggestions or existing scripts etc.?

Thanks for the help in advance,
RM
 
well yes in a sense, basically anything with a priority of 5 (as an example) would be "unfogged".

I've been attempting to script it myself for the past few days but am unfamiliar with RGSS, just know Turing and a bit of Java at the moment. Any help would be greatly appreciated.
 
This is a bit tricky because of the way the Tilemap is created. Each tile truthfully has it's own z dimension. The fog by default is set at 3000, way above your Tilemap.

I do have an idea however, that will create an additional tilemap (well, just a sprite), and put it on top of the fog when a tile has a certain terrain tag. This should cover it up.

Give me a few minutes to see what I can't come up with...
 
No more doing that. Here you go:

Code:
class Sprite_FogCover < Sprite
  attr_accessor :tileset_filename
  attr_accessor :autotiles
  attr_accessor :autotiles_name
  attr_accessor :terrain_tags
  attr_accessor :priorities
  attr_reader :map_data
  def initialize(viewport = nil)
    super(viewport)
    @refresh_data = nil
    @autotiles_name = []
  end
  def map_data=(map_data)
    @map_data = map_data
    if self.bitmap != nil
      self.bitmap.dispose
    end
    self.bitmap = Bitmap.new(@map_data.xsize * 32, @map_data.ysize * 32)
    refresh
  end
  def refresh
    @refresh_data = @map_data
    for z in 0...@map_data.zsize
      for x in 0...@map_data.xsize
        for y in 0...@map_data.ysize
          id = @map_data[x, y, z]
          next if id == 0
          next if terrain_tag(x, y) != 7
          id < 384 ? draw_autotile(x, y, id) : draw_tile(x, y, id)
        end
      end
    end  
  end
  def draw_tile(x, y, id)
    bit = RPG::Cache.tile(@tileset_name, id)
    self.bitmap.blt(x * 32, y * 32, bit, Rect.new(0, 0, 32, 32))
  end
  def draw_autotile(x, y, tile_id)
    filename = @autotiles_name[tile_id / 48 - 1]
    bit = RPG::Cache.autotile_tile(filename, tile_id % 48)
    self.bitmap.blt(x * 32, y * 32, bit, Rect.new(0, 0, 32, 32))
  end
  def update
    if @refresh_data != @map_data || Graphics.frame_count % 16 == 0
      refresh
    end  
  end
  def terrain_tag(x, y)
    for i in [2, 1, 0]
      tile_id = @map_data[x, y, i]
      if tile_id == nil
        return 0
      elsif @terrain_tags[tile_id] > 0
        return @terrain_tags[tile_id]
      end
    end
  end
end

class Spriteset_Map
  alias_method :seph_tilefogcover_scnmap_init, :initialize
  alias_method :seph_tilefogcover_scnmap_updt, :update
  def initialize
    seph_tilefogcover_scnmap_init
    @fog_cover_sprite = Sprite_FogCover.new(@viewport1)
    @fog_cover_sprite.tileset_filename = $game_map.tileset_name
    @fog_cover_sprite.autotiles = @tilemap.autotiles
    for i in 0..6
      @fog_cover_sprite.autotiles_name[i] = $game_map.autotile_names[i]
    end
    @fog_cover_sprite.terrain_tags = $game_map.terrain_tags
    @fog_cover_sprite.priorities = $game_map.priorities
    @fog_cover_sprite.map_data = $game_map.data
    @fog_cover_sprite.z = 3001
  end
  def update
    seph_tilefogcover_scnmap_updt
    unless @fog_cover_sprite.nil?
      @fog_cover_sprite.update 
      @fog_cover_sprite.ox = @tilemap.ox
      @fog_cover_sprite.oy = @tilemap.oy
    end
  end
end

module RPG::Cache
  #--------------------------------------------------------------------------
  # * Auto-Tiles
  #--------------------------------------------------------------------------
  Autotiles = [
    [[27, 28, 33, 34], [ 5, 28, 33, 34], [27,  6, 33, 34], [ 5,  6, 33, 34],
     [27, 28, 33, 12], [ 5, 28, 33, 12], [27,  6, 33, 12], [ 5,  6, 33, 12]],
    [[27, 28, 11, 34], [ 5, 28, 11, 34], [27,  6, 11, 34], [ 5,  6, 11, 34],
     [27, 28, 11, 12], [ 5, 28, 11, 12], [27,  6, 11, 12], [ 5,  6, 11, 12]],
    [[25, 26, 31, 32], [25,  6, 31, 32], [25, 26, 31, 12], [25,  6, 31, 12],
     [15, 16, 21, 22], [15, 16, 21, 12], [15, 16, 11, 22], [15, 16, 11, 12]],
    [[29, 30, 35, 36], [29, 30, 11, 36], [ 5, 30, 35, 36], [ 5, 30, 11, 36],
     [39, 40, 45, 46], [ 5, 40, 45, 46], [39,  6, 45, 46], [ 5,  6, 45, 46]],
    [[25, 30, 31, 36], [15, 16, 45, 46], [13, 14, 19, 20], [13, 14, 19, 12],
     [17, 18, 23, 24], [17, 18, 11, 24], [41, 42, 47, 48], [ 5, 42, 47, 48]],
    [[37, 38, 43, 44], [37,  6, 43, 44], [13, 18, 19, 24], [13, 14, 43, 44],
     [37, 42, 43, 48], [17, 18, 47, 48], [13, 18, 43, 48], [ 1,  2,  7,  8]]
  ]
  #--------------------------------------------------------------------------
  # * Autotile Cache
  #
  #   @autotile_cache = { 
  #     filename => { [autotile_id, frame_id, hue] => bitmap, ... },
  #     ...
  #    }
  #--------------------------------------------------------------------------
  @autotile_cache = {}
  #--------------------------------------------------------------------------
  # * Autotile Tile
  #--------------------------------------------------------------------------
  def self.autotile_tile(filename, tile_id, hue = 0, frame_id = nil)
    # Gets Autotile Bitmap
    autotile = self.autotile(filename)
    # Configures Frame ID if not specified
    if frame_id.nil?
      # Animated Tiles
      frames = autotile.width / 96
      # Configures Animation Offset
      fc = Graphics.frame_count / 16
      frame_id = (fc) % frames * 96
    end
    # Creates list if already not created
    @autotile_cache[filename] = {} unless @autotile_cache.has_key?(filename)
    # Gets Key
    key = [tile_id, frame_id, hue]
    # If Key Not Found
    unless @autotile_cache[filename].has_key?(key)
      # Reconfigure Tile ID
      tile_id %= 48
      # Creates Bitmap
      bitmap = Bitmap.new(32, 32)
      # Collects Auto-Tile Tile Layout
      tiles = Autotiles[tile_id / 8][tile_id % 8]
      # Draws Auto-Tile Rects
      for i in 0...4
        tile_position = tiles[i] - 1
        src_rect = Rect.new(tile_position % 6 * 16 + frame_id, 
          tile_position / 6 * 16, 16, 16)
        bitmap.blt(i % 2 * 16, i / 2 * 16, autotile, src_rect)
      end
      # Saves Autotile to Cache
      @autotile_cache[filename][key] = bitmap
      # Change Hue
      @autotile_cache[filename][key].hue_change(hue)
    end
    # Return Autotile
    return @autotile_cache[filename][key]
  end
end

Note: I took it from a demo with the MACL, so if an undefined method error occurs, let me know. I may have forgot to carryover something.

By default, the terrain tag is 7 to be drawn over the fog.

Enjoy! ^_^
 
I got another error :( I feel bad reporting them because I didn't even request it but here goes.  I think I may have noticed 2 things.

1 I'm not sure this includes autotiles because  I tried a plain room just with a ceiling autotile and the game loaded fine but the fog was same as ever.  I then assumed that this didn't support autotiles so tried a normal tile.

2 And got a wrong number of arguments on line 35 (2 of 3)

Sorry for the bad news man, this is a really cool fix though.

EDIT: No I see in the script that it may be that normal tiles are the part not supported.  I'll try and make it work again.

EDIT 2: I get that error with autotiles too.
 
Hey, that script is pretty good actually. Thanks for the help Seph!

However, i noticed the same problem as Calibre with the normal tiles: wrong number of arguments on line 35 (2 of 3)
Autotiles seem to work pretty great though.
 
Well just for reference, I definately get a script error on new game.  On line 35.  That is for both autotiles and normal tiles.  This was also definately in a new project.  It's not like I have anything I can visually show you in a demo.  I can upload the error screen if you wish but its definately on line 35 wrong number of arguments. 

To set it up, all i did was make a map on any interior, put just the ceiling autotile to terrain tag 7, added the fog to the tileset within the database (just for ease) and pressed new game but got the error.
 
Ok. Silly me. That's what I get for mass C&P.

Code:
class Sprite_FogCover < Sprite
  attr_accessor :tileset_name
  attr_accessor :autotiles
  attr_accessor :autotiles_name
  attr_accessor :terrain_tags
  attr_accessor :priorities
  attr_reader :map_data
  def initialize(viewport = nil)
    super(viewport)
    @refresh_data = nil
    @autotiles_name = []
  end
  def map_data=(map_data)
    @map_data = map_data
    if self.bitmap != nil
      self.bitmap.dispose
    end
    self.bitmap = Bitmap.new(@map_data.xsize * 32, @map_data.ysize * 32)
    refresh
  end
  def refresh
    @refresh_data = @map_data
    for z in 0...@map_data.zsize
      for x in 0...@map_data.xsize
        for y in 0...@map_data.ysize
          id = @map_data[x, y, z]
          next if id == 0
          next if terrain_tag(x, y) != 7
          id < 384 ? draw_autotile(x, y, id) : draw_tile(x, y, id)
        end
      end
    end  
  end
  def draw_tile(x, y, id)
    bit = RPG::Cache.tile(@tileset_name, id, 0)
    self.bitmap.blt(x * 32, y * 32, bit, Rect.new(0, 0, 32, 32))
  end
  def draw_autotile(x, y, tile_id)
    filename = @autotiles_name[tile_id / 48 - 1]
    bit = RPG::Cache.autotile_tile(filename, tile_id % 48)
    self.bitmap.blt(x * 32, y * 32, bit, Rect.new(0, 0, 32, 32))
  end
  def update
    if @refresh_data != @map_data || Graphics.frame_count % 16 == 0
      refresh
    end  
  end
  def terrain_tag(x, y)
    for i in [2, 1, 0]
      tile_id = @map_data[x, y, i]
      if tile_id == nil
        return 0
      elsif @terrain_tags[tile_id] > 0
        return @terrain_tags[tile_id]
      end
    end
  end
end

class Spriteset_Map
  alias_method :seph_tilefogcover_scnmap_init, :initialize
  alias_method :seph_tilefogcover_scnmap_updt, :update
  def initialize
    seph_tilefogcover_scnmap_init
    @fog_cover_sprite = Sprite_FogCover.new(@viewport1)
    @fog_cover_sprite.tileset_name = $game_map.tileset_name
    @fog_cover_sprite.autotiles = @tilemap.autotiles
    for i in 0..6
      @fog_cover_sprite.autotiles_name[i] = $game_map.autotile_names[i]
    end
    @fog_cover_sprite.terrain_tags = $game_map.terrain_tags
    @fog_cover_sprite.priorities = $game_map.priorities
    @fog_cover_sprite.map_data = $game_map.data
    @fog_cover_sprite.z = 3001
  end
  def update
    seph_tilefogcover_scnmap_updt
    unless @fog_cover_sprite.nil?
      @fog_cover_sprite.update 
      @fog_cover_sprite.ox = @tilemap.ox
      @fog_cover_sprite.oy = @tilemap.oy
    end
  end
end

module RPG::Cache
  #--------------------------------------------------------------------------
  # * Auto-Tiles
  #--------------------------------------------------------------------------
  Autotiles = [
    [[27, 28, 33, 34], [ 5, 28, 33, 34], [27,  6, 33, 34], [ 5,  6, 33, 34],
     [27, 28, 33, 12], [ 5, 28, 33, 12], [27,  6, 33, 12], [ 5,  6, 33, 12]],
    [[27, 28, 11, 34], [ 5, 28, 11, 34], [27,  6, 11, 34], [ 5,  6, 11, 34],
     [27, 28, 11, 12], [ 5, 28, 11, 12], [27,  6, 11, 12], [ 5,  6, 11, 12]],
    [[25, 26, 31, 32], [25,  6, 31, 32], [25, 26, 31, 12], [25,  6, 31, 12],
     [15, 16, 21, 22], [15, 16, 21, 12], [15, 16, 11, 22], [15, 16, 11, 12]],
    [[29, 30, 35, 36], [29, 30, 11, 36], [ 5, 30, 35, 36], [ 5, 30, 11, 36],
     [39, 40, 45, 46], [ 5, 40, 45, 46], [39,  6, 45, 46], [ 5,  6, 45, 46]],
    [[25, 30, 31, 36], [15, 16, 45, 46], [13, 14, 19, 20], [13, 14, 19, 12],
     [17, 18, 23, 24], [17, 18, 11, 24], [41, 42, 47, 48], [ 5, 42, 47, 48]],
    [[37, 38, 43, 44], [37,  6, 43, 44], [13, 18, 19, 24], [13, 14, 43, 44],
     [37, 42, 43, 48], [17, 18, 47, 48], [13, 18, 43, 48], [ 1,  2,  7,  8]]
  ]
  #--------------------------------------------------------------------------
  # * Autotile Cache
  #
  #   @autotile_cache = { 
  #     filename => { [autotile_id, frame_id, hue] => bitmap, ... },
  #     ...
  #    }
  #--------------------------------------------------------------------------
  @autotile_cache = {}
  #--------------------------------------------------------------------------
  # * Autotile Tile
  #--------------------------------------------------------------------------
  def self.autotile_tile(filename, tile_id, hue = 0, frame_id = nil)
    # Gets Autotile Bitmap
    autotile = self.autotile(filename)
    # Configures Frame ID if not specified
    if frame_id.nil?
      # Animated Tiles
      frames = autotile.width / 96
      # Configures Animation Offset
      fc = Graphics.frame_count / 16
      frame_id = (fc) % frames * 96
    end
    # Creates list if already not created
    @autotile_cache[filename] = {} unless @autotile_cache.has_key?(filename)
    # Gets Key
    key = [tile_id, frame_id, hue]
    # If Key Not Found
    unless @autotile_cache[filename].has_key?(key)
      # Reconfigure Tile ID
      tile_id %= 48
      # Creates Bitmap
      bitmap = Bitmap.new(32, 32)
      # Collects Auto-Tile Tile Layout
      tiles = Autotiles[tile_id / 8][tile_id % 8]
      # Draws Auto-Tile Rects
      for i in 0...4
        tile_position = tiles[i] - 1
        src_rect = Rect.new(tile_position % 6 * 16 + frame_id, 
          tile_position / 6 * 16, 16, 16)
        bitmap.blt(i % 2 * 16, i / 2 * 16, autotile, src_rect)
      end
      # Saves Autotile to Cache
      @autotile_cache[filename][key] = bitmap
      # Change Hue
      @autotile_cache[filename][key].hue_change(hue)
    end
    # Return Autotile
    return @autotile_cache[filename][key]
  end
end

Let me know how that works.
 
That's it man, you've got it.  You should make a thread of all your little scripts (if you haven't) save them going unnoticed.  This is a big help for mapping certain places if you're a fog whore.
 
Wow, yep that works perfectly. Thank you Seph, you helped me quite a bit with this little script.
I wouldn't call myself a fog whore lol, but i am a fan of using fogs in caves since most caves (in real-life) are quite dull with not much too much to see/do. This will definetely bring some extra life to my maps. Thank you again.

Btw, what are permission/credit usage of this script?
 
Hehe. Glad you guys like it.

I am saving most of them. I just try to do 3-5 of these little request of a day, so its hard to keep track of them.

Feel free to use it as you wish, just be sure to credit you. And you will find an update in my best bed v.5, whenever I get to that.
 
Lol. That's what I get for multi-tasking. I was trying to remind myself to credit both of you when I go to tidy up the script and add it to that hunk-o-junk I call a test bed, and just typed a clusterfuck. XD

Yeah, credit me and you two for your help with debugging. :p
 

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