Ejemplo n.º 1
0
    public void OnEntityAct(Action act)
    {
        switch(act) {
        case Action.spawning:
            fadeEnabled = false;

            starSprite.scale = Vector3.one;
            starSprite.color = Color.white;
            starSprite.Play(starIdleClip);

            glowSprite.scale = Vector3.one;
            glowSprite.color = Color.white;

            mCurBounce = 0;

            mLifeState = LifeState.None;

            planetAttach.enabled = mPlanetEnabledInitial;
            planetAttach.applyOrientation = true;
            planetAttach.applyGravity = false;
            gameObject.layer = Main.layerItem;
            mCollideLayerMask = 0;
            mReticle = Reticle.Type.Grab;

            if(resetMovementOnSpawn) {
                planetAttach.velocity = Vector2.zero;
                planetAttach.accel = Vector2.zero;
                planetAttach.ResetCurYVel();
            }

            mCurPulseTime = 0;
            break;
        }
    }
Ejemplo n.º 2
0
 public Cell(int row, int columns, int lastRow, int lastColumn)
 {
     CellCordinate = new Coordinates(row, columns);
     _lastColumn = lastColumn;
     _lastRow = lastRow;
     Neighbours = new NeighbouringCoordinates();
     SetupNeighbours();
     _cellState = LifeState.Dead;
     CalculatedState = LifeState.Dead;
 }
Ejemplo n.º 3
0
	void OnInit()
	{
		state = LifeState.Life;
		showSprite( body.GetComponent<tk2dSprite>() , initTime );
		showSprite( eye.GetComponent<tk2dSprite>() , initTime );
		foreach( GameObject dec in decs )
		{
			showSprite( dec.GetComponent<tk2dSprite>() , initTime );
		}

	}
Ejemplo n.º 4
0
        //private static Texture2D[] textureArray;
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="rect"></param>
        /// <param name="Velocity"></param>
        /// <param name="tex"></param>
        /// <param name="Shape"></param>
        public Enemy(Rectangle rect, Texture2D tex, string name, ObjectShape Shape)
            : base(rect, tex, Shape)
        {
            shoots = false;

            projectileTexture = null;
            EnemyName = name;
            state = LifeState.Alive;
            actionState = EnemyActionState.Standing;
            RunTextures = new List<Texture2D>();
            AttackTextures = new List<Texture2D>();
        }
Ejemplo n.º 5
0
    /*
     * // Cycles trough the lifestate cycle
     * // Alive -> Dying -> Death -> Respawning
     * // Also calls the manager script dying and death so other scripts can get called for on death and dying events.
     */
    public void Dying(LifeState state)
    {
        switch (state)
        {
        case LifeState.Dying:
            ManagerScript.Dying();
            DyingTimer = dyingTime;
            break;

        case LifeState.Death:
            ManagerScript.Death();
            DeathTimer = deathTime;
            break;
        }
    }
Ejemplo n.º 6
0
        public void create(Vector2f _position, String _file, uint _layer = 0)
        {
            Texture tex = new Texture(_file);

            mSprite = new Sprite(tex);

            mEntityType = EntityType.Default;
            mBody       = null;
            mLayer      = _layer;
            mLifeState  = LifeState.LifeState_Active;
            mPosition   = _position;

            mSprite.Position = mPosition;
            mDimensions      = tex.Size;
            mOrigin          = new Vector2f(mPosition.X + (mDimensions.X / 2), mPosition.Y + (mDimensions.Y / 2));
        }
Ejemplo n.º 7
0
    /*
     * // Handles Being death awaiting res
     */
    public void Death()
    {
        Vector3 pos = transform.position;

        pos.y = 0.5f;
        var t = Instantiate(DespawnObject, pos, Quaternion.identity) as GameObject;

        changeDespawnColor(t);

        _shieldTimer = -36;
        _Shielded    = false;
        Destroy(ShieldInst);

        transform.position = _DeathPoint.transform.position;
        _LifeState         = LifeState.Death;
    }
Ejemplo n.º 8
0
        public Player(Point topLeft)
            : base(new Rectangle(topLeft.X, topLeft.Y, NINJA_WIDTH, NINJA_HEIGHT), NinjaTexture)
        {
            velocity = Vector2.Zero;
            NinjaMovement = NinjaRunSpeed;

            ninjaLifeState = LifeState.Alive;
            hasGravity = true;
            actionState = NinjaActionState.Standing;

            running = new AnimationComponent(RunTextures, GetDrawFrameX(), GetDrawFrameY(), NINJA_WIDTH, NINJA_HEIGHT);
            jumping = new AnimationComponent(JumpTextures, GetDrawFrameX(), GetDrawFrameY(), NINJA_WIDTH, NINJA_HEIGHT);
            airborne = new AnimationComponent(AirborneTextures, GetDrawFrameX(), GetDrawFrameY(), NINJA_WIDTH, NINJA_HEIGHT);
            //wallJumping = new AnimationComponent(WallJumpTextures, GetDrawFrameX(), GetDrawFrameY(), NINJA_IMAGE_X, NINJA_IMAGE_Y);
            //wallClimbing = new AnimationComponent(WallClimbTextures, GetDrawFrameX(), GetDrawFrameY(), NINJA_IMAGE_X, NINJA_IMAGE_Y);
        }
Ejemplo n.º 9
0
 public virtual void Die(HitInfo info = null)
 {
     if (!IsDead())
     {
         if (ConVar.Global.developer > 1)
         {
             Debug.Log("[Combat]".PadRight(10) + base.gameObject.name + " died");
         }
         health    = 0f;
         lifestate = LifeState.Dead;
         Interface.CallHook("OnEntityDeath", this, info);
         using (TimeWarning.New("OnKilled"))
         {
             OnKilled(info);
         }
     }
 }
Ejemplo n.º 10
0
    private IEnumerator TakeLastBreaths()
    {
        state = LifeState.takingLastBreaths;

        MakeComponents(false);


        Rigidbody body = GetComponent <Rigidbody>();

        if (body)
        {
            //ragdollify
            body.WakeUp();
            cacheIsKinetic = body.isKinematic;
            cachePosition  = body.position;
            cacheRotation  = body.rotation;

            if (body.isKinematic)
            {
                body.isKinematic = false;
            }

            //twitch
            int twitches = Random.Range(2, 5);
            for (int i = 0; i < twitches; i++)
            {
                //if we are frozen don't do anything until we are not frozern
                RigidbodyFreeze rbf = GetComponent <RigidbodyFreeze>();
                if (rbf)
                {
                    while (rbf.Frozen)
                    {
                        yield return(new WaitForEndOfFrame());
                    }
                }

                body.AddForce(Random.onUnitSphere * body.mass / 5f, ForceMode.Impulse);
                body.AddTorque(Random.onUnitSphere * body.mass / 5f, ForceMode.Impulse);

                yield return(new WaitForSeconds(deathThrowDuration / (float)twitches));
            }
        }

        state = LifeState.dead;
    }
        /// <summary>
        /// Initializes a new instance of the <see cref="FieldViewModel"/> class.
        /// </summary>
        /// <param name="x">The x-coordinate.</param>
        /// <param name="y">The y-coordinate.</param>
        /// <param name="initialLifeState">Initial life state of the field.</param>
        public FieldViewModel(int x, int y, LifeState initialLifeState)
        {
            X = x;
            Y = y;

            switch (initialLifeState)
            {
            case LifeState.Dead:
                _isAlive = false;
                break;

            case LifeState.Alive:
                _isAlive = true;
                break;
            }

            _requestLifeStateChangeCommand = new SimpleCommand(OnLifeStateChangeRequested);
        }
Ejemplo n.º 12
0
    /*public void CreateCharacter(PlayerColor color, ControllerType type, WeaponType weapon)
     * {
     *  _PlayerColor = color;
     *  _PlayerController = type;
     *  _Weapon = weapon;
     *  _Score = 0;
     *  _LifeState = LifeState.Respawning;
     * }*/

    public void SpawnCharacter()
    {
        //Can only spawn characters which are allowed to spawn.
        if (_LifeState != LifeState.Respawning)
        {
            return;
        }

        //
        //Initialisation of the character
        //

        //Position the character at one of the spawnpoints
        for (int i = 0; i < _RespawnPoints.Length; ++i)
        {
            int position = UnityEngine.Random.Range(0, _RespawnPoints.Length);
            if (_RespawnPoints[position].GetComponent <Gen_SpawnPoint>().IsValid)
            {
                transform.position = _RespawnPoints[position].position;
                break;
            }
        }

        //Particles
        //Change color
        transform.FindChild("SpawnCircle").GetComponent <Renderer>().material.SetColor("_EmisionColor", SpawnColor);
        transform.FindChild("SpawnCircle").GetComponent <ParticleSystem>().Play();

        //Make the character visible
        VisScript.MakeVis();

        //If we are not in the intro screen, make the character disapear after a few seconds
        if (_BecomeInvis)
        {
            VisScript.setVisTimer(1);
        }

        //Set State to alive so character can get hit and can move
        _LifeState = LifeState.Alive;

        //Protect against spawndeath.
        Shield(SpawnProtection);
    }
        /// <summary>
        /// Creates a new instance of the <see cref="CuboidLifeBoard"/> class.
        /// </summary>
        /// <param name="width">The width of the cuboid.</param>
        /// <param name="height">The height of the cuboid.</param>
        /// <param name="depth">The depth of the cuboid.</param>
        /// <param name="alivePositions">The positions where the habitants are alive at the beginning of the game.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentOutOfRangeException">
        /// width - Cannot be lower 1!
        /// or
        /// height - Cannot be lower 1!
        /// or
        /// height - Cannot be lower 1!
        /// </exception>
        public static CuboidLifeBoard Create(int width, int height, int depth, IEnumerable <Position> alivePositions)
        {
            if (width < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(width), "Cannot be lower 1!");
            }

            if (height < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(height), "Cannot be lower 1!");
            }

            if (depth < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(height), "Cannot be lower 1!");
            }

            int lifeBoardWidth  = (2 * width) + (2 * depth);
            int lifeBoardHeight = (2 * depth) + height;

            LifeState[,] lifeBoard = new LifeState[lifeBoardWidth, lifeBoardHeight];
            for (int hIndex = 0; hIndex < lifeBoardWidth; ++hIndex)
            {
                for (int vIndex = 0; vIndex < lifeBoardHeight; ++vIndex)
                {
                    if (!IsLifePossible(hIndex, vIndex, width, height, depth))
                    {
                        lifeBoard[hIndex, vIndex] = LifeState.NoLifePossible;
                    }
                }
            }

            foreach (var alivePosition in alivePositions)
            {
                if (lifeBoard[alivePosition.X, alivePosition.Y] != LifeState.NoLifePossible)
                {
                    lifeBoard[alivePosition.X, alivePosition.Y] = LifeState.Alive;
                }
            }

            return(new CuboidLifeBoard(width, height, depth, lifeBoard));
        }
Ejemplo n.º 14
0
        public void ChangeLifeState(LifeState newState)
        {
            state = newState;
            switch (state)
            {
            case LifeState.LS_ON:
                lifeGO.SetActive(true);
                transform.anchoredPosition = startPosition;
                transform.localScale       = Vector3.one * regularSize;
                break;

            case LifeState.LS_FLIGHT:
                _timer = 0.0f;
                break;

            case LifeState.LS_OFF:
                lifeGO.SetActive(false);
                break;
            }
        }
Ejemplo n.º 15
0
        // Every time a player's life state changes we check to see if game is over
        private void OnHeroLifeStateChanged(LifeState prevLifeState, LifeState lifeState)
        {
            // If this Hero is down, check the rest of the party also
            if (lifeState == LifeState.Fainted)
            {
                // Check the life state of all players in the scene
                foreach (var p in NetworkManager.Singleton.ConnectedClientsList)
                {
                    // if any player is alive just retrun
                    var netState = p.PlayerObject.GetComponent <NetworkCharacterState>();
                    if (netState.NetworkLifeState.Value == LifeState.Alive)
                    {
                        return;
                    }
                }

                // If we made it this far, all players are down! switch to post game
                StartCoroutine(CoroGameOver(k_LoseDelay, false));
            }
        }
Ejemplo n.º 16
0
        private void OnLifeStateChanged(LifeState previousValue, LifeState newValue)
        {
            switch (newValue)
            {
            case LifeState.Alive:
                m_ClientVisualsAnimator.SetTrigger(m_AliveStateTriggerID);
                break;

            case LifeState.Fainted:
                m_ClientVisualsAnimator.SetTrigger(m_FaintedStateTriggerID);
                break;

            case LifeState.Dead:
                m_ClientVisualsAnimator.SetTrigger(m_DeadStateTriggerID);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(newValue), newValue, null);
            }
        }
 private void shatter()
 {
     _lifeState = LifeState.Shattered;
     for (int row = 0; row < ICE_DIVISIONS; row++)
     {
         for (int col = 0; col < ICE_DIVISIONS; col++)
         {
             _fragments[row, col].Health     = FRAGMENT_HEALTH * _statusEffects.Cryo / MAX_STAT_EFFECT;
             _fragments[row, col].Position.X = Position.X + (0.5f + _sprite.Width * (float)col / ICE_DIVISIONS);
             _fragments[row, col].Position.Y = Position.Y + (0.5f + _sprite.Height * (float)row / ICE_DIVISIONS);
             XnaHelper.RandomizeVector(ref _fragments[row, col].Velocity, -FRAGMENT_MAX_VELOCITY, FRAGMENT_MAX_VELOCITY,
                                       -FRAGMENT_MAX_VELOCITY, FRAGMENT_MAX_VELOCITY);
             Vector2.Add(ref _fragments[row, col].Velocity, ref _velocity, out _fragments[row, col].Velocity);
             Vector2.Multiply(ref _fragments[row, col].Velocity, FRAGMENT_VELOCITY_FACTOR, out _fragments[row, col].Velocity);
             _fragments[row, col].Angle           = 0f;
             _fragments[row, col].AngularVelocity = XnaHelper.RandomAngle(0.0f, FRAGMENT_MAX_ANGULAR_VELOCITY);
             _fragments[row, col].ScaleFactor     = 1f;
             _fragments[row, col].Active          = true;
         }
     }
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Create a new physical sprite
        /// </summary>
        /// <param name="unitName">key to find SpriteData and PhysicalData</param>
        public PhysicalUnit(string unitName)
        {
            _unitName = unitName;
            _sprite = new Sprite(unitName);
            PhysicalData pd = Data[unitName];

            if (pd.MovementParticleEffectName != null)
                _movementParticleEffect = new ParticleEffect(pd.MovementParticleEffectName);

            _mass = pd.Mass;
            _moveForce = pd.MoveForce;
            _maxSpeed = pd.MaxSpeed;
            _health = pd.Health;
            _decelerationFactor = pd.DecelerationFactor;

            _lifeState = LifeState.Dormant;     //not yet spawned
            _hitRect = new Rectangle(0, 0, (int)_sprite.Width, (int)_sprite.Height);

            MoveDirection = Vector2.Zero;
            LookDirection = Vector2.Zero;
        }
Ejemplo n.º 19
0
        public Enemy(Rectangle rect, int type, ObjectShape Shape, int vr, int projectileNum)
            : base(rect, null, Shape)
        {
            myType = (EnemyType) type;
            visionrange = vr;
            state = LifeState.Alive;
            actionState = EnemyActionState.Standing;

            if (vr == 0)
            {
                shoots = false;
                projectileTexture = null;
                projectiles = null;
            }
            else
            {
                shoots = true;
                projectileTexture = ProjectileTextures[0];
                projectiles = new List<Projectile>();
            }
        }
Ejemplo n.º 20
0
    private void DoReflexes()
    {
        // For times when its best to tell the microbe directly what to do (Life threatening, attaching to things etc);

        /* Check if we are willing to run, and there is a predator nearby, if so, flee for your life
         * If it was ran in evaluate environment, it would only work if the microbe was in the neutral state.
         * because we may need more of these very specific things in the future for things like latching onto rocks */
        // If you are predating and not being engulfed, don't run away until you switch state (keeps predators chasing
        // you even when their predators are nearby) Its not a good survival strategy but it makes the game more fun.
        if (predator != null && (lifeState != LifeState.PREDATING_STATE || microbe.IsBeingEngulfed))
        {
            try
            {
                if (!predator.Dead)
                {
                    if ((microbe.Translation - predator.Translation).LengthSquared() <=
                        (2000 + ((predator.HexCount * 8.0f) * 2)))
                    {
                        if (lifeState != LifeState.FLEEING_STATE)
                        {
                            // Reset target position for faster fleeing
                            hasTargetPosition = false;
                        }

                        boredom   = 0;
                        lifeState = LifeState.FLEEING_STATE;
                    }
                }
                else
                {
                    predator = null;
                }
            }
            catch (ObjectDisposedException)
            {
                // Our predator might be already disposed
                predator = null;
            }
        }
    }
Ejemplo n.º 21
0
        private void UpdateLifeState(int oldHP)
        {
            LifeState state = LifeState.FULL_LIFE;

            if (this.currentHP <= 0)
            {
                state = LifeState.DEAD;
            }
            else if (this.currentHP >= this.MaxHP)
            {
                state = LifeState.FULL_LIFE;
            }
            else if (oldHP < this.currentHP)
            {
                state = LifeState.INJURED;
            }
            else if (oldHP > this.currentHP)
            {
                state = LifeState.HEALED;
            }

            this.NotifyLifeStateChanged(state);
        }
Ejemplo n.º 22
0
        public LifeState CalculateLifeExpectancy()
        {
            if (Neighbours.Count < MIN_NEIGHBOURCOUNT)
            {
                throw new ArgumentOutOfRangeException(nameof(Neighbours), Neighbours, NotEnoughNeighbours);
            }
            expectedLifeState = CurrentLifeState;
            var aliveStateCount =
                neighbours.Count(each => each.CurrentLifeState == LifeState.Alive);

            if (CurrentLifeState == LifeState.Alive && (aliveStateCount < 2 || aliveStateCount > 3))
            {
                expectedLifeState = LifeState.Dead;
            }
            else if (CurrentLifeState == LifeState.Dead && aliveStateCount == 3)
            {
                expectedLifeState = LifeState.Alive;
            }

            Debug.WriteLine($"Calculated Expected Life Status of from '{Enum.GetName(typeof(LifeState), CurrentLifeState)}'" +
                            $" to '{Enum.GetName(typeof(LifeState), expectedLifeState)} for {Position.ToString()}'");

            return(expectedLifeState);
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Kills the enemy preventing him from being updated or drawn
 /// </summary>
 public void death()
 {
     if(state != LifeState.Dead)
     {
         deathEffectEmitter = new Emitter(drawRect, new Vector2(0, -11f), Math.PI / 2, 0.5, 0.001, 80, 45, Player.GoreTextures, new Vector2(0f, 0.75f), new Vector2(0, 15f), 1.0);
         state = LifeState.Dead;
         //actionState = EnemyActionState.Dying;
     }
 }
Ejemplo n.º 24
0
    public void Think(float delta, Random random, MicrobeAICommonData data)
    {
        _ = delta;

        // SetRandomTargetAndSpeed(random);

        // Clear the lists
        predatoryMicrobes.Clear();
        preyMicrobes.Clear();
        chunkList.Clear();

        prey = null;

        // 30 seconds about
        if (boredom == (int)random.Next(SpeciesFocus * 2, 1000.0f + SpeciesFocus * 2))
        {
            // Occasionally you need to reevaluate things
            boredom = 0;
            if (RollCheck(SpeciesActivity, 400, random))
            {
                lifeState = LifeState.PLANTLIKE_STATE;
            }
            else
            {
                lifeState = LifeState.NEUTRAL_STATE;
            }
        }
        else
        {
            boredom++;
        }

        switch (lifeState)
        {
        case LifeState.PLANTLIKE_STATE:
            // This ai would ideally just sit there, until it sees a nice opportunity pop-up unlike neutral,
            // which wanders randomly (has a gather chance) until something interesting pops up
            break;

        case LifeState.NEUTRAL_STATE:
        {
            // Before these would run every time, now they just run for the states that need them.
            boredom    = 0;
            preyPegged = false;
            prey       = null;
            if (predator == null)
            {
                GetNearestPredatorItem(data.AllMicrobes);
            }

            // Peg your prey
            if (!preyPegged)
            {
                prey = null;
                prey = GetNearestPreyItem(data.AllMicrobes);
                if (prey != null)
                {
                    preyPegged = true;
                }
            }

            if (targetChunk == null)
            {
                targetChunk = GetNearestChunkItem(data.AllChunks);
            }

            EvaluateEnvironment(random);
            break;
        }

        case LifeState.GATHERING_STATE:
        {
            // In this state you gather compounds
            if (RollCheck(SpeciesOpportunism, 400.0f, random))
            {
                lifeState = LifeState.SCAVENGING_STATE;
                boredom   = 0;
            }
            else
            {
                DoRunAndTumble(random);
            }

            break;
        }

        case LifeState.FLEEING_STATE:
        {
            if (predator == null)
            {
                GetNearestPredatorItem(data.AllMicrobes);
            }

            // In this state you run from predatory microbes
            if (predator != null)
            {
                DealWithPredators(random);
            }
            else
            {
                if (RollCheck(SpeciesActivity, 400, random))
                {
                    lifeState = LifeState.PLANTLIKE_STATE;
                    boredom   = 0;
                }
                else
                {
                    lifeState = LifeState.NEUTRAL_STATE;
                }
            }

            break;
        }

        case LifeState.PREDATING_STATE:
        {
            // Peg your prey
            if (!preyPegged)
            {
                prey = null;
                prey = GetNearestPreyItem(data.AllMicrobes);
                if (prey != null)
                {
                    preyPegged = true;
                }
            }

            if (preyPegged && prey != null)
            {
                DealWithPrey(data.AllMicrobes, random);
            }
            else
            {
                if (RollCheck(SpeciesActivity, 400, random))
                {
                    lifeState = LifeState.PLANTLIKE_STATE;
                    boredom   = 0;
                }
                else
                {
                    lifeState = LifeState.NEUTRAL_STATE;
                }
            }

            break;
        }

        case LifeState.SCAVENGING_STATE:
        {
            if (targetChunk == null)
            {
                targetChunk = GetNearestChunkItem(data.AllChunks);
            }

            if (targetChunk != null)
            {
                DealWithChunks(targetChunk, data.AllChunks);
            }
            else
            {
                if (!RollCheck(SpeciesOpportunism, 400, random))
                {
                    lifeState = LifeState.NEUTRAL_STATE;
                    boredom   = 0;
                }
                else
                {
                    lifeState = LifeState.SCAVENGING_STATE;
                }
            }

            break;
        }
        }

        // Run reflexes
        DoReflexes();

        // Clear the absorbed compounds for run and rumble
        microbe.TotalAbsorbedCompounds.Clear();
    }
Ejemplo n.º 25
0
        /// <summary>
        /// Create a new physical sprite from data
        /// </summary>
        /// <param name="pd">data from which to construct unit</param>
        protected PhysicalUnit(PhysicalData pd)
        {
            _unitName = pd.Name;
            _sprite = new Sprite(_unitName);

            if (pd.MovementParticleEffectName != null)
                _movementParticleEffect = new ParticleEffect(pd.MovementParticleEffectName);
            _burningParticleEffect = new ParticleEffect("Burning");

            _mass = pd.Mass;
            _moveForce = pd.MoveForce;
            _maxSpeed = pd.MaxSpeed;
            _maxHealth = pd.Health;
            _health = _maxHealth;
            _decelerationFactor = pd.DecelerationFactor;

            _lifeState = LifeState.Dormant;     //not yet spawned
            _hitRect = new Rectangle(0, 0, (int)_sprite.Width, (int)_sprite.Height);

            Position = Vector2.Zero;
            MoveDirection = Vector2.Zero;
            LookDirection = Vector2.Zero;

            _statusEffects = new StatEffect(0, 0, 0);
            _statusResist = new StatEffect(pd.FireResist, pd.CryoResist, pd.ShockResist);

            _fragments = new IceFragment[ICE_DIVISIONS, ICE_DIVISIONS];
        }
Ejemplo n.º 26
0
        public void ApplyDamage(int Damage)
        {
            if (_lifeState == LifeState.Destroyed || _lifeState == LifeState.BeingEaten)
                return;

            _health -= Damage;
            if (_health <= 0)
            {
                _lifeState = LifeState.Disabled;
                _sprite.Shade = Color.Gray;
                _angularVelocity = (float)MathHelper.PiOver4 * _health;
            }
            else
                _sprite.Flash(Color.Orange, TimeSpan.FromSeconds(0.1), 3);
        }
Ejemplo n.º 27
0
    /// <summary>
    /// For chasing down and killing prey in various ways
    /// </summary>
    private void DealWithPrey(List <Microbe> allMicrobes, Random random)
    {
        // Tick the engulf tick
        ticksSinceLastToggle += 1;

        bool lostPrey = false;

        try
        {
            targetPosition = prey.Translation;
        }
        catch (ObjectDisposedException)
        {
            lostPrey = true;
        }

        if (lostPrey)
        {
            preyPegged = false;
            prey       = null;
            return;
        }

        // Chase your prey if you dont like acting like a plant
        // Allows for emergence of Predatory Plants (Like a single cleed version of a venus fly trap)
        // Creatures with lethargicness of 400 will not actually chase prey, just lie in wait
        microbe.LookAtPoint = targetPosition;
        hasTargetPosition   = true;

        // Always set target Position, for use later in AI
        if (moveThisHunt)
        {
            if (moveFocused)
            {
                microbe.MovementDirection = new Vector3(0.0f, 0.0f, -Constants.AI_FOCUSED_MOVEMENT);
            }
            else
            {
                microbe.MovementDirection = new Vector3(0.0f, 0.0f, -Constants.AI_BASE_MOVEMENT);
            }
        }
        else
        {
            microbe.MovementDirection = new Vector3(0, 0, 0);
        }

        // Turn off engulf if prey is Dead
        // This is probabbly not working. This is almost certainly not working in the Godot version
        if (prey.Dead)
        {
            hasTargetPosition = false;
            prey = GetNearestPreyItem(allMicrobes);
            if (prey != null)
            {
                preyPegged = true;
            }

            microbe.EngulfMode = false;

            // You got a kill, good job
            if (!microbe.IsPlayerMicrobe && !microbe.Species.PlayerSpecies)
            {
                microbe.SuccessfulKill();
            }

            if (RollCheck(SpeciesOpportunism, 400.0f, random))
            {
                lifeState = LifeState.SCAVENGING_STATE;
                boredom   = 0;
            }
        }
        else
        {
            // Turn on engulfmode if close
            if ((microbe.Translation - targetPosition).LengthSquared() <= 300 + microbe.EngulfSize * 3.0f &&
                microbe.Compounds.GetCompoundAmount(atp) >= 1.0f &&
                !microbe.EngulfMode &&
                microbe.EngulfSize > Constants.ENGULF_SIZE_RATIO_REQ * prey.EngulfSize)
            {
                microbe.EngulfMode   = true;
                ticksSinceLastToggle = 0;
            }
            else if ((microbe.Translation - targetPosition).LengthSquared() >= 500 + microbe.EngulfSize * 3.0f &&
                     microbe.EngulfMode && ticksSinceLastToggle >= Constants.AI_ENGULF_INTERVAL)
            {
                microbe.EngulfMode   = false;
                ticksSinceLastToggle = 0;
            }
        }

        // Shoot toxins if able There should be AI that prefers shooting over engulfing, etc, not sure how to model that
        // without a million and one variables perhaps its a mix? Maybe a creature with a focus less then a certain
        // amount simply never attacks that way?  Maybe a creature with a specific focus, only ever shoots and never
        // engulfs? Maybe their lethargicness impacts that? I just dont want each enemy to feel the same you know.  For
        // now creatures with a focus under 100 will never shoot.
        if (SpeciesFocus >= 100.0f)
        {
            if (microbe.Hitpoints > 0 && microbe.AgentVacuoleCount > 0 &&
                (microbe.Translation - targetPosition).LengthSquared() <= SpeciesFocus * 10.0f)
            {
                if (microbe.Compounds.GetCompoundAmount(oxytoxy) >= Constants.MINIMUM_AGENT_EMISSION_AMOUNT)
                {
                    microbe.EmitToxin(oxytoxy);
                }
            }
        }
    }
Ejemplo n.º 28
0
        /// <summary>
        /// Attempt to absorb unit into black hole. 
        /// </summary>
        /// <returns>Amount of mass eaten
        public virtual float EatByBlackHole(Vector2 blackHolePos, float blackHoleRadius)
        {
            if (_lifeState == LifeState.Shattered)      //special handling
            {
                for (int row = 0; row < ICE_DIVISIONS; row++)
                    for (int col = 0; col < ICE_DIVISIONS; col++)
                    {
                        if (Vector2.Distance(_fragments[row, col].Position, blackHolePos) < blackHoleRadius)
                        {
                            _fragments[row, col].BeingEaten = true;
                        }
                    }
            }

            if (_lifeState != LifeState.BeingEaten && _lifeState != LifeState.Destroyed
                && _lifeState != LifeState.Ghost && blackHoleRadius > (Center - blackHolePos).Length())
            {
                _lifeState = LifeState.BeingEaten;
                _angularVelocity = 4 * MathHelper.TwoPi;
                return Mass;
            }
            return 0;
        }
Ejemplo n.º 29
0
 public void remove()
 {
     Texture = deadTexture;
     state   = LifeState.Dead;
 }
Ejemplo n.º 30
0
 public void TransferLifeState()
 {
     CurrentLifeState = expectedLifeState;
 }
Ejemplo n.º 31
0
 public void Respawn(Vector2 newPosition)
 {
     Position = newPosition;
     _lifeState = LifeState.Living;
     Reset();
 }
Ejemplo n.º 32
0
        public void ShouldSetACurrentLifeState(Position position, LifeState currentLifeState)
        {
            subject = new Cell(position, currentLifeState);

            subject.CurrentLifeState.Should().Be(currentLifeState);
        }
Ejemplo n.º 33
0
 /// <summary>
 /// Kills the ninja, preventing him from being updated or drawn
 /// </summary>
 public void death()
 {
     Point p = this.Location();
     Metrics.Metrics.writeLine("Level: City");
     Metrics.Metrics.writeLine("Death Location: ("+p.X+","+p.Y+")");
     ninjaLifeState = LifeState.Dead;
     MoveFrame(-500, -500);
 }
Ejemplo n.º 34
0
 public void Respawn(Vector2 newPosition)
 {
     System.Diagnostics.Debug.Assert(_lifeState == LifeState.Destroyed || _lifeState == LifeState.Dormant,
         "Error: Tried to respawn an enemy that was not destroyed or dormant");
     Position = newPosition;
     _lifeState = LifeState.Living;
     Reset();
 }
Ejemplo n.º 35
0
 public void die()
 {
     life_state = LifeState.dying;
     Destroy(gameObject, 1.0f);
 }
Ejemplo n.º 36
0
        public virtual void Update(GameTime gameTime)
        {
            switch(_lifeState)
            {
                case (LifeState.Living):
                    {
                        lookThisWay(LookDirection);
                        if (MoveDirection.Length() > 0)
                            moveThisWay(MoveDirection, gameTime);

                        break;
                    }

                case LifeState.Disabled:
                    {
                        break;
                    }
                case LifeState.BeingEaten:
                    {
                        _sprite.ScaleFactor -= 1.5f * (float)gameTime.ElapsedGameTime.TotalSeconds;
                        if (_sprite.ScaleFactor <= 0)
                            _lifeState = LifeState.Destroyed;
                        break;
                    }
                default:
                    {
                        return;     //don't update anything
                    }
            }

            stayInBounds(ScreenWidth, ScreenHeight);
            _velocity += _acceleration * (float)gameTime.ElapsedGameTime.TotalSeconds;
            Position += _velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
            controlVelocity(_maxSpeed, gameTime.ElapsedGameTime);
            _sprite.Angle += _angularVelocity * (float)gameTime.ElapsedGameTime.TotalSeconds;

            LookDirection = Vector2.Zero;
            MoveDirection = Vector2.Zero;
            _acceleration = Vector2.Zero;

            if (_movementParticleEffect != null)
                _movementParticleEffect.Update(gameTime);
            _hitRect.X = (int)Position.X - _hitRect.Width / 2;
            _hitRect.Y = (int)Position.Y - _hitRect.Height / 2;

            _sprite.Update(gameTime);
        }
Ejemplo n.º 37
0
 private void shatter()
 {
     _lifeState = LifeState.Shattered;
     for (int row = 0; row < ICE_DIVISIONS; row++)
         for (int col = 0 ; col < ICE_DIVISIONS ; col++)
         {
             _fragments[row, col].Health = FRAGMENT_HEALTH * _statusEffects.Cryo / MAX_STAT_EFFECT;
             _fragments[row, col].Position.X = Position.X + (0.5f + _sprite.Width * (float)col / ICE_DIVISIONS);
             _fragments[row, col].Position.Y = Position.Y + (0.5f + _sprite.Height * (float)row / ICE_DIVISIONS);
             XnaHelper.RandomizeVector(ref _fragments[row,col].Velocity, -FRAGMENT_MAX_VELOCITY, FRAGMENT_MAX_VELOCITY,
                                         -FRAGMENT_MAX_VELOCITY, FRAGMENT_MAX_VELOCITY);
             Vector2.Add(ref _fragments[row, col].Velocity, ref _velocity, out _fragments[row, col].Velocity);
             Vector2.Multiply(ref _fragments[row, col].Velocity, FRAGMENT_VELOCITY_FACTOR, out _fragments[row, col].Velocity);
             _fragments[row, col].Angle = 0f;
             _fragments[row, col].AngularVelocity = XnaHelper.RandomAngle(0.0f, FRAGMENT_MAX_ANGULAR_VELOCITY);
             _fragments[row, col].ScaleFactor = 1f;
             _fragments[row, col].Active = true;
         }
 }
Ejemplo n.º 38
0
 /// <summary>
 /// Attempt to absorb unit into black hole. 
 /// </summary>
 /// <returns>Whether unit was successfully eaten</returns>
 public bool EatByBlackHole()
 {
     if (_lifeState != LifeState.BeingEaten && _lifeState != LifeState.Destroyed)
     {
         _lifeState = LifeState.BeingEaten;
         _angularVelocity = 4 * MathHelper.TwoPi;
         return true;
     }
     return false;
 }
Ejemplo n.º 39
0
 public void Update()
 {
     float weight;
     switch (state)
     {
         case LifeState.ALIVE:
             break;
         case LifeState.DYING:
             currAnimTime += Time.deltaTime;
             if (currAnimTime > maxTime)
             {
                 currAnimTime = maxTime;
                 weight = 1;
                 state = LifeState.DYING2;
             }
             else
             {
                 float normTime = currAnimTime / maxTime;
                 weight = Mathf.Sin(normTime * Mathf.PI / 2);
             }
             ikSecondary.solver.leftHandEffector.positionWeight = weight;
             ikSecondary.solver.rightHandEffector.positionWeight = weight;
             break;
         case LifeState.DYING2:
             currAnimTime -= Time.deltaTime;
             if (currAnimTime < 0)
             {
                 currAnimTime = 0;
                 weight = 0;
                 state = LifeState.DEAD;
                 player.gameObject.SetActive(false);
             }
             break;
         case LifeState.DEAD:
             break;
     }
 }
Ejemplo n.º 40
0
 public Enemy(Rectangle rect, Texture2D tex, string name, ObjectShape Shape, int vr)
     : base(rect, tex, Shape)
 {
     shoots = true;
     visionrange = vr;
     projectiles = new List<Projectile>();
     EnemyName = name;
     state = LifeState.Alive;
     actionState = EnemyActionState.Standing;
     RunTextures = new List<Texture2D>();
     AttackTextures = new List<Texture2D>();
 }
Ejemplo n.º 41
0
 public void renewLife()
 {
     Texture = normalTexture;
     state   = LifeState.Alive;
 }
Ejemplo n.º 42
0
 public Cell(Position position, LifeState currentLifeState = LifeState.Dead)
 {
     Position         = position;
     CurrentLifeState = currentLifeState;
 }
Ejemplo n.º 43
0
 public virtual void InitializeHealth(float newhealth, float newmax)
 {
     _maxHealth = newmax;
     _health    = newhealth;
     lifestate  = LifeState.Alive;
 }
Ejemplo n.º 44
0
 public void Kill()
 {
     CurrentLifeState = LifeState.Dead;
 }
Ejemplo n.º 45
0
        public void ApplyDamage(float Damage)
        {
            if (Damage == 0.0f || _lifeState == LifeState.Destroyed || _lifeState == LifeState.BeingEaten
                || _lifeState == LifeState.Shattered)
                return;

            if (_lifeState == LifeState.Frozen)
            {   //attempt to shatter ice
                _iceIntegrity -= Damage;
                if (_iceIntegrity < 0)
                {
                    shatter();
                }
                return;
            }

            _health -= Damage;
            if (_health <= 0)
            {
                _lifeState = LifeState.Disabled;
                _sprite.Shade = Color.Gray;
                _angularVelocity = (float)MathHelper.PiOver4 * _health;
            }
            else
                _sprite.Flash(Color.Orange, TimeSpan.FromSeconds(0.1), 3);
        }
Ejemplo n.º 46
0
        public virtual void Update(long address, long radarAddress, int id)
        {
            this.index = id;
            IntPtr handle = Program.GameImplementation.GameController.Process.Handle;
            this.address = address;
            this.radarAddress = radarAddress;

            byte[] entityData = WinAPI.ReadMemory(handle, address, 6500);

            int vt = BitConverter.ToInt32(entityData, 0x8);
            int fn = WinAPI.ReadInt32(handle, vt + 2 * 0x4);
            int cls = WinAPI.ReadInt32(handle, fn + 0x1);
            this.classIDInt = WinAPI.ReadInt32(handle, cls + 20);
            this.classID = (ClassID)this.classIDInt;

            int namePointer = WinAPI.ReadInt32(handle, cls + 8);
            byte[] nameData = WinAPI.ReadMemory(handle, namePointer, 32);
            this.name = WinAPI.ReadString(handle, namePointer, 32, Encoding.ASCII); //Encoding.ASCII.GetString(nameData);

            if (this.name.Length > 0)
            {
                if (this.name[0] == 'C' && this.name != "C4")
                    this.name = this.name.Substring(1, this.name.Length - 1);
                if (this.name.StartsWith("Weapon"))
                {
                    this.classID = Enums.ClassID.Weapon;
                    this.name = this.name.Substring(6, this.name.Length - 6);
                }
                else if (this.name == "HEGrenade" || this.name == "Incendiary" || this.name == "Flash" || this.name == "Molotov" || this.name == "Decoy")
                {
                    this.classID = Enums.ClassID.Weapon;
                }
                else if (this.classID == Enums.ClassID.AK47 || this.classID == Enums.ClassID.DEagle)
                {
                    this.classID = Enums.ClassID.Weapon;
                }
            }
            if (!(
                    classID == Enums.ClassID.CSPlayer ||
                    classID == Enums.ClassID.Hostage ||
                    classID == Enums.ClassID.Chicken ||
                    classID == Enums.ClassID.Weapon ||
                    classID == Enums.ClassID.C4 ||
                    classID == Enums.ClassID.PlantedC4 ||
                    classID == Enums.ClassID.SmokeGrenade)
                )
                return;

            int newHealth = BitConverter.ToInt32(entityData, GameOffsets.CL_ENTITY_HEALTH);
            if (newHealth != health)
                HealthChanged(health, newHealth);
            this.health = newHealth;
            this.ownerEntity = BitConverter.ToInt16(entityData, GameOffsets.CL_ENTITY_OWNER_ENTITY);
            this.x = BitConverter.ToSingle(entityData, GameOffsets.CL_ENTITY_X);
            this.y = BitConverter.ToSingle(entityData, GameOffsets.CL_ENTITY_Y);
            this.z = BitConverter.ToSingle(entityData, GameOffsets.CL_ENTITY_Z);
            this.pitch = BitConverter.ToSingle(entityData, GameOffsets.CL_ENTITY_PITCH);
            this.yaw = BitConverter.ToSingle(entityData, GameOffsets.CL_ENTITY_YAW);
            this.roll = BitConverter.ToSingle(entityData, GameOffsets.CL_ENTITY_ROLL);
            this.viewAngle = new Vector3(pitch, yaw, roll);
            this.team = (Team)BitConverter.ToInt32(entityData, GameOffsets.CL_ENTITY_TEAM);//BitConverter.ToInt32(entityData, GameOffsets.CL_ENTITY_TEAM);
            this.vector3 = new Vector3(x, y, z);
            this.vector2 = new Vector2(x, y);
            this.velx = BitConverter.ToSingle(entityData, GameOffsets.CL_ENTITY_VELOCITY_X);
            this.vely = BitConverter.ToSingle(entityData, GameOffsets.CL_ENTITY_VELOCITY_Y);
            this.velz = BitConverter.ToSingle(entityData, GameOffsets.CL_ENTITY_VELOCITY_Z);
            this.baseVelx = BitConverter.ToSingle(entityData, GameOffsets.CL_ENTITY_BASE_VELOCITY_X);
            this.baseVely = BitConverter.ToSingle(entityData, GameOffsets.CL_ENTITY_BASE_VELOCITY_Y);
            this.baseVelz = BitConverter.ToSingle(entityData, GameOffsets.CL_ENTITY_BASE_VELOCITY_Z);
            this.punchX = BitConverter.ToSingle(entityData, GameOffsets.CL_ENTITY_PUNCHVEC);
            this.punchY = BitConverter.ToSingle(entityData, GameOffsets.CL_ENTITY_PUNCHVEC + 0x4);
            this.punchZ = BitConverter.ToSingle(entityData, GameOffsets.CL_ENTITY_PUNCHVEC + 0x8);
            this.punchVector = new Vector3(punchX, punchY, punchZ);
            this.state = (PlayerState)entityData[GameOffsets.CL_ENTITY_STATE];//BitConverter.ToInt32(entityData, GameOffsets.CL_ENTITY_STATE);
            this.spectatorView = (SpectatorView)entityData[GameOffsets.CL_ENTITY_SPECTATOR_VIEW];//BitConverter.ToInt32(entityData, GameOffsets.CL_ENTITY_SPECTATOR_VIEW);
            this.spectatorTarget = entityData[GameOffsets.CL_ENTITY_SPECTATOR_PLAYER];
            this.velocity = new Vector3(velx, vely, velz);
            this.baseVelocity = new Vector3(baseVelx, baseVely, baseVelz);
            this.isDormant = entityData[GameOffsets.CL_ENTITY_DORMANT] == 1;
            this.isSpotted = entityData[GameOffsets.CL_ENTITY_SPOTTED] == 1;
            this.spottedMask = BitConverter.ToInt32(entityData, GameOffsets.CL_ENTITY_SPOTTED_MASK);
            this.lifeState = (LifeState)entityData[GameOffsets.CL_ENTITY_LIFESTATE];//BitConverter.ToInt32(entityData, GameOffsets.CL_ENTITY_LIFESTATE);
            if (this.skeleton == null)
                this.skeleton = new Skeleton(
                    BitConverter.ToInt32(entityData, GameOffsets.CL_ENTITY_BONEMATRIX),
                    !(this.classID == Enums.ClassID.Chicken || this.classID == Enums.ClassID.Hostage || this.classID == Enums.ClassID.CSPlayer)
                    );
            else
                this.skeleton.Update(BitConverter.ToInt32(entityData, GameOffsets.CL_ENTITY_BONEMATRIX));
        }
Ejemplo n.º 47
0
    // For for figuring out which state to enter
    private void EvaluateEnvironment(Random random)
    {
        if (RollCheck(SpeciesOpportunism, 500.0f, random))
        {
            lifeState = LifeState.SCAVENGING_STATE;
            boredom   = 0;
        }
        else
        {
            if (prey != null && predator != null)
            {
                if (random.Next(0.0f, SpeciesAggression) >
                    random.Next(0.0f, SpeciesFear) &&
                    preyMicrobes.Count > 0)
                {
                    moveThisHunt = !RollCheck(SpeciesActivity, 500.0f, random);

                    if (microbe.AgentVacuoleCount > 0)
                    {
                        moveFocused = RollCheck(SpeciesFocus, 500.0f, random);
                    }

                    lifeState = LifeState.PREDATING_STATE;
                }
                else if (random.Next(0.0f, SpeciesAggression) <
                         random.Next(0.0f, SpeciesFear) &&
                         predatoryMicrobes.Count > 0)
                {
                    lifeState = LifeState.FLEEING_STATE;
                }
                else if (SpeciesAggression == SpeciesFear &&
                         preyMicrobes.Count > 0)
                {
                    // Prefer predating (makes game more fun)
                    moveThisHunt = !RollCheck(SpeciesActivity, 500.0f, random);

                    if (microbe.AgentVacuoleCount > 0)
                    {
                        moveFocused = RollCheck(SpeciesFocus, 500.0f, random);
                    }

                    lifeState = LifeState.PREDATING_STATE;
                }
                else if (RollCheck(SpeciesFocus, 500.0f, random) && random.Next(0, 10) <= 2)
                {
                    lifeState = LifeState.GATHERING_STATE;
                }
            }
            else if (prey != null)
            {
                moveThisHunt = !RollCheck(SpeciesActivity, 500.0f, random);

                if (microbe.AgentVacuoleCount > 0)
                {
                    moveFocused = RollCheck(SpeciesFocus, 500.0f, random);
                }

                lifeState = LifeState.PREDATING_STATE;
            }
            else if (predator != null)
            {
                lifeState = LifeState.FLEEING_STATE;

                // I want gathering to trigger more often so i added this here.
                // Because even with predators around you should still graze
                if (RollCheck(SpeciesFocus, 500.0f, random) && random.Next(0, 10) <= 5)
                {
                    lifeState = LifeState.GATHERING_STATE;
                }
            }
            else if (targetChunk != null)
            {
                lifeState = LifeState.SCAVENGING_STATE;
            }
            else if (random.Next(0, 10) < 8)
            {
                // Every 2 intervals || so
                lifeState = LifeState.GATHERING_STATE;
            }
            else if (RollCheck(SpeciesActivity, 400.0f, random))
            {
                // Every 10 intervals || so
                lifeState = LifeState.PLANTLIKE_STATE;
            }
        }
    }
Ejemplo n.º 48
0
    private void _Start()
    {
        starSprite.color = Color.white;

        mLifeState = LifeState.Grabbed;
        planetAttach.enabled = false;
        fadeEnabled = false;
        mCurBounce = 0;
        InvulnerableOff();
    }
Ejemplo n.º 49
0
 //This will not check if we're already in the state
 void SetLifeState(LifeState state)
 {
     //print ("Changing State: "+state);
     this.lastStateTime = Time.time;
     this.state = state;
 }
Ejemplo n.º 50
0
 public DeathIKController(CrossfadeFBBIK[] iks)
 {
     this.ikSecondary = iks[1];
     state = LifeState.ALIVE;
     currAnimTime = 0f;
     maxTime = 1.2f;
 }
        public virtual void Update(GameTime gameTime, Rectangle levelBounds)
        {
            switch (_lifeState)
            {
            case LifeState.Living:
            case LifeState.Ghost:
            {
                if (Panicked)
                {
                    _panicTimer -= gameTime.ElapsedGameTime;
                    if (_panicTimer <= TimeSpan.Zero)
                    {
                        _panicTimer = TimeSpan.FromSeconds(PANIC_DIRECTION_CHANGE_FREQUENCY);
                        XnaHelper.RandomizeVector(ref _moveDirection, -1, 1, -1, 1);
                        _lookDirection = _moveDirection;
                    }
                }
                lookThisWay(LookDirection);
                if (MoveDirection.Length() > 0)
                {
                    moveThisWay(MoveDirection, gameTime);
                }

                //handle burning
                ApplyDamage(_statusEffects.Fire * (float)gameTime.ElapsedGameTime.TotalSeconds * FIRE_DPS);

                break;
            }

            case LifeState.Disabled:
            case LifeState.Frozen:
            {
                if (_statusEffects.Cryo <= 0)
                {
                    _lifeState = LifeState.Living;
                    //still cold after defrosting
                    _statusEffects.Cryo = MAX_STAT_EFFECT / 2;
                }
                break;
            }

            case LifeState.Shattered:
            {
                for (int y = 0; y < ICE_DIVISIONS; y++)
                {
                    for (int x = 0; x < ICE_DIVISIONS; x++)
                    {
                        _fragments[x, y].Angle       += _fragments[x, y].AngularVelocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
                        _fragments[x, y].Position    += _fragments[x, y].Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
                        _fragments[x, y].Velocity    += _fragments[x, y].Acceleration * (float)gameTime.ElapsedGameTime.TotalSeconds;
                        _fragments[x, y].Acceleration = Vector2.Zero;
                        _fragments[x, y].Health      -= FRAGMENT_MELT_RATE * (float)gameTime.ElapsedGameTime.TotalSeconds;
                        _fragments[x, y].ScaleFactor  = _fragments[x, y].Health / FRAGMENT_HEALTH * FRAGMENT_SCALE_FACTOR;
                        XnaHelper.ClampVector(ref _fragments[x, y].Velocity, FRAGMENT_MAX_VELOCITY, out _fragments[x, y].Velocity);
                        if (_fragments[x, y].BeingEaten)
                        {
                            _fragments[x, y].Health -= FRAGMENT_EAT_RATE * (float)gameTime.ElapsedGameTime.TotalSeconds;
                        }
                    }
                }
                return;
            }

            case LifeState.BeingEaten:
            {
                _sprite.ScaleFactor -= BLACK_HOLE_EAT_SCALE_FACTOR * (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (_sprite.ScaleFactor <= 0)
                {
                    _lifeState = LifeState.Destroyed;
                }
                break;
            }

            case LifeState.Destroyed:
            default:
            {
                return;             //don't update anything
            }
            }

            stayInBounds(levelBounds.Width, levelBounds.Height);
            _velocity += _acceleration * (float)gameTime.ElapsedGameTime.TotalSeconds;
            Position  += _velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
            controlVelocity(_maxSpeed, gameTime.ElapsedGameTime);
            _sprite.Angle += _angularVelocity * (float)gameTime.ElapsedGameTime.TotalSeconds;

            LookDirection = Vector2.Zero;
            MoveDirection = Vector2.Zero;
            _acceleration = Vector2.Zero;

            if (_movementParticleEffect != null)
            {
                _movementParticleEffect.Update(gameTime);
            }

            //burning visual effect
            _burningParticleEffect.Spawn(Position, 0.0f, gameTime.ElapsedGameTime, _velocity);
            _burningParticleEffect.IntensityFactor = _statusEffects.Fire / MAX_STAT_EFFECT;
            _burningParticleEffect.Update(gameTime);

            //cryo visual effect
            if (_statusEffects.Cryo > 0 && _lifeState != LifeState.Disabled)
            {
                _sprite.Shade = Color.Lerp(Color.White, Color.Blue, _statusEffects.Cryo / MAX_STAT_EFFECT);
            }

            _hitRect.X = (int)Position.X - _hitRect.Width / 2;
            _hitRect.Y = (int)Position.Y - _hitRect.Height / 2;

            //manage stat effects
            if (_statusEffects.Cryo >= MAX_STAT_EFFECT && _lifeState != LifeState.Frozen)
            {
                _lifeState          = LifeState.Frozen;
                _iceIntegrity       = maxHealth * ICE_INTEGRITY_FACTOR;
                _statusEffects.Fire = 0;    //stop burning if frozen
            }

            //decrement every stat effect based on status resist
            _statusEffects -= _statusResist * (float)gameTime.ElapsedGameTime.TotalSeconds;
            _statusEffects.Clamp(0, MAX_STAT_EFFECT);

            _sprite.Update(gameTime);
        }
Ejemplo n.º 52
0
 public void Die(Transform player)
 {
     if (state == LifeState.ALIVE)
     {
         Vector3 location = player.transform.position;
         location.y = 0;
         Quaternion forward = Quaternion.LookRotation(player.forward);
         Vector3 leftHandLocation = location + (forward * new Vector3(-0.3f, 0, 3));
         Vector3 rightHandLocation = location + (forward * new Vector3(0.3f, 0, 3));
         ikSecondary.solver.leftHandEffector.position = leftHandLocation;
         ikSecondary.solver.rightHandEffector.position = rightHandLocation;
         state = LifeState.DYING;
         this.player = player;
     }
 }
Ejemplo n.º 53
0
 public Cell(int x, int y, LifeState currentLifeState = LifeState.Dead)
     : this(new Position(x, y), currentLifeState)
 {
 }
Ejemplo n.º 54
0
        public virtual void Update(GameTime gameTime, Rectangle levelBounds)
        {
            switch(_lifeState)
            {
                case LifeState.Living:
                case LifeState.Ghost:
                    {
                        if (Panicked)
                        {
                            _panicTimer -= gameTime.ElapsedGameTime;
                            if (_panicTimer <= TimeSpan.Zero)
                            {
                                _panicTimer = TimeSpan.FromSeconds(PANIC_DIRECTION_CHANGE_FREQUENCY);
                                XnaHelper.RandomizeVector(ref _moveDirection, -1, 1, -1, 1);
                                _lookDirection = _moveDirection;
                            }
                        }
                        lookThisWay(LookDirection);
                        if (MoveDirection.Length() > 0)
                            moveThisWay(MoveDirection, gameTime);

                        //handle burning
                        ApplyDamage(_statusEffects.Fire * (float)gameTime.ElapsedGameTime.TotalSeconds * FIRE_DPS);

                        break;
                    }
                case LifeState.Disabled:
                case LifeState.Frozen:
                    {
                        if (_statusEffects.Cryo <= 0)
                        {
                            _lifeState = LifeState.Living;
                            //still cold after defrosting
                            _statusEffects.Cryo = MAX_STAT_EFFECT / 2;
                        }
                        break;
                    }
                case LifeState.Shattered:
                    {
                        for (int y = 0; y < ICE_DIVISIONS; y++)
                            for (int x = 0; x < ICE_DIVISIONS; x++)
                            {
                                _fragments[x, y].Angle += _fragments[x, y].AngularVelocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
                                _fragments[x, y].Position += _fragments[x, y].Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
                                _fragments[x, y].Velocity += _fragments[x, y].Acceleration * (float)gameTime.ElapsedGameTime.TotalSeconds;
                                _fragments[x, y].Acceleration = Vector2.Zero;
                                _fragments[x, y].Health -= FRAGMENT_MELT_RATE * (float)gameTime.ElapsedGameTime.TotalSeconds;
                                _fragments[x, y].ScaleFactor = _fragments[x,y].Health / FRAGMENT_HEALTH * FRAGMENT_SCALE_FACTOR;
                                XnaHelper.ClampVector(ref _fragments[x, y].Velocity, FRAGMENT_MAX_VELOCITY, out _fragments[x, y].Velocity);
                                if (_fragments[x, y].BeingEaten)
                                {
                                    _fragments[x, y].Health -= FRAGMENT_EAT_RATE * (float)gameTime.ElapsedGameTime.TotalSeconds;
                                }
                            }
                        return;
                    }
                case LifeState.BeingEaten:
                    {
                        _sprite.ScaleFactor -= BLACK_HOLE_EAT_SCALE_FACTOR * (float)gameTime.ElapsedGameTime.TotalSeconds;
                        if (_sprite.ScaleFactor <= 0)
                            _lifeState = LifeState.Destroyed;
                        break;
                    }
                case LifeState.Destroyed:
                default:
                    {
                        return;     //don't update anything
                    }
            }

            stayInBounds(levelBounds.Width, levelBounds.Height);
            _velocity += _acceleration * (float)gameTime.ElapsedGameTime.TotalSeconds;
            Position += _velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
            controlVelocity(_maxSpeed, gameTime.ElapsedGameTime);
            _sprite.Angle += _angularVelocity * (float)gameTime.ElapsedGameTime.TotalSeconds;

            LookDirection = Vector2.Zero;
            MoveDirection = Vector2.Zero;
            _acceleration = Vector2.Zero;

            if (_movementParticleEffect != null)
                _movementParticleEffect.Update(gameTime);

            //burning visual effect
            _burningParticleEffect.Spawn(Position, 0.0f, gameTime.ElapsedGameTime, _velocity);
            _burningParticleEffect.IntensityFactor = _statusEffects.Fire / MAX_STAT_EFFECT;
            _burningParticleEffect.Update(gameTime);

            //cryo visual effect
            if (_statusEffects.Cryo > 0 && _lifeState != LifeState.Disabled)
            {
                _sprite.Shade = Color.Lerp(Color.White, Color.Blue, _statusEffects.Cryo / MAX_STAT_EFFECT);
            }

            _hitRect.X = (int)Position.X - _hitRect.Width / 2;
            _hitRect.Y = (int)Position.Y - _hitRect.Height / 2;

            //manage stat effects
            if (_statusEffects.Cryo >= MAX_STAT_EFFECT && _lifeState != LifeState.Frozen)
            {
                _lifeState = LifeState.Frozen;
                _iceIntegrity = maxHealth * ICE_INTEGRITY_FACTOR;
                _statusEffects.Fire = 0;    //stop burning if frozen
            }

            //decrement every stat effect based on status resist
            _statusEffects -= _statusResist * (float)gameTime.ElapsedGameTime.TotalSeconds;
            _statusEffects.Clamp(0, MAX_STAT_EFFECT);

            _sprite.Update(gameTime);
        }
Ejemplo n.º 55
0
 public void BringToLife()
 {
     CurrentLifeState = LifeState.Alive;
 }
Ejemplo n.º 56
0
    public void FlowerGrow(bool challengeInProgress)
    {
        this.isPaused = HUDController.Instance ? HUDController.Instance.IsPaused : false;

        if (!challengeInProgress && !this.isPaused)
        {
            timer += Time.deltaTime;
        }
        else
        {
            return;
        }

        switch (currentState)
        {
        case LifeState.None:
            if (HUDController.Instance)
            {
                if (HUDController.Instance.IsSeedPlanted)
                {
                    currentState = LifeState.Seed;
                    HUDController.Instance.DisplayCommand(true);
                }
            }
            break;

        case LifeState.Seed:
            if (timer > 5)
            {
                timer = 0;
                currentState++;
            }
            else
            {
                float baseSize = 5f;
                float size     = baseSize + (timer / 5) * (width - baseSize);
                stalk.sizeDelta = new Vector2(size, size);
            }
            break;

        case LifeState.Sapling:
            if (timer > 20)
            {
                timer           = 0;
                stalk.sizeDelta = new Vector2(width, maxHeight);
                currentState++;

                bulb.transform.localScale = new Vector3(0, 0, 1);
                bulb.SetActive(true);
            }
            else
            {
                stalk.sizeDelta = new Vector2(width, ((timer / 20) * (maxHeight - width)) + width);
            }
            break;

        case LifeState.Plant:
            if (timer > 15)
            {
                timer = 0;
                bulb.transform.localScale = new Vector3(1, 1, 1);
                currentState++;

                bloom.SetActive(true);
            }
            else
            {
                float scale = (timer / 15);
                bulb.transform.localScale = new Vector3(scale, scale, 1);
            }
            break;

        case LifeState.Flower:
            HUDController.Instance.PendRestart();
            break;
        }

        //if(timer >= 5 && !challengeInProgress && currentState != LifeState.Flower)
        //{
        //    Debug.Log(currentState);
        //    timer = 0;
        //    currentState++;
        //}
        //Debug.Log(timer);
    }
Ejemplo n.º 57
0
    void SetState(LifeState state)
    {
        mCurFadeTime = 0;

        mLifeState = state;

        switch(state) {
        case LifeState.None:
            break;
        case LifeState.Active:
            break;
        case LifeState.Grabbed:
            break;
        case LifeState.Thrown:
            break;
        case LifeState.Dying:
            gameObject.layer = Main.layerIgnoreRaycast;
            mReticle = Reticle.Type.NumType;
            break;
        case LifeState.Refreshing:
            break;
        }
    }
Ejemplo n.º 58
0
	void OnDead()
	{
		rigidbody.drag = 999f;
		fadeSprite( body.GetComponent<tk2dSprite>() , DeadTime);
		fadeSprite( eye.GetComponent<tk2dSprite>() , DeadTime);
		foreach( GameObject dec in decs )
		{
			fadeSprite( dec.GetComponent<tk2dSprite>() ,DeadTime );
		}
		fadeSprite( buttomLight.GetComponent<tk2dSprite>() ,DeadTime);

		state = LifeState.Dead;
	}
Ejemplo n.º 59
0
 //This will not check if we're already in the state
 void SetLifeState(LifeState state)
 {
     //print ("Changing State: "+state);
     this.lastStateTime = Time.time;
     this.state = state;
     if (state == LifeState.Loiter)
     {
         this.nextFire = Time.time + Random.Range(0f, this.wave.at.fireInterval);
     }
 }
Ejemplo n.º 60
0
 /// <summary>
 /// Kills the enemy preventing him from being updated or drawn
 /// </summary>
 public void death()
 {
     state = LifeState.Dead;
     actionState = EnemyActionState.Dying;
 }