Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> auto bitmapgeneration for minimaps ^_^
Kalkazad
post Jul 8 2008, 05:58 AM
Post #1


Level 1
Group Icon

Group: Member
Posts: 6
Type: Scripter
RM Skill: Masterful




huhu

if you are using a minimap-script and do not like to create every minimap-bitmap by yourself (screenshoting or something like that)
so here is an idea how to create the bitmaps (used for the minimaps) automaticaly

the bitmap will be created when entering a map
(this will slow down the loadingtime of bigger maps ---> so better create an minimap-bitmap-array (index = map_id) at the start of the game
when using parts of this script)


now just open a new project (or use yours ^_^)
put the following code above your main and try out =)
for testing, it will show the minimap (without position-cursors) in the upper-left corner

CODE
#==============================================================================
# ** Spriteset_Map
#------------------------------------------------------------------------------
#  This class brings together map screen sprites, tilemaps, etc. It's used
# within the Scene_Map class.
#==============================================================================

class Spriteset_Map
#--------------------------------------------------------------------------
# * Create Tilemap
#--------------------------------------------------------------------------
def create_tilemap
  @tilemap = Tilemap.new(@viewport1)
  @tilemap.bitmaps[0] = Cache.system("TileA1")
  @tilemap.bitmaps[1] = Cache.system("TileA2")
  @tilemap.bitmaps[2] = Cache.system("TileA3")
  @tilemap.bitmaps[3] = Cache.system("TileA4")
  @tilemap.bitmaps[4] = Cache.system("TileA5")
  @tilemap.bitmaps[5] = Cache.system("TileB")
  @tilemap.bitmaps[6] = Cache.system("TileC")
  @tilemap.bitmaps[7] = Cache.system("TileD")
  @tilemap.bitmaps[8] = Cache.system("TileE")
  @tilemap.map_data = $game_map.data
  @tilemap.passages = $game_map.passages
  # ▼ CREATE THE MINIMAP
  create_minimap
end  
  
  
#--------------------------------------------------------------------------
# ● Kalkazad's Create Minimap    yey ^_^
#--------------------------------------------------------------------------
def create_minimap
# ● mapsize
  w = $game_map.width
  h = $game_map.height
  
# ● minimapsize  
  zoom = 2.0
  minimap_width = (zoom*128).to_i
  minimap_height = (zoom*136).to_i
  
  expand = (16/zoom).to_i
  minimap_w = minimap_width * expand
  minimap_h = minimap_height * expand

# ● tilesize  
  dim_w = minimap_w / w
  dim_h = minimap_h / h
  if dim_w <= dim_h
    dim = dim_w
  else
    dim = dim_h
  end
  
  start_x = 0
  start_y = 0
  occu = 255

# ● create the minimap
  @minimap = Bitmap.new(w*dim, h*dim)
  
  if ((w+h) > 110)
    rgss_error = true
  else
    rgss_error = false
  end
  if rgss_error
    id_file  = File.new("tile_index.tix", "w")
  end
  
  
  for z in 0..2
    for y in 0..$game_map.height-1
      for x in 0..$game_map.width-1
        tile_id = @tilemap.map_data[x,y,z]
        pos_x = start_x + x*dim
        pos_y = start_y + y*dim
        if rgss_error
          s = "x:" + x.to_s + " y:" + y.to_s + " z:" + z.to_s
          id_file << s
        end
        tile = get_tile(tile_id)
        rect_dim = Rect.new(pos_x, pos_y, dim, dim)
        rect_tile = tile.rect
        @minimap.stretch_blt(rect_dim, tile, rect_tile, occu)
      end
    end
  end
  
  if rgss_error
    id_file.close
    File.delete("tile_index.tix")
  end
  
  
# ● show the minimap (just for testing)
  view_TEST = Viewport.new(10,10,minimap_width,minimap_height)
  @plane_TEST = Sprite.new(view_TEST)
  @plane_TEST.bitmap = @minimap
  @plane_TEST.zoom_x = (1.0 / expand)
  @plane_TEST.zoom_y = (1.0 / expand)
end #def create_tilemap

#--------------------------------------------------------------------------
# ● get_tile
#--------------------------------------------------------------------------
def get_tile(tile_id)
  tile = Bitmap.new(32,32)
  # ---------- A1 ----------------
  @a1 = [16]
  @a1[0] = 2048
  for i in 1..15
    @a1[i] = @a1[i-1]+48
  end
  # ---------- A2 ----------------  
  @a2 = [32]
  @a2[0] = 2816
  for i in 1..31
    @a2[i] = @a2[i-1]+48
  end
  # ---------- A3 ----------------  
  @a3 = [32]
  @a3[0] = 4352
  for i in 1..31
    @a3[i] = @a3[i-1]+48
  end
  # ---------- A4 ----------------  
  @a4 = [48]
  @a4[0] = 5888
  for i in 1..47
    @a4[i] = @a4[i-1]+48
  end
  
  if tile_id > 5886 #A4
      for i in 0..47
        if ((tile_id >= @a4[i]) && (tile_id <= (@a4[i]+46)))
          auto_tile = get_auto_tile(tile_id,@a4[i]-1,3)
          break
        end
      end
      tile_rect = Rect.new(0,0,32,32)
      tile.blt(0,0,auto_tile,tile_rect,255)
  elsif tile_id > 4350 #A3
      for i in 0..31
        if ((tile_id >= @a3[i]) && (tile_id <= (@a3[i]+46)))
          auto_tile = get_auto_tile(tile_id,@a3[i]-1,2)
          break
        end
      end
      tile_rect = Rect.new(0,0,32,32)
      tile.blt(0,0,auto_tile,tile_rect,255)
  elsif tile_id > 2800 #A2
      for i in 0..31
        if ((tile_id >= @a2[i]) && (tile_id <= (@a2[i]+46)))
          auto_tile = get_auto_tile(tile_id,@a2[i]-1,1)
          break
        end
      end
      tile_rect = Rect.new(0,0,32,32)
      tile.blt(0,0,auto_tile,tile_rect,255)
  elsif tile_id > 2000 #A1
      for i in 0..15
        if ((tile_id >= @a1[i]) && (tile_id <= (@a1[i]+46)))
          auto_tile = get_auto_tile(tile_id,@a1[i]-1,0)
          break
        end
      end
      tile_rect = Rect.new(0,0,32,32)
      tile.blt(0,0,auto_tile,tile_rect,255)
  elsif tile_id > 1500 #A5
      start_x = 0
      start_y = 0
      tile_pos = tile_id - 1536
      pos_y = (tile_pos*1.00) / (8.00)
      pos_x = (tile_pos*1.00) % (8.00)
      pos_x = pos_x.to_i
      pos_y = pos_y.to_i
      x = start_x + 32*pos_x
      y = start_y + 32*pos_y
      tile_rect = Rect.new(x,y,32,32)
      tilemap = @tilemap.bitmaps[4]
      tile.blt(0,0,tilemap,tile_rect,255)
  elsif ((tile_id > 0) && (tile_id < 1024)) #B-E
      if tile_id >= 768
        tilemap = @tilemap.bitmaps[8] #E
        tile_pos = tile_id - 3*256
      elsif tile_id >= 512
        tilemap = @tilemap.bitmaps[7] #D
        tile_pos = tile_id - 2*256
      elsif tile_id >= 256
        tilemap = @tilemap.bitmaps[6] #C
        tile_pos = tile_id - 1*256
      elsif tile_id >= 0
        tilemap = @tilemap.bitmaps[5] #B
        tile_pos = tile_id
      end #if
      if tile_pos < 128
        start_x = 0
        pos_y = (tile_pos / 8).to_i
      else
        start_x = 8*32
        pos_y = ((tile_pos-128) / 8).to_i
      end #if
      pos_x = tile_pos % 8
      x = start_x + 32*pos_x
      y = 32*pos_y
      tile_rect = Rect.new(x,y,32,32)
      tile.blt(0,0,tilemap,tile_rect,255)
  end #if
  return tile
end #def get_tile(tile_id)

#--------------------------------------------------------------------------
# ● get_auto_tile
#--------------------------------------------------------------------------
def get_auto_tile(tile_id, tile_correcture, tilemap_index)
  automap = @tilemap.bitmaps[tilemap_index]
  auto = Bitmap.new(32,32)
  auto_id = tile_id - tile_correcture
  field = tile_correcture + 1
  case tilemap_index
  when 0 #A1
      autotyp = 32
      case field
      when @a1[0]
        start_x = 0
        start_y = 0
      when @a1[1]
        start_x = 0
        start_y = 3
      when @a1[2]
        start_x = 6
        start_y = 0
      when @a1[3]
        start_x = 6
        start_y = 3
      when @a1[4]
        start_x = 8
        start_y = 0
      when @a1[5]
        start_x = 14
        start_y = 0
      when @a1[6]
        start_x = 8
        start_y = 3
      when @a1[7]
        start_x = 14
        start_y = 3
      when @a1[8]
        start_x = 0
        start_y = 6
      when @a1[9]
        start_x = 6
        start_y = 6
      when @a1[10]
        start_x = 0
        start_y = 9
      when @a1[11]
        start_x = 6
        start_y = 9
      when @a1[12]
        start_x = 8
        start_y = 6  
      when @a1[13]
        start_x = 14
        start_y = 6
      when @a1[14]
        start_x = 8
        start_y = 9
      when @a1[15]
        start_x = 14
        start_y = 9
      end #case field
  when 1 #A2
      autotyp = 32
      n = 0;
      for i in 0..31
        if ((field - i*48) == @a2[0])
          n = i
          break
        end
      end
      start_x = 2*(n%8)
      start_y = 3*(n/8).to_i
  when 2 #A3
      autotyp = 22
      n = 0;
      for i in 0..31
        if ((field - i*48) == @a3[0])
          n = i
          break
        end
      end
      start_x = 2*(n%8)
      start_y = 2*(n/8).to_i
  when 3 #A4
        autotyp = 32
        n = 0;
        for i in 0..47
          if ((field - i*48) == @a4[0])
            n = i
            break
          end
        end
        start_x = 2*(n%8)
        start_y = (n/8).to_i
        case start_y
        when 1
          start_y = 3
          autotyp = 22
        when 2
          start_y = 5
        when 3
          start_y = 8
          autotyp = 22
        when 4
          start_y = 10
        when 5
          start_y = 13
          autotyp = 22
        end
  end #case tilemap_index
  
  case autotyp
  when 22
      upper = Array.new(4, 0)
      lower = Array.new(4, 0)
      case auto_id
      when 1
        upper = [1, 1, 2, 1]
        lower = [1, 2, 2, 2]
      when 2
        upper = [0, 1, 1, 1]
        lower = [0, 2, 1, 2]
      when 3
        upper = [1, 0, 2, 0]
        lower = [1, 1, 2, 1]
      when 4
        upper = [0, 0, 1, 0]
        lower = [0, 1, 1, 1]
      when 5
        upper = [2, 1, 3, 1]
        lower = [2, 2, 3, 2]
      when 6
        upper = [0, 1, 3, 1]
        lower = [0, 2, 3, 2]
      when 7
        upper = [2, 0, 3, 0]
        lower = [2, 1, 3, 1]
      when 8
        upper = [0, 0, 3, 0]
        lower = [0, 1, 3, 1]
      when 9
        upper = [1, 2, 2, 2]
        lower = [1, 3, 2, 3]
      when 10
        upper = [0, 2, 1, 2]
        lower = [0, 3, 1, 3]
      when 11
        upper = [1, 0, 2, 0]
        lower = [1, 3, 2, 3]
      when 12
        upper = [0, 0, 1, 0]
        lower = [0, 3, 1, 3]
      when 13
        upper = [2, 2, 3, 2]
        lower = [2, 3, 3, 3]
      when 14
        upper = [0, 2, 3, 2]
        lower = [0, 3, 3, 3]
      when 15
        upper = [2, 0, 3, 0]
        lower = [2, 3, 3, 3]
      when 16
        upper = [0, 0, 3, 0]
        lower = [0, 3, 3, 3]
      end #case
  when 32
      upper = Array.new(4, 0)
      lower = Array.new(4, 0)
      case auto_id
      when 1
        upper = [1, 3, 2, 3]
        lower = [1, 4, 2, 4]
      when 2
        upper = [2, 0, 2, 3]
        lower = [1, 4, 2, 4]
      when 3
        upper = [1, 3, 3, 0]
        lower = [1, 4, 2, 4]
      when 4
        upper = [2, 0, 3, 0]
        lower = [1, 3, 2, 3]
      when 5
        upper = [1, 3, 2, 3]
        lower = [1, 4, 3, 1]
      when 6
        upper = [2, 0, 2, 3]
        lower = [1, 4, 3, 1]
      when 7
        upper = [2, 3, 3, 0]
        lower = [2, 4, 3, 1]
      when 8
        upper = [2, 0, 3, 0]
        lower = [1, 4, 3, 1]
      when 9
        upper = [1, 3, 2, 3]
        lower = [2, 1, 2, 4]
      when 10
        upper = [2, 0, 1, 3]
        lower = [2, 1, 1, 4]
      when 11
        upper = [1, 3, 3, 0]
        lower = [2, 1, 2, 4]
      when 12
        upper = [2, 0, 3, 0]
        lower = [2, 1, 2, 4]
      when 13
        upper = [1, 4, 2, 4]
        lower = [2, 1, 3, 1]
      when 14
        upper = [2, 0, 2, 3]
        lower = [2, 1, 3, 1]
      when 15
        upper = [1, 3, 3, 0]
        lower = [2, 1, 3, 1]
      when 16
        upper = [2, 0, 3, 0]
        lower = [2, 1, 3, 1]
      when 17
        upper = [0, 3, 1, 3]
        lower = [0, 4, 1, 4]
      when 18
        upper = [0, 3, 3, 0]
        lower = [0, 4, 1, 4]
      when 19
        upper = [0, 3 ,1 ,3]
        lower = [0, 4 ,3 ,1]
      when 20
        upper = [0, 3, 3, 0]
        lower = [0, 4, 3, 1]
      when 21
        upper = [1, 2, 2, 2]
        lower = [1, 3, 2, 3]
      when 22
        upper = [1, 2, 2, 2]
        lower = [1, 3, 3, 1]
      when 23
        upper = [1, 2, 2, 2]
        lower = [2, 1, 2, 3]
      when 24
        upper = [1, 2, 2, 2]
        lower = [2, 1, 3, 1]
      when 25
        upper = [2, 3, 3, 3]
        lower = [2, 4, 3, 4]
      when 26
        upper = [2, 3, 3, 3]
        lower = [2, 1, 3, 4]
      when 27
        upper = [2, 0, 3, 3]
        lower = [2, 4, 3, 4]
      when 28
        upper = [2, 0, 3, 3]
        lower = [2, 1, 3, 4]
      when 29
        upper = [1, 4, 2, 4]
        lower = [1, 5, 2, 5]
      when 30
        upper = [2, 0, 2, 4]
        lower = [1, 5, 2, 5]
      when 31
        upper = [1, 4, 3, 0]
        lower = [1, 5, 2, 5]
      when 32
        upper = [2, 0, 3, 0]
        lower = [1, 5, 2, 5]
      when 33
        upper = [0, 3, 3, 3]
        lower = [0, 4, 3, 4]
      when 34
        upper = [1, 2, 2, 2]
        lower = [1, 5, 2, 5]
      when 35
        upper = [0, 2, 1, 2]
        lower = [0, 3, 1, 3]
      when 36
        upper = [0, 2, 1, 2]
        lower = [0, 3, 3, 1]
      when 37
        upper = [2, 2, 3, 2]
        lower = [2, 3, 3, 3]
      when 38
        upper = [2, 2, 3, 2]
        lower = [2, 1, 3, 3]
      when 39
        upper = [2, 4, 3, 4]
        lower = [2, 5, 3, 5]
      when 40
        upper = [2, 0, 3, 4]
        lower = [2, 5, 3, 5]
      when 41
        upper = [0, 4, 1, 4]
        lower = [0, 5, 1, 5]
      when 42
        upper = [0, 4, 3, 0]
        lower = [0, 5, 1, 5]
      when 43
        upper = [0, 0, 1, 0]
        lower = [0, 3, 3, 3]
      when 44
        upper = [0, 0, 1, 2]
        lower = [0, 1, 1, 5]
      when 45
        upper = [0, 4, 3, 4]
        lower = [0, 1, 1, 1]
      when 46
        upper = [2, 2, 1, 0]
        lower = [2, 5, 1, 1]
      when 47
        upper = [2, 2, 0, 1]
        lower = [2, 5, 1, 1]
      end #case
  end #case autotyp    
  for f in 0..3
    upper[f] *= 16
    lower[f] *= 16
    if ((f % 2) == 0)
      upper[f] += start_x*32
      lower[f] += start_x*32
    else
      upper[f] += start_y*32
      lower[f] += start_y*32
    end
  end
  auto_rect_ol = Rect.new(upper[0],upper[1],16,16)
  auto_rect_or = Rect.new(upper[2],upper[3],16,16)
  auto_rect_ul = Rect.new(lower[0],lower[1],16,16)
  auto_rect_ur = Rect.new(lower[2],lower[3],16,16)
  auto.blt(0,0,automap,auto_rect_ol,255)
  auto.blt(16,0,automap,auto_rect_or,255)
  auto.blt(0,16,automap,auto_rect_ul,255)
  auto.blt(16,16,automap,auto_rect_ur,255)
  return auto
end #def get_auto_tile(tile_id, tile_correcture, tilemap_index)  

end #class


This post has been edited by Kalkazad: Jul 8 2008, 05:39 PM
Go to the top of the page
 
+Quote Post
   
Psiclone
post Jul 8 2008, 09:01 AM
Post #2


Level 2
Group Icon

Group: Member
Posts: 29
Type: None
RM Skill: Skilled




Do you think it would be possible to make this work for the other tilesets? Otherwise, this is a very nice script smile.gif Just what I was looking for.
Go to the top of the page
 
+Quote Post
   
Kalkazad
post Jul 8 2008, 12:44 PM
Post #3


Level 1
Group Icon

Group: Member
Posts: 6
Type: Scripter
RM Skill: Masterful




okay i will update this script
it will be working for the other 2 tilesets too

----------------------------------------------------
update:
----------------------------------------------------
the script is now working for all tilesets
(gogo for testing an bug report xD )

i hope that i also 'removed' a rgss-error poping up if the current map is bigger than 55x55 or something like that
there is still an error when the map's width is a bit lower than it's height (like w50 h55 or w40 h44), i'll try to fix this during the next days
and to optimize my current solution to prevent the rgss-error happy.gif

cause of the extremly slow loadingspeed of bigger maps (creating the minimap everytime you enter a map)
i will write a function that creates all minimaps at the start of a new game

This post has been edited by Kalkazad: Jul 8 2008, 05:55 PM
Go to the top of the page
 
+Quote Post
   
Shadow Lord
post Jul 13 2008, 05:13 AM
Post #4


Level 2
Group Icon

Group: Member
Posts: 23
Type: Developer
RM Skill: Masterful




Dumb question, but how do I set up a Map item that allows you to see the image?
Go to the top of the page
 
+Quote Post
   
Stoltz
post Jan 6 2009, 05:23 PM
Post #5


Level 1
Group Icon

Group: Member
Posts: 6
Type: None
RM Skill: Beginner




Can you make so you can turn the mini map on/off ? =) like m turn it on and off
Go to the top of the page
 
+Quote Post
   
BigEd781
post Jan 6 2009, 06:28 PM
Post #6


No method: 'stupid_title' found for `nil:NilClass'
Group Icon

Group: Revolutionary
Posts: 1,829
Type: Scripter
RM Skill: Undisclosed




QUOTE (Kalkazad @ Jul 8 2008, 12:44 PM) *
i will write a function that creates all minimaps at the start of a new game


You are going to have a hard time with that. I had trouble finding a way to save a Bitmap object to disk. To get around this, I serialized the Bitmap and saved it that way between game plays. the problem was that I had to use get/set pixel when serializing and it took too long (2-3 seconds for a 544x416 image). If you come up with a better way I am all ears.


__________________________
`
Give me teh codez!!!


I am the master debator!
Go to the top of the page
 
+Quote Post
   
Genshyu
post Jan 6 2009, 06:41 PM
Post #7


Level 8
Group Icon

Group: Revolutionary
Posts: 118
Type: Scripter
RM Skill: Intermediate




I like it.


__________________________
My current Scripts.

[Show/Hide] Save / Load Scripts.



Things I am currently Learning:
RGSS2.
If you use a script you don't have to give credit :D I'm nice like that. However, if you wan't to give credit then Give Credit to Craig Ramsey.
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 19th June 2013 - 06:32 AM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker