예제 #1
0
    // Update is called once per frame
    void Update()
    {
        if (!HUDController.Instance.IsPaused)
        {
            switch (state)
            {
            case FlyState.Entering:
                Move(true, enteringSpeed);

                if (Mathf.Abs(transform.position.x - finalDestination.x) < 25 &&
                    (transform.position.y < flowerRect.sizeDelta.y + flowerRect.transform.position.y && transform.position.y > flowerRect.transform.position.y))
                {
                    state = FlyState.Sitting;
                    Activate();
                }
                break;

            case FlyState.Leaving:
                Move(false, leavingSpeed);

                if (IsOffScreen())
                {
                    Destroy(this.gameObject);
                }
                break;
            }
        }
    }
예제 #2
0
    private void Start()
    {
        if (instance == null)
        {
            instance = this;
        }
        else
        {
            Destroy(gameObject);
        }
        MovementSM = new StateMachine();

        Standing   = new StandingState(this, MovementSM);
        Fly        = new FlyState(this, MovementSM);
        Swing      = new SwingState(this, MovementSM);
        Create     = new CreateState(this, MovementSM);
        Transition = new TransitionState(this, MovementSM);

        ActivCube = CubePrefabs[0];
        MovementSM.Initialize(Create);


        Platform  = GameObject.FindGameObjectWithTag("Platform");
        LastBlock = Platform;
    }
예제 #3
0
 // Update is called once per frame
 void Update()
 {
     if (curFlyCoolDown > 0)
     {
         curFlyCoolDown -= Time.deltaTime;
         if (curFlyCoolDown <= 0.0f)
         {
             curFlyCoolDown = 0.0f;
             if (flyState == FlyState.WaitForFly)
             {
                 if (enterSky)
                 {
                     flyState = FlyState.Flying;
                 }
                 else
                 {
                     flyState = FlyState.ReadyToFly;
                 }
             }
         }
     }
     if (flyState == FlyState.Flying)
     {
         DropInSky();
     }
 }
예제 #4
0
        static void DoFly(FlyState state)
        {
            Player p = state.player;

            if (p.Pos == state.oldPos)
            {
                return;
            }

            int      x = p.Pos.BlockX, z = p.Pos.BlockZ;
            int      y     = (p.Pos.Y - 60) / 32;
            ExtBlock glass = (ExtBlock)Block.Glass;

            for (int yy = y - 1; yy <= y; yy++)
            {
                for (int zz = z - 2; zz <= z + 2; zz++)
                {
                    for (int xx = x - 2; xx <= x + 2; xx++)
                    {
                        Vec3U16 pos;
                        pos.X = (ushort)xx; pos.Y = (ushort)yy; pos.Z = (ushort)zz;
                        if (p.level.IsAirAt(pos.X, pos.Y, pos.Z))
                        {
                            state.glassCoords.Add(pos);
                        }
                    }
                }
            }

            foreach (Vec3U16 P in state.glassCoords)
            {
                if (state.lastGlass.Contains(P))
                {
                    continue;
                }
                state.lastGlass.Add(P);
                p.SendBlockchange(P.X, P.Y, P.Z, glass);
            }

            for (int i = 0; i < state.lastGlass.Count; i++)
            {
                Vec3U16 P = state.lastGlass[i];
                if (state.glassCoords.Contains(P))
                {
                    continue;
                }

                p.RevertBlock(P.X, P.Y, P.Z);
                state.lastGlass.RemoveAt(i); i--;
            }

            state.glassCoords.Clear();
            state.oldPos = p.Pos;
        }
예제 #5
0
    public void EndFly()
    {
        flyState = curFlyCoolDown <= 0.0f ? FlyState.ReadyToFly : FlyState.WaitForFly;

        //播放音效
        if (this.tag == "player" && this.GetComponent <Player>().photonView.isMine)
        {
            GameObject Audio = GameObject.Find("Audio");
            Audio.GetComponent <AudioManager>().PlaySeaIn();
        }
    }
 private void KillFly()
 {
     anim.SetBool("StealthMode", false);
     spriteRenderer.sprite = startingSprite;
     spriteRenderer.color = Color.white;
     audioSources[0].Stop();
     audioSources[1].pitch = Random.Range(0.5f, 3f);
     audioSources[1].Play();
     state = FlyState.DeathPause;
     transform.up = Vector3.down;
     Invoke("PauseBeforeDying", 1f);
 }
예제 #7
0
    public void Send()
    {
        randomInterval = Random.Range(.3f, 2);
        state          = FlyState.FLYING;
        aniMaster.SetBool("isStuck", false);
        aniMaster.SetBool("isDead", false);

        GetNewTarget();

        ReArc();
        gameObject.SetActive(true);
    }
예제 #8
0
 private void Reset()
 {
     state              = FlyState.INACTIVE;
     target             = Vector3.zero;
     rigidbody.position = startPosition;
     arcVector.x        = 0;
     arcVector.y        = 0;
     arcVector.z        = 0;
     deltaTime          = 0;
     randomInterval     = 0;
     distFromTarget     = 0;
     gameObject.SetActive(false);
 }
    public void Revive()
    {
        state = FlyState.Alive;
        if (spriteRenderer == null)
            ComponentSetup();
        spriteRenderer.color = Color.white;
        audioSources[0].PlayDelayed(Random.Range(0, 2f));
        rb.gravityScale = 0f;


        transform.right = Vector3.right;
        transform.up = Vector3.up;
    }
예제 #10
0
    public void StartFly()
    {
        flyState       = FlyState.Flying;
        curFlyCoolDown = flyCooldown;//技能冷却
        float verticalSpeed = gameObject.GetComponent <Player>().GetSpeed() * gameObject.transform.forward.normalized.y;

        flySpeed = minFlySpeed + verticalSpeed;

        //播放音效
        if (this.tag == "player" && this.GetComponent <Player>().photonView.isMine)
        {
            GameObject Audio = GameObject.Find("Audio");
            Audio.GetComponent <AudioManager>().PlaySeaOut();
        }
    }
예제 #11
0
    public void Revive()
    {
        health = 1;
        state  = FlyState.Alive;
        if (anim == null)
        {
            ComponentSetup();
        }
        anim.SetBool("StealthMode", false);
        spriteRenderer.color = Color.white;
        audioSources[0].PlayDelayed(Random.Range(0, 2f));
        rb.gravityScale = 0f;


        transform.right = Vector3.right;
        transform.up    = Vector3.up;
    }
예제 #12
0
    void Awake()
    {
        m_hRigidbody = this.GetComponent<Rigidbody>();
        m_hCollider  = this.GetComponent<Collider>();
        m_hParticlesController = this.GetComponentInChildren<ParticlesController>();

        m_hDelay = new DelayState(this);
        FlyState hFly = new FlyState(this);
        m_hDelay.Next = hFly;

        m_hCurrent = m_hDelay;

        damageRates = new Dictionary<ArmorType, float>();
        damageRates.Add(ArmorType.Light, LightArmorDamageRate);
        damageRates.Add(ArmorType.Medium, MediumArmorDamageRate);
        damageRates.Add(ArmorType.Heavy, HeavyArmorDamageRate);
    }
예제 #13
0
        static void FlyCallback(SchedulerTask task)
        {
            FlyState state = (FlyState)task.State;
            Player   p     = state.player;

            if (state.player.isFlying)
            {
                DoFly(state); return;
            }

            foreach (Vec3U16 pos in state.lastGlass)
            {
                p.SendBlockchange(pos.X, pos.Y, pos.Z, Block.Air);
            }
            p.Message("Stopped flying");
            task.Repeating = false;
        }
예제 #14
0
    void OnTriggerEnter(Collider col)
    {
        if (state == FlyState.FLYING)
        {
            if (col.tag.Equals("NeckbeardAlive"))
            {
                state = FlyState.ATTACHED;

                aniMaster.SetBool("isStuck", true);
                this.rigidbody.velocity = Vector3.zero;
                transform.parent        = col.transform;
                rotateQuaternion        = transform.rotation;
                rotateQuaternion.z      = 0;
                rotateQuaternion.x      = 0;
                transform.rotation      = rotateQuaternion;
            }
        }
    }
예제 #15
0
 public FlyWanderAct(CreatureAI creature, float seconds, float turnTime, float radius, float altitude, float perchTime) :
     base(creature)
 {
     Altitude            = altitude;
     Name                = "FlyWander " + seconds;
     WanderTime          = new Timer(seconds, false);
     TurnTime            = new Timer(turnTime, false);
     PerchTime           = new Timer(perchTime, false);
     Radius              = radius;
     YRadius             = 2.0f;
     GravityCompensation = 0.1f;
     Damping             = 0.25f;
     TurnThreshold       = 2.0f;
     OriginalGravity     = creature.Physics.Gravity;
     CanPerchOnWalls     = false;
     CanPerchOnGround    = true;
     CanPerchOnObjects   = true;
     State               = FlyState.Wandering;
 }
예제 #16
0
    private void PickRandomState()
    {
        // schedule next state change
        _timeToStateChange = Random.Range(minTimeInState, maxTimeInState);

        float r = Random.Range(0, 1f);

        if (r < 0.15)
        {
            _state = FlyState.Hovering;
        }
        else if (r < 0.5)
        {
            _state = FlyState.Bimbling;
        }
        else
        {
            _state = FlyState.Moving;
            SetRandomTarget();
        }
    }
예제 #17
0
        public override void Use(Player p, string message, CommandData data)
        {
            if (!Hacks.CanUseFly(p))
            {
                p.Message("You cannot use &T/Fly &Son this map.");
                p.isFlying = false; return;
            }

            p.isFlying = !p.isFlying;
            if (!p.isFlying)
            {
                return;
            }

            p.Message("You are now flying. &cJump!");

            FlyState state = new FlyState();

            state.player = p;
            SchedulerTask task = new SchedulerTask(FlyCallback, state, TimeSpan.Zero, true);

            p.CriticalTasks.Add(task);
        }
예제 #18
0
        public override void Use(Player p, string message)
        {
            if (!Hacks.CanUseHacks(p, p.level))
            {
                Player.Message(p, "You cannot use %T/Fly %Son this map.");
                p.isFlying = false; return;
            }

            p.isFlying = !p.isFlying;
            if (!p.isFlying)
            {
                return;
            }

            Player.Message(p, "You are now flying. &cJump!");

            FlyState state = new FlyState();

            state.player = p;
            SchedulerTask task = new SchedulerTask(FlyCallback, state, TimeSpan.Zero, true);

            p.CriticalTasks.Add(task);
        }
예제 #19
0
 public void StopAnimation()
 {
     state = FlyState.Alive;
 }
예제 #20
0
        public override IEnumerable <Status> Run()
        {
            PerchTime.Reset();
            WanderTime.Reset();
            TurnTime.Reset();
            while (true)
            {
                if (State == FlyState.Perching)
                {
                    PerchTime.Reset();
                    while (!PerchTime.HasTriggered)
                    {
                        Agent.Creature.Physics.Velocity     = Vector3.Zero;
                        Agent.Creature.CurrentCharacterMode = CharacterMode.Idle;
                        PerchTime.Update(DwarfTime.LastTime);
                        yield return(Act.Status.Running);
                    }
                    // When we're done flying, go back to walking and just fall.
                    Agent.Creature.CurrentCharacterMode = CharacterMode.Walking;
                    Agent.Creature.Physics.Gravity      = OriginalGravity;
                    yield return(Act.Status.Success);
                }

                Agent.Creature.Physics.Gravity = Vector3.Zero;
                // Store the last position of the bird to sample from
                Vector3 oldPosition = Agent.Position;

                // Get the height of the terrain beneath the bird.
                var surfaceHeight = VoxelHelpers.FindFirstVoxelBelow(new VoxelHandle(
                                                                         Agent.Chunks.ChunkData, GlobalVoxelCoordinate.FromVector3(oldPosition)))
                                    .Coordinate.Y + 1;

                // Immediately start flying.
                Agent.Creature.CurrentCharacterMode = CharacterMode.Flying;

                // Use this to determine when to start turning.
                float currentDistance = 999;

                {
                    // Pick a target within a box floating some distance above the surface.
                    float randomX = MathFunctions.Rand() * Radius - Radius / 2.0f;
                    float randomZ = MathFunctions.Rand() * Radius - Radius / 2.0f;
                    float randomY = (float)MathFunctions.Random.NextDouble() * YRadius + Altitude + surfaceHeight;

                    // Set the target to that random location.
                    LocalTarget = new Vector3(randomX + oldPosition.X, randomY, randomZ + oldPosition.Z);
                }


                // Keep flying until a timer has trigerred.
                while ((!WanderTime.HasTriggered && State == FlyState.Wandering) || (State == FlyState.SearchingForPerch))
                {
                    // If we hit the ground, switch to walking, otherwise switch to flying.
                    Agent.Creature.CurrentCharacterMode = CharacterMode.Flying;

                    WanderTime.Update(DwarfTime.LastTime);

                    // If we're near a target, or a timeout occured, pick a new ranodm target.
                    if (TurnTime.Update(DwarfTime.LastTime) || TurnTime.HasTriggered || currentDistance < TurnThreshold)
                    {
                        // Pick a target within a box floating some distance above the surface.
                        float randomX = MathFunctions.Rand() * Radius - Radius / 2.0f;
                        float randomZ = MathFunctions.Rand() * Radius - Radius / 2.0f;
                        float randomY = (float)MathFunctions.Random.NextDouble() * YRadius + Altitude + surfaceHeight;

                        // Set the target to that random location.
                        LocalTarget = new Vector3(randomX + oldPosition.X, randomY, randomZ + oldPosition.Z);
                    }

                    // Set the current distance to the target so we know when to go to a new target.
                    currentDistance = (Agent.Position - LocalTarget).Length();

                    // Output from the force controller.
                    Vector3 output =
                        Creature.Controller.GetOutput((float)DwarfTime.LastTime.ElapsedGameTime.TotalSeconds,
                                                      LocalTarget, Creature.Physics.GlobalTransform.Translation);

                    // We apply a linear combination of the force controller and the
                    // feed forward force to the bird to make it lazily turn around and fly.
                    Creature.Physics.ApplyForce(output * Damping * GravityCompensation,
                                                (float)DwarfTime.LastTime.ElapsedGameTime.TotalSeconds);


                    if (State == FlyState.Wandering && WanderTime.HasTriggered)
                    {
                        State = FlyState.SearchingForPerch;
                    }

                    if (State == FlyState.SearchingForPerch)
                    {
                        var vox = Creature.Physics.CurrentVoxel;
                        if (!vox.IsValid)
                        {
                            yield return(Act.Status.Running);

                            continue;
                        }
                        if (vox.IsValid && vox.WaterCell.WaterLevel > 0)
                        {
                            yield return(Act.Status.Running);

                            continue;
                        }

                        if (CanPerchOnGround)
                        {
                            Creature.Physics.ApplyForce(OriginalGravity, (float)DwarfTime.LastTime.ElapsedGameTime.TotalSeconds);
                            var below = new VoxelHandle(Creature.World.ChunkManager.ChunkData,
                                                        vox.Coordinate + new GlobalVoxelOffset(0, -1, 0));

                            if (below.IsValid && !below.IsEmpty && below.WaterCell.WaterLevel == 0)
                            {
                                State = FlyState.Perching;
                                continue;
                            }
                        }

                        if (CanPerchOnWalls)
                        {
                            foreach (var n in VoxelHelpers.EnumerateManhattanNeighbors(Creature.Physics.CurrentVoxel.Coordinate)
                                     .Select(c => new VoxelHandle(Creature.World.ChunkManager.ChunkData, c)))
                            {
                                if (n.IsValid && n.Coordinate.Y >= vox.Coordinate.Y && !n.IsEmpty)
                                {
                                    State = FlyState.Perching;
                                }
                            }
                        }

                        /*
                         * if (CanPerchOnObjects)
                         * {
                         *  List<Body> objetcs = new List<Body>();
                         *  PlayState.ComponentManager.GetBodiesIntersecting(Creature.Physics.BoundingBox, objetcs, CollisionManager.CollisionType.Static);
                         *
                         *  if (objetcs.Count > 0)
                         *  {
                         *      State = FlyState.Perching;
                         *      continue;
                         *  }
                         * }
                         */
                    }

                    yield return(Status.Running);
                }

                yield return(Status.Running);
            }
        }
예제 #21
0
 public void Die()
 {
     _state = FlyState.Dead;
     // TODO disable animation
 }
예제 #22
0
 void swatted()
 {
     state     = FlyState.DEAD;
     deltaTime = 0;
     aniMaster.SetBool("isDead", true);
 }
예제 #23
0
 public void Click()
 {
     this.Complete();
     state = FlyState.Leaving;
 }
예제 #24
0
 public void WaitForFly()
 {
     flyState = FlyState.WaitForFly;
 }
예제 #25
0
 private void PauseBeforeDying()
 {
     state           = FlyState.Dead;
     rb.gravityScale = 5f;
 }
예제 #26
0
 public void StartAnimation()
 {
     state = FlyState.InAnimation;
 }
예제 #27
-2
    protected virtual void Awake()
    {
        m_hForward = false;
        m_hBackward = false;
        m_hRight = false;
        m_hLeft = false;

        m_hWheels = new List<Wheel>();
        m_hRigidbody = this.GetComponent<Rigidbody>();
        m_hRigidbody.interpolation = RigidbodyInterpolation.None;
        //Initialize effective wheels
        List<Transform> gfxPos = this.GetComponentsInChildren<Transform>().Where(hT => hT.GetComponent<WheelCollider>() == null).ToList();
        this.GetComponentsInChildren<WheelCollider>().ToList().ForEach(hW => m_hWheels.Add(new Wheel(hW, gfxPos.OrderBy(hP => Vector3.Distance(hP.position, hW.transform.position)).First().gameObject)));
        m_hWheels = m_hWheels.OrderByDescending(hW => hW.Collider.transform.localPosition.z).ToList();

        //Initialize extra wheels
        m_hFakeWheels = GetComponentsInChildren<FakeWheel>().ToList();

        //Initialize VehicleTurret
        m_hTurret = GetComponentInChildren<VehicleTurret>();

        //Initialize IWeapon
        m_hCurrentWeapon = GetComponentInChildren<IWeapon>();

        m_hActor = GetComponent<Actor>();

        //Initialize Drive/Brake System
        switch (DriveType)
        {
            case DriveType.AWD:
                m_hEngine = new AwdDrive(Hp, m_hWheels);
                break;
            case DriveType.RWD:
                m_hEngine = new RearDrive(Hp, m_hWheels);
                break;
            case DriveType.FWD:
                m_hEngine = new ForwardDrive(Hp, m_hWheels);
                break;
            default:
                break;
        }


        m_hConstanForce = this.GetComponent<ConstantForce>();
        m_hReverseCOM = new Vector3(0.0f, -2.0f, 0.0f);

        m_hOriginalCOM = m_hRigidbody.centerOfMass;


        GroundState hGroundState = new GroundState(this);
        FlyState hFlyState = new FlyState(this);
        TurnedState hTurned = new TurnedState(this, m_hReverseCOM);

        hGroundState.Next = hFlyState;
        hFlyState.Grounded = hGroundState;
        hFlyState.Turned = hTurned;
        hTurned.Next = hFlyState;
        m_hFlyState = hFlyState;
    }