Exemplo n.º 1
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.gameObject.layer == 13)
     {
         Vector2 ExplosionDirection;
         ExplosionDirection = (collision.gameObject.transform.position - transform.position);
         ExplosionDirection.Normalize();
         _rb.AddForce(ExplosionDirection * 1000f);
     }
 }
Exemplo n.º 2
0
    void Start()
    {
        explosionDirectionLeft  = Left.GetComponent <ExplosionDirection>();
        explosionDirectionRight = Right.GetComponent <ExplosionDirection>();
        explosionDirectionUp    = Up.GetComponent <ExplosionDirection>();
        explosionDirectionDown  = Down.GetComponent <ExplosionDirection>();

        explosionDirectionLeft.Boom(DIRECTION_LEFT);
        explosionDirectionRight.Boom(DIRECTION_RIGHT);
        explosionDirectionUp.Boom(DIRECTION_UP);
        explosionDirectionDown.Boom(DIRECTION_DOWN);
    }
Exemplo n.º 3
0
        public void Setup(bool isSource, ExplosionDirection direction, int bombRange, GroundTile groundTile)
        {
            CheckHitSomething();
            if (isSource)
            {
                onSourceExplosion.Invoke();
                bombRange--;
                SpreadExplosion(groundTile.GetBottomNeighbor(), ExplosionDirection.Down, bombRange);
                SpreadExplosion(groundTile.GetTopNeighbor(), ExplosionDirection.Up, bombRange);
                SpreadExplosion(groundTile.GetLeftNeighbor(), ExplosionDirection.Left, bombRange);
                SpreadExplosion(groundTile.GetRightNeighbor(), ExplosionDirection.Right, bombRange);
            }
            else
            {
                animator.SetBool("isDerivate", true);
                if (direction == ExplosionDirection.Up || direction == ExplosionDirection.Down)
                {
                    transform.rotation = Quaternion.Euler(0, 0, 90);
                }

                if (bombRange > 0)
                {
                    bombRange--;
                    switch (direction)
                    {
                    case ExplosionDirection.Up:
                        SpreadExplosion(groundTile.GetTopNeighbor(), direction, bombRange);
                        break;

                    case ExplosionDirection.Down:
                        SpreadExplosion(groundTile.GetBottomNeighbor(), direction, bombRange);
                        break;

                    case ExplosionDirection.Right:
                        SpreadExplosion(groundTile.GetRightNeighbor(), direction, bombRange);
                        break;

                    case ExplosionDirection.Left:
                        SpreadExplosion(groundTile.GetLeftNeighbor(), direction, bombRange);
                        break;
                    }
                }
                else
                {
                    //Explosion Tail
                }
            }
            StartCoroutine(DestroyGameObjectOnClients(gameObject, 1f));
        }
Exemplo n.º 4
0
        public void Setup(bool isSource, ExplosionDirection direction, int bombRange, GroundTile groundTile)
        {
            CheckHitSomething();
            if (isSource)
            {
                onSourceExplosion.Invoke();
                bombRange--;
                SpreadExplosion(groundTile.GetBottomNeighbor(), ExplosionDirection.Down, bombRange);
                SpreadExplosion(groundTile.GetTopNeighbor(), ExplosionDirection.Up, bombRange);
                SpreadExplosion(groundTile.GetLeftNeighbor(), ExplosionDirection.Left, bombRange);
                SpreadExplosion(groundTile.GetRightNeighbor(), ExplosionDirection.Right, bombRange);
            }
            else
            {
                if (bombRange > 0)
                {
                    bombRange--;
                    switch (direction)
                    {
                    case ExplosionDirection.Up:
                        SpreadExplosion(groundTile.GetTopNeighbor(), direction, bombRange);
                        break;

                    case ExplosionDirection.Down:
                        SpreadExplosion(groundTile.GetBottomNeighbor(), direction, bombRange);
                        break;

                    case ExplosionDirection.Right:
                        SpreadExplosion(groundTile.GetRightNeighbor(), direction, bombRange);
                        break;

                    case ExplosionDirection.Left:
                        SpreadExplosion(groundTile.GetLeftNeighbor(), direction, bombRange);
                        break;
                    }
                }
                else
                {
                    //Explosion Tail
                }
            }
            Destroy(gameObject, 1f);
        }
Exemplo n.º 5
0
        private void SpreadExplosion(GroundTile.NeighborInfo neighborInfo, ExplosionDirection direction, int bombRange)
        {
            switch (neighborInfo.neighborType)
            {
            case GroundTile.NeighborType.Destructable:
                //Destroy the Destructable
                Loottable loottable = neighborInfo.gameObject.GetComponent <Loottable>();
                loottable.Loot();
                Destroy(neighborInfo.gameObject);
                break;

            case GroundTile.NeighborType.Indestructable:
                //Nothing to do
                break;

            case GroundTile.NeighborType.Empty:
                //Spawn Explosion
                Explosion explosion = Instantiate(explosionPrefab, neighborInfo.gameObject.transform.position, Quaternion.identity).GetComponent <Explosion>();
                explosion.Setup(false, direction, bombRange, neighborInfo.gameObject.GetComponent <GroundTile>());
                break;
            }
        }
Exemplo n.º 6
0
        private bool canWePlaceExplosion(int X, int Y, PhysicalMap map, ExplosionDirection direction)
        {
            bool result = false;

            lock (map.MapMatrix)
            {
                switch (direction)
                {
                case ExplosionDirection.UP:
                {
                    for (int j = X; j < X + size.Width; j++)
                    {
                        for (int k = Y; (k < Y + size.Height) && (k < map.Height); k++)
                        {
                            if (map.MapMatrix[k][j] == (int)PhysicalMap.KindOfArea.PHYSICACOBJECT)
                            {
                                int i = Y;
                                while (map.MapMatrix[i][j] == (int)PhysicalMap.KindOfArea.PHYSICACOBJECT)
                                {
                                    i++;
                                }
                                newLocation.X = X;
                                newLocation.Y = i - 1;
                                return(true);
                            }
                        }
                    }
                }
                break;

                case ExplosionDirection.DOWN:
                {
                    for (int j = X; j < X + size.Width; j++)
                    {
                        for (int k = Y + size.Height; (k > Y) && (k > 0); k--)
                        {
                            if (map.MapMatrix[k][j] == (int)PhysicalMap.KindOfArea.PHYSICACOBJECT)
                            {
                                int i = Y + size.Height;
                                while (map.MapMatrix[i][j] == (int)PhysicalMap.KindOfArea.PHYSICACOBJECT)
                                {
                                    i--;
                                }
                                newLocation.X = X;
                                newLocation.Y = i - size.Height + 2;
                                return(true);
                            }
                        }
                    }
                }
                break;

                case ExplosionDirection.LEFT:
                {
                    for (int i = Y; i < Y + size.Height; i++)
                    {
                        for (int k = X; (k < X + size.Width) && (k < map.Width); k++)
                        {
                            if (map.MapMatrix[i][k] == (int)PhysicalMap.KindOfArea.PHYSICACOBJECT)
                            {
                                int j = X;
                                while (map.MapMatrix[i][j] == (int)PhysicalMap.KindOfArea.PHYSICACOBJECT)
                                {
                                    j++;
                                }
                                newLocation.X = j;
                                newLocation.Y = Y;
                                return(true);
                            }
                        }
                    }
                }
                break;

                case ExplosionDirection.RIGHT:
                {
                    for (int i = Y; i < Y + size.Height; i++)
                    {
                        for (int k = X + size.Width; (k > X) && (k > 0); k--)
                        {
                            if (map.MapMatrix[i][k] == (int)PhysicalMap.KindOfArea.PHYSICACOBJECT)
                            {
                                int j = X + size.Width;
                                while (map.MapMatrix[i][j] == (int)PhysicalMap.KindOfArea.PHYSICACOBJECT)
                                {
                                    j--;
                                }
                                newLocation.X = j - size.Width + 2;
                                newLocation.Y = Y;
                                return(true);
                            }
                        }
                    }
                }
                break;
                }
                return(result);
            }
        }