public IProjectile FireProjectile()
        {
            if (this.Target != null && this.Target.Exists && this.frameCount >= this.Speed)
            {
                this.frameCount = 0;
                Projectile projectile = null;

                if (Math.Abs(this.lastAngle - this.towerAngle) < 1)
                {
                    switch (this.projectileType)
                    {
                    case ProjectileSelection.ArrowProjectile:
                        projectile = new ArrowProjectile(
                            this.Coordinates.X,
                            this.Coordinates.Y,
                            this.Target,
                            this.Damage);
                        break;

                    case ProjectileSelection.FireProjectile:
                        projectile = new FireProjectile(
                            this.Coordinates.X,
                            this.Coordinates.Y,
                            this.Target,
                            this.Damage);
                        break;

                    case ProjectileSelection.FreezeProjectile:
                        projectile = new FreezeProjectile(
                            this.Coordinates.X,
                            this.Coordinates.Y,
                            this.Target,
                            this.Damage);
                        break;

                    case ProjectileSelection.SniperProjectile:
                        projectile = new SniperProjectile(
                            this.Coordinates.X,
                            this.Coordinates.Y,
                            this.Target,
                            this.Damage);
                        break;
                    }

                    return(projectile);
                }
            }
            else
            {
                this.frameCount++;
            }

            return(null);
        }
Exemple #2
0
    public bool attackCheck(Grid grid,
                            CoordinateSet currentTankCoordinates,
                            GridNode targetNode,
                            bool updateState)
    {
        int gridSize     = grid.getGridSize();
        int currentTankX = currentTankCoordinates.getX();
        int currentTankY = currentTankCoordinates.getY();
        int targetNodeX  = targetNode.getCoordinateSet().getX();
        int targetNodeY  = targetNode.getCoordinateSet().getY();

        if (updateState)
        {
            redTanks  = GameObject.FindGameObjectsWithTag("Red Tank");
            blueTanks = GameObject.FindGameObjectsWithTag("Blue Tank");

            for (int i = 0; i < redTanks.Length; i++)
            {
                if (redTanks[i].transform.position == new Vector3(currentTankX, .8f, currentTankY))
                {
                    sniperFire = redTanks[i];
                }
            }

            for (int i = 0; i < blueTanks.Length; i++)
            {
                if (blueTanks[i].transform.position == new Vector3(currentTankX, .8f, currentTankY))
                {
                    sniperFire = blueTanks[i];
                }
            }

            sniperScript = sniperFire.GetComponent <SniperProjectile>();

            if (sniperScript == null)
            {
                Debug.Log("SniperProjectile Script is null");
            }
        }

        switch (this.orientation)
        {
        case Orientations.Up:
            for (int i = 1; i <= this.distance; i++)
            {
                // Check for index out of bounds
                if (currentTankY + i >= gridSize)
                {
                    break;
                }

                // Check for mountains
                if (grid.getGridNode(currentTankX, currentTankY + i).getTerrain() is Mountain)
                {
                    return(false);
                }

                // Do final check to see if this is the target node
                if (currentTankX == targetNodeX && (currentTankY + i) == targetNodeY)
                {
                    return(true);
                }
            }
            break;

        case Orientations.Right:
            break;

        case Orientations.Down:
            for (int i = 1; i <= this.distance; i++)
            {
                // Check for index out of bounds
                if (currentTankY - i < 0)
                {
                    continue;
                }

                // Check for mountains
                if (grid.getGridNode(currentTankX, currentTankY - i).getTerrain() is Mountain)
                {
                    return(false);
                }

                // Do final check to see if this is the target node
                if ((currentTankX) == targetNodeX && (currentTankY - i) == targetNodeY)
                {
                    return(true);
                }
            }
            break;

        case Orientations.Left:
            break;
        }

        return(false);
    }