Inscrit le: 12 Nov 2011 Messages: 1062 Sujets: 107 Spécialité en worldedit: Inactif(Enfin presque) Médailles: 1 (En savoir plus...)
Posté le: 08/03/15 18:16 Sujet du message: Bug création d'unité
Voilà, j'ai un gros problème, j'ai fait(enfin pratiquement terminé) un snake avec possibilité de rejouer quand on perd.
Or, j'ai un gros problème: Quand on perd le jeu nous propose de:
1) Rejouer
2) Baisser la difficulté
3) Augmenter la difficulté
4) Quitter le jeu
Sauf que lorsqu'on choisit une option de 1 à 3, ça nous crée deux serpents et parfois lorsqu'on fait la 4 ça nous en crée quand même, j'ai pas réussis à situer exactement d'où venait le problème(même si ça à l'air de se trouver soit dans SetDifficulty soit dans ChooseDifficulty).
Donc j'aimerais que ceux qui s'y connaissent mieux que moi(et c'est pas difficile d'en être ) m'indiquent où ça d*****e et pourquoi.
Jass:
static method Move takes nothing returns nothing
local integer i = 0
local integer j = 0
local integer o = 0
local boolean defeat
local real x
local real y
[Gros skipping de trucs inutiles]
//On propose de rejouer:
call DialogClear(Dialog)
set DButton[3] = DialogAddButtonBJ( Dialog, "Rejouer")
set DButton[4] = DialogAddButtonBJ( Dialog, "Réduire la difficulté")
set DButton[5] = DialogAddButtonBJ( Dialog, "Augmenter la difficulté")
set DButton[6] = DialogAddButtonBJ( Dialog, "Quitter")
call DialogDisplay(Player(0), Dialog, true)
set Game.Trigger[5] = CreateTrigger( )
call TriggerRegisterDialogEvent(Game.Trigger[5], Dialog)
call TriggerAddAction(Game.Trigger[5], function Snakes.Replay )
call PauseTimer( Timer )
endif
endif
endmethod
static method SetDifficulty takes nothing returns nothing
local integer i = 0
call BJDebugMsg(I2S(PlayAgain))
if PlayAgain == 1 then
loop
exitwhen i == 3
if GetClickedButton() == DButton[i] then
set Difficulty = i
endif
set i = i + 1
endloop
endif
if PlayAgain != 2 then
call Snakes.Initsnake()
endif
endmethod
static method ChooseDifficulty takes nothing returns nothing
set Game = Snakes.allocate()
if PlayAgain == 1 then
set DButton[0] = DialogAddButtonBJ( Dialog, "Facile")
set DButton[1] = DialogAddButtonBJ( Dialog, "Difficile")
set DButton[2] = DialogAddButtonBJ( Dialog, "Impossible")
call DialogDisplay(Player(0), Dialog, true)
set Game.Trigger[4] = CreateTrigger( )
call TriggerRegisterDialogEvent(Game.Trigger[4], Dialog)
call TriggerAddAction(Game.Trigger[4], function Snakes.SetDifficulty )
endif
if PlayAgain == 0 then
call Snakes.SetDifficulty( )
endif
endmethod
static method Replay takes nothing returns nothing
if Game != null then
call BJDebugMsg("#")
call DestroyTrigger( Game.Trigger[0] )
call DestroyTrigger( Game.Trigger[1] )
call DestroyTrigger( Game.Trigger[2] )
call DestroyTrigger( Game.Trigger[3] )
call DestroyTrigger( Game.Trigger[4] )
call DestroyTrigger( Game.Trigger[5] )
call Game.deallocate()
endif
if GetClickedButton( ) == DButton[3] then
call DialogClear( Dialog )
set GameAmount = GameAmount + 1
set PlayAgain = 0
call Snakes.ChooseDifficulty( )
elseif GetClickedButton( ) == DButton[4] then
call DialogClear( Dialog )
if Difficulty > 1 then
set Difficulty = Difficulty - 1
set GameAmount = GameAmount + 1
set PlayAgain = 0
call Snakes.ChooseDifficulty( )
endif
elseif GetClickedButton( ) == DButton[5] then
call DialogClear( Dialog )
if Difficulty < 3 then
set Difficulty = Difficulty + 1
set GameAmount = GameAmount + 1
set PlayAgain = 0
call Snakes.ChooseDifficulty( )
endif
elseif GetClickedButton( ) == DButton[6] then
set PlayAgain = 2
endif
endmethod
function CreateToken takes real x, real y returns nothing
set Token = CreateUnit( Player(12) , 'h002' , x , y + 32 , 0.00 )
call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Other\\Awaken\\Awaken.mdl", x, y) )
endfunction
//La struct, c'est elle qui fait un peu tout le job en fait
struct Snakes
unit array Snake[8192] //On ne peut pas modifier la taille d'un tableau dans une struct, donc je prend large
real array Angle[8192] //" "
real array X[8192]
real array Y[8192]
integer Length
trigger array Trigger[6]
real Direction
static method Initsnake takes nothing returns nothing
local integer v = 0
local real x = TileX[12]
local real y = TileY[12]
set Game.Length = 0
set Game.Snake[Game.Length] = CreateUnit( Player(0), 'h000', x, y, 0.00)
set Game.X[Game.Length] = x
set Game.Y[Game.Length] = y
set Game.Direction = 0.00 * bj_DEGTORAD
loop
exitwhen v == 3
call Game.AddBodyPart()
set v = v + 1
endloop
set Game.Trigger[0] = CreateTrigger( )
call TriggerRegisterPlayerKeyEventBJ( Game.Trigger[0], Player(0), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_UP )
call TriggerAddAction( Game.Trigger[0], function Snakes.MoveUp )
set Game.Trigger[1] = CreateTrigger( )
call TriggerRegisterPlayerKeyEventBJ( Game.Trigger[1], Player(0), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_RIGHT )
call TriggerAddAction( Game.Trigger[1], function Snakes.MoveRight )
set Game.Trigger[2] = CreateTrigger( )
call TriggerRegisterPlayerKeyEventBJ( Game.Trigger[2], Player(0), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_DOWN )
call TriggerAddAction( Game.Trigger[2], function Snakes.MoveDown )
set Game.Trigger[3] = CreateTrigger( )
call TriggerRegisterPlayerKeyEventBJ( Game.Trigger[3], Player(0), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_LEFT )
call TriggerAddAction( Game.Trigger[3], function Snakes.MoveLeft )
call TimerStart( Timer, Interval, true, function Snakes.Move )
endmethod
method AddBodyPart takes nothing returns nothing
local real x = GetUnitX40;this.Snake[this.Length]) - 128 * Cos40;this.Angle[this.Length])
local real y = GetUnitY40;this.Snake[this.Length]) - 128 * Sin40;this.Angle[this.Length])
set this.Length = this.Length + 1
set this.Snake[this.Length] = CreateUnit40; Player40;1), 'h001', x, y, this.Angle[this.Length])
set this.X[this.Length] = x
set this.Y[this.Length] = y
set this.Angle[this.Length] = this.Angle[this.Length - 1]
if Difficulty == 1 then
set Count = Count + 1
if Count == CountMax then
call PauseTimer40; Timer )
set Interval = Interval - 0.03
call TimerStart40; Timer, Interval, true, function Snakes.Move )
set Count = 0
endif
elseif Difficulty == 2 then
set x = GetUnitX40;this.Snake[this.Length]) - 128 * Cos40;this.Angle[this.Length])
set y = GetUnitY40;this.Snake[this.Length]) - 128 * Sin40;this.Angle[this.Length])
set this.Length = this.Length + 1
set this.Snake[this.Length] = CreateUnit40; Player40;1), 'h001', x, y, this.Angle[this.Length])
set this.X[this.Length] = x
set this.Y[this.Length] = y
set this.Angle[this.Length] = this.Angle[this.Length - 1]
set Count = Count + 1
if Count == CountMax then
call PauseTimer40; Timer )
set Interval = Interval - 0.03
call TimerStart40; Timer, Interval, true, function Snakes.Move )
set Count = 0
endif
endif
endmethod
static method MoveUp takes nothing returns nothing
//ça sert à rien de demander au serpent de garder la même direction
if Game.Direction != 90.00 * bj_DEGTORAD then
//Pour éviter les retournements suicides
if Game.Length != 1 then
if Game.Direction != 270.00 * bj_DEGTORAD then
set Game.Direction = 90.00 * bj_DEGTORAD
endif
endif
endif
endmethod
static method MoveRight takes nothing returns nothing
//ça sert à rien de demander au serpent de garder la même direction
if Game.Direction != 0.00 * bj_DEGTORAD then
//Pour éviter les retournements suicides
if Game.Length != 1 then
if Game.Direction != 180.00 * bj_DEGTORAD then
set Game.Direction = 0.00 * bj_DEGTORAD
endif
endif
endif
endmethod
static method MoveDown takes nothing returns nothing
//ça sert à rien de demander au serpent de garder la même direction
if Game.Direction != 270.00 * bj_DEGTORAD then
//Pour éviter les retournements suicides
if Game.Length != 1 then
if Game.Direction != 90.00 * bj_DEGTORAD then
set Game.Direction = 270.00 * bj_DEGTORAD
endif
endif
endif
endmethod
static method MoveLeft takes nothing returns nothing
//ça sert à rien de demander au serpent de garder la même direction
if Game.Direction != 180.00 * bj_DEGTORAD then
//Pour éviter les retournements suicides
if Game.Length != 1 then
if Game.Direction != 0.00 * bj_DEGTORAD then
set Game.Direction = 180.00 * bj_DEGTORAD
endif
endif
endif
endmethod
static method Move takes nothing returns nothing
local integer i = 0
local integer j = 0
local integer o = 0
local boolean defeat
local real x
local real y
//Le mouvement
if GetUnitState40;Game.Snake[0], UNIT_STATE_LIFE) >= 0 then
set Game.X[0] = Game.X[0] + 128 * Cos40;Game.Direction)
set Game.Y[0] = Game.Y[0] + 128 * Sin40;Game.Direction)
set Game.Angle[0] = Game.Direction
call SetUnitFacingTimed40; Game.Snake[0], Game.Angle[0], 0.02)
set i = Game.Length
loop
exitwhen i == 0
set Game.X[i] = GetUnitX40; Game.Snake[i - 1] )
set Game.Y[i] = GetUnitY40; Game.Snake[i - 1] )
set Game.Angle[i] = GetUnitFacing40; Game.Snake[i - 1] )
set i = i - 1
endloop
set j = Game.Length
loop
exitwhen j == -1
call SetUnitX40; Game.Snake[j], Game.X[j])
call SetUnitY40; Game.Snake[j], Game.Y[j])
call SetUnitFacing40; Game.Snake[j], Game.Angle[j])
set j = j - 1
endloop
//La récupération de pièces:
set x = GetUnitX40;Token)
set y = GetUnitY40;Token)
if SquareRoot40; 40;Game.X[0] - x ) * 40;Game.X[0] - x ) + 40;Game.Y[0] - y ) * 40;Game.Y[0] - y ) ) <= 96 then
call RemoveUnit40;Token)
call Game.AddBodyPart40; )
set o = GetRandomInt40;1,Tiles)
call DestroyEffect40;AddSpecialEffect40;"Abilities\\Spells\\Items\\ResourceItems\\ResourceEffectTarget.mdl", x, y) )
call CreateToken40; TileX[o], TileY[o] )
endif
//La mort
if Game.X[0] > GetRectCenterX40;bj_mapInitialPlayableArea) + 40;12 * 128) + 32 then
set defeat = true
elseif Game.X[0] < GetRectCenterX40;bj_mapInitialPlayableArea) - 40;12 * 128) - 32 then
set defeat = true
elseif Game.Y[0] < GetRectCenterY40;bj_mapInitialPlayableArea) - 40;6 * 128) - 32 then
set defeat = true
elseif Game.Y[0] > GetRectCenterY40;bj_mapInitialPlayableArea) + 40;12 * 128) - 32 then
set defeat = true
endif
set i = Game.Length
loop
exitwhen i == 0
if SquareRoot40; 40;Game.X[0] - Game.X[i]) * 40;Game.X[0] - Game.X[i]) + 40;Game.Y[0] - Game.Y[i]) * 40;Game.Y[0] - Game.Y[i]) ) <= 96 then
set defeat = true
endif
set i = i - 1
endloop
//On détruit tous les bouts du serpent
if defeat == true then
set i = Game.Length
loop
exitwhen i == -1
call KillUnit40; Game.Snake[i] )
call DestroyEffect40; AddSpecialEffect40; Effect, Game.X[i], Game.Y[i] ) )
set i = i-1
endloop
//On propose de rejouer:
call DialogClear40;Dialog)
set DButton[3] = DialogAddButtonBJ40; Dialog, "Rejouer")
set DButton[4] = DialogAddButtonBJ40; Dialog, "Réduire la difficulté")
set DButton[5] = DialogAddButtonBJ40; Dialog, "Augmenter la difficulté")
set DButton[6] = DialogAddButtonBJ40; Dialog, "Quitter")
call DialogDisplay40;Player40;0), Dialog, true)
set Game.Trigger[5] = CreateTrigger40; )
call TriggerRegisterDialogEvent40;Game.Trigger[5], Dialog)
call TriggerAddAction40;Game.Trigger[5], function Snakes.Replay )
call PauseTimer40; Timer )
endif
endif
endmethod
static method SetDifficulty takes nothing returns nothing
local integer i = 0
call BJDebugMsg40;I2S40;PlayAgain))
if PlayAgain == 1 then
loop
exitwhen i == 3
if GetClickedButton40;) == DButton[i] then
set Difficulty = i
endif
set i = i + 1
endloop
endif
if PlayAgain != 2 then
call Snakes.Initsnake40;)
endif
endmethod
static method ChooseDifficulty takes nothing returns nothing
set Game = Snakes.allocate40;)
if PlayAgain == 1 then
set DButton[0] = DialogAddButtonBJ40; Dialog, "Facile")
set DButton[1] = DialogAddButtonBJ40; Dialog, "Difficile")
set DButton[2] = DialogAddButtonBJ40; Dialog, "Impossible")
call DialogDisplay40;Player40;0), Dialog, true)
set Game.Trigger[4] = CreateTrigger40; )
call TriggerRegisterDialogEvent40;Game.Trigger[4], Dialog)
call TriggerAddAction40;Game.Trigger[4], function Snakes.SetDifficulty )
endif
if PlayAgain == 0 then
call Snakes.SetDifficulty40; )
endif
endmethod
static method Replay takes nothing returns nothing
if Game != null then
call BJDebugMsg40;"#")
call DestroyTrigger40; Game.Trigger[0] )
call DestroyTrigger40; Game.Trigger[1] )
call DestroyTrigger40; Game.Trigger[2] )
call DestroyTrigger40; Game.Trigger[3] )
call DestroyTrigger40; Game.Trigger[4] )
call DestroyTrigger40; Game.Trigger[5] )
call Game.deallocate40;)
endif
if GetClickedButton40; ) == DButton[3] then
call DialogClear40; Dialog )
set GameAmount = GameAmount + 1
set PlayAgain = 0
call Snakes.ChooseDifficulty40; )
elseif GetClickedButton40; ) == DButton[4] then
call DialogClear40; Dialog )
if Difficulty > 1 then
set Difficulty = Difficulty - 1
set GameAmount = GameAmount + 1
set PlayAgain = 0
call Snakes.ChooseDifficulty40; )
endif
elseif GetClickedButton40; ) == DButton[5] then
call DialogClear40; Dialog )
if Difficulty < 3 then
set Difficulty = Difficulty + 1
set GameAmount = GameAmount + 1
set PlayAgain = 0
call Snakes.ChooseDifficulty40; )
endif
elseif GetClickedButton40; ) == DButton[6] then
set PlayAgain = 2
endif
endmethod
endstruct
function TimeIsCool takes nothing returns nothing
local string s
set Numbers[0] = Numbers[0] + 1
set Numbers[6] = Numbers[6] + 1
if Numbers[0] == 10 then
set Numbers[0] = 0
set Numbers[1] = Numbers[1] + 1
endif
if Numbers[6] == 60 then
set Numbers[2] = Numbers[2] + 1
set Numbers[7] = Numbers[7] + 1
set Numbers[6] = 0
set Numbers[1] = 0
endif
if Numbers[2] == 10 then
set Numbers[3] = Numbers[3] + 1
set Numbers[2] = 0
endif
if Numbers[7] == 60 then
set Numbers[4] = Numbers[4] + 1
set Numbers[7] = 0
set Numbers[3] = 0
endif
if Numbers[4] == 10 then
set Numbers[5] = Numbers[5] + 1
set Numbers[4] = 0
endif
set s = "Temps de jeu: " + I2S40;Numbers[5]) + I2S40;Numbers[4]) + ":" + I2S40;Numbers[3]) + I2S40;Numbers[2]) + ":" + I2S40;Numbers[1]) + I2S40;Numbers[0])
call MultiboardSetTitleText40; Board, s)
endfunction
//Starting the game
function Launchgame takes nothing returns nothing
local timer t = CreateTimer( )
local fogmodifier fog
local integer h = 0
local unit u
local integer o = 0
//Toutes ces lignes sont là pour créer la visibilité
//Immobiliser la caméra
//Et la centrer sur la zone de jeu
call SetFloatGameState(GAME_STATE_TIME_OF_DAY, 12)
call SuspendTimeOfDay( true )
set fog = CreateFogModifierRect(Player(0), FOG_OF_WAR_VISIBLE, bj_mapInitialPlayableArea, true, false)
call FogModifierStart(fog)
call CameraSetupApplyForceDuration(gg_cam_Camera_001, true, 0)
call SetCameraBoundsToRect( gg_rct_Rect_001)
set fog = null
set u = CreateUnit( Player(12), 'hfoo', 0.00, 0.00, 0.00)
call ShowUnit(u, false)
call SetCameraTargetController( u, 0.00, 0.00, false)
//Là, on créer des emplacements, pour l'esthétique mais aussi pour pouvoir
//faire apparaître des pièces plus tard
set TileX[Tiles] = GetRectCenterX(bj_mapInitialPlayableArea) - (12 * 128) + 64
set TileY[Tiles] = GetRectCenterY(bj_mapInitialPlayableArea) + (6 * 128) - 64
loop
exitwhen h == ( 12 * 24 )
call CreateDestructable('B000', TileX[Tiles], TileY[Tiles], 0.00, 0.32, 0)
set Tiles = Tiles + 1
set TileX[Tiles] = TileX[Tiles - 1] + 128.00
if TileX[Tiles] >= GetRectCenterX(bj_mapInitialPlayableArea) + (12 * 128) then
set TileX[Tiles] = GetRectCenterX(bj_mapInitialPlayableArea) - (12 * 128) + 64
set TileY[Tiles] = TileY[Tiles - 1] - 128.00
else
set TileY[Tiles] = TileY[Tiles - 1]
endif
set h = h + 1
endloop
set Board = CreateMultiboard( )
set Numbers[0] = 0
set Numbers[1] = 0
set Numbers[2] = 0
set Numbers[3] = 0
set Numbers[4] = 0
set Numbers[5] = 0
set Numbers[6] = 0
set Numbers[7] = 0
call MultiboardDisplay( Board, true )
call TimerStart( t, 1.00, true, function TimeIsCool )
call Snakes.ChooseDifficulty( )
set o = GetRandomInt(1, Tiles)
call CreateToken( TileX[o], TileY[o] )
endfunction
function Start takes nothing returns nothing
local timer t = CreateTimer( )
call TimerStart( t, 0.01, false, function Launchgame )
endfunction
Inscrit le: 21 Fév 2010 Messages: 1785 Sujets: 22 Spécialité en worldedit: La modestie Médailles: 1 (En savoir plus...)
Posté le: 08/03/15 20:55 Sujet du message:
Tu as 2 triggers associés au même Dialog, et ils sont faits de telle sorte que les 2 créent des serpents.
Utilise 2 dialogs au lieu d'un seul, c'est le plus simple (ou alors, détruis Game.Trigger[4] avant de demander le replay).
Sinon, je sais pas ce que tu fais avec la difficulté, mais dans "SetDifficulty", tu choisis une difficulté entre 0 et 2 alors que dans "Replay", elle est mise entre 1 et 3. _________________
Vous ne pouvez pas poster de nouveaux sujets dans ce forum Vous ne pouvez pas répondre aux sujets dans ce forum Vous ne pouvez pas éditer vos messages dans ce forum Vous ne pouvez pas supprimer vos messages dans ce forum Vous ne pouvez pas voter dans les sondages de ce forum