Предыдущая Следующая
і
sprite[i] = new Sprite(l2, l0);
}
platform = new Sprite();
}
/// <summary> /// Инициализация /// <summary>
protected override void Initialize()
і
for (int i = 0; sprite.Length > i;
і
sprite[i].spritePosition = new Vector2(rand.Next(l0, Window.ClientBounds.Width - 500), j = j - 300);
}
platform.spritePosition = new Vector2(Window.ClientBounds.Width / 2,
140 Игровые столкновения
Проект Collision 141
Window.ClientBounds.Height base.Initialize();
}
90);
/// <summary>
/// Загрузка компонентов игры /// <summary>
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();
}
}
/// <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();
Collisions();
}
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)) Предыдущая Следующая
|