Collisions et physique : créer un simulateur de vaisseau spatial
CHAPITRE 10
223
protected override void Initialize()
{
physicsSimulator = new PhysicsSimulator();
ship = new Player(physicsSimulator);
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
ship.LoadContent(Content, "ship2");
ship.ResetPosition();
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
physicsSimulator.Update(gameTime.ElapsedGameTime.Seconds * 0.001f);
ship.Update(gameTime);
foreach (Asteroid asteroid in asteroids)
{
asteroid.Update(gameTime);
}
elapsedTimeSinceLastNewAsteroid += gameTime.ElapsedGameTime;
if (elapsedTimeSinceLastNewAsteroid.Seconds >= NEW_ASTEROID_TIME)
{
asteroids.Add(new Asteroid(physicsSimulator, Content));
elapsedTimeSinceLastNewAsteroid = TimeSpan.Zero;
}
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin();
ship.Draw(spriteBatch);
foreach (Asteroid asteroid in asteroids)
asteroid.Draw(spriteBatch);
spriteBatch.End();
base.Draw(gameTime);
}
}
=Labat FM.book Page 223 Vendredi, 19. juin 2009 4:01 16
CHAPITRE 10
223
protected override void Initialize()
{
physicsSimulator = new PhysicsSimulator();
ship = new Player(physicsSimulator);
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
ship.LoadContent(Content, "ship2");
ship.ResetPosition();
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
physicsSimulator.Update(gameTime.ElapsedGameTime.Seconds * 0.001f);
ship.Update(gameTime);
foreach (Asteroid asteroid in asteroids)
{
asteroid.Update(gameTime);
}
elapsedTimeSinceLastNewAsteroid += gameTime.ElapsedGameTime;
if (elapsedTimeSinceLastNewAsteroid.Seconds >= NEW_ASTEROID_TIME)
{
asteroids.Add(new Asteroid(physicsSimulator, Content));
elapsedTimeSinceLastNewAsteroid = TimeSpan.Zero;
}
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin();
ship.Draw(spriteBatch);
foreach (Asteroid asteroid in asteroids)
asteroid.Draw(spriteBatch);
spriteBatch.End();
base.Draw(gameTime);
}
}
=Labat FM.book Page 223 Vendredi, 19. juin 2009 4:01 16
