/// <summary> /// Respawns the player. /// </summary> /// <param name="game">Game.</param> private void RespawnPlayer(GameNode game) { if (game.State.lives > 0) { if (IsClearToAddShip(Vector2.zero)) { _creator.CreateSpaceship(); } } else { game.State.playing = false; if (game.State.score > int.Parse(_highScore.First().Component1.view.score.text)) { _highScore.First().Component1.view.score.text = game.State.score.ToString(); _highScore.First().Component1.view.name.text = ""; _highScore.First().Component1.view.Show(); } else { _highScore.First().Component1.view.Hide(); _mainMenus.First().Component1.view.Show(); } } }
private void OnUpdate(float delta, Bullet bullet, Collisions collisions, Entity entity) { var game = _games.First(); foreach (var hit in collisions.hits) { var asteroid = hit.gameObject.GetComponent <Asteroid>(); if (asteroid == null) { continue; } asteroid.GetComponent <Hitpoints>().hp--; game.State.hits++; if (asteroid.size == AsteroidSize.Large) { game.State.score += 20; } else if (asteroid.size == AsteroidSize.Medium) { game.State.score += 50; } else { game.State.score += 100; } entity.Destroy(); } collisions.hits.Clear(); }
/// <summary> /// Spawns the asteroid. /// </summary> private void SpawnAsteroid() { var spaceship = spaceships.First(); var position = FindPositionForNewAsteroid(spaceship); var asteroid = _creator.CreateAsteroid(AsteroidSize.Large, position); // Give it a kick var vel = UnityEngine.Random.insideUnitCircle.normalized; var torque = vel.x / 2; var rigidBody = asteroid.GetComponent <Rigidbody2D>(); rigidBody.AddForce(vel, ForceMode2D.Impulse); rigidBody.AddTorque(torque, ForceMode2D.Impulse); }
/// <summary> /// Raises the update event. /// </summary> /// <param name="arg1">Arg1.</param> /// <param name="spaceship">Spaceship.</param> /// <param name="transform">Transform.</param> /// <param name="entity">Entity.</param> /// <param name="collisions">Collisions.</param> private void OnUpdate(float arg1, Spaceship spaceship, Transform transform, Entity entity, Collisions collisions) { var game = _games.First(); foreach (var hit in collisions.hits) { var asteroid = hit.gameObject.GetComponent <Asteroid>(); if (asteroid == null) { continue; } _creator.CreateSpaceshipInDeathroes(spaceship.transform); entity.Destroy(); game.State.lives--; } collisions.hits.Clear(); }