Предыдущая Следующая
protected override void LoadGraphicsContent(bool loadAllContent)
{
if (loadAllContent)
{
spriteBatch = new SpriteBatch(graphics.GraphicsDevice);
background1 = content.Load<Texture2D>("Content\\Textures\\background1"); background2 = content.Load<Texture2D>("Content\\Textures\\background2"); platform.Load(content, "Content\\Textures\\platform"); sprite[0].Load(content, "Content\\Textures\\0"); sprite[1].Load(content, "Content\\Textures\\1"); sprite[2].Load(content, "Content\\Textures\\2"); sprite[3].Load(content, "Content\\Textures\\3"); sprite[4].Load(content, "Content\\Textures\\4");
} }
/// <summary>
/// Освобождаем ресурсы
/// <summary>
protected override void UnloadGraphicsContent(bool unloadAllContent)
{
if (unloadAllContent == true)
{
content.Unload();
134 Устройства ввода
Проект PauseGame 135
/// <summary>
/// Обновляем состояние игры /// <summary>
protected override void Update(GameTime gameTime)
{
keyboardState = Keyboard.GetState(); if (keyboardState.IsKeyDown(Keys.Escape)) this.Exit();
Pause();
if (paused == false)
{
double elapsed = gameTime.ElapsedGameTime.TotalSeconds; for (int i = 0; sprite.Length > i;
{
sprite[i].UpdateFrame(elapsed);
}
MoveSprite(); MovePlatform();
}
base.Update(gameTime);
}
/// <summary>
/// Движение спрайта по вертикали
/// <summary>
public void MoveSprite()
{
for (int i = 0; sprite.Length > i;
{
sprite[i].spritePosition += sprite[i].speedSprite;
if (sprite[i].spritePosition.Y > Window.ClientBounds.Height)
{
sprite[i].spritePosition = new Vector2(rand.Next(10, Window.ClientBounds.Width -
300 - sprite[i].spriteTexture.Width / 12), -500);
} } }
/// <summary>
/// Движение платформы по экрану
/// <summary>
public void MovePlatform()
{
if (keyboardState.IsKeyDown(Keys.Left))
platform.spritePosition.X -= 10; else if (keyboardState.IsKeyDown(Keys.Right))
platform.spritePosition.X += 10;
if (platform.spritePosition.X < 10) platform.spritePosition.X = 10;
else if (platform.spritePosition.X >Window.ClientBounds.Width -400) platform.spritePosition.X = Window.ClientBounds.Width - 400;
}
/// <summary> /// Пауза в игре /// <summary> public void Pause()
{
if (keyboardState.IsKeyDown(Keys.P))
{
pauseKeyDown = true;
}
else if (pauseKeyDown)
{
pauseKeyDown = false; paused = !paused;
}
}
/// <summary>
/// Рисуем на экране Предыдущая Следующая
|