public void ApplyOn(PlayerShip ship) { GameObject powerUp = ChoosePowerUp(ship); powerUp.Center = ship.Center; ship.AddChild(powerUp); Play(Properties.Resources.start); Delete(); }
public override void Update(float deltaTime) { PlayerShip player = Parent as PlayerShip; if (player != null) { player.ShieldActivated = true; } CheckForCollisions(); if (Environment.TickCount - startTime > duration) { Delete(); if (player != null) { player.ShieldActivated = false; } } }
public override void Update(float deltaTime) { PlayerShip player = Parent as PlayerShip; if (firstFrame) { firstFrame = false; if (player != null) { player.Cannon.ShotInterval = 0; } } else if (Environment.TickCount - startTime > duration) { if (player != null) { player.Cannon.DefaultShotInterval(); } Delete(); } }
public override void Update(float deltaTime) { PlayerShip player = Parent as PlayerShip; if (firstFrame) { firstFrame = false; if (player != null) { player.Speed = PlayerShip.MAX_SPEED; } } else if (Environment.TickCount - startTime > duration) { if (player != null) { player.Speed = PlayerShip.MIN_SPEED; } Delete(); } }
private void Form1_Load(object sender, EventArgs e) { Random rnd = new Random(); GameObject world = scene.World; { var noise = new[] { Properties.Resources.space_noise_1, Properties.Resources.space_noise_2, Properties.Resources.space_noise_3 }; world.AddChild(new SpaceNoise(noise[0], 3 * 1.5f, 1.00f, false, false)); world.AddChild(new SpaceNoise(noise[0], 3 * 2.5f, 2.00f, true, true)); world.AddChild(new SpaceNoise(noise[1], 3 * 3.5f, 1.50f, false, true)); world.AddChild(new SpaceNoise(noise[2], 3 * 5.5f, 2.00f, true, false)); } world.AddChild(new StarSpawner()); EnemySpawner[] spawners = new EnemySpawner[] { new EnemySpawner(0, 500, new FuncBehavior(x => Math.Sin(x * 10) * 0.9, 175)), new EnemySpawner(11, 500, new FollowPlayerBehavior(200)), new EnemySpawner(29, 500, new FuncBehavior(x => - 0.9 * (2 / Math.PI) * Math.Asin(Math.Sin(Math.PI * x * 3)), 250)), new EnemySpawner(20, 500, new FlockingBehavior(200)), new EnemySpawner(42, 500, new FuncBehavior(x => (Math.Sin(x * 10) + Math.Sin(x * 5)) * 0.5, 275)), new EnemySpawner(63, 500, new FuncBehavior(x => Math.Atan(x * 10 - 5) * -0.5, 200)), new EnemySpawner(54, 500, new FuncBehavior(x => (Math.Sin((x + 1) * 10 + 15) - Math.Sin((x + 1) * 15)) * 0.2 - 0.4, 300)), }; world.AddChildren(spawners); world.AddChild(new EnemySpawnerDirector(spawners)); PlayerShip player = new PlayerShip(33); player.CenterY = world.CenterY; player.Left = world.Left + 100; world.AddChild(player); }
private GameObject ChoosePowerUp(PlayerShip ship) { int attempts = 0; GameObject result = null; do { attempts++; result = powerUps[rnd.Next(powerUps.Count)](); if (ship.AllChildren.Any((m) => m.GetType().Equals(result.GetType()))) { result = null; } } while (result == null && attempts < 100); if (result == null) { // If we reach here, we probably have all the powerups, // in which case, simply add the first power up on the list result = powerUps[0](); } return(result); }
protected virtual void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.CompareTag("Projectile")) { Projectile projectile = other.GetComponent <Projectile>(); if (projectile.GetFraction() != fraction) { projectile.SetCollisionInfo(speed); projectile.Explode(); Explode(); } } else if (other.gameObject.CompareTag("Ship")) { PlayerShip ship = other.GetComponent <PlayerShip>(); if (ship != null) { Explode(); GameController.Multiplier += 1f; } } }