Exemplo n.º 1
0
        public void Update(GameTime gameTime)
        {
            if (!dead)
            {
                GatherInput();
            }

            // This is unacceptable, start level over IMMEDIATELY
            if (Position.Y >= level.bottom)
            {
                scream.Play();
                level.endLevel.Invoke(0);
            }

            HandleJump();

            CheckWalls();

            if (dead)
            {
                currentClip            = death;
                animPlayer.keepPlaying = false;
            }
            else if (jumping || !grounded)
            {
                currentClip = jump;
            }
            else if (Velocity.X != 0.0f)
            {
                currentClip = walk;
            }
            else
            {
                currentClip = idle;
            }

            animPlayer.PlayContinueClip(currentClip, gameTime, 5);

            if (Velocity.X > 0)
            {
                direction = SpriteEffects.None;
            }
            else if (Velocity.X < 0)
            {
                direction = SpriteEffects.FlipHorizontally;
            }

            Position += Velocity;

            CheckCollision();

            camera.CenterOn(Position);
        }
Exemplo n.º 2
0
        public void Update(GameTime gameTime)
        {
            if (dead)
            {
                if (animPlayer.isDone)
                {
                    animPlayer.Freeze();
                }
                animPlayer.PlayContinueClip(currentClip, gameTime, 3);
                return;
            }
            animPlayer.PlayContinueClip(currentClip, gameTime, 3);
            Vector2 velocity = Vector2.Zero;

            checkDieKillPlayer(gameTime);

            if (state == EnemyState.walking)
            {
                currentClip = walk;
                try
                {
                    Tile t;
                    Tile t2;
                    if (direction == SpriteEffects.FlipHorizontally)
                    {
                        t = level.tiles[(int)(EnemyBox.Center.X / Tile.TileSize.X) - 1,
                                        (int)(EnemyBox.Center.Y / Tile.TileSize.Y) + 1];
                        t2 = level.tiles[(int)(EnemyBox.Center.X / Tile.TileSize.X) - 1,
                                         (int)(EnemyBox.Center.Y / Tile.TileSize.X)];
                    }
                    else
                    {
                        t = level.tiles[(int)(EnemyBox.Center.X / Tile.TileSize.X) + 1,
                                        (int)(EnemyBox.Center.Y / Tile.TileSize.Y) + 1];
                        t2 = level.tiles[(int)(EnemyBox.Center.X / Tile.TileSize.X) + 1,
                                         (int)(EnemyBox.Center.Y / Tile.TileSize.X)];
                    }
                    if (t.Behavior == TileBehavior.air || t2.Behavior == TileBehavior.ground)
                    {
                        initialWaitTime = (float)gameTime.TotalGameTime.TotalSeconds;
                        state           = EnemyState.waiting;
                    }
                }
                catch { }
                if (direction == SpriteEffects.FlipHorizontally)
                {
                    velocity = new Vector2(-1, 0);
                }
                else
                {
                    velocity = new Vector2(1, 0);
                }

                Position += velocity;
            }
            else if (state == EnemyState.waiting)
            {
                currentClip = idle;
                if ((float)gameTime.TotalGameTime.TotalSeconds - initialWaitTime > 2.0f)
                {
                    state = EnemyState.walking;
                    if (direction == SpriteEffects.FlipHorizontally)
                    {
                        direction = SpriteEffects.None;
                    }
                    else
                    {
                        direction = SpriteEffects.FlipHorizontally;
                    }
                }
            }
        }