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.

[Review]World Map Script

ive done my hardest to playtest all the bugs out. so far it is working amazing for me. but i know there are a few things i did wrong. namely i know i messed up Sprite_Cursor's viewport(i did what i did to remove the extra cursor it seemed to be creating), my method text in Window_Map might also be done wrong, to be honnest im not sure. im sure i made a more errors in my Main_Window_Map and New_Scene_Map :) other then that i know some of my comments need updating i will do that before release(most of the comment errors are due to recomondations that i change the names of classes. anyways here is the code.
Module
Code:
#------------------------------------------------------------------------------

# module Map_Items

#------------------------------------------------------------------------------

module Map_Items

  # All icons are to be located in your Graphics/Icon folder

 

  # Icon used for the players current location 

  PLAYER_ICON = "player"  

  

  # Icon used for the cursor 

  CURSOR = "cursor"    

  

  # Cursor offset type: 

  # 1 = Static Choices(cursor can only go where the player can move)

  # 2 = Free Choice(cursor can freely move)

  CURSOR_TYPE = 1  

  

  # Name Styles:

  # 1 = Under the cursor on the town the cursor is on

  # 2 = Help window on top of screen

  # 3 = None

  NAME_STYLE = 2

  

  # Only for type CURSOR_TYPE 2

  # Number of pixels to move per left(down) or right(up) press

  MOVE_PIXEL = 15

  

  # Only for type CURSOR_TYPE 2

  # Number of pixels around the icon you can click

  PIXEL_OFFSET = 20

  

  # Only for type NAME_STYLE 2

  # Opacity of Name Window

  NAME_WINDOW_OPACITY = 255

  

  # Show player icon above town?

  SHOW_PLAYER = true

  

  # Sound effect on move

  MOVE_SE = RPG::AudioFile.new("018-Teleport01", 80)

  

  # Number of the text color you want to use

  # Please note that you only need Window_Base(216 Colors) if you want to use a 

  # non-default color

  TOWN_TEXT_COLOR = 211 

  

  # Turn fog on and off

  FOG_ON = true

  

  # Graphic used for fog, must be in the Graphics/Fogs Folder

  FOG_GRAPHIC = "001-Fog01"

  

  # Fog Opacity

  FOG_OPACITY = 64

  

  # Fog scroll X

  FOG_SX = 1

  

  # Fog Scroll Y

  FOG_SY = 1

  

  # Fog Blending Type(1=Normal, 2=Add, 3=Subtract)

  FOG_BLEND_TYPE = 1 

 

  # Dont touch

  TOWN_COORD = {}  

# Setting Up a New Town

# 1. Assign a starting x coord

# 2. Assign a starting y coord

# 3. Assign what map you want it to go too

# 4. Assign a x coord on the map you will be moving to

# 5. Assign a y coord on the map you will be moving to

# 6. Assign the direction you want the player to face

#     2 = down

#     4 = left

#     6 = right

#     8 = up

# 7. Assign a icon graphic

# 8. Assign a switch for locking and unlocking the town

# 

# [starting_x, starting_y, map_id, map_x, map_y, direction, icon, 

#   switch, name of town]

#

# E.g TOWN_COORD[1] = [200,200,2,2,2,2,"town3", 1, "Lost Island"]

#

# VERY IMPORTANT: Put the towns in the order you want the game to cycle threw

# them. you dont have to unlock them in order, just insert them in the order

# you plan too have them cycle.

  TOWN_COORD[0] = [80,130,1,8,4,2,"town3",1,"Saar",] 

  TOWN_COORD[1] = [150,300,2,6,2,4,"snowtown",2,"Alphian"] 

  TOWN_COORD[2] = [215,390,3,2,8,2,"mountain",3,"Dwarven Mine"]        

  TOWN_COORD[3] = [270,105,4,1,2,2,"castle",4,"Royal Palace"]        

  TOWN_COORD[4] = [425,340,5,12,2,6,"tower",5,"Reeve"]        

  TOWN_COORD[5] = [450,100,6,2,6,2,"ruins",6,"Lost Ruins"]        

  TOWN_COORD[6] = [520,50,7,2,2,8,"forrest",7,"Elven Forrest",] 

end
Sprite_Cursor
Code:
#==============================================================================

# ** Sprite_Cursor

#------------------------------------------------------------------------------

#  This sprite is used to display the cursor for Plague_Map.

#==============================================================================

 

class Sprite_Cursor < RPG::Sprite

 def initialize(viewport = Viewport.new(0, 0, 0, 0))

    super(viewport)

    update

  end

  #--------------------------------------------------------------------------

  # * Dispose

  #--------------------------------------------------------------------------

  def dispose

    if self.bitmap != nil

      self.bitmap.dispose

    end

    super

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    super

  end

end

 
Window_Map
Code:
#==============================================================================

# ** Window_Plague_Map

#------------------------------------------------------------------------------

#  This window displays the name box for Plague_Map

#==============================================================================

 

class Window_Map < Window_Base

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    super(0, 0, 640, 64)

    self.contents = Bitmap.new(width - 32, height - 32)

    self.z = 2010

    @text = ""

    refresh

  end

  def text=(text1)

    @text = text1

    refresh

  end  

  #--------------------------------------------------------------------------

  # * Refresh

  #--------------------------------------------------------------------------

  def refresh

    self.contents.clear

    cx = contents.text_size(@text).width

    self.contents.font.color = normal_color

    self.contents.draw_text((320-(cx/1.5)), 0, cx, 32, @text)

  end

end

 
Main_Window_Map
Code:
#==============================================================================

# ** Plague_Map Script

#------------------------------------------------------------------------------

#  Script by            :   Plague180

#  Last Update          :   March 29, 2010

#  Version              :   1.0

#  Contact Information  :   plague180([url=http://www.hbgames.org]http://www.hbgames.org[/url])

#  Contact Information  :   [email=plague180@yahoo.com]plague180@yahoo.com[/email]

#------------------------------------------------------------------------------

# * Version History :

# 29MAR10 - Version 1.0 Testing Release

#-----------------------------------------------------------------------------

 

class Main_Window_Map < Window_Base

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize(index=$game_map.map_id-1)

    super(0, 0, 640, 480)

    self.contents = Bitmap.new(640-32, 480-32)

    self.z = 2010

    self.opacity = 0

    @pindex = index 

    @cursor = Sprite_Cursor.new()

    @cursor.bitmap = RPG::Cache.icon(Map_Items::CURSOR)

    @cursor.z = 2020 

    if Map_Items::CURSOR_TYPE == 2

     @cursor.x = Map_Items::TOWN_COORD[@pindex][0] + RPG::Cache.icon(Map_Items::TOWN_COORD[@pindex][6]).width/4

     @cursor.y = Map_Items::TOWN_COORD[@pindex][1] + RPG::Cache.icon(Map_Items::TOWN_COORD[@pindex][6]).height

     @cursor.z = 2020

    end  

    refresh

  end

  #--------------------------------------------------------------------------

  # * Return value of @pindex

  #-------------------------------------------------------------------------- 

  def pindex

    return @pindex

  end  

  #--------------------------------------------------------------------------

  # * Move Player To New Map

  #--------------------------------------------------------------------------

  def move(index=0)

      $game_system.se_play(Map_Items::MOVE_SE)

      if Map_Items::CURSOR_TYPE == 1

        index = @pindex

      end

      Audio.bgm_fade(800)

      Audio.bgs_fade(800)

      Audio.me_fade(800)

      $game_temp.player_new_map_id = Map_Items::TOWN_COORD[index][2]

      $game_temp.player_new_x = Map_Items::TOWN_COORD[index][3]

      $game_temp.player_new_y = Map_Items::TOWN_COORD[index][4]

      $game_temp.player_new_direction = Map_Items::TOWN_COORD[index][5]

      $game_temp.player_transferring = true

      $game_map.autoplay

      $scene = Scene_Map.new

  end 

  #--------------------------------------------------------------------------

  # * Check if can move(and do it if you can)

  #--------------------------------------------------------------------------

  def move_if_can

    for i in 0...Map_Items::TOWN_COORD.size

      if @cursor.x > Map_Items::TOWN_COORD[i][0]-Map_Items::PIXEL_OFFSET && @cursor.x < Map_Items::TOWN_COORD[i][0] + RPG::Cache.icon(Map_Items::TOWN_COORD[i][6]).width + Map_Items::PIXEL_OFFSET

        if @cursor.y > Map_Items::TOWN_COORD[i][1]-Map_Items::PIXEL_OFFSET && @cursor.y < Map_Items::TOWN_COORD[i][1] + RPG::Cache.icon(Map_Items::TOWN_COORD[i][6]).height + Map_Items::PIXEL_OFFSET

          move(i)

        end

      end 

    end  

  end  

  #--------------------------------------------------------------------------

  # * Check if you can click on town, if so show name

  #--------------------------------------------------------------------------

  def check_name

      for i in 0...Map_Items::TOWN_COORD.size

      if @cursor.x > Map_Items::TOWN_COORD[i][0]-Map_Items::PIXEL_OFFSET && @cursor.x < Map_Items::TOWN_COORD[i][0] + RPG::Cache.icon(Map_Items::TOWN_COORD[i][6]).width + Map_Items::PIXEL_OFFSET

        if @cursor.y > Map_Items::TOWN_COORD[i][1]-Map_Items::PIXEL_OFFSET && @cursor.y < Map_Items::TOWN_COORD[i][1] + RPG::Cache.icon(Map_Items::TOWN_COORD[i][6]).height + Map_Items::PIXEL_OFFSET

          self.contents.clear

          refresh 

          self.contents.font.size = 18

          self.contents.font.color = text_color(Map_Items::TOWN_TEXT_COLOR)

          cx = contents.text_size(Map_Items::TOWN_COORD[i][8]).width

          if $game_switches[Map_Items::TOWN_COORD[i][7]] == true #unlocked?

            self.contents.draw_text(@cursor.x-cx/2,@cursor.y,cx,32,Map_Items::TOWN_COORD[i][8])

          end   

        end

      end 

    end 

  end  

  #--------------------------------------------------------------------------

  # * Check if you can click on town, if so show name window

  #--------------------------------------------------------------------------

  def check_name_window

      for i in 0...Map_Items::TOWN_COORD.size

      if @cursor.x > Map_Items::TOWN_COORD[i][0]-Map_Items::PIXEL_OFFSET && @cursor.x < Map_Items::TOWN_COORD[i][0] + RPG::Cache.icon(Map_Items::TOWN_COORD[i][6]).width + Map_Items::PIXEL_OFFSET

        if @cursor.y > Map_Items::TOWN_COORD[i][1]-Map_Items::PIXEL_OFFSET && @cursor.y < Map_Items::TOWN_COORD[i][1] + RPG::Cache.icon(Map_Items::TOWN_COORD[i][6]).height + Map_Items::PIXEL_OFFSET

          if $game_switches[Map_Items::TOWN_COORD[i][7]] == true #unlocked?

            return Map_Items::TOWN_COORD[i][8]

          end

        end  

      end 

    end 

    return ""

  end 

  #--------------------------------------------------------------------------

  # * Move Cursor Right 

  #--------------------------------------------------------------------------

  def move_cursor_right_one

     @cursor.x += Map_Items::MOVE_PIXEL

     refresh

  end

  #--------------------------------------------------------------------------

  # * Move Cursor Left 

  #--------------------------------------------------------------------------

  def move_cursor_left_one

     @cursor.x -= Map_Items::MOVE_PIXEL

     refresh

  end

  #--------------------------------------------------------------------------

  # * Move Cursor Up 

  #--------------------------------------------------------------------------

  def move_cursor_up_one

     @cursor.y -= Map_Items::MOVE_PIXEL

     refresh

  end

  #--------------------------------------------------------------------------

  # * Move Cursor Down

  #--------------------------------------------------------------------------

  def move_cursor_down_one

     @cursor.y += Map_Items::MOVE_PIXEL

     refresh

  end

  #--------------------------------------------------------------------------

  # * Move Cursor Right

  #--------------------------------------------------------------------------

  def move_cursor_right

      @pindex += 1

      if @pindex > Map_Items::TOWN_COORD.size-1

        @pindex = 0

      end

      if  $game_switches[Map_Items::TOWN_COORD[@pindex][7]] == false

        @pindex += 1

      end 

     refresh

   end 

  #--------------------------------------------------------------------------

  # * Move Cursor Left

  #--------------------------------------------------------------------------

  def move_cursor_left

      @pindex -= 1

      if @pindex < 0

        @pindex = Map_Items::TOWN_COORD.size-1

      end 

      if  $game_switches[Map_Items::TOWN_COORD[@pindex][7]] == false

        @pindex -= 1

      end

      refresh

  end  

  #--------------------------------------------------------------------------

  # * Move Cursor Up

  #--------------------------------------------------------------------------

  def move_cursor_up

      @pindex += 1

      if @pindex > Map_Items::TOWN_COORD.size-1

        @pindex = 0

      end

      if  $game_switches[Map_Items::TOWN_COORD[@pindex][7]] == false

        @pindex += 1

      end 

     refresh

  end

  #--------------------------------------------------------------------------

  # * Move Cursor Down

  #--------------------------------------------------------------------------

  def move_cursor_down

      @pindex -= 1

      if @pindex < 0

        @pindex = Map_Items::TOWN_COORD.size-1

      end 

      if  $game_switches[Map_Items::TOWN_COORD[@pindex][7]] == false

        @pindex -= 1

      end

      refresh

  end

  #--------------------------------------------------------------------------

  # * Draw Player

  #--------------------------------------------------------------------------  

  def draw_player

    bitmap = RPG::Cache.icon(Map_Items::PLAYER_ICON) 

    @player_offset_x = Map_Items::TOWN_COORD[$game_map.map_id-1][0]+((RPG::Cache.icon(Map_Items::TOWN_COORD[$game_map.map_id-1][6]).width/2)-(bitmap.width/2))

    @player_offset_y = Map_Items::TOWN_COORD[$game_map.map_id-1][1]-bitmap.height

    self.contents.blt(@player_offset_x,@player_offset_y, bitmap, Rect.new(0,0,RPG::Cache.icon(Map_Items::PLAYER_ICON).height,RPG::Cache.icon(Map_Items::PLAYER_ICON).width))

  end 

  #--------------------------------------------------------------------------

  # * Draw Towns

  #--------------------------------------------------------------------------

  def draw_towns

    for i in 0...Map_Items::TOWN_COORD.size

      if $game_switches[Map_Items::TOWN_COORD[i][7]] == true #unlocked?

        bitmap = RPG::Cache.icon(Map_Items::TOWN_COORD[i][6]) 

        self.contents.blt(Map_Items::TOWN_COORD[i][0], Map_Items::TOWN_COORD[i][1], bitmap, Rect.new(0,0,bitmap.width,bitmap.height))

      end 

    end

  end 

  #--------------------------------------------------------------------------

  # * Draw Cursor

  #--------------------------------------------------------------------------

  def draw_cursor

     if Map_Items::CURSOR_TYPE == 1

        bitmap = @cursor.bitmap

        if $game_switches[Map_Items::TOWN_COORD[@pindex][7]] == true#unlocked

          if Map_Items::TOWN_COORD[@pindex][6] != nil#if custom town graphic

            x = Map_Items::TOWN_COORD[@pindex][0]+(RPG::Cache.icon(Map_Items::TOWN_COORD[@pindex][6]).width/2)-(bitmap.width/2)

            y = Map_Items::TOWN_COORD[@pindex][1]+(RPG::Cache.icon(Map_Items::TOWN_COORD[@pindex][6]).height+3)

          end

          if Map_Items::TOWN_COORD[@pindex][6] != nil#checks for custom icon

            self.contents.blt(x, y, bitmap, Rect.new(0,0,bitmap.height,bitmap.width))

          else #not custom

            self.contents.blt(Map_Items::TOWN_COORD[@pindex][0], Map_Items::TOWN_COORD[@pindex][1]+bitmap.width, bitmap, Rect.new(0,0,bitmap.height,bitmap.width))

          end 

          if Map_Items::NAME_STYLE == 1 # draw text under cursor

            self.contents.font.size = 18

               cx = contents.text_size(Map_Items::TOWN_COORD[@pindex][8]).width

               x = Map_Items::TOWN_COORD[@pindex][0]+(RPG::Cache.icon(Map_Items::TOWN_COORD[@pindex][6]).width/2)-cx/2

               self.contents.font.color = text_color(Map_Items::TOWN_TEXT_COLOR)

               self.contents.draw_text(x,y,cx,32,Map_Items::TOWN_COORD[@pindex][8])

          end 

        end

      end 

      if Map_Items::CURSOR_TYPE == 2

         bitmap = @cursor.bitmap

         self.contents.blt(@cursor.x, @cursor.y, bitmap, Rect.new(0,0,bitmap.height,bitmap.width))

      end  

    end 

  #--------------------------------------------------------------------------

  # * Refresh

  #--------------------------------------------------------------------------

  def check_cursor_bounds

     if @cursor.x < 0

       @cursor.x = 0

     end

     if @cursor.x > 640 - RPG::Cache.icon(Map_Items::CURSOR).width - 32

       @cursor.x = 640 - RPG::Cache.icon(Map_Items::CURSOR).width - 32

     end  

     if @cursor.y < 0

       @cursor.y = 0

     end

     if @cursor.y > 480 - RPG::Cache.icon(Map_Items::CURSOR).height - 32

       @cursor.y = 480 - RPG::Cache.icon(Map_Items::CURSOR).height - 32

     end 

  end  

  #--------------------------------------------------------------------------

  # * Refresh

  #--------------------------------------------------------------------------

  def refresh

    self.contents.clear

    check_cursor_bounds

    #draws player

    if Map_Items::SHOW_PLAYER == true

      draw_player

    end 

    #draws all towns

    draw_towns

    #draw cursor

    draw_cursor

  end

end #class
New_Scene_Map
Code:
#==============================================================================

# ** Plague_Scene_Map Script

#------------------------------------------------------------------------------

#  Script by            :   Plague180

#  Last Update          :   March 29, 2010

#  Version              :   1.0

#  Contact Information  :   plague180([url=http://www.hbgames.org]http://www.hbgames.org[/url])

#  Contact Information  :   [email=plague180@yahoo.com]plague180@yahoo.com[/email]

#------------------------------------------------------------------------------

# e.g $scene = New_Scene_Map.new("World_Map.bmp")

class New_Scene_Map 

   def initialize(name)

    @name = name.to_s

    @map = Sprite.new

    @map.bitmap = RPG::Cache.picture(@name)

    @map.z = 2000

    if Map_Items::FOG_ON == true

      @fog = Plane.new

      @fog.bitmap = RPG::Cache.fog(Map_Items::FOG_GRAPHIC,0)

      @fog.opacity = Map_Items::FOG_OPACITY

      @fog.blend_type = Map_Items::FOG_BLEND_TYPE

      @fog.z = 2005

    end

  end

  #--------------------------------------------------------------------------

  # * Main Processing

  #--------------------------------------------------------------------------

  def main

    # Make Plague Map window

    @plague_map = Main_Window_Map.new()

    # Make name window

    if Map_Items::NAME_STYLE == 2

      @name_window = Window_Map.new

      @name_window.opacity = Map_Items::NAME_WINDOW_OPACITY

      @name_window.text = Map_Items::TOWN_COORD[@plague_map.pindex][8]

    end

    # Execute transition

    Graphics.transition

    # Main loop

    loop do

      # Update game screen

      Graphics.update

      # Update input information

      Input.update

      # Frame update

      update

      # Abort loop if screen is changed

      if $scene != self

        break

      end

    end

    # Prepare for transition

    Graphics.freeze

    # Dispose of windows

    @plague_map.dispose

    @map.dispose

    if Map_Items::FOG_ON == true

      @fog.dispose 

    end

    if Map_Items::NAME_STYLE == 2

      @name_window.dispose

    end

  end

  def update

    # Update windows

    @plague_map.update

    @map.update

    if Map_Items::FOG_ON == true

      @fog.ox += Map_Items::FOG_SX

      @fog.oy -= Map_Items::FOG_SY 

    end

    if Map_Items::NAME_STYLE == 1

      @plague_map.check_name

    end  

    if Map_Items::NAME_STYLE == 2

      @name_window.text = Map_Items::TOWN_COORD[@plague_map.pindex][8]

      @name_window.update

      if Map_Items::CURSOR_TYPE == 2

        @name_window.text = @plague_map.check_name_window

        @name_window.update

      end  

    end

    # If B button was pressed

    if Input.trigger?(Input::B)

      # Return to map

      $scene = Scene_Map.new

      return

    end

    if Input.trigger?(Input::RIGHT)

      # Move the cursor to the right

      if Map_Items::CURSOR_TYPE == 1

        @plague_map.move_cursor_right

      end  

      if Map_Items::CURSOR_TYPE == 2

        @plague_map.move_cursor_right_one

      end 

      return

    end

    # If L button was pressed

    if Input.trigger?(Input::LEFT)

      # Move the cursor to the left

      if Map_Items::CURSOR_TYPE == 1

        @plague_map.move_cursor_left

      end

      if Map_Items::CURSOR_TYPE == 2

        @plague_map.move_cursor_left_one

      end  

      return

    end

    # If Up button was pressed

    if Input.trigger?(Input::UP)

      # Move the cursor to the left

      if Map_Items::CURSOR_TYPE == 1

        @plague_map.move_cursor_up

      end

      if Map_Items::CURSOR_TYPE == 2

        @plague_map.move_cursor_up_one

      end  

      return

    end

    # If Down button was pressed

    if Input.trigger?(Input::DOWN)

      # Move the cursor to the left

      if Map_Items::CURSOR_TYPE == 1

        @plague_map.move_cursor_down

      end

      if Map_Items::CURSOR_TYPE == 2

        @plague_map.move_cursor_down_one

      end  

      return

    end

    if Input.trigger?(Input::C)

        # Switch to item screen

        if Map_Items::CURSOR_TYPE == 1

          @plague_map.move

        end  

        if Map_Items::CURSOR_TYPE == 2

         @plague_map.move_if_can

        end  

    end  

  end

end

 

thanks for any advice, and i wont cry over harse advice, i know im still learning, will upload demo if any wants to see it in action without making all their own graphics.
 
yes original :) my first ok/good one at least. any advice about how to improve the script, but mostly just dumb errors i made. like i know i shouldnt have made a veiwport of (0,0,0,0) in Spite_Cursor
 
Ok. I first off, I personally prefer data-structures vs. constants when creating bunch of objects with several attributes (your locations). Arrays are easy to setup and all, but variable reference is horrible. If you wanted to add a new attribute, it would always just be thrown on the end, but sometimes its better suited somewhere else. Additionally, you can't really assign defaults to arrays for your purpose. So instead of:
Code:
#   TOWN_COORD[0] = [80,130,1,8,4,2,"town3",1,"Saar",]

#   TOWN_COORD[1] = [150,300,2,6,2,4,"snowtown",2,"Alphian"]

#   TOWN_COORD[2] = [215,390,3,2,8,2,"mountain",3,"Dwarven Mine"]        

#   TOWN_COORD[3] = [270,105,4,1,2,2,"castle",4,"Royal Palace"]        

#   TOWN_COORD[4] = [425,340,5,12,2,6,"tower",5,"Reeve"]        

#   TOWN_COORD[5] = [450,100,6,2,6,2,"ruins",6,"Lost Ruins"]        

#   TOWN_COORD[6] = [520,50,7,2,2,8,"forrest",7,"Elven Forrest",]

Perhaps a better way to go about this is creating a data class that holds this data and creating a container to hold it. Something like this:
Code:
module Map_Items

  Towns = {}

end

 

class Map_Items::Town

  @@id = 0

  attr_reader :id

  attr_reader :screen_x

  attr_reader :screen_y

  attr_reader :map_id

  # ...

  def initialize(screen_x, screen_y, map_id, ...)

    @screen_x = screen_x

    # ...

    @@id += 1

    @id = 1

    Map_Items[Towns][@id] = self

  end

end

 

# Insert town creation here

Map_Items::Town.new(150,300,2,6,2,4,"snowtown",2,"Alphian")

# ...

as you can see it still creates your constant but now you can access attributes for objects instead of indexed locations. I threw in 2 useful tools:

1) Auto-ID increaser: Increases the @id each time a new town is created. Does so with a class variable which is simple enough to create. I also created this class below Data::Object that does this already for you. If you want to use it, your class code would look like this:
Code:
# The class is the parent class for all data structure objects.

# It's sole purpose is keep keep @id instances auto-incrementing.

class Data::Object

  @@ids = {}

  attr_accessor :id

  def initialize

    @@ids[self.class] = 0 unless @@ids.has_key?(self.class)

    @@ids[self.class] += 1

    @id = @@ids[self.class]

  end

end

 

class Map_Items::Town < Data::Object

  attr_reader :id

  attr_reader :screen_x

  attr_reader :screen_y

  attr_reader :map_id

  # ...

  def initialize(screen_x, screen_y, map_id, ...)

    super()

    @screen_x = screen_x

    # ...

    Map_Items[Towns][@id] = self

  end

end

I plan to make an addition to that class that also takes care of the second feature very soon.

2) Auto-adding object to the container. Basically, the following line stores the object right into the container directly when it is initialized. Simple enough but very useful:
Map_Items[Towns][@id] = self

--------------------------------------------------------

Code:
class Sprite_Cursor < RPG::Sprite

  def initialize(viewport = Viewport.new(0, 0, 0, 0))

These two lines in part 2 also catch me. The first you know about is the viewport change. Why did you do this? Secondly, is making the cursor a child of RPG::Sprite. Because of this, it also includes all those methods and addons in the RPG::Sprite class. You don't need to do this. < Sprite to me would be more than enough.

Finally, whats the point of this class at all? I see now real additions to the default Sprite method coding. Anytime you have a method and the only code in it is "super" you basically have a blank method, but are truthfully calling 2 method. More method calls are fine, but if they aren't actually doing anything, they are pointless.

--------------------------------------------------------

self.contents.draw_text((320-(cx/1.5)), 0, cx, 32, @text)

Looks like you are just centering the text on your window here, but you are actually doing it wrong. First, the contents of the window is 32 pixels less than the actual size of the window (to make up for the window borders). So your text would always be 16 pixels more right than it would need to be. Secondly, the draw_text function already has a center function, thus you would never need to get the text size here, nor make a variable (2 good things). So instead your method would look like this (you can also remove the 2 lines before this line because the font color will always be normal so you would never need to set it and you no longer need your cx variable):

self.contents.draw_text(0, 0, contents.width, 32, @text, 1)

Finally, I don't see any point in a refresh method at all. Refresh is just a second protocol of your text= method, and since there isn't anything else going on in this method, you can just move it into your text= method. I also threw in something so it wouldn't redraw the text if the text hadn't changed.

Code:
 

def text=(text)

  if @text != text

    @text = text

    self.contents.clear

    self.contents.draw_text(0, 0, contents.width, 32, @text, 1)

  end

end

--------------------------------------------------------

I shall give you some time to take those into consideration and update your code. Once you have I'll review the rest.
 
so im working on understanding all that you posted/ changing up my script. im kinda confused about the class "Map_Items::Town" that you posted, i understand most the code you posted, but i cant seem to get you sugested data structure to work. not sure what im missing. following your example:
Code:
module Map_Items

  Towns = {}

end

 

class Map_Items::Town

  @@id = 0

  attr_reader :screen_x

  attr_reader :screen_y

  attr_reader :map_id

  attr_reader :map_x

  attr_reader :map_y

  attr_reader :direction

  attr_reader :icon_name

  attr_reader :town_name

  attr_reader :switch

  def initialize(screen_x, screen_y, map_id, map_x, map_y, direction, icon_name, town_name, switch)

    @screen_x = screen_x

    @screen_y = screen_y

    @map_id = map_id

    @map_x = map_x

    @map_y = map_y

    @direction = direction

    @icon_name = icon_name

    @town_name = town_name

    @switch = switch

    @@id += 1

    @id = 1

    Map_Items[Towns][@id] = self

  end

end

Map_Items::Town.new(150,300,2,6,2,4,"snowtown",2,"Alphian")
or
edit:
Code:
module Map_Items

  Towns = {}

end

class Data::Object

  @@ids = {}

  attr_accessor :id

  def initialize 

    @@ids[self.class] = 0 unless @@ids.has_key?(self.class)

    @@ids[self.class] += 1

    @id = @@ids[self.class]

  end

end 

class Map_Items::Town < Data::Object

  @@id = 0

  attr_reader :screen_x

  attr_reader :screen_y

  attr_reader :map_id

  attr_reader :map_x

  attr_reader :map_y

  attr_reader :direction

  attr_reader :icon_name

  attr_reader :town_name

  attr_reader :switch

  def initialize(screen_x, screen_y, map_id, map_x, map_y, direction, icon_name, town_name, switch)

   super()

    @screen_x = screen_x

    @screen_y = screen_y

    @map_id = map_id

    @map_x = map_x

    @map_y = map_y

    @direction = direction

    @icon_name = icon_name

    @town_name = town_name

    @switch = switch

    @@id += 1

    @id = 1

    Map_Items[Towns][@id] = self

  end

end

Map_Items::Town.new(150,300,2,6,2,4,"snowtown",2,"Alphian")

 
 
so i havent put too much time into trying to solve this myself cause ive been really busy with work, but i have the next 3 days off so i was really really hopeing to finish making my data structure better. so i can start working on the last few features i need before release. also seph, i was wondering do you think this is useful? or am i wasting my time because i dont include mouse funct? cursor type 2 is like the mouse, but doesnt use it...idk but first im gonna work on adding subsections. if i can solve how i want to do it(because my recent attempt failed horribly)
 
Ok. I updated the Data::Object class to support containers, making it one more step to being useful. Below is your modified code.

Code:
module Map_Items

  Towns = {}

end

 

# The class is the parent class for all data structure objects.

# It's sole purpose is keep keep @id instances auto-incrementing.

class Data::Object

  @@ids = {}

  @@containers = {}

  attr_accessor :id

  def initialize

    @@ids[self.class] = 0 unless @@ids.has_key?(self.class)

    @@ids[self.class] += 1

    @id = @@ids[self.class]

    if @@containers.has_key?(self.class)

      @@containers[self.class][@id] = self

    end

  end

  def self.set_container(class_name, container)

    @@containers[class_name] = container

  end

end

 

class Map_Items::Town < Data::Object

  Data::Object.add_container(self, Map_Items::Towns)

  attr_reader :screen_x

  attr_reader :screen_y

  attr_reader :map_id

  attr_reader :map_x

  attr_reader :map_y

  attr_reader :direction

  attr_reader :icon_name

  attr_reader :town_name

  attr_reader :switch

  def initialize(screen_x, screen_y, map_id, map_x, map_y, direction, icon_name, town_name, switch)

   super()

    @screen_x = screen_x

    @screen_y = screen_y

    @map_id = map_id

    @map_x = map_x

    @map_y = map_y

    @direction = direction

    @icon_name = icon_name

    @town_name = town_name

    @switch = switch

  end

end

Map_Items::Town.new(150,300,2,6,2,4,"snowtown",2,"Alphian")

 

The idea of Data::Object is that in that initialization, the @id instance is taken care of. It also now adds the objects into the container list as well.

---------------------------

No scripting is ever futile scripting. I've scripted just about everything and often for a purpose. Its about learning. Everything you do is just evolution on your skills. I try to keep my scripts as simple as possible while maintaining their power and organization so others could read them and learn. If there is anything you dont understand above, just let me know and I'll walk through it. And if you need any help with anything you want to add, ask. I am always willing to spend time for someone who is wanting to learn.
 
reading threw it makes sence to me though i do have a few questions. firstly when you have a class name with a double colen does that mean anything? or is it just a nameing standard thing? the second is even though the code makes sence im not sure what i have to add make it work besides unique data for my script. im more then willing to do the work, just not sure what work needs doing.

p.s. someday i will make a script that you didnt help me with :p thank you so much for your continued support!!! will have to find some fun way to thank you one of these days
 
It means its a sub-class/module. Like the RPG modle.
Code:
module RPG

  class Item

  end

end

 

# Same as writing

 

class RPG::Item

The only thing here it that the RPG module or class has to be defined before RPG::Item. It all has to do with scope.

-------------------

All you need to do is just what you did before. Although instead of using
map_x = Map_Items::Towns[id][index]

you would use

max_x = Map_Items::Towns[id].map_x

--------------------

I am a helper. Always have been. Ego strokes are about all I need lol
 
thanks i get off work in about 2 hours, so ill get right on making the changes, then ill repost here :) as for the ego if it helps you are the number 1 helper for me. i have several of your scripts in my game. plus about 5 small less then 50 line scripts you wrote me me for fixing small little problems(e.g. sound effects for each tile) :)

edit:
so i started converting all the code, but i keep getting a no method error on this line
Code:
@player_offset_x = Map_Items::Towns[$game_map.map_id-1].screen_x + ((RPG::Cache.icon(Map_Items::Towns[$game_map.map_id-1].icon).width / 2) - (bitmap.width / 2))

even when i added the method to Map_Items:Towns, im not sure what the problem is.
 
ok, after a fair amount of tweaking and play testing i think i have gotten all the new bugs out from th new data structure :) mind looking to see if there is anything else you would change before i release it? (i will update comments and instructions in the mean time.
Data_Structure
Code:
#==============================================================================

# **  Data::Object, Map_Items::Town

#------------------------------------------------------------------------------

#  These classes were created by SephirothSpawn!!! <3 my Hero :)

#==============================================================================

module Map_Items

  Towns = {}

end

class Data::Object

  @@ids = {}

  @@containers = {}

  attr_accessor :id

  def initialize

    @@ids[self.class] = 0 unless @@ids.has_key?(self.class)

    @@ids[self.class] += 1

    @id = @@ids[self.class]

    if @@containers.has_key?(self.class)

      @@containers[self.class][@id] = self

    end

  end

  def self.add_container(class_name, container)

    @@containers[class_name] = container

  end

end

class Map_Items::Town < Data::Object

  Data::Object.add_container(self, Map_Items::Towns)

  attr_reader :screen_x

  attr_reader :screen_y

  attr_reader :map_id

  attr_reader :map_x

  attr_reader :map_y

  attr_reader :direction

  attr_reader :icon

  attr_reader :town_name

  attr_reader :switch

  def initialize(screen_x, screen_y, map_id, map_x, map_y, direction, icon, town_name, switch)

   super()

    @screen_x = screen_x

    @screen_y = screen_y

    @map_id = map_id

    @map_x = map_x

    @map_y = map_y

    @direction = direction

    @icon = icon

    @town_name = town_name

    @switch = switch

  end

  def self.screen_x

    return @screen_x

  end 

  def self.screen_y

    return @screen_y

  end 

  def self.map_id

    return @map_id

  end 

  def self.map_x

    return @map_x

  end 

  def self.map_y

    return @map_y

  end 

  def self.direction

    return @direction

  end 

  def self.icon

    return @icon

  end 

  def self.town_name

    return @town_name

  end 

  def self.switch

    return @switch

  end 

end 
Module
Code:
#------------------------------------------------------------------------------

# module Map_Items

#------------------------------------------------------------------------------

# Configure all settings here.

#============================================================================== 

 

module Map_Items

  # All icons are to be located in your Graphics/Icon folder

 

  # Icon used for the players current location 

  PLAYER_ICON = "player"  

  

  # Icon used for the cursor 

  CURSOR = "cursor"    

  

  # Cursor offset type: 

  # 1 = Static Choices(cursor can only go where the player can move)

  # 2 = Free Choice(cursor can freely move)

  CURSOR_TYPE = 2  

  

  # Name Styles:

  # 1 = Under the cursor on the town the cursor is on

  # 2 = Help window on top of screen

  # 3 = None

  NAME_STYLE = 2

  

  # Only for type CURSOR_TYPE 2

  # Number of pixels to move per left(down) or right(up) press

  MOVE_PIXEL = 15

  

  # Only for type CURSOR_TYPE 2

  # Number of pixels around the icon you can click

  PIXEL_OFFSET = 20

  

  # Only for type NAME_STYLE 2

  # Opacity of Name Window

  NAME_WINDOW_OPACITY = 235

  

  # Show player icon above town?

  SHOW_PLAYER = true

  # Sound effect on move

  MOVE_SE = RPG::AudioFile.new("018-Teleport01", 80)

  

  # Number of the text color you want to use

  # Please note that you only need Window_Base(216 Colors) if you want to use a 

  # non-default color

  TOWN_TEXT_COLOR = 211 

  

  # Turn fog on and off

  FOG_ON = true

  

  # Graphic used for fog, must be in the Graphics/Fogs Folder

  FOG_GRAPHIC = "001-Fog01"

  

  # Fog Opacity

  FOG_OPACITY = 64

  

  # Fog scroll X

  FOG_SX = 1

  

  # Fog Scroll Y

  FOG_SY = 1

  

  # Fog Blending Type(1=Normal, 2=Add, 3=Subtract)

  FOG_BLEND_TYPE = 1 

end 

# Setup your towns here

Map_Items::Town.new(80,130,1,8,4,2,"town3","Saar",1)

Map_Items::Town.new(150,300,2,6,2,4,"snowtown","Alphian",2) 

Map_Items::Town.new(215,370,3,2,8,2,"mountain","Dwarven Mine",3)   

Map_Items::Town.new(270,105,4,1,2,2,"castle","Royal Palace",4)      

Map_Items::Town.new(425,340,5,12,2,6,"tower","Reeve",5) 

Map_Items::Town.new(450,100,6,2,6,2,"ruins","Lost Ruins",6)        

Map_Items::Town.new(520,50,7,2,2,8,"forrest","Elven Forrest",7)  
Sprite_Cursor
Code:
#==============================================================================

# ** Sprite_Cursor

#------------------------------------------------------------------------------

#  This sprite is used to display the cursor for Plague_Map.

#==============================================================================

 

class Sprite_Cursor < Sprite

 def initialize(viewport = Viewport.new(0, 0, 0, 0))

    super(viewport)

    update

  end

  #--------------------------------------------------------------------------

  # * Dispose

  #--------------------------------------------------------------------------

  def dispose

    if self.bitmap != nil

      self.bitmap.dispose

    end

    super

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    super

  end

end

 
Window_Map
Code:
 #==============================================================================

# ** Window_Map

#------------------------------------------------------------------------------

#  This window displays the name box for Window_Map

#==============================================================================

 

class Window_Map < Window_Base

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    super(0, 0, 640, 64)

    self.contents = Bitmap.new(width - 32, height - 32)

    self.z = 2010

    @text = ""

  end

  def text=(text)

    if @text != text

      @text = text

      self.contents.clear

      self.contents.draw_text(0, 0, contents.width, 32, @text, 1)

    end

  end

end

 
Main_Window_Map
Code:
#==============================================================================

# ** Plague_Map Script

#------------------------------------------------------------------------------

#  Script by            :   Plague180

#  Last Update          :   March 29, 2010

#  Version              :   1.0

#  Contact Information  :   plague180([url=http://www.hbgames.org]http://www.hbgames.org[/url])

#  Contact Information  :   [email=plague180@yahoo.com]plague180@yahoo.com[/email]

#------------------------------------------------------------------------------

# * Version History :

# 29MAR10 - Version 1.0 Testing Release

#-----------------------------------------------------------------------------

 

class Main_Window_Map < Window_Base

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize(index=$game_map.map_id)

    super(0, 0, 640, 480)

    self.contents = Bitmap.new(640-32, 480-32)

    self.z = 2010

    self.opacity = 0

    @pindex = index 

    @cursor = Sprite_Cursor.new()

    @cursor.bitmap = RPG::Cache.icon(Map_Items::CURSOR)

    @cursor.z = 2020 

    if Map_Items::CURSOR_TYPE == 2

     @cursor.x = Map_Items::Towns[@pindex].screen_x + RPG::Cache.icon(Map_Items::Towns[@pindex].icon).width/4

     @cursor.y = Map_Items::Towns[@pindex].screen_y + RPG::Cache.icon(Map_Items::Towns[@pindex].icon).height

     @cursor.z = 2020

    end  

    refresh

  end

  #--------------------------------------------------------------------------

  # * Return value of @pindex

  #-------------------------------------------------------------------------- 

  def pindex

    return @pindex 

  end  

  #--------------------------------------------------------------------------

  # * Move Player To New Map

  #--------------------------------------------------------------------------

  def move(index=0)

      $game_system.se_play(Map_Items::MOVE_SE)

      if Map_Items::CURSOR_TYPE == 1

        index = @pindex

      end

      Audio.bgm_fade(800)

      Audio.bgs_fade(800)

      Audio.me_fade(800)

      $game_temp.player_new_map_id = Map_Items::Towns[index].map_id

      $game_temp.player_new_x = Map_Items::Towns[index].map_x

      $game_temp.player_new_y = Map_Items::Towns[index].map_y

      $game_temp.player_new_direction = Map_Items::Towns[index].direction

      $game_temp.player_transferring = true

      $game_map.autoplay

      $scene = Scene_Map.new

  end 

  #--------------------------------------------------------------------------

  # * Check if can move(and do it if you can)

  #--------------------------------------------------------------------------

  def move_if_can

    for i in 0...Map_Items::Towns.size

      if @cursor.x > Map_Items::Towns[i].screen_x-Map_Items::PIXEL_OFFSET && @cursor.x < Map_Items::Towns[i].screen_x + RPG::Cache.icon(Map_Items::Towns[i].icon).width + Map_Items::PIXEL_OFFSET

        if @cursor.y > Map_Items::Towns[i].screen_y-Map_Items::PIXEL_OFFSET && @cursor.y < Map_Items::Towns[i].screen_y + RPG::Cache.icon(Map_Items::Towns[i].icon).height + Map_Items::PIXEL_OFFSET

          move(i)

        end

      end 

    end  

  end  

  #--------------------------------------------------------------------------

  # * Check if you can click on town, if so show name

  #--------------------------------------------------------------------------

  def check_name

      for i in 1...Map_Items::Towns.size+1

      if @cursor.x > Map_Items::Towns[i].screen_x - Map_Items::PIXEL_OFFSET && @cursor.x < Map_Items::Towns[i].screen_x + RPG::Cache.icon(Map_Items::Towns[i].icon).width + Map_Items::PIXEL_OFFSET

        if @cursor.y > Map_Items::Towns[i].screen_y - Map_Items::PIXEL_OFFSET && @cursor.y < Map_Items::Towns[i].screen_y + RPG::Cache.icon(Map_Items::Towns[i].icon).height + Map_Items::PIXEL_OFFSET

          self.contents.clear

          refresh 

          self.contents.font.size = 18

          self.contents.font.color = text_color(Map_Items::TOWN_TEXT_COLOR)

          cx = contents.text_size(Map_Items::Towns[i].town_name).width

          if $game_switches[Map_Items::Towns[i].switch] == true #unlocked?

            self.contents.draw_text(@cursor.x-cx/2,@cursor.y,cx,32,Map_Items::Towns[i].town_name)

          end   

        end

      end 

    end 

  end  

  #--------------------------------------------------------------------------

  # * Check if you can click on town, if so show name window

  #--------------------------------------------------------------------------

  def check_name_window

      for i in 1...Map_Items::Towns.size+1

      if @cursor.x > Map_Items::Towns[i].screen_x - Map_Items::PIXEL_OFFSET && @cursor.x < Map_Items::Towns[i].screen_x + RPG::Cache.icon(Map_Items::Towns[i].icon).width + Map_Items::PIXEL_OFFSET

        if @cursor.y > Map_Items::Towns[i].screen_y-Map_Items::PIXEL_OFFSET && @cursor.y < Map_Items::Towns[i].screen_y + RPG::Cache.icon(Map_Items::Towns[i].icon).height + Map_Items::PIXEL_OFFSET

          if $game_switches[Map_Items::Towns[i].switch] == true #unlocked?

            return Map_Items::Towns[i].town_name

          end

        end  

      end 

    end 

    return ""

  end 

  #--------------------------------------------------------------------------

  # * Move Cursor Right 

  #--------------------------------------------------------------------------

  def move_cursor_right_one

     @cursor.x += Map_Items::MOVE_PIXEL

     refresh

  end

  #--------------------------------------------------------------------------

  # * Move Cursor Left 

  #--------------------------------------------------------------------------

  def move_cursor_left_one

     @cursor.x -= Map_Items::MOVE_PIXEL

     refresh

  end

  #--------------------------------------------------------------------------

  # * Move Cursor Up 

  #--------------------------------------------------------------------------

  def move_cursor_up_one

     @cursor.y -= Map_Items::MOVE_PIXEL

     refresh

  end

  #--------------------------------------------------------------------------

  # * Move Cursor Down

  #--------------------------------------------------------------------------

  def move_cursor_down_one

     @cursor.y += Map_Items::MOVE_PIXEL

     refresh

  end

  #--------------------------------------------------------------------------

  # * Move Cursor Right

  #--------------------------------------------------------------------------

  def move_cursor_right

      @pindex += 1

      if @pindex > Map_Items::Towns.size

        @pindex = 1

      end

      if  $game_switches[Map_Items::Towns[@pindex].switch] == false

        @pindex += 1

      end 

     refresh

   end 

  #--------------------------------------------------------------------------

  # * Move Cursor Left

  #--------------------------------------------------------------------------

  def move_cursor_left

      @pindex -= 1

      if @pindex < 1

        @pindex = Map_Items::Towns.size

      end 

      if  $game_switches[Map_Items::Towns[@pindex].switch] == false

        @pindex -= 1

      end

      refresh

  end  

  #--------------------------------------------------------------------------

  # * Move Cursor Up

  #--------------------------------------------------------------------------

  def move_cursor_up

      @pindex += 1

      if @pindex > Map_Items::Towns.size

        @pindex = 1

      end

      if  $game_switches[Map_Items::Towns[@pindex].switch] == false

        @pindex += 1

      end 

     refresh

  end

  #--------------------------------------------------------------------------

  # * Move Cursor Down

  #--------------------------------------------------------------------------

  def move_cursor_down

      @pindex -= 1

      if @pindex < 1

        @pindex = Map_Items::Towns.size

      end 

      if  $game_switches[Map_Items::Towns[@pindex].switch] == false

        @pindex -= 1

      end

      refresh

  end

  #--------------------------------------------------------------------------

  # * Draw Player

  #--------------------------------------------------------------------------  

  def draw_player

    bitmap = RPG::Cache.icon(Map_Items::PLAYER_ICON) 

    @player_offset_x = Map_Items::Towns[$game_map.map_id].screen_x + ((RPG::Cache.icon(Map_Items::Towns[$game_map.map_id].icon).width / 2) - (bitmap.width / 2))

    @player_offset_y = Map_Items::Towns[$game_map.map_id].screen_y-bitmap.height

    self.contents.blt(@player_offset_x,@player_offset_y, bitmap, Rect.new(0,0,RPG::Cache.icon(Map_Items::PLAYER_ICON).height,RPG::Cache.icon(Map_Items::PLAYER_ICON).width))

  end 

  #--------------------------------------------------------------------------

  # * Draw Towns

  #--------------------------------------------------------------------------

  def draw_towns

    for i in 1...Map_Items::Towns.size+1

      if $game_switches[Map_Items::Towns[i].switch] == true #unlocked?

        bitmap = RPG::Cache.icon(Map_Items::Towns[i].icon) 

        self.contents.blt(Map_Items::Towns[i].screen_x, Map_Items::Towns[i].screen_y, bitmap, Rect.new(0,0,bitmap.width,bitmap.height))

      end 

    end

  end 

  #--------------------------------------------------------------------------

  # * Draw Cursor

  #--------------------------------------------------------------------------

  def draw_cursor

     if Map_Items::CURSOR_TYPE == 1

        bitmap = @cursor.bitmap

        if $game_switches[Map_Items::Towns[@pindex].switch] == true#unlocked

            x = Map_Items::Towns[@pindex].screen_x + (RPG::Cache.icon(Map_Items::Towns[@pindex].icon).width/2)-(bitmap.width/2)

            y = Map_Items::Towns[@pindex].screen_y + (RPG::Cache.icon(Map_Items::Towns[@pindex].icon).height+3)

            self.contents.blt(x, y, bitmap, Rect.new(0,0,bitmap.height,bitmap.width))

          if Map_Items::NAME_STYLE == 1 # draw text under cursor

            self.contents.font.size = 18

               cx = contents.text_size(Map_Items::Towns[@pindex].town_name).width

               x = Map_Items::Towns[@pindex].screen_x+(RPG::Cache.icon(Map_Items::Towns[@pindex].icon).width/2)-cx/2

               self.contents.font.color = text_color(Map_Items::TOWN_TEXT_COLOR)

               self.contents.draw_text(x,y,cx,32,Map_Items::Towns[@pindex].town_name)

          end 

        end

      end 

      if Map_Items::CURSOR_TYPE == 2

         bitmap = @cursor.bitmap

         self.contents.blt(@cursor.x, @cursor.y, bitmap, Rect.new(0,0,bitmap.height,bitmap.width))

      end  

    end 

  #--------------------------------------------------------------------------

  # * Refresh

  #--------------------------------------------------------------------------

  def check_cursor_bounds

     if @cursor.x < 0

       @cursor.x = 0

     end

     if @cursor.x > 640 - RPG::Cache.icon(Map_Items::CURSOR).width - 32

       @cursor.x = 640 - RPG::Cache.icon(Map_Items::CURSOR).width - 32

     end  

     if @cursor.y < 0

       @cursor.y = 0

     end

     if @cursor.y > 480 - RPG::Cache.icon(Map_Items::CURSOR).height - 32

       @cursor.y = 480 - RPG::Cache.icon(Map_Items::CURSOR).height - 32

     end 

  end  

  #--------------------------------------------------------------------------

  # * Refresh

  #--------------------------------------------------------------------------

  def refresh

    self.contents.clear

    check_cursor_bounds

    #draws player

    if Map_Items::SHOW_PLAYER == true

      draw_player

    end 

    #draws all towns

    draw_towns

    #draw cursor

    draw_cursor

  end

end #class 
New_Scene_Map
Code:
#==============================================================================

# ** Plague_Scene_Map Script

#------------------------------------------------------------------------------

#  Script by            :   Plague180

#  Last Update          :   March 29, 2010

#  Version              :   1.0

#  Contact Information  :   plague180([url=http://www.hbgames.org]http://www.hbgames.org[/url])

#  Contact Information  :   [email=plague180@yahoo.com]plague180@yahoo.com[/email]

#------------------------------------------------------------------------------

# e.g $scene = New_Scene_Map.new("World_Map.bmp")

class New_Scene_Map 

   def initialize(name)

    @name = name.to_s

    @map = Sprite.new

    @map.bitmap = RPG::Cache.picture(@name)

    @map.z = 2000

    if Map_Items::FOG_ON == true

      @fog = Plane.new

      @fog.bitmap = RPG::Cache.fog(Map_Items::FOG_GRAPHIC,0)

      @fog.opacity = Map_Items::FOG_OPACITY

      @fog.blend_type = Map_Items::FOG_BLEND_TYPE

      @fog.z = 2005

    end

  end

  #--------------------------------------------------------------------------

  # * Main Processing

  #--------------------------------------------------------------------------

  def main

    # Make Plague Map window

    @plague_map = Main_Window_Map.new()

    # Make name window

    if Map_Items::NAME_STYLE == 2

      @name_window = Window_Map.new

      @name_window.opacity = Map_Items::NAME_WINDOW_OPACITY

      @name_window.text = Map_Items::Towns[@plague_map.pindex+1].town_name

    end

    # Execute transition

    Graphics.transition

    # Main loop

    loop do

      # Update game screen

      Graphics.update

      # Update input information

      Input.update

      # Frame update

      update

      # Abort loop if screen is changed

      if $scene != self

        break

      end

    end

    # Prepare for transition

    Graphics.freeze

    # Dispose of windows

    @plague_map.dispose

    @map.dispose

    if Map_Items::FOG_ON == true

      @fog.dispose 

    end

    if Map_Items::NAME_STYLE == 2

      @name_window.dispose

    end

  end

  def update

    # Update windows

    @plague_map.update

    @map.update

    if Map_Items::FOG_ON == true

      @fog.ox += Map_Items::FOG_SX

      @fog.oy -= Map_Items::FOG_SY 

    end

    if Map_Items::NAME_STYLE == 1

      @plague_map.check_name

    end  

    if Map_Items::NAME_STYLE == 2

      @name_window.text = Map_Items::Towns[@plague_map.pindex].town_name

      @name_window.update

      if Map_Items::CURSOR_TYPE == 2

        @name_window.text = @plague_map.check_name_window

        @name_window.update

      end  

    end

    # If B button was pressed

    if Input.trigger?(Input::B)

      # Return to map

      $scene = Scene_Map.new

      return

    end

    if Input.trigger?(Input::RIGHT)

      # Move the cursor to the right

      if Map_Items::CURSOR_TYPE == 1

        @plague_map.move_cursor_right

      end  

      if Map_Items::CURSOR_TYPE == 2

        @plague_map.move_cursor_right_one

      end 

      return

    end

    # If L button was pressed

    if Input.trigger?(Input::LEFT)

      # Move the cursor to the left

      if Map_Items::CURSOR_TYPE == 1

        @plague_map.move_cursor_left

      end

      if Map_Items::CURSOR_TYPE == 2

        @plague_map.move_cursor_left_one

      end  

      return

    end

    # If Up button was pressed

    if Input.trigger?(Input::UP)

      # Move the cursor to the left

      if Map_Items::CURSOR_TYPE == 1

        @plague_map.move_cursor_up

      end

      if Map_Items::CURSOR_TYPE == 2

        @plague_map.move_cursor_up_one

      end  

      return

    end

    # If Down button was pressed

    if Input.trigger?(Input::DOWN)

      # Move the cursor to the left

      if Map_Items::CURSOR_TYPE == 1

        @plague_map.move_cursor_down

      end

      if Map_Items::CURSOR_TYPE == 2

        @plague_map.move_cursor_down_one

      end  

      return

    end

    if Input.trigger?(Input::C)

        # Switch to item screen

        if Map_Items::CURSOR_TYPE == 1

          @plague_map.move

        end  

        if Map_Items::CURSOR_TYPE == 2

         @plague_map.move_if_can

        end  

    end  

  end

end

 
 
I think I told you about my view on constants in another thread... you seem to like me saying that apparently, or at least that'S the best explanation I can guess for lines like these:
Code:
# Icon used for the cursor

CURSOR = "cursor"
Seriously now... while you can argue about customizeability usage of constants in the average script, the quoted case is just ridiculous. If you want to be in the user's face with what they can customize easily, at least be subtle about it and don't make 'em wade through an insane amount of pointless constants to find the one you're looking for.


Also, a few words on documentation: Your headers state completely different names than your classes are actually named (which is good! your class names don't need a 'Plague_' in 'em ;) ). I keep seeing Plague_something in there, which I guess has some meaning to you, however doesn't follow any existing way of documentation and therefore should be changed. Same goes for this:
These classes were created by SephirothSpawn!!! <3 my Hero :)
While Seph sure apprechiates the love, a simple These classes were created by SephirothSpawn does the job perfectly and doesn't make you look like a script kiddie.

Lastly, I noticed you use different date formats in your changelogs than you use for your release dates. I was wondering if I should point it out at all, but considering I tried to figure out who 29Mario was, I think I should.


So yeah, as usual, be aware that I might be more picky about that kind of stuff than others, but I think stuff like this is important. (and I'm kind of afraid your signature is pointing to me, even though I totally can't imagine that that's possible :p )
 
SephirothSpawn":1betdzyj said:
*gives Blue a hug*

Ohhhh... Zeriab....
Even though I'm afraid to spam this topic, I thought I let you guys know that got me laughing so hard that my co-workers actually came to my office to see if everything was alright with me XD

Nice. *goes back into I-guess-grumpy mode again* :p
 
blue, i want to start with yes, my sig is pointed at you cause you seem to get frustrated by me alot. i promsie im not trying too annoy you. im not sure what your saying about constants..why would i want to not let users change thier cursor and such...? im more then willing to listen i just dont understand atm. as for the 29mar10 its: march 29, 2010 just in miltary format, im in the navy so i guess im just too used to it. ill change that asap. i got rid of the plague stuff in the class names cause you suggested it :) (see i listen) and lastly about the comments i did mention in my post that they are NOT up to date, i want the code to work before the i spend time on the doc.

p.s.ill keep the line about seph unless he insist that i dont.
 
Well, first of all, you don't really annoy me at all (that'd be kind of insolent to assume you addressed ME with this post :/ ) and I'm not really 'grumpy' either as far as I can tell ^^" I just tend to write rather factual, or at least try to, which is why I might sound harsh once in a while. I assure you I'm having no problems giving you a hand here; sorry if I had you assume anything else.

So yeah, actual feedback (getting factual again):
On the cursor thing, yes, of course you want users to change the cursor. However, you don't do that with the constant, you allow them to choose the filename of the cursor - something very well possible in the actual script itself, if there's an actual need for it. Having someone look for that line is just as hard as looking for it within the other scripts, and pointing people there is just as hard as pointing them to the other place. Note that this isn't a case of choosing between modes or anything, it's simply a case of adjusting in case the user's already using another script using a cursor.

And yeah, I figured out the date eventually ^^" It's perfectly understandable once you realize it's a date, actually - the problem I had is I didn't think it was, since directly before that (four lines above), you used a different, very apparent date format. There's nothing wrong with using any date format really (even if it's military-only, as long as it's fairly understandable), but you should stick to it throughout, IMO.

Sorry about missing that the headers aren't up-to-date, I only read you have an updated script, so I didn't think that excludes them ^^" And about Seph's line... it's your call (as for all of the above) and not vital for the script itself anyway ;)
 
thanks for you opinion blue, i will change my sig to reflect your inner happiness :P ill prob stick with the constants cause i dont personally like to have to do $map.cursor = "filename" or what ever for all the features i choose to use, because ether way im gonna have aton of documentation to look threw to find all the code i need for the features i do want to use. sorry if that doesnt make sence, i just dont see any good reason to do it your way...maybe im just confused its been along watch.
 
Again, I laughed hard! :biggrin: But I apprechiate having a place in there ;)

And as far as the constants go... it's your script, and I can only tell you my opinion... I think it's a pretty valid opinion from a scripting style point of view (valid as in purposeful and explained), but I'm also aware noone else on this forum shares it :p So do as you like, but deep down in your scripted hearts, you all know I'm right! :grin:

Keep up the good work!
 

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