IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

XNA/Monogame Discussion :

information sur gamestate


Sujet :

XNA/Monogame

  1. #1
    Membre habitué
    Inscrit en
    Janvier 2008
    Messages
    1 159
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 1 159
    Points : 149
    Points
    149
    Par défaut information sur gamestate
    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 );
    		}
    	}
    }
    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;
    			}
    		}
    	}
    }
    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
    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;
    			}
    		}
    	}
    }
    quelq un pourrait il m eclairer.

  2. #2
    Expert confirmé

    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2007
    Messages
    1 895
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Septembre 2007
    Messages : 1 895
    Points : 4 551
    Points
    4 551
    Par défaut
    Citation Envoyé par kate59 Voir le message
    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

    quelq un pourrait il m eclairer.
    Certainement. Comme je le dit dans ton thread "menus...", j'ai écrit un article sur le sujet ici.
    [FAQ des forums][FAQ Développement 2D, 3D et Jeux][Si vous ne savez pas ou vous en êtes...]
    Essayez d'écrire clairement (c'est à dire avec des mots français complets). SMS est votre ennemi.
    Evitez les arguments inutiles - DirectMachin vs. OpenTruc ou G++ vs. Café. C'est dépassé tout ça.
    Et si vous êtes sages, vous aurez peut être vous aussi la chance de passer à la télé. Ou pas.

    Ce site contient un forum d'entraide gratuit. Il ne s'use que si l'on ne s'en sert pas.

  3. #3
    Membre habitué
    Inscrit en
    Janvier 2008
    Messages
    1 159
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 1 159
    Points : 149
    Points
    149
    Par défaut
    bonjour,
    merci de ta reponse le sujet que je lis ma mieux fait comprendre le systeme mais je ne vois toujours comment tout cela peut fonctionner via xna enfin plutot comment m y pendre.aurait tu un exemple de projet concret a me montrer.pour m expliquer.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 12
    Dernier message: 12/12/2004, 14h25
  2. Réponses: 6
    Dernier message: 28/04/2004, 10h41
  3. Réponses: 3
    Dernier message: 01/02/2004, 21h24
  4. Informations sur les procédures stockées
    Par jfphan dans le forum MS SQL Server
    Réponses: 4
    Dernier message: 13/01/2004, 14h30
  5. Réponses: 6
    Dernier message: 28/09/2003, 17h49

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo