예제 #1
0
        public void Update(GameTime gameTime)
        {
            if (IsTongueCaptured)
            {
                Vector2 previousPosition = new Vector2(Position.X, Position.Y);
                Physics.Move(this);
                Position = previousPosition;
            }
            if (!IsTongueCaptured)
            {
                Physics.Move(this);
            }

            if (!IsSlidingShell)
            {
                if (EnemyState.ToString() == "SuperMario.EnemyStates.HidingInsideShellKoopa")
                {
                    koopaShellTimeout--;

                    if (koopaShellTimeout <= 0)
                    {
                        koopaShellTimeout = GameValues.EnemyKoopaShellTimeout;
                        EnemyState = new LeftWalkingKoopa(Position, this);
                        Velocity = new Vector2(-MaxVelocity.X, 0);
                    }

                    else if (koopaShellTimeout % GameValues.EnemyKoopaShellUpdateDelay == 0)
                    {
                        EnemyState = new ComingOutOfShellKoopa(Position, this);
                        EnemyState.ScoreSprite.ScoringOn = false;
                    }
                }

                else if (EnemyState.ToString() == "SuperMario.EnemyStates.ComingOutOfShellKoopa")
                {
                    koopaShellTimeout--;

                    if (koopaShellTimeout <= 0)
                    {
                        koopaShellTimeout = GameValues.EnemyKoopaShellTimeout;
                        EnemyState = new LeftWalkingKoopa(Position, this);
                        Velocity = new Vector2(-MaxVelocity.X, 0);
                    }

                    else if (koopaShellTimeout % GameValues.EnemyKoopaShellUpdateDelay == 0)
                    {
                        EnemyState = new HidingInsideShellKoopa(Position, this);
                        EnemyState.ScoreSprite.ScoringOn = false;

                    }
                }

                else if (this.EnemyState.ToString() == "SuperMario.EnemyStates.DeadGoomba")
                {
                    deadGoombaTimeout--;

                    if (deadGoombaTimeout <= 0)
                    {
                        EnemyState = new NoEnemy(this);
                    }
                }
            }

            if (EnemyState.ToString() == "SuperMario.EnemyStates.NoEnemy" || EnemyState.ToString() == "SuperMario.EnemyStates.DeadGoomba" || EnemyState.ToString() == "SuperMario.EnemyStates.FlippedGoomba" || EnemyState.ToString() == "SuperMario.EnemyStates.FlippedKoopaShell")
            {
                CollisionRectangle = GameValues.EmptyCollisionRectangle;
            }

            if (EnemyState.ToString() == "SuperMario.EnemyStates.FlippedGoomba" || EnemyState.ToString() == "SuperMario.EnemyStates.FlippedKoopaShell")
            {
                float yAcceleration = GameValues.EnemyFlippedYAcceleration;
                Position = new Vector2(Position.X, Position.Y + FallingVelocity.Y);
                FallingVelocity = new Vector2(FallingVelocity.X, FallingVelocity.Y + yAcceleration);
            }

            if (EnemyState.ToString() == "SuperMario.EnemyStates.CrawfisLeft" || EnemyState.ToString() == "SuperMario.EnemyStates.CrawfisRight")
            {
                AI();
            }

            Fireball.Update(gameTime);
            EnemyState.Update(gameTime, Position);
        }
예제 #2
0
        public Enemy(Vector2 position, string enemyState)
        {
            Position = position;
            MaxVelocity = new Vector2(GameValues.EnemyMaxXVelocity, GameValues.PhysicsMaxYVelocity);
            Acceleration = Vector2.Zero;
            EnemyStateTransitionMachine = new EnemyStateTransitionMachine();
            IsFlipped = false;
            IsSlidingShell = false;
            IsTongueCaptured = false;
            rand = new Random();
            randBuffer = 0;
            Fireball = new Fireball(Vector2.Zero, false, true);

            koopaShellTimeout = GameValues.EnemyKoopaShellTimeout;
            deadGoombaTimeout = GameValues.EnemyDeadEnemyTimeout;

            if (enemyState == "WalkingGoomba")
            {
                EnemyState = new WalkingGoomba(position, this);
                Velocity = new Vector2(-MaxVelocity.X, 0);
            }

            else if (enemyState == "RightWalkingKoopa")
            {
                EnemyState = new RightWalkingKoopa(position, this);
                Velocity = new Vector2(MaxVelocity.X, 0);
            }

            else if (enemyState == "LeftWalkingKoopa")
            {
                EnemyState = new LeftWalkingKoopa(position, this);
                Velocity = new Vector2(-MaxVelocity.X, 0);
            }

            else if (enemyState == "PiranhaPlant")
            {
                EnemyState = new PiranhaPlant(position, this);
            }

            else if (enemyState == "HidingInsideShellKoopa")
            {
                EnemyState = new HidingInsideShellKoopa(position, this);
            }

            else if (enemyState == "ComingOutOfShellKoopa")
            {
                EnemyState = new ComingOutOfShellKoopa(position, this);
            }

            else if (enemyState == "CrawfisLeft")
            {
                EnemyState = new CrawfisLeft(position, this);
                Velocity = new Vector2(-MaxVelocity.X, 0);
            }

            else if (enemyState == "BowserLeft")
            {
                EnemyState = new BowserLeft(position, this);
                Velocity = new Vector2(-MaxVelocity.X, 0);
            }

            else if (enemyState == "NoEnemy")
            {
                EnemyState = new NoEnemy(this);
            }

            CollisionRectangle = EnemyState.CollisionRectangle;
        }