Example #1
0
    public override void Start(MonoBehaviour behaviour, Sequencer.StateInstance state)
    {
        Entity       ai      = (Entity)behaviour;
        PlanetAttach pa      = ai.planetAttach;
        AIState      aiState = (AIState)state;

        if (accel > 0)
        {
            if (usePlayerDir)
            {
                Player player = SceneLevel.instance.player;

                aiState.curPlanetDir = pa.GetDirTo(player.planetAttach, horizontalOnly);
            }
            else if (!useDir)
            {
                aiState.curPlanetDir = Util.Vector2DRot(new Vector2(1, 0), angle * Mathf.Deg2Rad);
            }

            pa.accel = aiState.curPlanetDir * accel;
        }
        else
        {
            pa.accel = Vector2.zero;
        }
    }
Example #2
0
    public override bool Update(MonoBehaviour behaviour, Sequencer.StateInstance state)
    {
        bool done = true;

        if (followPlayer && !state.IsDelayReached(followPlayerDuration))
        {
            Entity       ai      = (Entity)behaviour;
            PlanetAttach pa      = ai.planetAttach;
            AIState      aiState = (AIState)state;
            Player       player  = SceneLevel.instance.player;

            aiState.curPlanetDir = pa.GetDirTo(player.planetAttach, followPlayerHorizontal);

            if (followPlayerHorizontal)
            {
                pa.velocity = new Vector2(Mathf.Abs(pa.velocity.x) * aiState.curPlanetDir.x, pa.velocity.y);
            }
            else
            {
                pa.velocity = aiState.curPlanetDir * pa.velocity.magnitude;
            }

            done = false;
        }

        return(done);
    }
Example #3
0
    public override void Start(MonoBehaviour behaviour, Sequencer.StateInstance state)
    {
        Entity       ai = (Entity)behaviour;
        PlanetAttach pa = ai.planetAttach;

        pa.maxVelocity = velocity;
    }
Example #4
0
 void OnPlanetLand(PlanetAttach pa)
 {
     if (!mFirstLand)
     {
         mFirstLand = true;
         SetTentacleVulnerable(true);
     }
 }
Example #5
0
    public override void Start(MonoBehaviour behaviour, Sequencer.StateInstance state)
    {
        Entity       ai     = (Entity)behaviour;
        PlanetAttach pa     = ai.planetAttach;
        Player       player = SceneLevel.instance.player;

        ((AIState)state).curPlanetDir = pa.GetDirTo(player.planetAttach, horizontalOnly);
    }
 void OnPlanetLand(PlanetAttach pa)
 {
     //perform proper animation
     if(creature != null) {
         if(creature.action != Entity.Action.NumActions)
             PlayAnim(creature.action);
     }
 }
Example #7
0
    public Entity.Action actOnLand = Entity.Action.idle;     //set to none or NumAction to keep jump state

    public override void Start(MonoBehaviour behaviour, Sequencer.StateInstance state)
    {
        Entity       ai = (Entity)behaviour;
        PlanetAttach pa = ai.planetAttach;

        pa.Jump(speedMin < speedMax ? Random.Range(speedMin, speedMax) : speedMin);
        ai.action = Entity.Action.jump;
    }
Example #8
0
 void OnPlanetLand(PlanetAttach pa)
 {
     //perform proper animation
     if (creature != null)
     {
         if (creature.action != Entity.Action.NumActions)
         {
             PlayAnim(creature.action);
         }
     }
 }
 void OnPlanetLand(PlanetAttach pa)
 {
     //perform proper animation
     switch(player.action) {
     case Entity.Action.hurt:
         break;
     default:
         PlayAnim(player.action);
         break;
     }
 }
Example #10
0
    protected virtual void Awake()
    {
        mStats        = GetComponent <EntityStats>();
        mPlanetAttach = GetComponent <PlanetAttach>();

        Component[] cs = GetComponentsInChildren(typeof(IListener), true);
        mListeners = new IListener[cs.Length];
        for (int i = 0; i < cs.Length; i++)
        {
            mListeners[i] = cs[i] as IListener;
        }
    }
Example #11
0
    void OnPlanetLand(PlanetAttach pa)
    {
        Vector2 vel = planetAttach.velocity;

        vel.y = Mathf.Abs(vel.y);
        planetAttach.velocity = vel;
        planetAttach.ResetCurYVel();

        if (mCurBounce < numBounce)
        {
            mCurBounce++;
        }
    }
Example #12
0
    void OnPlanetLand(PlanetAttach pa)
    {
        //perform proper animation
        switch (player.action)
        {
        case Entity.Action.hurt:
            break;

        default:
            PlayAnim(player.action);
            break;
        }
    }
Example #13
0
    public override bool Update(MonoBehaviour behaviour, Sequencer.StateInstance state)
    {
        Entity       ai = (Entity)behaviour;
        PlanetAttach pa = ai.planetAttach;

        bool done = pa.isGround;

        if (done && actOnLand != Entity.Action.none)
        {
            ai.action = actOnLand;
        }

        return(pa.isGround);
    }
Example #14
0
    public override bool Update(MonoBehaviour behaviour, Sequencer.StateInstance state)
    {
        AIState aiState = (AIState)state;
        Entity  ai      = (Entity)behaviour;

        PlanetAttach pa     = ai.planetAttach;
        Player       player = SceneLevel.instance.player;

        //Debug.Log("side: "+pa.CheckSide(player.planetAttach));
        Vector2 prevDir = aiState.curPlanetDir;

        aiState.curPlanetDir = pa.GetDirTo(player.planetAttach, horizontalOnly);

        bool done = true;

        //cap speed on opposite dir
        if (Vector2.Dot(prevDir, aiState.curPlanetDir) < 0.0f)
        {
            if (useBreakSpeed)
            {
                pa.velocity = prevDir * breakSpeed;
            }

            if (doneAfterNumChangeDir > 0 && aiState.counter < doneAfterNumChangeDir)
            {
                aiState.counter++;
            }
        }

        if (doneAfterNumChangeDir > 0)
        {
            done = doneAfterNumChangeDir == aiState.counter && Vector2.Dot(pa.planetDir, aiState.curPlanetDir) > 0.0f;
        }

        //pa.velocity = Vector2.zero;
        pa.accel = aiState.curPlanetDir * accel;

        return(done);
    }
Example #15
0
    public override void Start(MonoBehaviour behaviour, Sequencer.StateInstance state)
    {
        Entity       ai      = (Entity)behaviour;
        PlanetAttach pa      = ai.planetAttach;
        AIState      aiState = (AIState)state;

        float speed = speedMin < speedMax?Random.Range(speedMin, speedMax) : speedMin;

        if (speed > 0)
        {
            if (followPlayer)
            {
                Player player = SceneLevel.instance.player;

                aiState.curPlanetDir = pa.GetDirTo(player.planetAttach, followPlayerHorizontal);
            }
            else if (!useDir)
            {
                aiState.curPlanetDir = Util.Vector2DRot(new Vector2(1, 0), angle * Mathf.Deg2Rad);
            }

            pa.velocity = aiState.curPlanetDir * speed;

            ai.action = Entity.Action.move;
        }
        else
        {
            pa.velocity = Vector2.zero;

            ai.action = Entity.Action.idle;
        }

        if (resetAccel)
        {
            pa.accel = Vector2.zero;
        }
    }
Example #16
0
    void Update()
    {
        switch (mCurState)
        {
        case State.Inactive:
            break;

        case State.Spawn:
            Transform t = EntityManager.instance.Spawn(type, null, null, null, useSpawnFX);

            //set position
            Vector3 spawnPos  = t.position;
            Vector3 pos       = transform.position;
            Vector2 posSpread = Random.insideUnitCircle * radiusSpread;
            pos.x     += posSpread.x;
            pos.y     += posSpread.y;
            pos.z      = spawnPos.z;
            t.position = pos;

            float angle = angleMin != angleMax?Random.Range(angleMin, angleMax) * Mathf.Deg2Rad : angleMin;

            float speed = speedMin != speedMax?Random.Range(speedMin, speedMax) : speedMin;

            ProjBullet proj = t.GetComponentInChildren <ProjBullet>();
            if (proj != null)
            {
                if (useUpVector)
                {
                    Vector2 u = transform.up;
                    proj.dir = u;
                }
                else
                {
                    proj.dir = Vector2.up;
                }

                if (angle != 0)
                {
                    proj.dir = Util.Vector2DRot(proj.dir, angle);
                }

                proj.speed = speed;
            }
            else
            {
                PlanetAttach pa = t.GetComponentInChildren <PlanetAttach>();
                if (pa != null)
                {
                    Vector2 dir;

                    if (useUpVector)
                    {
                        Vector2 u = transform.up;
                        dir = pa.ConvertToPlanetDir(angle != 0 ? Util.Vector2DRot(u, angle) : u);
                    }
                    else
                    {
                        dir = angle != 0 ? Util.Vector2DRot(Vector2.up, angle) : Vector2.up;
                    }

                    if (horizontalOnly)
                    {
                        dir.x = Mathf.Sign(dir.x);
                        dir.y = 0;
                    }

                    pa.velocity = dir * speed;
                    pa.RefreshPos();
                    pa.ResetCurYVel();
                }
            }

            ChangeState(State.SpawnWait);
            break;

        case State.SpawnWait:
            mCurTime += Time.deltaTime;
            if (mCurTime >= delayPerPeriod)
            {
                ChangeState(State.Spawn);
            }
            break;

        case State.PeriodWait:
            mCurTime += Time.deltaTime;
            if (mCurTime >= delayPeriod)
            {
                ChangeState(State.Spawn);
            }
            break;
        }
    }
Example #17
0
    void OnPlanetLand(PlanetAttach pa)
    {
        Vector2 vel = planetAttach.velocity;
        vel.y = Mathf.Abs(vel.y);
        planetAttach.velocity = vel;
        planetAttach.ResetCurYVel();

        if(mCurBounce < numBounce) {
            mCurBounce++;
        }
    }
Example #18
0
    void Update()
    {
        PlanetAttach planetAttach = mPlayer.planetAttach;

        float xS = Input.GetAxis("Horizontal");

        if (xS > 0.0f)
        {
            xS = -1.0f;
        }
        else if (xS < 0.0f)
        {
            xS = 1.0f;
        }

        if (planetAttach.jumpCounter < maxJump)
        {
            if (Input.GetButtonDown("Jump"))
            {
                mPlayer.action = Entity.Action.jump;

                planetAttach.Jump(mPlayer.jumpSpeed);

                if (xS != 0.0f)
                {
                    planetAttach.velocity.x = xS * mPlayer.moveSpeed;
                }
            }
        }

        if (planetAttach.jumpCounter == 0 && planetAttach.isGround)
        {
            if (xS == 0)
            {
                if (mPlayer.action == Entity.Action.move || mPlayer.action == Entity.Action.jump)
                {
                    mPlayer.action = Entity.Action.idle;

                    planetAttach.velocity.x = 0;
                }
            }
            else
            {
                mPlayer.action = Entity.Action.move;

                planetAttach.velocity.x = xS * mPlayer.moveSpeed;
            }

            planetAttach.accel = Vector2.zero;
        }
        else if (mPlayer.action == Entity.Action.jump)
        {
            planetAttach.accel.x = xS * airControlAccel;
        }

        if (Input.GetButtonDown("Fire"))
        {
            mGrabber.Fire(true);
        }
        else if (Input.GetButtonUp("Fire"))
        {
            mGrabber.Fire(false);
        }
        else if (Input.GetButtonDown("Expel"))
        {
            mGrabber.Expel();
        }
    }
Example #19
0
 void OnPlanetLand(PlanetAttach pa)
 {
     if(!mFirstLand) {
         mFirstLand = true;
         SetTentacleVulnerable(true);
     }
 }
Example #20
0
    protected virtual void Awake()
    {
        mStats = GetComponent<EntityStats>();
        mPlanetAttach = GetComponent<PlanetAttach>();

        Component[] cs = GetComponentsInChildren(typeof(IListener), true);
        mListeners = new IListener[cs.Length];
        for(int i = 0; i < cs.Length; i++) {
            mListeners[i] = cs[i] as IListener;
        }
    }