Développement XNA pour la XBox et le PC
212
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
ServiceHelper.Game = this;
Components.Add(new KeyboardService(this));
graphics.PreferredBackBufferHeight = SCREEN_HEIGHT;
graphics.PreferredBackBufferWidth = SCREEN_WIDTH;
}
protected override void Initialize()
{
playerShip = new Player();
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
playerShip.LoadContent(Content, "ship");
playerShip.ResetPosition();
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
playerShip.Update(gameTime);
foreach (Asteroid asteroid in asteroids)
asteroid.Update(gameTime);
elapsedTimeSinceLastNewAsteroid += gameTime.ElapsedGameTime;
if (elapsedTimeSinceLastNewAsteroid.Seconds >= NEW_METEOR_TIME)
{
asteroids.Add(new Asteroid(Content));
elapsedTimeSinceLastNewAsteroid = TimeSpan.Zero;
}
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin();
playerShip.Draw(spriteBatch);
foreach (Asteroid asteroid in asteroids)
=Labat FM.book Page 212 Vendredi, 19. juin 2009 4:01 16
Précédent

- 233/366

Suivant