public BuilderBuildings(Util.Buildings building, Unit builder, ManagerMouse managerMouse, ManagerBuildings managerBuildings, ManagerUnits managerUnits)
        {
            this.builder = builder;

            this.managerMouse     = managerMouse;
            this.managerUnits     = managerUnits;
            this.managerBuildings = managerBuildings;

            this.building = Buildings.Building.Factory(building, managerMouse, managerBuildings.managerMap, managerUnits);
        }
示例#2
0
    void MeteorHit(Vector2 hitPos)
    {
        dealtDamage = true;

        //Meteor Explosion
        gameObject.GetComponent <Collider2D> ().enabled   = false;
        gameObject.GetComponent <Rigidbody2D> ().velocity = Vector2.zero;
        gameObject.GetComponent <AudioSource> ().Play();
        Transform fire = transform.GetChild(0);

        for (int i = 0; i < fire.childCount; i++)
        {
            fire.GetChild(i).GetComponent <ParticleSystem> ().Stop();
        }

        Transform explosion = transform.GetChild(1);

        for (int i = 0; i < explosion.childCount; i++)
        {
            explosion.GetChild(i).GetComponent <ParticleSystem> ().Play();
        }


        StartCoroutine(WaitDestroy());

        var hits = Physics2D.OverlapCircleAll(hitPos, HitRadius);

        for (int i = 0; i < hits.Length; i++)
        {
            //print(hits[i].name);
            var damageable = hits [i].transform.root.GetComponentInChildren <Damageable> ();

            if (damageable != null)
            {
                damageable.TakeDamage(BaseDamage);
                //Dont do this with a string comparison?
                if (damageable.tag == "Person")
                {
                    CitizenBehaviour person = damageable.GetComponent <CitizenBehaviour>();
                    person.CurrentAction = new StunAction(person, person.gameObject, Random.Range(5f, 10f), hitPos, person.CurrentAction);
                }

                if (damageable.tag == "Building")
                {
                    Buildings.Building building = damageable.GetComponent <Buildings.Building> ();

                    building.StartFire();
                }
            }
        }
    }
        public void Update()
        {
            if (building.isBuilding)
            {
                building.Update();
            }

            if (!building.isBuilding && building.isWorking)
            {
                managerBuildings.AddBuilding(building);
                building = Building.Factory((building.information as InformationBuilding).Type, managerMouse, managerBuildings.managerMap, managerUnits);

                builder.workState   = WorkigState.NOTHING;
                builder.position.Y += 32 * 2;
                builder.MoveTo(0, 1);
            }
        }
示例#4
0
        public void Combat()
        {
            if ((target != null || targetBuilding != null) && !(this is Builder))
            {
                Vector2 attackPosition = target != null ? target.position : targetBuilding.position;
                int     armor          = target != null ? target.information.Armor : 0;
                float   hitPoints      = target != null ? target.information.HitPoints : targetBuilding.information.HitPoints;

                int x = 0, y = 0;
                if (animations.current.ToLower().Contains("down"))
                {
                    y = -1;
                }
                if (animations.current.ToLower().Contains("up"))
                {
                    y = 1;
                }
                if (animations.current.ToLower().Contains("left"))
                {
                    x = 1;
                }
                if (animations.current.ToLower().Contains("right"))
                {
                    x = -1;
                }

                int adjustX = ((int)attackPosition.X - (int)position.X) / 32;
                int adjustY = ((int)attackPosition.Y - (int)position.Y) / 32;

                float distance = Vector2.Distance(attackPosition, position);

                if (adjustX == 5 && oldAdjust.X == 6 && adjustY == 6 && oldAdjust.Y == 5)
                {
                    adjustX = 4;
                    adjustY = 4;
                }

                if (!shoot)
                {
                    missilePosition = position;
                }

                if ((Math.Abs(adjustX) > information.Range || Math.Abs(adjustY) > information.Range) && lastPosition != position)
                {
                    Move((int)Math.Max(0, attackPosition.X / 32 + information.Range * x),
                         (int)Math.Max(0, attackPosition.Y / 32 + information.Range * y));
                    lastPosition = position;

                    animations.currentAnimation = AnimationType.WALKING;
                    animations.Play(animations.current);

                    if (information.Type == Util.Units.TROLL_AXETHROWER)
                    {
                        missilePosition = position;
                        targetPosition  = attackPosition;
                        shoot           = false;
                    }
                }
                else
                {
                    if (information.Type == Util.Units.TROLL_AXETHROWER || information.Type == Util.Units.ELVEN_ARCHER)
                    {
                        if (targetPosition == Vector2.Zero)
                        {
                            targetPosition = attackPosition;
                        }

                        transition = false;
                        shoot      = true;

                        if (information.Type == Util.Units.TROLL_AXETHROWER)
                        {
                            angle += 0.1f;
                        }
                        else
                        {
                            double opposite = Math.Abs(position.Y - attackPosition.Y);
                            double adjacent = Math.Abs(position.X - attackPosition.X);

                            angle = (float)Math.Atan(opposite / adjacent);// (float)(Math.Atan2(position.X, -position.Y));
                        }

                        Vector2 difference = targetPosition - missilePosition;
                        difference.Normalize();

                        missilePosition += difference * 5f;

                        if ((int)Vector2.Distance(missilePosition, targetPosition) <= 2)
                        {
                            angle = 0;

                            missilePosition = position;
                            targetPosition  = attackPosition;

                            float reduce = ((information.Damage - armor) + information.Piercing) / 30f;
                            ReduceHitPoints(reduce < 0 ? 0.01f : reduce);
                        }
                    }
                    else
                    {
                        float reduce = ((information.Damage - armor) + information.Piercing) / 30f;
                        ReduceHitPoints(reduce < 0 ? 0.01f : reduce);
                    }

                    if (adjustX > 0 && adjustY == 0)
                    {
                        animations.Change("right");
                    }
                    else if (adjustX > 0 && adjustY > 0)
                    {
                        animations.Change("downRight");
                    }
                    else if (adjustX == 0 && adjustY > 0)
                    {
                        animations.Change("down");
                    }
                    else if (adjustX < 0 && adjustY > 0)
                    {
                        animations.Change("downLeft");
                    }
                    else if (adjustX < 0 && adjustY == 0)
                    {
                        animations.Change("left");
                    }
                    else if (adjustX < 0 && adjustY < 0)
                    {
                        animations.Change("upLeft");
                    }
                    else if (adjustX == 0 && adjustY < 0)
                    {
                        animations.Change("up");
                    }
                    else if (adjustX > 0 && adjustY < 0)
                    {
                        animations.Change("upRight");
                    }

                    animations.currentAnimation = AnimationType.ATTACKING;
                    animations.Play(animations.current);
                }

                oldAdjust = new Point(adjustX, adjustY);

                if (Math.Abs(adjustX) > 4 + information.Range || Math.Abs(adjustY) > 4 + information.Range ||
                    hitPoints <= 0 || information.HitPoints <= 0 ||
                    (target != null && target.workState != WorkigState.NOTHING))
                {
                    target         = null;
                    targetBuilding = null;
                    shoot          = false;

                    animations.currentAnimation = AnimationType.WALKING;
                    animations.Play(animations.current);
                }
            }
        }
示例#5
0
 private void PrintBuildingInfo(Buildings.Building building)
 {
     overlay.PrintBuildingInfo(building);
 }