//public static Asteroid[] asteroids; //Чем меньше значение массива тем быстрее мерцание и меньше обьектов /// <summary> /// Метод инициализации объектов /// </summary> public static void Load() { Random rnd = new Random(); _objs = new BaseObject[50]; ship = new Ship(new Point(10, 400), new Point(5, 5), new Size(10, 10)); //bullet = new Bullet(new Point(ship.Rect.X + 40, ship.Rect.Y + 20), new Point(4, 0), new Size(4, 1)); medKit = new MedKit(new Point(rnd.Next(0, Game.Height), rnd.Next(0, Game.Height - 75)), new Point(-rnd.Next(30, 50) / 5, 30), new Size(25, 25)); int a = Game.Height; int b = 4; int c = 0; int r; for (var i = 0; i < _objs.Length; i++) { r = rnd.Next(5, 50); _objs[i] = new Star(new Point(rnd.Next(c, a), rnd.Next(c, a)), new Point(-r, r), new Size(b, b)); if (r > 51) { throw new GameObjectException("Слишком большая скорость"); } if (r < -50) { throw new GameObjectException("Слишком низкая скорость"); } if (a > Game.Height || a < 0 || b > 4 || b < 0 || c < 0 || c > a) { throw new GameObjectException("Один из параметров не верный"); } } for (var i = 0; i < 2; i++) { r = rnd.Next(30, 50); //asteroids[i] = new Asteroid(new Point(rnd.Next(c, a), rnd.Next(c, a)), //new Point(-r /5, r), new Size(r, r)); asteroids.Add(new Asteroid(new Point(rnd.Next(c, a), rnd.Next(c, a)), new Point(-r / 5, r), new Size(r, r))); if (r > 51) { throw new GameObjectException(); } if (r < -50) { throw new GameObjectException(); } if (a > Game.Height || a < 0 || c < 0 || c > a) { throw new GameObjectException(); } } //for (int i = 0; i < _objs.Length / 4; i++) // _objs[i] = new BaseObject(new Point(rnd.Next(1, 600), i * rnd.Next(1, 20)), new Point(-i, -i), new // Size(10, 10)); //for (int i = _objs.Length / 4; i < _objs.Length; i++) // _objs[i] = new Star(new Point(rnd.Next(1, 600), i * rnd.Next(1, 25)), new Point(-i, 0), new Size(5, // 5)); //for (int i = _objs.Length / 4 + _objs.Length / 4; i < _objs.Length; i++) // _objs[i] = new Planet(new Point(600,i*20), new Point(-i, 0), new Size(5, // 5)); //for (int i = _objs.Length / 4 + _objs.Length / 2; i < _objs.Length; i++) // _objs[i] = new Ship(new Point(600, i * 20), new Point(-i, 0), new Size(5, // 5)); }
public void LoadStars() { Random rnd = new Random(); for (int i = 0; i < starAmount; i++) { starArray[i] = new Star(graphicsManager, content, rnd); } }
public static void Update() { for (int i = 0; i < stars.Length; i++) { if (stars[i] == null) { stars[i] = new Star(new Size(Rnd.Next(0, 5), Rnd.Next(0, 5)), true); } else { stars[i].Update(ref stars[i]); } if (stars[i].Position.X < 0) { stars[i] = null; } } for (int i = 0; i < ListAsteroid.Length; i++) { if (ListAsteroid[i] == null) { ListAsteroid[i] = new Asteroid(imageAsteroid); } ListAsteroid[i]?.Update(ref ListAsteroid[i]); if (BulletHits(ref ListAsteroid[i])) { continue; } if (ListAsteroid[i] != null && ship.Collision(ListAsteroid[i])) { Log("Корабль подбит"); timerBonus.Start(); ListAsteroid[i] = null; ship.Damage(); } } for (int i = 0; i < bullets.Length; ++i) { if (bullets[i] != null) { bullets[i].Update(ref bullets[i]); } } SystemSounds.Asterisk.Play(); ship.Update(ref ship); if (ship.Live <= 0) { ship?.Die(); } if (heart != null) { if (heart.Collision(ship)) { Log("Колличество жизней увеличено"); ship.Heal(); heart = null; } heart?.Update(ref heart); } GC.Collect(); }