public void SpawnAsteroid(AsteroidModel prev) { if (prev) { _asteroids.Remove(prev); } // pick a random spawner position int index = Random.Range(0, _spawnPositions.Count); Vector3 position = _spawnPositions[index]; GameObject asteroid = Instantiate(asteroidPrefab); asteroid.transform.parent = asteroidContainer; asteroid.transform.position = position; // get a random direction and force Vector3 dir = new Vector3( Random.Range(-1.0f, 1.0f), Random.Range(-1.0f, 1.0f), 0.0f ); float force = Random.Range(forceMin, forceMax); Rigidbody rb = asteroid.GetComponent <Rigidbody>(); rb.AddForce(dir.normalized * force); AsteroidView view = asteroid.GetComponent <AsteroidView>(); AsteroidModel model = asteroid.GetComponent <AsteroidModel>(); _asteroids.Add(model); view.controller = this; numAsteroids++; }
public AsteroidController(AsteroidModel model, AsteroidView view) { _view = view; // Bind Model model.Velocity.Subscribe(v => _view.SetVelocity(v)); // Bind View >>> view.TriggerEnterEvents.Subscribe(col => { switch (col.gameObject.layer) { case Layers.AsteroidsTriggers: LevelController.ChangeAsteroidsOnScreenCount(1); break; default: Destroy(); break; } }); view.TriggerExitEvents.Subscribe(col => { switch (col.gameObject.layer) { case Layers.AsteroidsTriggers: LevelController.ChangeAsteroidsOnScreenCount(-1); break; } }); }
private void ManipulationWithEnemy(AsteroidView enemy, Health health) { enemy.SetHealth(health); enemy.KillPoint = _dataEnemies.AsteroidKillPoint; health.OnDeath += enemy.Death; _listenerShowMessageDeathEnemy.Add(enemy); new EnemiesSpawn(_dataPlayer).RandomSpawnLocation(enemy); }
void Awake() { asteroidController = GetComponentInChildren <AsteroidController>(); asteroidModel = new AsteroidModel(); asteroidController.asteroidModel = asteroidModel; asteroidView = GetComponentInChildren <AsteroidView>(); asteroidController.asteroidView = asteroidView; asteroidView.asteroidModel = asteroidModel; }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { base.Initialize(); var foo = new AsteroidView(); foo.AsteroidModel.Speed = 3; foo.AsteroidModel.Move(); }
public AsteroidFactory(Vector3 position) { View = GameObject.Instantiate( Refs.Instance.AsteroidViewPrefab, position, Quaternion.identity, Refs.Instance.Gameplay ); Model = new AsteroidModel(); Controller = new AsteroidController(Model, View); }
private void Start() { asModel = new AsteroidModel(type, position); asView = CreateAsteroidView(type, position); disposables = new CompositeDisposable(); Observable.EveryUpdate() .Subscribe(_ => { asModel.UpdatePosition(-1 * Time.deltaTime); }) .AddTo(disposables); asModel.position .ObserveEveryValueChanged(position => position.Value) .Subscribe(posValue => { asView.UpdatePosition(posValue); }) .AddTo(disposables); asView.isCollided .ObserveEveryValueChanged(position => position.Value) .Subscribe(posValue => { asModel.LoseHp(); asView.CloseFlag(); }) .AddTo(disposables); MessageBroker.Default .Receive <DeathNotice>() .Where(msg => msg.sender == asModel && msg.objectType == SpaceObjectType.asteroid) .Subscribe(_ => { SelfDestruct(); }) .AddTo(disposables); MessageBroker.Default .Receive <GameOverNotice>() .Subscribe(msg => { disposables.Dispose(); }) .AddTo(this); }
public override PoolableView GetOpponent() { Vector3 randomPos = RandomPosition(); string asteroidParentTag = StringEnum.GetStringValue(SpaceWarriorTag.AsteroidsParent); AsteroidView asteroid = asteroidPool.GetInstance(); AddOutOfScreenComponent(asteroid); asteroid.Reinit( randomPos, Quaternion.identity, GameObject.FindGameObjectWithTag(asteroidParentTag).transform ); asteroid.Init( levelManager.LevelInfo.Asteroid.Health, levelManager.LevelInfo.Asteroid.MinSpeed, levelManager.LevelInfo.Asteroid.MaxSpeed ); CreatedObjectCount++; return(asteroid); }
private void OnHitByLaser(AsteroidView asteroidView, PlayerShipLaserView playerShipLaserView, int health) { asteroidHitByLaserSignal.Dispatch(asteroidView, playerShipLaserView, health); }