Beispiel #1
0
 public override void Die(BaseCharacter killer)
 {
     if (killer.tag == MainGame.Tag.Bomber) {
         Explode();
     }
     else {
         base.Die(killer);
     }
 }
 public virtual void Die(BaseCharacter killer)
 {
     dead = true;
 }
        protected void UpdateMovement(GameTime gameTime)
        {
            Vector2 direction = input.GetDirection();
            if (direction == Vector2.Zero) {
                velocity.X = MathHelper.Lerp(velocity.X, 0, deceleration_Walk);
                if (MathHelper.Distance(velocity.X, 0) < 0.01f)
                    velocity.X = 0;
                velocity.Y = MathHelper.Lerp(velocity.Y, 0, deceleration_Walk);
                if (MathHelper.Distance(velocity.Y, 0) < 0.01f)
                    velocity.Y = 0;
            }
            else {
                velocity += direction * acceleration_Walk;
            }
            velocity = new Vector2(MathHelper.Clamp(velocity.X, -1f, 1f), MathHelper.Clamp(velocity.Y, -1f, 1f));

            Vector2 newPosition = position + (velocity * speed_Walk) * (float)gameTime.ElapsedGameTime.TotalSeconds;

            //Clamp position to scene borders
            newPosition = new Vector2(MathHelper.Clamp(newPosition.X, 0 + baseRectangle.Width * 0.5f,
                                                       game.graphics.PreferredBackBufferWidth - baseRectangle.Width * 0.5f),
                                      MathHelper.Clamp(newPosition.Y, 0 + baseRectangle.Height * 0.5f,
                                                       game.graphics.PreferredBackBufferHeight - baseRectangle.Height * 0.5f));

            characterHit = null;
            characterHit = GetCollisions(newPosition);

            if (characterHit == null) {
                position = newPosition;
            }
            else {
                collided = true;
                velocity = Vector2.Zero;
            }
        }
 public virtual void Reset()
 {
     respawnTimer = new Timer();
     characterHit = null;
     collided = false;
     dead = false;
 }
        public BaseCharacter GetCollisions(Vector2 position)
        {
            List<BaseCharacter> characterList = game.sceneControl.gameplay.characterList;
            characterList = characterList.Where(character => character != this).ToList();
            characterList = characterList.Where(character => !character.dead).ToList();

            Rectangle newCollisionRectangle = new Rectangle((int)position.X,
                                                         (int)position.Y,
                                                         (int)baseRectangle.Width,
                                                         (int)baseRectangle.Height);

            BaseCharacter characterHit = null;
            foreach (BaseCharacter character in characterList) {
                if (newCollisionRectangle.Intersects(character.CollisionRectangle)) {
                    characterHit = character;
                    break;
                }
            }
            return characterHit;
        }