Beispiel #1
0
        // Calculate the reflected color
        private RayColor GetReflectedColor(RayColor color)
        {
            // Calculate the filtered color
            var reflectedColor = new RayColor(!Color.R && color.R, !Color.G && color.G, !Color.B && color.B, RayColor.DEFAULT_ALPHA);

            return(reflectedColor);
        }
Beispiel #2
0
 /// <summary>
 /// Set ennemies properties.
 /// </summary>
 /// <param name="hitpoints">Life of an ennemy.</param>
 /// <param name="speed">Speed of an ennemy.</param>
 /// <param name="color">Color of an ennemy.</param>
 /// <param name="spawnTime">Time before the ennemy spawn after the previous ennemy.</param>
 public Enemy(int hitpoints, float speed, RayColor color, float spawnTime)
 {
     this.Hitpoints = hitpoints;
     this.Speed     = speed;
     this.Color     = color;
     this.SpawnTime = spawnTime;
 }
Beispiel #3
0
        /// <summary>
        /// Update the current objective color.
        /// </summary>
        /// <param name="color"></param>
        public override void SetColor(RayColor color)
        {
            base.SetColor(color);

            // Changed the color of the object
            _meshRenderer.material.color = color.GetColor();
        }
Beispiel #4
0
 public void RayDoor(RayColor rayColor)
 {
     if (rayColor == doorColor)
     {
         Destroy(this.gameObject);
     }
 }
Beispiel #5
0
        /// <summary>
        /// Compute the filtered color.
        /// </summary>
        /// <param name="color"></param>
        /// <returns></returns>
        private RayColor FilterColor(RayColor color)
        {
            // Calculate the filtered color
            var filteredColor = new RayColor(Color.R && color.R, Color.G && color.G, Color.B && color.B, RayColor.DEFAULT_ALPHA);

            return(filteredColor);
        }
Beispiel #6
0
        public override void HandleReceivedRay(Ray ray)
        {
            var filteredColor = FilterColor(ray.Color);
            var newColor      = new RayColor(ray.Color.R ^ filteredColor.R, ray.Color.G ^ filteredColor.G, ray.Color.B ^ filteredColor.B, RayColor.DEFAULT_ALPHA);

            EmitNewRay(ray.Direction, newColor, ray);
        }
Beispiel #7
0
    /// <summary>
    /// Set hthe color of an item.
    /// </summary>
    /// <param name="color"></param>
    public void SetColor(RayColor color)
    {
        Color = color;
        var _image = this.GetComponentInChildren <Image>();
        var _text  = this.GetComponentInChildren <Text>();

        _text.text   = Color.GetName();
        _image.color = Color.GetColor();
    }
Beispiel #8
0
    private Enemy CreateEnemyFromJSON(JSONObject enemy)
    {
        int      hitpoints = enemy ["Hitpoints"] != null ? (int)enemy ["Hitpoints"].n : _defaultHitpoints;
        float    speed     = enemy ["Speed"] != null ? enemy ["Speed"].n : _defaultSpeed;
        RayColor color     = enemy ["Color"] != null?RayColor.Parse(enemy ["Color"].str) : _defaultColor;

        float spawnTime = enemy ["SpawnTime"] != null ? enemy ["SpawnTime"].n : _defaultSpawnInterval;

        return(new Enemy(hitpoints, speed, color, spawnTime));
    }
Beispiel #9
0
    /// <summary>
    /// Determines how many enemies of each colors are in the given wave.
    /// Returns a String to be when displaying the next wave message.
    /// </summary>
    /// <param name="wave"></param>
    private void SetUpEnemyColorDico(IEnumerable <Enemy> wave)
    {
        ResetEnemyColorDico();

        foreach (var enemy in wave)
        {
            RayColor color = enemy.Color;
            _dicoEnemyColors [color] += 1;
        }
    }
Beispiel #10
0
        // Update the current filter color
        public override void SetColor(RayColor color)
        {
            base.SetColor(color);
            // Changed the color of the object
            foreach (var renderer in _renderers)
            {
                renderer.material.color = color.GetColor();
            }

            UpdateEmittedRays();
        }
Beispiel #11
0
    /// <summary>
    /// Apply a ray color to an item.
    /// </summary>
    /// <param name="rayColor">Color of the ray.</param>
    public void SetSelectedItemColor(RayColor rayColor)
    {
        var ib = _selectedItem.GetComponent <ItemBase>();

        if (ib != null)
        {
            ib.SetColor(rayColor);
        }

        _selectedItem = null;
    }
Beispiel #12
0
    /// <summary>
    /// Sets up specific settings (Players Lives, Spawn Interval, ...).
    /// </summary>
    /// <param name="data"></param>
    private void SetUpGameInfo(JSONObject data)
    {
        _defaultSpawnInterval = data["Info"].GetField("DefaultSpawnInterval").n;
        _defaultHitpoints     = (int)data["Info"].GetField("DefaultHitpoints").i;
        _defaultSpeed         = data["Info"].GetField("DefaultSpeed").n;
        _defaultColor         = RayColor.Parse(data["Info"].GetField("DefaultColor").str);

        LivesLeft   = (int)data["Info"].GetField("Lives").i;
        _spawnPoint = GameObject.FindGameObjectWithTag("Spawn Point");

        GoButton.GetComponent <Button>().onClick.AddListener(CallNextPhase);
    }
Beispiel #13
0
        public Ray EmitNewRay(Direction direction, RayColor rayColor, Ray parent)
        {
            Debug.LogWarning(string.Format("Emitting new ray from {0} with color {1} and direction {2}",
                                           transform.gameObject,
                                           rayColor,
                                           direction
                                           ));
            Ray ray = new Ray(this, rayColor, direction, parent);

            EmittedRays.Add(ray);
            StartReboundFeedback();
            return(ray);
        }
Beispiel #14
0
        public override void HandleReceivedRay(Ray ray)
        {
            RayColor filteredColor = GetFilteredColor(ray.Color);

            if (filteredColor.R || filteredColor.G || filteredColor.B)
            {
                EmitNewRay(ray.Direction, filteredColor, ray);
            }

            Direction reflectionDirection = GetReflectionDirection(ray);
            RayColor  reflectedColor      = GetReflectedColor(ray.Color);

            if (reflectionDirection != Direction.None &&
                (reflectedColor.R || reflectedColor.G || reflectedColor.B))
            {
                EmitNewRay(reflectionDirection, reflectedColor, ray);
            }
        }
Beispiel #15
0
        /// <summary>
        /// Calculate the damage dealt to an ennemy.
        /// </summary>
        /// <param name="enemyColor"></param>
        /// <returns></returns>
        private int CalculateDamage(RayColor enemyColor)
        {
            var damage = 0;

            if (enemyColor.B != Color.B)
            {
                damage += DamageBase;
            }
            if (enemyColor.G != Color.G)
            {
                damage += DamageBase;
            }
            if (enemyColor.R != Color.R)
            {
                damage += DamageBase;
            }

            return(damage);
        }
Beispiel #16
0
        /// <summary>
        /// Set a gradient with the same color at the beginning and the end (we have to use a Gradient...).
        /// </summary>
        /// <param name="color"></param>
        private void SetLineRendererColor(RayColor color)
        {
            var gradient = new Gradient();

            gradient.SetKeys(
                new[]
            {
                new GradientColorKey(color.GetColor(), 0.0f), new GradientColorKey(color.GetColor(), 1.0f)
            },
                new[]
            {
                new GradientAlphaKey(color.Alpha, 0.0f), new GradientAlphaKey(color.Alpha, 1.0f)
            }
                );

            Debug.Log(gradient);

            // Apply the gradient
            LineRenderer.colorGradient = gradient;
        }
Beispiel #17
0
 /// <summary>
 /// Defined a ray
 /// </summary>
 /// <param name="rayEmitter">Source of the ray.</param>
 /// <param name="color">Color of the ray.</param>
 /// <param name="direction">Direction of the ray from the source.</param>
 /// <param name="parent">The ray received.</param>
 public Ray(RaySensitive rayEmitter, RayColor color, Direction direction, Ray parent)
 {
     RayEmitter         = rayEmitter;
     LineRendererParent = new GameObject(string.Format("Ray {0} {1}",
                                                       color,
                                                       direction
                                                       ));
     LineRendererParent.transform.position = rayEmitter.transform.position + VectorOffset;
     LineRendererParent.transform.rotation = rayEmitter.transform.rotation;
     LineRendererParent.transform.parent   = rayEmitter.transform;
     LineRenderer            = LineRendererParent.AddComponent <LineRenderer>();
     LineRenderer.startWidth = 0.3f;
     LineRenderer.endWidth   = 0.3f;
     LineRenderer.material   = new Material(Shader.Find("Sprites/Default"));
     LineRenderer.enabled    = true;
     Color       = color;
     Enabled     = true;
     Direction   = direction;
     RayReceiver = null;
     Parent      = parent;
     Id          = CreateId();
 }
Beispiel #18
0
        /// <summary>
        /// Calculate the total color of the received rays
        /// </summary>
        private void CalculateColor()
        {
            if (ReceveidRays.Count > 0)
            {
                RayColor color = ReceveidRays[0].Color;
                for (int i = 1; i < ReceveidRays.Count; i++)
                {
                    color = RayColor.Add(color, ReceveidRays[i].Color);
                }

                Color   = color;
                Enabled = true;
            }
            else
            {
                Color   = RayColor.NONE;
                Enabled = false;
            }

            if (Color != RayColor.NONE && UseLaser && LineRenderer != null)
            {
                SetLineRendererColor(Color);
            }
        }
Beispiel #19
0
    /// <summary>
    /// Load the level saved in the corresponding JSON file.
    /// </summary>
    /// <param name="level">Name of the level saved in the corresponding JSON file.</param>
    public void LoadLevel(string level)
    {
        string jsonText;

        if (PlayerPrefs.GetInt("currentLevelIsCustom", 0) == 1)
        {
            jsonText = LevelManager.LoadLevel(level).ToString();
        }
        else
        {
            jsonText = LoadFile(level);
        }

        JSONObject dataAsJson = new JSONObject(jsonText);

        // Create board from file
        dataAsJson.GetField("Board", delegate(JSONObject boardData)
        {
            BoardManager.BoardSize.x = (int)boardData["Size"]["X"].i;
            BoardManager.BoardSize.y = (int)boardData["Size"]["Y"].i;

            BoardManager.CellSize   = (int)boardData["CellSize"].i;
            BoardManager.CellOffset = (int)boardData["CellOffset"].i;

            BoardManager.SpawnPoint.x = (int)boardData["SpawnPoint"]["X"].i;
            BoardManager.SpawnPoint.y = (int)boardData["SpawnPoint"]["Y"].i;

            foreach (var path in boardData["Paths"].list)
            {
                BoardManager.Paths.Add(new BoardPath((int)path["X1"].i, (int)path["Y1"].i, (int)path["X2"].i,
                                                     (int)path["Y2"].i));
            }

            BoardManager.EndPoint.x = (int)boardData["EndPoint"]["X"].i;
            BoardManager.EndPoint.y = (int)boardData["EndPoint"]["Y"].i;

            BoardManager.CreateBoard();
        }, Debug.LogError);

        // Load player inventory
        if (dataAsJson["Inventory"].HasField("Mirrors") && dataAsJson["Inventory"]["Mirrors"].i > 0)
        {
            CreateInventoryItem(MirrorInventoryItemPrefab, "mirror", (int)dataAsJson["Inventory"]["Mirrors"].i);
        }

        if (dataAsJson["Inventory"].HasField("MirrorFilters") && dataAsJson["Inventory"]["MirrorFilters"].i > 0)
        {
            CreateInventoryItem(FilterMirrorInventoryItemPrefab, "mirror-filter",
                                (int)dataAsJson["Inventory"]["MirrorFilters"].i);
        }

        if (dataAsJson["Inventory"].HasField("Prisms") && dataAsJson["Inventory"]["Prisms"].i > 0)
        {
            CreateInventoryItem(PrismInventoryItemPrefab, "prism", (int)dataAsJson["Inventory"]["Prisms"].i);
        }

        if (dataAsJson["Inventory"].HasField("Filters") && dataAsJson["Inventory"]["Filters"].i > 0)
        {
            CreateInventoryItem(FilterInventoryItemPrefab, "filter", (int)dataAsJson["Inventory"]["Filters"].i);
        }

        if (dataAsJson["Inventory"].HasField("Obstacles") && dataAsJson["Inventory"]["Obstacles"].i > 0)
        {
            CreateInventoryItem(ObstacleInventoryItemPrefab, "obstacle", (int)dataAsJson["Inventory"]["Obstacles"].i);
        }

        if (dataAsJson["Inventory"].HasField("StandardTurret") && dataAsJson["Inventory"]["StandardTurret"].i > 0)
        {
            CreateInventoryItem(StandardTurretInventoryItemPrefab, "standard-turret",
                                (int)dataAsJson["Inventory"]["StandardTurret"].i);
        }

        if (dataAsJson["Inventory"].HasField("MissileTurret") && dataAsJson["Inventory"]["MissileTurret"].i > 0)
        {
            CreateInventoryItem(MissileTurretInventoryItemPrefab, "missile-turret",
                                (int)dataAsJson["Inventory"]["MissileTurret"].i);
        }

        if (dataAsJson["Inventory"].HasField("LaserTurret") && dataAsJson["Inventory"]["LaserTurret"].i > 0)
        {
            CreateInventoryItem(LaserTurretInventoryItemPrefab, "laser-turret",
                                (int)dataAsJson["Inventory"]["LaserTurret"].i);
        }

        foreach (var jsonEntity in dataAsJson["Entities"].list)
        {
            GameObject objectInstance = null;
            switch (jsonEntity["Type"].str)
            {
            case "Mirror":
                Debug.Log("Instanciating a mirror...");
                objectInstance = Instantiate(MirrorPrefab, ItemsContainer.transform);
                Mirror mirror = objectInstance.GetComponentInChildren <Mirror>();
                mirror.Orientation = (Direction)jsonEntity["Orientation"].i;
                break;

            case "Filter":
                Debug.Log("Instanciating a filter...");
                objectInstance = Instantiate(FilterPrefab, ItemsContainer.transform);
                Filter filter = objectInstance.GetComponentInChildren <Filter>();
                filter.Color = new RayColor(
                    jsonEntity["Red"].b,
                    jsonEntity["Green"].b,
                    jsonEntity["Blue"].b,
                    RayColor.DEFAULT_ALPHA);
                break;

            case "Prism":
                Debug.Log("Instanciating a prism...");
                objectInstance = Instantiate(PrismPrefab, ItemsContainer.transform);
                // Prism prism = objectInstance.GetComponentInChildren<Prism>();
                break;

            case "Filter Mirror":
                Debug.Log("Instanciating a filter mirror...");
                objectInstance = Instantiate(FilterMirrorPrefab, ItemsContainer.transform);
                FilterMirror filterMirror = objectInstance.GetComponentInChildren <FilterMirror>();
                filterMirror.Orientation = (Direction)jsonEntity["Orientation"].i;
                filterMirror.Color       = new RayColor(
                    jsonEntity["Red"].b,
                    jsonEntity["Green"].b,
                    jsonEntity["Blue"].b,
                    RayColor.DEFAULT_ALPHA);
                break;

            case "Light Source":
                Debug.Log("Instanciating a light source...");
                objectInstance = Instantiate(LightSourcePrefab, ItemsContainer.transform);
                Laser laser = objectInstance.GetComponentInChildren <Laser>();
                foreach (var jsonRay in jsonEntity["Rays"].list)
                {
                    RayColor rayColor =
                        new RayColor(jsonRay["Red"].b, jsonRay["Green"].b, jsonRay["Blue"].b,
                                     RayColor.DEFAULT_ALPHA);
                    RaySource raySource =
                        new RaySource((Direction)jsonRay["Direction"].i, jsonRay["Enabled"].b, rayColor);
                    laser.AddSource(raySource);
                }

                break;

            case "Obstacle":
                Debug.Log("Instanciating an obstacle...");
                objectInstance = Instantiate(ObstaclePrefab, ItemsContainer.transform);
                break;

            case "Standard Turret":
                Debug.Log("Instanciating a standard turret...");
                objectInstance = Instantiate(StandardTurretPrefab, ItemsContainer.transform);
                break;

            case "Missile Turret":
                Debug.Log("Instanciating a missile turret...");
                objectInstance = Instantiate(MissileTurretPrefab, ItemsContainer.transform);
                break;

            case "Laser Turret":
                Debug.Log("Instanciating a laser turret...");
                objectInstance = Instantiate(LaserTurretPrefab, ItemsContainer.transform);
                break;

            default:
                Debug.LogError(string.Format("Object of type {0} is not supported.", jsonEntity["Type"].str));
                break;
            }

            if (objectInstance == null)
            {
                continue;
            }

            var objectInstancePosition = new Vector2Int((int)jsonEntity["X"].i, (int)jsonEntity["Y"].i);
            if (!BoardManager.AddItem(objectInstance, objectInstancePosition))
            {
                Debug.LogError(string.Format("Could not instantiate {0} at position {1}.", objectInstance,
                                             objectInstancePosition));
                Destroy(objectInstance);
                continue;
            }

            var dragAndDrop = objectInstance.GetComponentInChildren <DragAndDrop>();
            if (dragAndDrop)
            {
                dragAndDrop.IsDraggable = jsonEntity["Draggable"].b;
            }

            var raySensitive = objectInstance.GetComponentInChildren <RaySensitive>();
            if (raySensitive)
            {
                raySensitive.ColliderEnabled = true;
            }
        }

        if (dataAsJson != null)
        {
            TdManager.SetUpGame(dataAsJson);
        }
    }
Beispiel #20
0
 /// <summary>
 /// Effect - Recolor tower to boost dmg
 /// </summary>
 /// <param name="ray"></param>
 public override void HandleReceivedRay(Ray ray)
 {
     this.color = ray.Color;
     //TODO Recolor
 }
Beispiel #21
0
 public virtual void SetColor(RayColor color)
 {
     Color  = color;
     _color = color;
 }
Beispiel #22
0
 /// <summary>
 /// Removes an enemy from the local tracking enemy color dictionary.
 /// Should be called every time an enemy is destroyed (killed or reached end of TD).
 /// </summary>
 /// <param name="color"></param>
 public void UpdateDeath(RayColor color)
 {
     _dicoEnemyColors [color] -= 1;
     WaveText.text             = string.Format("Wave : {0}/{1}{2}{3}", CurrentWave, WavesTotal, Environment.NewLine, GetNextWaveColors());
 }
Beispiel #23
0
 /// <summary>
 /// Save the color of the set item.
 /// </summary>
 /// <param name="jsonObject"></param>
 /// <param name="color"></param>
 private void SaveItemColor(JSONObject jsonObject, RayColor color)
 {
     jsonObject.AddField("Red", color.R);
     jsonObject.AddField("Green", color.G);
     jsonObject.AddField("Blue", color.B);
 }
Beispiel #24
0
 public void UpdateLightSouthEastColor(Int32 value)
 {
     _currentLightSouthEastColor = _colorOptions[value];
 }
Beispiel #25
0
 public void UpdateLightNorthWestColor(Int32 value)
 {
     _currentLightNorthWestColor = _colorOptions[value];
 }
Beispiel #26
0
 /// <summary>
 /// Add a ray to the light source on the board.
 /// </summary>
 /// <param name="laser">Represents the laser to add.</param>
 /// <param name="color">The color of the laser.</param>
 /// <param name="direction">The direction of the laser from the light source.</param>
 private void AddRayToLightSource(Laser laser, RayColor color, Direction direction)
 {
     laser.AddSource(new RaySource(direction, color != RayColor.NONE, color));
 }
Beispiel #27
0
 public RaySource(Direction direction, bool enabled, RayColor color)
 {
     Direction  = direction;
     Enabled    = enabled;
     this.Color = color;
 }