#==============================================================================
# ■ Scene_Carte
# par Brendan 75
# 29/12/09
#-----------------------------------------------------------------------------
# Mappemonde adaptable à n'importe qu'elle région.
#==============================================================================
class Scene_Carte
#--------------------------------------------------------------------------
# ● Initialize
#--------------------------------------------------------------------------
def initialize
# Numéro de la variable des coordonnée du hero en X et en Y
$var_x = 60
$var_y = 61
# Nom de l'image de fond (avec l'extension et entre guillement)
@carte_img = "Koden.png"
# Nom de l'image du curseur (avec l'extension et entre guillement)
@curseur_img = "map_curseur.png"
# Nom de l'image réprésentant le personnage (avec l'extension et entre guillement)
@perso_img = "map_hero.png"
# La map est-elle visible en fond ? (true si oui, false si non)
@spriteset_visible = true
# Coordonnées X et Y de la carte
@map_x = 0
@map_y = 0
# Taille des cases (mettre 32 pour 32x32)
@cote_case = 8
# Nombre de case à la verticale et à l'horizontale
@nb_case_v = 18
@nb_case_h = 24
# Coordonnées X et Y des noms
@text_x = 0
@text_y = 0
# Couleur du texte pour les noms (Color.new(Rouge, Vert, Bleu), par défaut blanc)
@text_color = Color.new(255, 255, 255)
# Taille du texte pour les noms ($fontsize pour la taille par défaut)
@text_size = $fontsize
# Police du texte pour les noms ($fontface pour la police par défaut, nom entre guillemet)
@text_police = $fontface
# Idem pour les descriptions.
@desc_x = 0
@desc_y = 0
@desc_color = Color.new(255, 255, 255)
@desc_size = $fontsize
@desc_police = $fontface
#--------------------------------------------------------------------------
# Les zones
#
# -> Nom (entre guillemets)
# -> Description
# -> Découvert
# -> type (0:"normal" 1:"ville")
#
#--------------------------------------------------------------------------
if $local == nil
$local = []
for x in 0.. @nb_case_h-1
$local[x] = []
for y in 0.. @nb_case_v-1
$local[x][y] = ["","", false, 0]
end
end
end
# - init(x, y, nom, desc, type) pour initialisé une zone. -
init(0, 0, "Exemple 1", "Rien qu'un exemple.", 0)
init(3, 2..4, "Exemple 2", "Rien qu'un exemple...", 0)
# ---------------------------------------------------------
note
end
#--------------------------------------------------------------------------
# ● Main
#--------------------------------------------------------------------------
def main
@spriteset = Spriteset_Map.new if @spriteset_visible
@background = Sprite.new
@map.bitmap = RPG::Cache.picture(@carte_img)
@background.x = 0
@background.y = 0
@background.z = 5
@curseur = Sprite.new
@curseur.bitmap = RPG::Cache.picture(@curseur_img)
@curseur.x = @map_x + @cote_case * ($game_variables[$var_x]-1)
@curseur.y = @map_y + @cote_case * ($game_variables[$var_y]-1)
@curseur.z = 8
@index = [$game_variables[$var_x],$game_variables[$var_y]]
@hero = Sprite.new
@hero.bitmap = RPG::Cache.picture(@perso_img)
@hero.x = @map_x + @cote_case * ($game_variables[$var_x]-1)
@hero.y = @map_y + @cote_case * ($game_variables[$var_y]-1)
@hero.z = 7
@text = Window_Base.new(0 - 16, 0 - 16, 672, 512)
@text.opacity = 0
@text.contents = Bitmap.new(672, 512)
@text.z = 6
refresh
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@spriteset.dispose if @spriteset_visible
@background.dispose
@curseur.dispose
@hero.dispose
@text.dispose
end
#--------------------------------------------------------------------------
# ● Update
#--------------------------------------------------------------------------
def update
@curseur.x = @map_x + @cote_case * (@index[0]-1)
@curseur.y = @map_y + @cote_case * (@index[1]-1)
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
return
end
if Input.trigger?(Input::DOWN)
if @index[1] != @nb_case_v
$game_system.se_play($data_system.cursor_se)
@index[1] += 1
end
refresh
return
end
if Input.trigger?(Input::UP)
if @index[1] != 1
$game_system.se_play($data_system.cursor_se)
@index[1] -= 1
end
refresh
return
end
if Input.trigger?(Input::LEFT)
if @index[0] != 1
$game_system.se_play($data_system.cursor_se)
@index[0] -= 1
end
refresh
return
end
if Input.trigger?(Input::RIGHT)
if @index[0] != @nb_case_h
$game_system.se_play($data_system.cursor_se)
@index[0] += 1
end
refresh
return
end
end
#--------------------------------------------------------------------------
# ● Refresh
#--------------------------------------------------------------------------
def refresh
@text.contents.clear
string = $local[@index[0]][@index[1]][0]
desc = $local[@index[0]][@index[1]][1]
@text.contents.font.name = @text_police
@text.contents.font.size = @text_size
@text.draw_text(@text_x, @text_y, 247, 16, string, 1, @text_color, 0)
@text.contents.font.name = @desc_police
@text.contents.font.size = @desc_size
@text.draw_text(@desc_x, @desc_y, 247, 16, desc, 1, @desc_color, 0)
end
#--------------------------------------------------------------------------
# ● Init(x, y, nom, desc, type)
#--------------------------------------------------------------------------
def init(o_x, o_y, nom, desc, o_type)
if o_type.is_a? String
case o_type
when "ville"
type = 1
else
type = 0
end
else
type = o_type
end
if o_x.is_a? Range
o_x.each {|x|
if o_y.is_a? Range
o_y.each {|y| $local[x][y] = [nom,desc, false, type] }
else
$local[x][o_y] = [nom,desc, false, type]
end
}
else
if o_y.is_a? Range
o_y.each {|y| $local[o_x][y] = [nom,desc, false, type] }
else
$local[o_x][o_y] = [nom,desc, false, type]
end
end
end
#--------------------------------------------------------------------------
# ● note
#--------------------------------------------------------------------------
def note
logfile = File.open("Data/carte.txt", "w")
logfile.write("# ---------- Mappemonde ----------\n")
logfile.write("\n")
empty = 0
for x in 0..$local.size-1
for y in 0..$local[x].size-1
nom = $local[x][y][0]
if nom.length != 0
desc = $local[x][y][1]
type = $local[x][y][3] == 0 ? "normal" : "ville"
string = x.to_s + '.' + y.to_s + ' -> ' + nom + ' : ' + desc + '('+type+')'
logfile.write(string)
logfile.write("\n")
else
empty += 1
end
end
end
logfile.write("\n")
string = "Et #{empty.to_s} case"+ (empty > 1 ? "s vides." : " vide.")
logfile.write(string)
logfile.close
end
end
#==============================================================================
# ■ Appel depuis la map
#
# Remplacez :
# -> Y par la touche qui ouvre la carte depuis la carte.
# -> 200 par le n°de l'interrupteur qui active cette fonction.
#
#==============================================================================
class Scene_Map
alias map_update update
def update
if Input.trigger?(Input::Y) and $game_switches[200]
$scene = Scene_Carte.new
end
map_update
end
end
#==============================================================================
# ■ Interpreter
#
# Fonctions lié à la carte.
#
#==============================================================================
class Interpreter
#--------------------------------------------------------------------------
# ● Init_map (facultatif) - Remise à Zéro des infos de la map.
#--------------------------------------------------------------------------
def init_map
Scene_Carte.initialize
end
#--------------------------------------------------------------------------
# ● Init_local - Modification des infos sur un lieu (comme les "init" ligne 82)
#--------------------------------------------------------------------------
def init_local(x, y, nom, desc, type)
Scene_Carte.init(x, y, nom, desc, type)
Scene_Carte.note
end
#--------------------------------------------------------------------------
# ● Scene_carte - Appel de la Carte
#--------------------------------------------------------------------------
def scene_carte
$scene = Scene_Carte.new
end
#--------------------------------------------------------------------------
# ● Local - Défini la position du héro
#--------------------------------------------------------------------------
def local(x_or_name, o_y = nil)
if $local == nil
Scene_Carte.initialize
end
@data = []
if y == nil
@exist = false
for x in 0..$local.size-1
for y in 0..$local[x].size-1
if $local[x][y][0] == x_or_name and
!@exist @exist == true
@data = [x, y]
$local[x][y][2] = true
end
end
end
print("le lieu : #{x_or_name} n'existe pas.") if
!@exist @data [1, 1] if
!@exist else
@data = [x_or_name, o_y]
$local[x_or_name][o_y][2] = true
end
$game_variables[$var_x] = @data[0]
$game_variables[$var_y] = @data[1]
end
end