Maire Lv.9
Age : 37 Inscrit le : 04/02/2009 Messages : 326
| Sujet: [VX] Mouvements supplémentaires Mar 6 Oct 2009 - 3:39 | |
| Mouvements supplémentaires.v2 -IntroductionParfois j'ai besoin de petites fonctions simples, qui ne méritent pas de script à part entière, alors je les regourpent toutes là-dedans. Il y a des mouvements supplementaires, des accesseurs, des choses assez simples. Ce script se décompose en differents modules correspondants à des classes comme l'interpreteur ou character. Il y a ausi un module mixte. Cette organisation me permet de simplifier les inclusions. -InstallationCe script n'échappe pas à la régle du "copiez en dessous de material". Il n'a pas de nécéssité particulière. -script: - Spoiler:
- Code:
-
#=============================================================================== # # # Mouvements supplémentaires .v2 # # #=============================================================================== # #By Vincentmhd #http://vincentmhdmaker.canalblog.com/ #2/10/2009 #v1 -> v2 :Ajout des directions diagonales pour la méthode go_to et approach_to # :Ajout des méthodes step_to, travel_to # :méthode analogue à go_to et approach_to suf qu'elles tiennent compte de la passabilité # :le perso peut se coinser mais ça devrait être plus rare car il y a une pseudo intelligence artificielle #=====================================NOTE====================================== # #Ce script ajoute de petites fonctions. Elle se décompose en plusieurs modules #chacun spécifiques à une classe sauf pour MIXTE qui contient des méthodes #communes. # #Je ne peux pas m'amuser à toutes les expliquer car c'est une sorte de fourre #tout personnel. # #-------------------------------------------------------------------------------
module MIXTE #------------------------------------------------------------------------------# #Wait at random between min and max # #------------------------------------------------------------------------------# def wait_between(min,max) middle = min + rand(max - min) @wait_count = middle end #------------------------------------------------------------------------------# #Wait at random between 0 and max # #------------------------------------------------------------------------------# def wait_between_M(max) middle = rand(max) @wait_count = middle end #------------------------------------------------------------------------------# # * Erase Event #------------------------------------------------------------------------------# def erase_event(id) $game_map.events[id].erase end #------------------------------------------------------------------------------# # * Start Event #------------------------------------------------------------------------------# def start_event(id) $game_map.events[id].start end
#------------------------------------------------------------------------------# # * Tint Screen #------------------------------------------------------------------------------# def Tint_Screen(r, g, b, a, t, bool = false) tone = Tone.new(r,g,b,a) $game_map.screen.start_tone_change(tone, t) @wait_count = t if bool end #------------------------------------------------------------------------------# # * Tint Screen Relative #------------------------------------------------------------------------------# def Tint_Screen_R(r, g, b, a, t, bool = false) red = $game_map.screen.tone_target.red + r green = $game_map.screen.tone_target.green + g blue = $game_map.screen.tone_target.blue + b alpha = $game_map.screen.tone_target.gray + a tone = Tone.new(red, green, blue, alpha) $game_map.screen.start_tone_change(tone, t) @wait_count = t if bool end #------------------------------------------------------------------------------# # * Screen Flash #------------------------------------------------------------------------------# def Flash_Screen(r, g, b, a, t, bool = false) tone = Color.new(r,g,b,a) $game_map.screen.start_flash(tone, t) @wait_count = t if bool end #------------------------------------------------------------------------------# # * Screen Flash Relative #------------------------------------------------------------------------------# def Flash_Screen_R( r, g, b, a, t, bool = false) if $game_map.screen.flash_duration != 0 red = $game_map.screen.flash_color.red + r green = $game_map.screen.flash_color.green + g blue = $game_map.screen.flash_color.blue + b alpha = $game_map.screen.flash_color.alpha + a else red = $game_map.screen.tone_target.red + r green = $game_map.screen.tone_target.green + g blue = $game_map.screen.tone_target.blue + b alpha = $game_map.screen.tone_target.gray + a end tone = Color.new(red, green, blue, alpha) $game_map.screen.start_flash(tone, t) @wait_count = t if bool end
#==============================================================================# end #module MIXTE end# #==============================================================================#
module EVENT #------------------------------------------------------------------------------# #Change event trigger: # # # #0: Input Touch # #1: Contact Heros # #2: Contact Event # #3: Automatic # #4: Parallel Process # #5+: None # # # #------------------------------------------------------------------------------# attr_accessor :trigger def change_trigger( t ) @trigger = t end
#==============================================================================# end #module EVENT end# #==============================================================================#
module INTERPRETER def change_trigger(t, id = @event_id) $game_map.events[id].trigger = t end #==============================================================================# end #module INTERPRETER end# #==============================================================================#
module CHARACTER #------------------------------------------------------------------------------# #Change event priority # #------------------------------------------------------------------------------# attr_accessor :priority_type def change_priority(p) @priority_type = p end #------------------------------------------------------------------------------# #Selfswitches for move id = ' ' # #------------------------------------------------------------------------------# def self_switches(id, value) key = [$game_map.map_id, @id, id] $game_self_switches[key] = (value) $game_map.need_refresh = true end #------------------------------------------------------------------------------# #Manual start event if(player is on the event) # #------------------------------------------------------------------------------# def start_if_on if $game_player.x == @x && $game_player.y== @y start end end #------------------------------------------------------------------------------# #Ramdom moveTo (x et y are arrays) # #------------------------------------------------------------------------------# def moveto_R_between(x,y) index = rand(x.size) moveto(x[index],y[index]) end #------------------------------------------------------------------------------# #Order moveTo (x et y are arrays) # #------------------------------------------------------------------------------# attr_accessor :order def moveto_O(x,y) if (@order == nil) || (@order == (x.size - 1)) @order = 0 else @order +=1 end moveto(x[@order],y[@order]) end #------------------------------------------------------------------------------# #Random moveTo in a rect # #------------------------------------------------------------------------------# def moveto_R_in(x_min, x_max, y_min, y_max) x = x_min + rand(x_max - x_min + 1) y = y_min + rand(y_max - y_min + 1) moveto(x.to_i,y.to_i) end #------------------------------------------------------------------------------# #moveto_P si passable # #------------------------------------------------------------------------------# def moveto_P(x, y) if passable?(x,y) moveto(x.to_i,y.to_i) end end #------------------------------------------------------------------------------# #Random moveto_P in a rect # #------------------------------------------------------------------------------# def moveto_P_in(x_min, x_max, y_min, y_max) x = x_min + rand(x_max - x_min + 1) y = y_min + rand(y_max - y_min + 1) while passable?(x,y) moveto_P(x.to_i,y.to_i) x = x_min + rand(x_max - x_min + 1) y = y_min + rand(y_max - y_min + 1) end end #------------------------------------------------------------------------------- # * Jump if place is passable # x_plus : x-coordinate plus value # y_plus : y-coordinate plus value #------------------------------------------------------------------------------- def jump_P(x_plus, y_plus) if passable? (@x + x_plus, @y + y_plus) if x_plus.abs > y_plus.abs # Horizontal distance is longer x_plus < 0 ? turn_left : turn_right elsif x_plus.abs > y_plus.abs # Vertical distance is longer y_plus < 0 ? turn_up : turn_down end @x += x_plus @y += y_plus distance = Math.sqrt(x_plus * x_plus + y_plus * y_plus).round @jump_peak = 10 + distance - @move_speed @jump_count = @jump_peak * 2 @stop_count = 0 straighten end end #------------------------------------------------------------------------------- # * Jump if place is passable in Star # x_plus : x-coordinate plus value # y_plus : y-coordinate plus value #------------------------------------------------------------------------------- def jump_C(star) dir = rand(8) ok = false a = 0 while ok == false case dir when 0 #down ok = passable?(@x,@y-star) when 1 #left ok = passable?(@x-star,@y) when 2 #right ok = passable?(@x+star,@y) when 3 #up ok = passable?(@x,@y+star) when 4 #down left ok = passable?(@x-star,@y-star) when 5 #down rigth ok = passable?(@x+star,@y-star) when 6 #up left ok = passable?(@x-star,@y+star) when 7 #up right ok = passable?(@x+star,@y+star) end if (ok==false) dir = rand(8) end end if ok == true case dir when 0 #down jump(0,-star) when 1 #left jump(-star,0) when 2 #right jump(star,0) when 3 #up jump(0,star) when 4 #down left jump(-star,-star) when 5 #down rigth jump(star,-star) when 6 #up left jump(-star,star) when 7 #up right jump(star,star) end end end #------------------------------------------------------------------------------- # Approach to (x, y) !!Passability is not considered #------------------------------------------------------------------------------- attr_accessor :target_x, :target_y, :impasse, :nbsmove def approach_to(x,y) @target_x = x @target_y = y sx = @x - @target_x sy = @y - @target_y #mvts obliques if ((sx.abs > 0)&&(sy.abs > 0)) if (sx > 0) if (sy > 0) move_upper_left else move_lower_left end else if (sy > 0) move_upper_right else move_lower_right end end else #mvts rectilignes if ((sx.abs > 0)||(sy.abs > 0)) if (sx.abs > sy.abs) # Horizontal distance is longer if (sx > 0) move_left() else move_right() end else # Vertical distance is longer if (sy > 0) move_up() else move_down() end end end end end def move_coef(down,left,right,up) coef = rand(down + left + right + up) if coef < down move_down else if coef < (down + left) move_left else if coef < (down + left + right) move_right else move_up end end end end #------------------------------------------------------------------------------- # step to (x, y) Passability is considered #------------------------------------------------------------------------------- def step_to(x,y) sx = @x - @target_x sy = @y - @target_y a = @x.to_i b = @y.to_i c = 0 if @impasse == nil @impasse = 0 end if @nbsmove == nil @nbsmove = 0 end @nbsmove +=1 coef = (100*@impasse.to_f/@nbsmove.to_f).to_i if ((coef >= 50) && (@nbsmove > 15))||(@nbsmove > 40) @impasse = 0 @nbsmove = 1 end coef = (100*@impasse.to_f/@nbsmove.to_f).to_i chance = rand(100) case chance when 0 ... coef #déplacement au hasard while(!((!((@x == a) && (@y == b)))||(c > 5))) move_random c +=1 end when coef ... (coef + (100 - coef)/4) #déplacement seulement rectiligne mais réfléchi if (sx.abs > sy.abs) # Horizontal distance is longer if (sx > 0) if passable?(@x-1, @y) move_left() else @impasse += 1 while(!((!((@x == a) && (@y == b)))||(c > 5))) move_random c +=1 end end else if passable?(@x+1, @y) move_right() else @impasse += 1 while(!((!((@x == a) && (@y == b)))||(c > 5))) move_random c +=1 end end end else # Vertical distance is longer if (sy > 0) if passable?(@x, @y-1) move_up() else @impasse += 1 while(!((!((@x == a) && (@y == b)))||(c > 5))) move_random c +=1 end end else if passable?(@x, @y+1) move_down() else @impasse += 1 while(!((!((@x == a) && (@y == b)))||(c > 5))) move_random c +=1 end end end end
else #Déplacement normal if ((sx.abs > 0)&&(sy.abs > 0)) if (sx > 0) if (sy > 0) if passable?(@x-1, @y-1) move_upper_left else @impasse += 1 while(!((!((@x == a) && (@y == b)))||(c > 5))) move_random c +=1 end end else if passable?(@x-1, @y+1) move_lower_left else @impasse += 1 while(!((!((@x == a) && (@y == b)))||(c > 5))) move_random c +=1 end end end else if (sy > 0) if passable?(@x+1, @y-1) move_upper_right else @impasse += 1 while(!((!((@x == a) && (@y == b)))||(c > 5))) move_random c +=1 end end else if passable?(@x+1, @y+1) move_lower_right else @impasse += 1 while(!((!((@x == a) && (@y == b)))||(c > 5))) move_random c +=1 end end end end else if ((sx.abs > 0)||(sy.abs > 0)) if (sx.abs > sy.abs) # Horizontal distance is longer if (sx > 0) if passable?(@x-1, @y) move_left() else @impasse += 1 while(!((!((@x == a) && (@y == b)))||(c > 5))) move_random c +=1 end end else if passable?(@x+1, @y) move_right() else @impasse += 1 while(!((!((@x == a) && (@y == b)))||(c > 5))) move_random c +=1 end end end else # Vertical distance is longer if (sy > 0) if passable?(@x, @y-1) move_up() else @impasse += 1 while(!((!((@x == a) && (@y == b)))||(c > 5))) move_random c +=1 end end else if passable?(@x, @y+1) move_down() else @impasse += 1 while(!((!((@x == a) && (@y == b)))||(c > 5))) c +=1 move_random end end end end end end end end #------------------------------------------------------------------------------- # Go to (x, y) absolue !!Passability is not considered #------------------------------------------------------------------------------- def go_to(x,y) @target_x = x @target_y = y @custom_index = 1 end #------------------------------------------------------------------------------- # Go to (x, y) relative !!Passability is not considered #------------------------------------------------------------------------------- def go_to_R(x,y) @target_x = @x + x @target_y = @y + y @custom_index = 1 end
#------------------------------------------------------------------------------- # Go to (x_min, x_max, y_min, y_max) !!Passability is not considered #------------------------------------------------------------------------------- def go_to_in(x_min, x_max, y_min, y_max) @target_x = x_min + rand(x_max - x_min + 1) @target_y = y_min + rand(y_max - y_min + 1) @custom_index = 1 end #------------------------------------------------------------------------------- # Go to (x_min, x_max, y_min, y_max) if P !!Passability is not considered #------------------------------------------------------------------------------- def go_to_in_P(x_min, x_max, y_min, y_max) @target_x = x_min + rand(x_max - x_min + 1) @target_y = y_min + rand(y_max - y_min + 1) while !(passable?(@target_x,@target_y)) @target_x = x_min + rand(x_max - x_min + 1) @target_y = y_min + rand(y_max - y_min + 1) end @custom_index = 1 end #------------------------------------------------------------------------------- # Travel to (x, y) absolue Passability is considered #------------------------------------------------------------------------------- def travel_to(x,y) @target_x = x @target_y = y @custom_index = 2 end #------------------------------------------------------------------------------- # Travel to (x, y) relative Passability is considered #------------------------------------------------------------------------------- def travel_to_R(x,y) @target_x = @x + x @target_y = @y + y @custom_index = 2 end
#------------------------------------------------------------------------------- # Travel to (x_min, x_max, y_min, y_max) Passability is considered #------------------------------------------------------------------------------- def travel_to_in(x_min, x_max, y_min, y_max) @target_x = x_min + rand(x_max - x_min + 1) @target_y = y_min + rand(y_max - y_min + 1) @custom_index = 2 end #------------------------------------------------------------------------------- # Travel to (x_min, x_max, y_min, y_max) if P #------------------------------------------------------------------------------- def travel_to_in_P(x_min, x_max, y_min, y_max) @target_x = x_min + rand(x_max - x_min + 1) @target_y = y_min + rand(y_max - y_min + 1) while !(passable?(@target_x,@target_y)) @target_x = x_min + rand(x_max - x_min + 1) @target_y = y_min + rand(y_max - y_min + 1) end @custom_index = 2 end
#------------------------------------------------------------------------------- # Show balloon #------------------------------------------------------------------------------- def show_balloon(id) @balloon_id = id end #==============================================================================# end #module CHARACTER end# #==============================================================================#
#------------------------------------------------------------------------------# #Inclusion des modules + appoint # #------------------------------------------------------------------------------# class Game_Interpreter include MIXTE include INTERPRETER end
class Game_Character include MIXTE include CHARACTER #------------------------------------------------------------------------------- # Custom moves (x y) #------------------------------------------------------------------------------- alias go_to_move_type_custom move_type_custom def move_type_custom if stopping? case @custom_index when nil go_to_move_type_custom when 1 if ((@x == @target_x)&&(@y==@target_y)) @custom_index = nil else approach_to(@target_x, @target_y) end when 2 if ((@x == @target_x)&&(@y==@target_y)) #print(@impasse.to_f/@nbsmove.to_f) #verif % de réussite @custom_index = nil @nbsmove = 0 @impasse = 0 else step_to(@target_x, @target_y) end else #nothing end end end end
class Game_Event include MIXTE include EVENT end #------------------------------------------------------------------------------# #Appoints divers # #------------------------------------------------------------------------------#
class Game_Screen attr_reader :tone_target, :flash_duration, :flash_color end
Modification du déclenchementCette méthode modifie le trigger de l'event en question, cette méthode peut être très puissante... Appel Déplacement: - Spoiler:
- Code:
-
attr_accessor :trigger def change_trigger( t ) @trigger = t end
Appel Interpreter: - Spoiler:
- Code:
-
def change_trigger(t, id = @event_id) $game_map.events[id].trigger = t end Modification de la priorité d'un event (de la couche)Cette méthode modifie la couche de l'event: dessus, desous, même que le héro, elle va de paire avec le changement de trigger, cette méthode peut être aussi très puissante si bien exploitée... Appel Déplacement: - Spoiler:
- Code:
-
attr_accessor :priority_type def change_priority(p) @priority_type = p end Modification Selfswitches pendant un déplacementCette fonction me manquait car je me demande pourquoi ils ont mis une fonction pour modifier les game_switches mais pas les variables et les selfswitches?! id correspond à "A", "B" ... value true or false Appel Déplacement: - Spoiler:
- Code:
-
def self_switches(id, value) key = [$game_map.map_id, @id, id] $game_self_switches[key] = (value) $game_map.need_refresh = true end Start event if onC'est un besoin particulier. L'event commence manuellement si le player est sur la même case. Appel Déplacement: - Spoiler:
- Code:
-
def start_if_on if $game_player.x == @x && $game_player.y== @y start end end Montre une émoticoneAppel Déplacement: - Spoiler:
- Code:
-
def show_balloon(id) @balloon_id = id end Les déplacementsTéléportation aléatoire dans une liste de positions x est y sont des arrays de taille identique. Appel Déplacement: - Spoiler:
- Code:
-
def moveto_R_between(x,y) index = rand(x.size) moveto(x[index],y[index]) end Téléportation ordonnée dans une liste de positions x est y sont des arrays de taille identique. Appel Déplacement: - Spoiler:
- Code:
-
attr_accessor :order def moveto_O(x,y) if (@order == nil) || (@order == (x.size - 1)) @order = 0 else @order +=1 end moveto(x[@order],y[@order]) end Téléportation aleatoire dans une zone rectangulaire Appel Déplacement: - Spoiler:
- Code:
-
def moveto_R_in(x_min, x_max, y_min, y_max) x = x_min + rand(x_max - x_min + 1) y = y_min + rand(y_max - y_min + 1) moveto(x.to_i,y.to_i) end Téléportation si la case est passableAppel Déplacement: - Spoiler:
- Code:
-
def moveto_P(x, y) if passable?(x,y) moveto(x.to_i,y.to_i) end end Téléportation aleatoire dans une zone rectangulaire et si la case est passableAppel Déplacement: - Spoiler:
- Code:
-
def moveto_P_in(x_min, x_max, y_min, y_max) x = x_min + rand(x_max - x_min + 1) y = y_min + rand(y_max - y_min + 1) while passable?(x,y) moveto_P(x.to_i,y.to_i) x = x_min + rand(x_max - x_min + 1) y = y_min + rand(y_max - y_min + 1) end end Saut si la case est passableAppel Déplacement: - Spoiler:
- Code:
-
def jump_P(x_plus, y_plus) if passable? (@x + x_plus, @y + y_plus) if x_plus.abs > y_plus.abs # Horizontal distance is longer x_plus < 0 ? turn_left : turn_right elsif x_plus.abs > y_plus.abs # Vertical distance is longer y_plus < 0 ? turn_up : turn_down end @x += x_plus @y += y_plus distance = Math.sqrt(x_plus * x_plus + y_plus * y_plus).round @jump_peak = 10 + distance - @move_speed @jump_count = @jump_peak * 2 @stop_count = 0 straighten end end Saut sur une des case autour au rayon spécifié et si la case est passableAppel Déplacement: - Spoiler:
- Code:
-
def jump_C(star) dir = rand(8) ok = false a = 0 while ok == false case dir when 0 #down ok = passable?(@x,@y-star) when 1 #left ok = passable?(@x-star,@y) when 2 #right ok = passable?(@x+star,@y) when 3 #up ok = passable?(@x,@y+star) when 4 #down left ok = passable?(@x-star,@y-star) when 5 #down rigth ok = passable?(@x+star,@y-star) when 6 #up left ok = passable?(@x-star,@y+star) when 7 #up right ok = passable?(@x+star,@y+star) end if (ok==false) dir = rand(8) end end if ok == true case dir when 0 #down jump(0,-star) when 1 #left jump(-star,0) when 2 #right jump(star,0) when 3 #up jump(0,star) when 4 #down left jump(-star,-star) when 5 #down rigth jump(star,-star) when 6 #up left jump(-star,star) when 7 #up right jump(star,star) end end end S'approcher d'une positionAttention ce déplacement ne tient pas compte de la passabilité et peut bloquer l'event. Appel Déplacement: - Spoiler:
- Code:
-
#------------------------------------------------------------------------------- # Approach to (x, y) !!Passability is not considered #------------------------------------------------------------------------------- attr_accessor :target_x, :target_y def approach_to(x,y) @target_x = x @target_y = y sx = @x - @target_x sy = @y - @target_y #mvts obliques if ((sx.abs > 0)&&(sy.abs > 0)) if (sx > 0) if (sy > 0) move_upper_left else move_lower_left end else if (sy > 0) move_upper_right else move_lower_right end end else #mvts rectilignes if ((sx.abs > 0)||(sy.abs > 0)) if (sx.abs > sy.abs) # Horizontal distance is longer if (sx > 0) move_left() else move_right() end else # Vertical distance is longer if (sy > 0) move_up() else move_down() end end end end end Aller àAttention ce déplacement ne tient pas compte de la passabilité et peut bloquer l'event. Comme d'habitude il y a deux types de coordonnées: absolues et relatives. Ce déplacement se fait tant que le personnage n'a pas atteint les coordonées (blocage possible). Appel Déplacement: - Spoiler:
- Code:
-
#------------------------------------------------------------------------------- # Go to (x, y) absolue !!Passability is not considered #------------------------------------------------------------------------------- def go_to(x,y) @target_x = x @target_y = y @custom_index = 1 end #------------------------------------------------------------------------------- # Go to (x, y) relative !!Passability is not considered #------------------------------------------------------------------------------- def go_to_R(x,y) @target_x = @x + x @target_y = @y + y @custom_index = 1 end
#------------------------------------------------------------------------------- # Go to (x y) #------------------------------------------------------------------------------- alias go_to_move_type_custom move_type_custom def move_type_custom if stopping? case @custom_index when 1 if ((@x == @target_x)&&(@y==@target_y)) @custom_index = nil end approach_to(@target_x, @target_y) else #nothing end end go_to_move_type_custom end -Démo:voir les résultats du concours de Sept 2009: Lien Les meilleures applications sont dans les events des cellules mirroirs. -Crédit: Vincentmhd |
|