예제 #1
0
        protected Enemy(Texture2D texture, SpawnAreas spawnArea, AiTypes aiType, float speed, List <Animation> animations)
        {
            switch (spawnArea)
            {
            case SpawnAreas.Left:
                spawnX = random.Next(spawnLeft.X, spawnLeft.X + spawnLeft.Width);
                spawnY = random.Next(spawnLeft.Y, spawnLeft.Y + spawnLeft.Height);
                break;

            case SpawnAreas.Middle:
                spawnX = random.Next(spawnMiddle.X, spawnMiddle.X + spawnMiddle.Width);
                spawnY = random.Next(spawnMiddle.Y, spawnMiddle.Y + spawnMiddle.Height);
                break;

            case SpawnAreas.Right:
                spawnX = random.Next(spawnRight.X, spawnRight.X + spawnRight.Width);
                spawnY = random.Next(spawnRight.Y, spawnRight.Y + spawnRight.Height);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(spawnArea), spawnArea, null);
            }

            CollidableObject = new CollidableObject(texture, new Vector2(spawnX, spawnY), new Rectangle(0, 0, 100, 100), 0f);
            _aiType          = aiType;
            this.speed       = speed;

            _animationSet = new AnimationSet(animations, AnimationStates.Walk, AnimationDirections.Down);


            Rectangle initialSourceRectangle = Rectangle.Empty;

            // Set initialSourceRectangle to the first frame in the first animation
            animations[0].SetToFrame(ref initialSourceRectangle, 0);


            // Set initial targets
            switch (aiType)
            {
            case AiTypes.Brute:
                SetTarget(Targets.Knight);
                break;

            case AiTypes.Smart:
                SetTarget(Targets.Door);
                break;

            case AiTypes.Rush:
                SetTarget(Targets.Door);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(aiType), aiType, null);
            }
        }
예제 #2
0
 public Projectile(Texture2D texture, Vector2 from, Vector2 to, float velocity, Rectangle bounds)
 {
     _direction        = Vector2.Normalize(new Vector2(to.X - from.X, to.Y - from.Y));
     _collidableObject = new CollidableObject(texture, from)
     {
         Rotation = (float)Math.Atan(_direction.Y / _direction.X)
     };
     _velocity = velocity;
     _bounds   = bounds;
     Active    = true;
 }
예제 #3
0
        protected Player(Texture2D texture, Vector2 spawnPosition, PlayerControlScheme controlScheme, List <Animation> animations)
        {
            _controlScheme = controlScheme;
            _animationSet  = new AnimationSet(animations, AnimationStates.Idle, AnimationDirections.Down);

            Rectangle initialSourceRectangle = Rectangle.Empty;

            // Set initialSourceRectangle to the first frame in the first animation
            animations[0].SetToFrame(ref initialSourceRectangle, 0);
            CollidableObject = new CollidableObject(texture, spawnPosition, initialSourceRectangle, 0f);
        }
예제 #4
0
 /// <summary>
 /// Creates a new Projectile
 /// </summary>
 /// <param name="texture"></param>
 /// <param name="position">The spawn position of the object</param>
 /// <param name="velocity"></param>
 /// <param name="rotation"></param>
 /// <param name="bounds">Play area bounds for where the arrow can be</param>
 public Projectile(Texture2D texture, Vector2 position, float velocity, float rotation, Rectangle bounds)
 {
     // Create a new collidableobject
     _collidableObject = new CollidableObject(texture, position)
     {
         Rotation = rotation
     };
     // Set velocity
     _velocity = velocity;
     // Set direction
     _direction = new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation));
     _bounds    = bounds;
     Active     = true;
 }
예제 #5
0
 /// <summary>
 ///     Detects a pixel level collision between this and an other CollidableObject.
 /// </summary>
 /// <param name="collidable">The CollidableObject to check a collision against</param>
 /// <returns>True if colliding, false if not.</returns>
 public bool IsColliding(CollidableObject collidable)
 {
     // If rectangle of objects intersects
     if (BoundingRectangle.Intersects(collidable.BoundingRectangle))
     {
         // And any of the pixels of objects intersect
         if (IntersectPixels(Transform, SourceRectangle, TextureData, collidable.Transform, collidable.SourceRectangle, collidable.TextureData))
         {
             // Then return true
             return(true);
         }
     }
     // Else return false
     return(false);
 }