bonjour je me suis renseigner pour game state mais je ne comprend trop son installation et sa mise en pratique quelqu un aurait il modele a me montrer et a expliquer:merci voici dans ma recherche j ai trouver ce scrptis:
la 1 page
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254 using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Storage; using Microsoft.Xna.Framework.Content; namespace GameStateDLL { public enum StateStatus { None, Opening, Normal, Closing } public abstract class BaseGameState { // La couleur du texte par défaut public virtual Color ForeGround { get { return Color.Black; } } // Le délais avant l'activation du state // Ce délais est utile pour ne pas "sauter" un state avec des détections clavier // Ex: Si 2 menus de suite, le fait d'appuyer trop longtemps sur le menu #1 prendrait // automatiquement le premier choix du menu #2. Le délais évite cela. public virtual TimeSpan OpeningTime { get { return TimeSpan.FromMilliseconds( 250.0 ); } } // Le Statut du GameState, où on en est private StateStatus _Status; // Une référence a la partie private Game _TheGame; // Le font utilisé private SpriteFont _TheSpriteFont; // Une référence au clavier private KeyboardState _TheKeyBoard; // Le spriteBatch utilisé private SpriteBatch _TheSpriteBatch; public virtual StateStatus Status { get { return _Status; } set { _Status = value; } } public virtual Game TheGame { get { return _TheGame; } set { _TheGame = value; } } public virtual KeyboardState TheKeyBoard { get { return _TheKeyBoard; } set { _TheKeyBoard = value; } } public virtual SpriteFont TheSpriteFont { get { return _TheSpriteFont; } set { _TheSpriteFont = value; } } public virtual SpriteBatch TheSpriteBatch { get { return _TheSpriteBatch; } set { _TheSpriteBatch = value; } } protected TimeSpan StartedGameTime = TimeSpan.Zero; public BaseGameState( Game theGame, SpriteFont theSpriteFont, SpriteBatch theSpriteBatch ) { TheGame = theGame; TheSpriteFont = theSpriteFont; TheSpriteBatch = theSpriteBatch; Status = StateStatus.Opening; } #region Drawing public virtual void Draw( GameTime theGameTime ) { switch ( Status ) { case StateStatus.Opening: DrawBeginning( theGameTime ); break; case StateStatus.Normal: DrawState( theGameTime ); break; case StateStatus.Closing: DrawEnding( theGameTime ); break; } PlaySound( theGameTime ); } public virtual void DrawBeginning( GameTime theGameTime ) { DrawState( theGameTime ); } public virtual void DrawState( GameTime theGameTime ) { } public virtual void DrawEnding( GameTime theGameTime ) { DrawState( theGameTime ); } #endregion // Drawing #region Sounds public virtual void PlaySound( GameTime theGameTime ) { switch ( Status ) { case StateStatus.Opening: PlaySoundBeginning( theGameTime ); break; case StateStatus.Normal: PlaySoundState( theGameTime ); break; case StateStatus.Closing: PlaySoundEnding( theGameTime ); break; } } public virtual void PlaySoundBeginning( GameTime theGameTime ) { } public virtual void PlaySoundState( GameTime theGameTime ) { } public virtual void PlaySoundEnding( GameTime theGameTime ) { } #endregion // Sounds public virtual void Update( GameTime theGameTime ) { InputsUpdate( theGameTime ); StateUpdate( theGameTime ); } #region InputsUpdate public virtual void InputsUpdate( GameTime theGameTime ) { TheKeyBoard = Keyboard.GetState(); switch ( Status ) { case StateStatus.Opening: InputsUpdateBeginning( theGameTime ); break; case StateStatus.Normal: InputsUpdateState( theGameTime ); break; case StateStatus.Closing: InputsUpdateEnding( theGameTime ); break; } } public virtual void InputsUpdateBeginning( GameTime theGameTime ) { } public virtual void InputsUpdateState( GameTime theGameTime ) { } public virtual void InputsUpdateEnding( GameTime theGameTime ) { } #endregion // InputsUpdate #region StateUpdate public virtual void StateUpdate( GameTime theGameTime ) { switch ( Status ) { case StateStatus.Opening: StateUpdateBeginning( theGameTime ); break; case StateStatus.Normal: StateUpdateState( theGameTime ); break; case StateStatus.Closing: StateUpdateEnding( theGameTime ); break; } } public virtual void StateUpdateBeginning( GameTime theGameTime ) { if ( StartedGameTime == TimeSpan.Zero ) StartedGameTime = theGameTime.TotalGameTime; else if ( theGameTime.TotalGameTime - StartedGameTime >= OpeningTime ) Status = StateStatus.Normal; } public virtual void StateUpdateState( GameTime theGameTime ) { } public virtual void StateUpdateEnding( GameTime theGameTime ) { } #endregion // StateUpdate public virtual void WriteString( string str, int x, int y ) { TheSpriteBatch.DrawString( TheSpriteFont, str, new Vector2( x, y ), ForeGround ); } public virtual void WriteString( string str, int x, int y, Color color ) { TheSpriteBatch.DrawString( TheSpriteFont, str, new Vector2( x, y ), color ); } } }et une 3 page que je ne comprens pas trop a quoi elle sert:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146 la seconde page qui fait appel a la 1 using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Storage; using Microsoft.Xna.Framework.Content; namespace GameStateDLL { public abstract class MenuGameState : BaseGameState { public virtual Keys ForwardKey { get { return Keys.Down; } } public virtual Keys BackwardKey { get { return Keys.Up; } } public virtual Keys EnterKey { get { return Keys.Enter; } } public virtual TimeSpan DelayBetweenMove { get { return TimeSpan.FromMilliseconds(150.0); } } public virtual bool InfiniteMenu { get { return true; } } public virtual Color HighlightForeGround { get { return Color.Red; } } public abstract string[] Choices { get; } // Voir le délais dans BaseGameState, le pourquoi de l'existence de ceci est le meme protected TimeSpan LastMove = TimeSpan.Zero; protected int choix = -1; public MenuGameState( Game theGame, SpriteFont theSpriteFont, SpriteBatch theSpriteBatch ) : base( theGame, theSpriteFont, theSpriteBatch ) { if ( Choices.Length > 0 ) choix = 0; } public override void StateUpdateState( GameTime theGameTime ) { if ( LastMove != TimeSpan.Zero && theGameTime.TotalGameTime - LastMove >= DelayBetweenMove ) LastMove = TimeSpan.Zero; } public override void InputsUpdateState( GameTime theGameTime ) { if ( LastMove == TimeSpan.Zero && Choices.Length > 0 ) { bool move = false; if ( TheKeyBoard.IsKeyDown( EnterKey ) == true ) { move = true; FaitSonChoix( choix ); } else if ( TheKeyBoard.IsKeyDown( ForwardKey ) == true ) { move = true; MoveChoix( choix, 1 ); } else if ( TheKeyBoard.IsKeyDown( BackwardKey ) == true ) { move = true; MoveChoix( choix, -1 ); } if ( move ) LastMove = theGameTime.TotalGameTime; } } public virtual void FaitSonChoix( int id ) { } public virtual void MoveChoix( int id, int incr ) { int nextID = id + incr; if ( nextID < 0 ) nextID = InfiniteMenu ? ( Choices.Length - 1 ) : 0; if ( nextID >= Choices.Length ) nextID = InfiniteMenu ? 0 : ( Choices.Length - 1 ); choix = nextID; } public override void DrawState( GameTime theGameTime ) { Rectangle titleRectangle = WriteTitle(); WriteMenu( titleRectangle ); } public virtual Rectangle WriteTitle() { string title = "##### Menu #####"; Vector2 titleSize = TheSpriteFont.MeasureString( title ); Rectangle clientSize = TheGame.Window.ClientBounds; int startingX = (int)( ( clientSize.Width / 2 ) - ( titleSize.X / 2 ) ); int startingY = 10; WriteString( title, startingX, startingY ); return new Rectangle( startingX, startingY, (int)titleSize.X, (int)titleSize.Y ); } public virtual void WriteMenu( Rectangle titleRectangle ) { Rectangle clientSize = TheGame.Window.ClientBounds; const int interligne = 20; int currentY = ( titleRectangle.Height + titleRectangle.Y ); for ( int i = 0; i < Choices.Length; ++i ) { currentY += interligne; string ligne = String.Format( "{0}{1}{2}", i == choix ? "> " : "", Choices[i], i == choix ? " <" : "" ); Vector2 lineSize = TheSpriteFont.MeasureString( ligne ); int startingX = (int)( ( clientSize.Width / 2 ) - ( lineSize.X / 2 ) ); WriteString( ligne, startingX, currentY, i == choix ? HighlightForeGround: ForeGround ); currentY += (int)lineSize.Y; } } } }
quelq un pourrait il m eclairer.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Storage; using Microsoft.Xna.Framework.Content; using GameStateDLL; namespace GameStateDemo { public class MyMenuGameState : MenuGameState { public override string[] Choices { get { return new string[] { "Jouer", "Revoir le SplashScreen", "Quitter" }; } } public MyMenuGameState( Game theGame, SpriteFont theSpriteFont, SpriteBatch theSpriteBatch ) : base( theGame, theSpriteFont, theSpriteBatch ) { } public override void FaitSonChoix( int id ) { switch ( choix ) { case 0: // Jouer MyGame.CurrentState = new MyLoadingGameState( TheGame, TheSpriteFont, TheSpriteBatch ); break; case 1: // Revoir le SplashScreen MyGame.CurrentState = new MySplashGameState( TheGame, TheSpriteFont, TheSpriteBatch ); break; case 2: // Quitter MyGame.CurrentState = new MyGenericGameState( TheGame, TheSpriteFont, TheSpriteBatch ); break; } } } }
Partager