Le Deal du moment : -34%
-34% LG OLED55B3 – TV OLED 4K 55″ 2023 ...
Voir le deal
919 €

Aller en bas

Ce tuto vous semble-t-il utile?

13 - 65%
7 - 35%
 
Total des votes: 20
 
Anonymous
Invité
Invité

"Tuto": Comprendre un script Empty "Tuto": Comprendre un script

Ven 31 Oct 2008 - 13:15
Je préviens tout de suite, je ne me considère pas vraiment comme un programmeur Ruby (pour les autre langages oui,mais là non) j'en suis au stade d'auto apprentissage. Sur ce tuto je compte publier mes travaux sur les script, c'est à dite que je vais prendre un script et essayer de comprendre et d'expliciter chaque ligne. Les informations sur ce tuto ne seront pas à prendre telle quelle car il n'y aura d'intérêt que si vous suivez la progression pour voir où j'ai fait des erreur (où nous avons fait des erreurs car j'espère que vous allez participer).

Ceci étant dit allons y


LÉGENDE:

- Conventions
- Commentaires perso
- explications syntaxe
- explication fonctionnement
- validation de mes dires par quelqu'un d'autre ou par démonstration



##################################################
# Mog Basic Menu Plus V 1.0 # |=====>Des conventions : mettre le nom du script et son auteur en commentaire
##################################################
# By Moghunter #
# http://www.atelier-rgss.com #
##################################################
#Menu padrão VX com adição de alguns extras, neste
#script você poderá trabalhar em cima dele e adaptá-lo |======> euh... j'ai pris allemand LV2|mettre des commentaires genre ce script marche sur telle ou telle plateforme
#facilmente ao seu jogo.
#-------------------------------------------------
##############
# Game_Actor # |====>cette partie du script va servir à définir l'expérience dans le menu statut
##############
class(on definit la classe="une categorie" où l'on travaille) Game_Actor < (hereditée entre classes) Game_Battler
def now_exp
return @exp - @exp_list[@level] |===>exp totale
end|<===fin de def now_exp
def next_exp
return @exp_list[@level+1] > 0 ? @exp_list[@level+1] - @exp_list[@level] : 0|==>exp jusqu'au prochain niveau
end|<===fin de def next_exp
end|<===fin de classe (cool c'est la récré)

###############
# Window_Base #
###############
class Window_Base < Window
def draw_actor_level_menu(actor, x, y)
self.contents.font.color = system_color
self.contents.draw_text(x, y, 32, WLH, Vocab::level_a)
self.contents.font.color = normal_color
self.contents.draw_text(x + 16, y, 24, WLH, actor.level, 2)
end
def draw_actor_class_menu(actor, x, y)
self.contents.font.color = normal_color
self.contents.draw_text(x, y, 85, WLH, actor.class.name)
end
def exp_gauge_color1

return text_color(30)
end
def exp_gauge_color2
return text_color(31)
end
def draw_actor_exp_meter(actor, x, y, width = 100)
if actor.next_exp != 0
exp = actor.now_exp
else
exp = 1
end
gw = width * exp / [actor.next_exp, 1].max
gc1 = exp_gauge_color1
gc2 = exp_gauge_color2
self.contents.fill_rect(x, y + WLH - 8, width, 6, gauge_back_color)
self.contents.gradient_fill_rect(x, y + WLH - 8, gw, 6, gc1, gc2)
self.contents.font.color = system_color
self.contents.draw_text(x, y, 30, WLH, "Exp")
self.contents.font.color = normal_color
xr = x + width
self.contents.draw_text(xr - 60, y, 60, WLH, actor.next_rest_exp_s, 2)
end
end
#####################
# Window_MenuStatus #
#####################
class Window_MenuStatus < Window_Selectable
def initialize(x, y)
super(x, y, 384, 416)
refresh
self.active = false
self.index = -1
end
def refresh
self.contents.clear
@item_max = $game_party.members.size
for actor in $game_party.members
draw_actor_face(actor, 2, actor.index * 96 + 2, 92)
x = 104
y = actor.index * 96 + WLH / 2
draw_actor_name(actor, x, y)
draw_actor_class_menu(actor, x + 120, y)
draw_actor_level_menu(actor, x + 200, y)
draw_actor_state(actor, x, y + WLH * 2)
draw_actor_hp(actor, x + 120, y + WLH * 1)
draw_actor_mp(actor, x + 120, y + WLH * 2)
draw_actor_exp_meter(actor, x , y + WLH * 1)
end
end
def update_cursor
if @index < 0
self.cursor_rect.empty
elsif @index < @item_max
self.cursor_rect.set(0, @index * 96, contents.width, 96)
elsif @index >= 100
self.cursor_rect.set(0, (@index - 100) * 96, contents.width, 96)
else
self.cursor_rect.set(0, 0, contents.width, @item_max * 96)
end
end
end
############
# Game_Map #
############
class Game_Map
attr_reader :map_id
def mpname
$mpname = load_data("Data/MapInfos.rvdata")
$mpname[@map_id].name
end
end
###############
# Window_Time #
###############
class Window_Mapname < Window_Base
def initialize(x, y)
super(x, y, 160, WLH + 64)
refresh
end
def refresh
self.contents.clear
self.contents.font.color = system_color
self.contents.draw_text(4, 0, 120, 32, "Location")
self.contents.font.color = normal_color
self.contents.draw_text(4, 32, 120, 32, $game_map.mpname.to_s, 2)
end
end
###############
# Window_Time #
###############
class Window_Time < Window_Base
def initialize(x, y)
super(x, y, 160, WLH + 64)
refresh
end
def refresh
self.contents.clear
self.contents.font.color = system_color
self.contents.draw_text(4, 0, 120, 32, "Play Time")
@total_sec = Graphics.frame_count / Graphics.frame_rate
hour = @total_sec / 60 / 60
min = @total_sec / 60 % 60
sec = @total_sec % 60
text = sprintf("%02d:%02d:%02d", hour, min, sec)
self.contents.font.color = normal_color
self.contents.draw_text(4, 32, 120, 32, text, 2)
end
def update
super
if Graphics.frame_count / Graphics.frame_rate != @total_sec
refresh
end
end
end
##############
# Scene_Menu #
##############
class Scene_Menu
def main
start
perform_transition
Input.update
loop do
Graphics.update
Input.update
update
break if $scene != self
end
Graphics.update
pre_terminate
Graphics.freeze
terminate
end
def initialize(menu_index = 0)
@menu_index = menu_index
end
def create_menu_background
@menuback_sprite = Sprite.new
@menuback_sprite.bitmap = $game_temp.background_bitmap
@menuback_sprite.color.set(16, 16, 16, 128)
update_menu_background
end
def create_menu_background
@menuback_sprite = Sprite.new
@menuback_sprite.bitmap = $game_temp.background_bitmap
@menuback_sprite.color.set(16, 16, 16, 128)
update_menu_background
end
def dispose_menu_background
@menuback_sprite.dispose
end
def update_menu_background
end
def perform_transition
Graphics.transition(10)
end
def start
create_menu_background
create_command_window
@gold_window = Window_Gold.new(0, 360)
@status_window = Window_MenuStatus.new(160, 0)
@playtime_window = Window_Time .new(0, 270)
@mapname_window = Window_Mapname.new(0, 178)
@status_window.openness = 0
@playtime_window.openness = 0
@mapname_window.openness = 0
@gold_window.openness = 0
@status_window.open
@playtime_window.open
@mapname_window.open
@gold_window.open
end
def pre_terminate
@status_window.close
@playtime_window.close
@mapname_window.close
@gold_window.close
@command_window.close
begin
@status_window.update
@playtime_window.update
@mapname_window.update
@gold_window.update
@command_window.update
Graphics.update
end until @status_window.openness == 0
end
def terminate
dispose_menu_background
@command_window.dispose
@gold_window.dispose
@status_window.dispose

@playtime_window.dispose
@mapname_window.dispose
end
def update
update_menu_background
@command_window.update
@gold_window.update
@status_window.update
@mapname_window.update
@playtime_window.update
if @command_window.active
update_command_selection
elsif @status_window.active
update_actor_selection
end
end
def create_command_window
s1 = Vocab::item
s2 = Vocab::skill
s3 = Vocab::equip
s4 = Vocab::status
s5 = Vocab::save
s6 = Vocab::game_end
@command_window = Window_Command.new(160, [s1, s2, s3, s4, s5, s6])
@command_window.index = @menu_index
@command_window.openness = 0
@command_window.open
if $game_party.members.size == 0
@command_window.draw_item(0, false)
@command_window.draw_item(1, false)
@command_window.draw_item(2, false)
@command_window.draw_item(3, false)
end
if $game_system.save_disabled
@command_window.draw_item(4, false)
end
end
def update_command_selection
if Input.trigger?(Input::B)
Sound.play_cancel
$scene = Scene_Map.new
elsif Input.trigger?(Input::C)
if $game_party.members.size == 0 and @command_window.index < 4
Sound.play_buzzer
return
elsif $game_system.save_disabled and @command_window.index == 4
Sound.play_buzzer
return
end
Sound.play_decision
case @command_window.index
when 0
$scene = Scene_Item.new
when 1,2,3
start_actor_selection
when 4
$scene = Scene_File.new(true, false, false)
when 5
$scene = Scene_End.new
end
end
end
def start_actor_selection
@command_window.active = false
@status_window.active = true
if $game_party.last_actor_index < @status_window.item_max
@status_window.index = $game_party.last_actor_index
else
@status_window.index = 0
end
end
def end_actor_selection
@command_window.active = true
@status_window.active = false
@status_window.index = -1
end
def update_actor_selection
if Input.trigger?(Input::B)
Sound.play_cancel
end_actor_selection
elsif Input.trigger?(Input::C)
$game_party.last_actor_index = @status_window.index
Sound.play_decision
case @command_window.index
when 1
$scene = Scene_Skill.new(@status_window.index)
when 2
$scene = Scene_Equip.new(@status_window.index)
when 3
$scene = Scene_Status.new(@status_window.index)
end
end
end
end
$mogscript = {} if $mogscript == nil
$mogscript["basic_menu_plus"] = true

EDIT: laisser des posts et je modifierai par la suite.
Chocolatmiam
Chocolatmiam
Membre

Nombre de messages : 12
Localisation : Dans mon placard
Distinction : aucune
Date d'inscription : 03/11/2008

"Tuto": Comprendre un script Empty Re: "Tuto": Comprendre un script

Lun 17 Nov 2008 - 21:22
Hmm , je n'ai pas tout compris , ça va un peut vite pour la noob de tout ce qui touche à la programmation que je suis Smile , peut-être ( si je puis me permettre) que détailler un peu plus permettra aux non-initiés de mieux suivre le tuto ? (Après c'est peut-être aussi juste moi qui ne suis pas assez familière avec le making and cie ^^ )
Namor41
Namor41
Membre

Nombre de messages : 57
Age : 57
Localisation : Canada (Québec)
Distinction : aucune
Date d'inscription : 10/05/2008

"Tuto": Comprendre un script Empty Re: "Tuto": Comprendre un script

Mar 18 Nov 2008 - 20:36
Pourrais-tu mettre une autre couleur que le rouge? C'est vraiment fatiguant pour les yeux. Oui, c'est assez difficile à comprendre pour un néophyte en script comme moi.

Merci
Contenu sponsorisé

"Tuto": Comprendre un script Empty Re: "Tuto": Comprendre un script

Revenir en haut
Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum