public void PlayContinueClip(Clip clp, GameTime gameTime, int framerate)
 {
     if (clp == playing)
         return;
     playing = clp;
     startTime = (float)gameTime.TotalGameTime.TotalSeconds;
     speed = framerate;
     isDone = false;
 }
Exemple #2
0
 public Enemy(ContentManager content, Camera camera, Level level)
 {
     this.camera = camera;
     this.level = level;
     walk = new Clip(content.Load<Texture2D>("Monsters/e/walk"), 5);
     death = new Clip(content.Load<Texture2D>("Monsters/e/death"), 4);
     idle = new Clip(content.Load<Texture2D>("Monsters/e/idle"), 4);
     squish = content.Load<SoundEffect>("Squish");
     currentClip = walk;
     animPlayer = new AnimationPlayer();
     int d = Helper.rnd.Next(1);
     if (d == 0)
         direction = SpriteEffects.None;
     else
         direction = SpriteEffects.FlipHorizontally;
 }
Exemple #3
0
        public Player(ContentManager content, Camera camera, Level level)
        {
            image = content.Load<Texture2D>("TileMain");

            death = new Clip(content.Load<Texture2D>("Player/death"), 4);
            walk = new Clip(content.Load<Texture2D>("Player/walk"), 5);
            jump = new Clip(content.Load<Texture2D>("Player/jump"), 1);
            idle = new Clip(content.Load<Texture2D>("Player/idle"), 2);
            scream = content.Load<SoundEffect>("Scream");

            animPlayer = new AnimationPlayer();

            currentClip = idle;

            this.camera = camera;
            this.level = level;
        }
Exemple #4
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);
        }
Exemple #5
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;
                }
            }
        }
Exemple #6
0
 private void checkDieKillPlayer(GameTime gameTime)
 {
     if (level.player.FeetBox.Intersects(HeadBox))
     {
         dead = true;
         currentClip = death;
         state = EnemyState.dead;
         animPlayer.keepPlaying = false;
         animPlayer.PlayContinueClip(death, gameTime, 3);
         level.player.ForceJump();
         squish.Play();
     }
     else if (level.player.PlayerBox.Intersects(EnemyBox))
         level.player.Kill(gameTime);
 }