Пример #1
0
        protected override void RunReactive()
        {
            _asteroidsId.Clear();
            _hashtable.Clear();
            var health = (float)_photonServer.CurrentRoom.CustomProperties[RoomDataConstants.Health];

            for (int i = 0; i < ReactedEntitiesCount; i++)
            {
                var entity = ReactedEntities[i];
                if (!_world.IsEntityExists(entity))
                {
                    continue;
                }
                var asteroidCollision = _world.GetComponent <AsteroidCollision> (entity);
                health -= _gameConfig.DamageFromAsteroid;

                var asteroid = _world.GetComponent <Asteroid> (asteroidCollision.AsteroidEntity);
                _asteroidsId.Add(asteroid.Id);
            }

            _photonServer.OpRaiseEvent(GameEventCode.DamageByAsteroids, _asteroidsId.ToArray(), true, ServerSpawnAsteroidSystem.All);

            _hashtable[RoomDataConstants.Health] = health;
            _photonServer.CurrentRoom.SetCustomProperties(_hashtable);

            SoundManager.PlayCollisionSound();

            if (health <= 0)
            {
                _photonServer.CurrentRoom.IsOpen    = false;
                _photonServer.CurrentRoom.IsVisible = false;
            }
        }
Пример #2
0
        private void DoControl()
        {
            var shootCameraTransform = _sceneDescription.ShootPlayerCamera.transform;
            var euler = shootCameraTransform.eulerAngles;
            var x     = euler.y;
            var y     = euler.x;
            //Debug.Log ("Before: " + euler);
            var xSpeed = _gameConfig.xSpeed;
            var ySpeed = _gameConfig.xSpeed;

            x += Input.GetAxis("Mouse X") * xSpeed * _gameConfig.ShootCameraDistance * 0.02f;
            y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;

            Quaternion rotation = Quaternion.Euler(y, x, 0);

            shootCameraTransform.rotation = rotation;

            var camera           = _sceneDescription.GameCamera;
            var ray              = camera.ViewportPointToRay(Vector2.one / 2f);
            var targetWorldPoint = ray.GetPoint(1000);

            _photonServer.OpRaiseEvent(GameEventCode.ChangeShootCamera, targetWorldPoint, false, ServerSpawnAsteroidSystem.All);

            if (Input.GetMouseButtonDown(0))
            {
                _world.CreateEntityWith <WantShoot> (out _);
            }
        }
Пример #3
0
        protected override void RunReactive()
        {
            var camera = _sceneDescription.GameCamera;
            var ray    = camera.ViewportPointToRay(Vector2.one / 2f);

            if (Physics.Raycast(ray, out var hitInfo))
            {
                var asteroidView = hitInfo.transform.GetComponent <AsteroidView> ();
                if (asteroidView)
                {
                    var asteroid = _world.GetComponent <Asteroid> (asteroidView.Entity);
                    _photonServer.OpRaiseEvent(GameEventCode.ShootAsteroid, asteroid.Id, true, ServerSpawnAsteroidSystem.All);
                }
            }
            else
            {
                _photonServer.OpRaiseEvent(GameEventCode.ShootAsteroid, -1, true, ServerSpawnAsteroidSystem.All);
            }
        }
 private void Try(PlayerRole newRole)
 {
     if (_photonServer.CurrentRoom != null && _photonServer.LocalPlayer != null)
     {
         var id = _photonServer.LocalPlayer.ID;
         if (_gameState.Roles.TryGetValue(id, out var role))
         {
             if (role != newRole)
             {
                 var playerWithRole = _gameState.GetPlayerWithRole(newRole);
                 if (playerWithRole == -1)
                 {
                     _photonServer.OpRaiseEvent(GameEventCode.ChangeRole, (byte)newRole, true, toServerOnly);
                 }
             }
         }
     }
 }
Пример #5
0
        public void Run()
        {
            var playerTransform = _world.GetComponent <TransformRef> (_gameState.ShipEntity);

            foreach (var index in _asteroids)
            {
                var position = _asteroids.Components2[index].value;
                var distance = (position - playerTransform.value.position).sqrMagnitude;
                if (distance > _gameConfig.DeathDistance * _gameConfig.DeathDistance)
                {
                    _asteroidIds.Add(_asteroids.Components1[index].Id);
                }
            }

            if (_asteroidIds.Count > 0)
            {
                _photonServer.OpRaiseEvent(GameEventCode.KillAsteroids, _asteroidIds.ToArray(), true, ServerSpawnAsteroidSystem.All);
                _asteroidIds.Clear();
            }
        }
        public void Run()
        {
            var time = Time.realtimeSinceStartup;
            var lastGenerationTime     = GameState.lastGenerationTime;
            var timeFromLastGeneration = time - lastGenerationTime;

            if (timeFromLastGeneration > GameConfig.GenerationInterval)
            {
                var lastId = photonServer.CurrentRoom.CustomProperties.ContainsKey(RoomDataConstants.LastGeneratedId) ? (int)photonServer.CurrentRoom.CustomProperties[RoomDataConstants.LastGeneratedId] : 0;

                GameState.lastGenerationTime = Time.realtimeSinceStartup;
                var asteroidAmount = Random.Range(GameConfig.MinAsteroidPerGeneration, GameConfig.MaxAsteroidsPerGeneration);
                _asteroids.Clear();
                for (int i = 0; i < asteroidAmount; i++)
                {
                    lastId++;
                    Vector3 shipPosition = sceneDescription.Ship.transform.position;
                    var     position     = shipPosition + Random.onUnitSphere * Random.Range(GameConfig.MinGenerationRadius, GameConfig.MaxGenerationRadius);

                    var direction     = Quaternion.LookRotation(shipPosition - position);
                    var speed         = Random.Range(GameConfig.MinAsteroidSpeed, GameConfig.MaxAsteroidSpeed);
                    var asteroidIndex = Random.Range(0, GameConfig.AsteroidsPrefabs.Length);

                    var asteroidDesc = new AsteroidDesc();
                    asteroidDesc.Id       = lastId;
                    asteroidDesc.Position = position;
                    asteroidDesc.Rotation = direction;
                    asteroidDesc.Speed    = speed;
                    asteroidDesc.Index    = asteroidIndex;
                    _asteroids.Add(asteroidDesc);
                }
                Debug.Log($"Want generate: {_asteroids.Count}");
                _hashtable.Clear();
                _hashtable[RoomDataConstants.LastGeneratedId] = lastId;
                photonServer.CurrentRoom.SetCustomProperties(_hashtable);
                photonServer.OpRaiseEvent(GameEventCode.SpawnAsteroids, _asteroids.ToArray(), true, All);
            }
        }