示例#1
0
    // Use this for initialization
    void Start()
    {
        faction = ShipDefinitions.stringToFaction(gameObject.tag);
        ship    = GetComponent <ShipIntf>();

        if (GetComponent <FiringModule>() == null)
        {
            gameObject.AddComponent <DummyFiringMod>();
        }
    }
示例#2
0
    // Use this for initialization
    void Start()
    {
        ship           = gameObject.transform.parent.GetComponent <ShipIntf>();
        moveSpeed     += Random.Range(-0.3f, 0.3f);
        rotationSpeed += Random.Range(-2, 2);
        gameObject.GetComponent <SpriteRenderer>().enabled = false;

        if (ship.getShipType() == ShipDefinitions.ShipType.Peacock)
        {
            moveSpeed     *= 0.8f;
            rotationSpeed *= 0.8f;
        }
    }
示例#3
0
    // spawn the given ship at the given location
    void spawnShip(Vector2 spawnPoint, GameObject ship)
    {
        GameObject obj = ship;

        obj.transform.position = spawnPoint;

        ShipIntf ctrl = obj.GetComponent <ShipIntf>();

        if (GameObject.Find("GameLogic").GetComponent <Pause>().getPaused())
        {
            ctrl.pause();
        }
    }
示例#4
0
    public void spawnShip(Vector2 spawningPt, ShipDefinitions.ShipEntity entity)
    {
        GameObject ship;

        if (entity.faction == ShipDefinitions.Faction.Enemy)
        {
            if (entity.shipType == ShipDefinitions.ShipType.Ruby)
            {
                ship = getShipRubyPirate();
            }
            else if (entity.shipType == ShipDefinitions.ShipType.Peacock)
            {
                ship = getShipPeacockPirate();
            }
            else
            {
                return;
            }
        }
        else
        {
            if (entity.shipType == ShipDefinitions.ShipType.Ruby)
            {
                ship = getShipRuby();
            }
            else if (entity.shipType == ShipDefinitions.ShipType.Peacock)
            {
                ship = getShipPeacock();
            }
            else
            {
                return;
            }
        }

        ShipIntf shipIntf = ship.GetComponent <ShipIntf>();

        shipIntf.setEngineType(entity.engType);
        shipIntf.setWeaponType(entity.weapType);
        shipIntf.setShipType(entity.shipType);
        shipIntf.setFaction(entity.faction);

        ship.GetComponent <MainShip>().setItems(entity.items);
        //ship.AddComponent<AIController>();

        spawnShip(spawningPt, ship);
    }
示例#5
0
    /*
     * initializes various variables
     */
    void Start()
    {
        faction    = ShipDefinitions.stringToFaction(gameObject.tag);
        ship       = this.GetComponent <ShipIntf>();
        tag        = gameObject.tag;
        tagReserve = tag;
        badVector  = new Vector3(1e5f, 1e5f, 1e5f);

        if (GetComponent <FiringModule>() == null)
        {
            gameObject.AddComponent <DummyFiringMod>();
        }

        if (GetComponent <TargetFinder>() == null)
        {
            gameObject.AddComponent <TargetFinder>();
        }
    }
示例#6
0
    /*
     *
     */
    private void handleState()
    {
        if (state == ShipDefinitions.SState.Searching)
        {
            // purpose of state is to find a target
            // if target is found, switch to state aiming
            Vector3    target = badVector;
            GameObject obj    = GetComponent <TargetFinder>().getTarget(faction);

            /*
             * if ((GetComponent<FiringModule>().GetType().
             *  Equals(typeof(HealMod))))
             * {
             *  obj = GetComponent<TargetFinder>().getFriendly(faction);
             * }
             */
            this.target = obj;
            if (obj)
            {
                target = obj.transform.position;
            }
            else
            {
                obj = GetComponent <TargetFinder>().getFriendly(faction);
                if (obj)
                {
                    if (!obj.Equals(gameObject))
                    {
                        target = obj.transform.position;
                    }
                }
            }

            if (target != badVector)
            {
                this.target = obj;
                state       = ShipDefinitions.SState.Aiming;
            }
            else
            {
                ship.brake();
            }
        }
        else if (state == ShipDefinitions.SState.Aiming)
        {
            bool move = true;
            if (target == null)
            {
                state = ShipDefinitions.SState.Searching;
                return;
            }

            Vector3 diff = target.transform.position - transform.position;
            //print(diff);
            float targetAngle = Mathf.Atan(diff.y / diff.x) * 180 / Mathf.PI + 90;
            if (diff.x > 0)
            {
                targetAngle = 180 + targetAngle;
            }
            targetAngle = (int)targetAngle;
            float shipAngle = transform.rotation.eulerAngles.z;

            if (ShipDefinitions.quickestRotation(shipAngle, targetAngle))
            {
                ship.rotate(0.5f);
            }
            else
            {
                ship.rotate(-0.5f);
            }


            ShipIntf shipObject = GetComponent <ShipIntf>();
            if ((shipAngle + shipObject.getEffectiveAngle() > targetAngle &&
                 shipAngle - shipObject.getEffectiveAngle() < targetAngle))
            {
                if (Vector3.Distance(transform.position,
                                     target.transform.position) < shipObject.getEffectiveDistance())
                {
                    if (target.GetComponent <ShipController>() != null)
                    {
                        if (target.GetComponent <ShipController>()
                            .getFaction() != faction)
                        {
                            state = ShipDefinitions.SState.Firing;
                        }
                        else
                        {
                            ship.brake();
                            move  = false;
                            state = ShipDefinitions.SState.Searching;
                        }
                    }

                    if ((GetComponent <FiringModule>().GetType().
                         Equals(typeof(HealMod))))
                    {
                        if (target.GetComponent <ShipIntf>().getHealthPercent() < 0.95)
                        {
                            state = ShipDefinitions.SState.Firing;
                        }
                    }
                }
            }
            shipObject = null;
            if (move)
            {
                ship.move(1);
            }
            else
            {
                ship.brake();
            }
        }
        else if (state == ShipDefinitions.SState.Firing)
        {
            ship.fire();

            if (GetComponent <FiringModule>().canFire() == false)
            {
                state = ShipDefinitions.SState.Cooling;
            }
        }
        else if (state == ShipDefinitions.SState.Cooling)
        {
            if (GetComponent <FiringModule>().canFire())
            {
                state = ShipDefinitions.SState.Searching;
            }
        }
    }