Exemple #1
0
        public void GotHit(int healthLost)
        {
            Hit = true;
            hitTimer.SetDelay(hitDelay);

            // decrease health
            Hitpoints = Hitpoints - healthLost;
        }
Exemple #2
0
        protected void fallAway()
        {
            this.Fallen = true;
            resetTimer.SetDelay(resetDelay);

            // this is so it falls
            physicsLine.body.BodyType = BodyType.Dynamic;
        }
Exemple #3
0
        protected void doBlink(float dt)
        {
            blinkTimer.Update(dt);

            if (blinkTimer.IsTimeUp())
            {
                blinkTimer.SetDelay(blinkDelay);
                toggleBlink();
            }
        }
Exemple #4
0
 public void Dive()
 {
     changeBehavior(BatBehavior.Diving);
     Movement.Move();
     diveTimer.SetDelay(diveTimerDelay);
     if (this.FacingRight)
     {
         DiveRight();
     }
     else
     {
         DiveLeft();
     }
 }
Exemple #5
0
        /*
         * public override void Respawn()
         * {
         *  base.Respawn();
         *  SetUpEnemy(this.SpawnPosition, EnemyFactory.BatWidth, EnemyFactory.BatHeight, EnemyFactory.BatHealth, EnemyFactory.BatHitDelay, EnemyFactory.BatRecoveryDelay);
         * }
         */

        // Activities:
        private bool checkFlap()
        {
            if (this.Position.Y >= ConvertUnits.ToSimUnits(this.SpawnPosition.Y) || this.PhysicsContainer.Object.OnGround)
            {
                if (flapTimer.IsTimeUp())
                {
                    flapTimer.SetDelay(flapTimerDelay);
                    enemyEvent.flap = true;
                    return(true);
                }
            }

            return(false);
        }
Exemple #6
0
        public bool CheckForPlayer(bool playerInSight)
        {
            if (playerInSight)
            {
                if (!EnemySeesPlayer)
                {
                    EnemySeesPlayer = true;
                    enemySawPlayerTimer.SetDelay(enemySightDelay);
                }

                if (enemySawPlayerTimer.IsTimeUp())
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                if (EnemySeesPlayer)
                {
                    EnemySeesPlayer = false;
                    enemySawPlayerTimer.SetDelay(enemySightDelay);
                }

                if (enemySawPlayerTimer.IsTimeUp())
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }
Exemple #7
0
        protected bool onCollision(Fixture fix1, Fixture fix2, Contact contact)
        {
            if (fix2.IsSensor)
            {
                return(false);
            }

            if (this.Fallen)
            {
                if (fix2.CollisionCategories == GameConstants.GroundCollisionCategory)
                {
                    // We need to check if the falling platform is actually colliding with the ground since farseer isn't accurate enough for our purposes...

                    Entity ground = fix2.Body.UserData as Entity;

                    float leftPlatformPoint  = this.Position.X - this.Width * 0.5f;
                    float rightPlatformPoint = this.Position.X + this.Width * 0.5f;
                    float leftGroundPoint    = ground.Position.X - ground.Width * 0.5f;
                    float rightGroundPoint   = ground.Position.X + ground.Width * 0.5f;

                    if (rightPlatformPoint >= leftGroundPoint && rightPlatformPoint <= rightGroundPoint)
                    {
                        die();
                    }
                    else if (leftPlatformPoint >= leftGroundPoint && leftPlatformPoint <= rightGroundPoint)
                    {
                        die();
                    }
                }

                return(false);
            }

            if (!this.CollidedWithLivingEntity)
            {
                if (onCollisionWithLivingEntity(fix1, fix2, contact))
                {
                    this.CollidedWithLivingEntity = true;
                    fallTimer.SetDelay(fallDelay);
                }
            }

            return(true);
        }
Exemple #8
0
        public void ActivateWithDisplayEntity(DisplayEntity displayEntity, float lifetime, bool fadeAway, bool alphaAway, float initialOpacity, float initialAlpha)
        {
            this.Active = true;
            lifeTimer.SetDelay(lifetime);
            this.fadeAway       = fadeAway;
            this.alphaAway      = alphaAway;
            this.initialOpacity = initialOpacity;
            this.initialAlpha   = initialAlpha;

            // Extract drawing information from the display entity
            SpriteSheet   = displayEntity.SpriteSheet;
            SourceRect    = displayEntity.SourceRect;
            Position      = displayEntity.Position;
            Scale         = displayEntity.Scale;
            Color         = displayEntity.Color;
            Rotation      = displayEntity.Rotation;
            SpriteEffects = displayEntity.SpriteEffects;
            LayerDepth    = displayEntity.LayerDepth + 0.001f;
            Width         = SourceRect.Width;
            Height        = SourceRect.Height;
            origin        = new Vector2(Width * 0.5f, Height * 0.5f);
        }
Exemple #9
0
        public void TurnAround(Enemy enemy)
        {
            Stop();

            if (!turnAround)
            {
                turnAround = true;
                turnAroundTimer.SetDelay(turnAroundTimerDelay);
            }

            if (turnAroundTimer.IsTimeUp())
            {
                turnAround = false;

                if (enemy.FacingRight)
                {
                    enemy.FacingRight = false;
                }
                else
                {
                    enemy.FacingRight = true;
                }
            }
        }
Exemple #10
0
        protected override void performChecks()
        {
            // we don't care about the ceiling
            checkForGround();
            checkForWall(false, false);
            checkForCharOnHead(true, false);

            // record the previous values to the next values
            prevOnGround    = nextOnGround;
            prevOnLeftWall  = nextOnLeftWall;
            prevOnRightWall = nextOnRightWall;

            // record the next values
            nextOnGround    = onGroundPhysics;
            nextOnLeftWall  = OnLeftWall;
            nextOnRightWall = OnRightWall;

            if (onGroundPhysics)
            {
                enableOnGroundDelay = true;
            }
            if (OnLeftWall)
            {
                enableOnLeftWallDelay = true;
            }
            if (OnRightWall)
            {
                enableOnRightWallDelay = true;
            }

            onGroundDelay = false;
            if (enableOnGroundDelay && !onGroundPhysics)
            {
                if (prevOnGround && !nextOnGround)
                {
                    if (body.LinearVelocity.Y >= 0) // so that it doesn't happen when shooting upwards off a platform
                    {
                        onGroundTimer.SetDelay(onGroundOrWallDelay);
                    }
                }

                if (!onGroundPhysics && !onGroundTimer.IsTimeUp())
                {
                    onGroundDelay = true;
                }
            }

            if (enableOnLeftWallDelay && !OnLeftWall)
            {
                if (prevOnLeftWall && !nextOnLeftWall)
                {
                    onLeftWallTimer.SetDelay(onGroundOrWallDelay);
                }

                if (!OnLeftWall && !onLeftWallTimer.IsTimeUp())
                {
                    OnLeftWall = true;
                }
            }

            if (enableOnRightWallDelay && !OnRightWall)
            {
                if (prevOnRightWall && !nextOnRightWall)
                {
                    onRightWallTimer.SetDelay(onGroundOrWallDelay);
                }

                if (!OnRightWall && !onRightWallTimer.IsTimeUp())
                {
                    OnRightWall = true;
                }
            }
        }
Exemple #11
0
 private void recovering()
 {
     Hit        = false;
     Recovering = true;
     recoveryTimer.SetDelay(recoveryDelay);
 }