public void CheckCollision()
 {
     if (CollisionEngine.CollisionCheck(new Rectangle((int)(pos.X - dims.X / 2), (int)(pos.Y - dims.Y / 2), (int)dims.X, (int)dims.Y), Globals.currWorld.levels[Globals.currWorld.currLevel].platforms))
     {
         parent.DeleteProjectile(this);
     }
     if (CollisionEngine.CollisionCheck(new Rectangle((int)pos.X, (int)pos.Y, (int)dims.X, (int)dims.Y), ((CollisionObject)Globals.currWorld.hero).GetCollisionBox()))
     {
         ((Entity)Globals.currWorld.hero).GetHit(damage);
         parent.DeleteProjectile(this);
     }
 }
 public void Attack()
 {
     isAttacking = true;
     if (attackingCounter == new TimeSpan(0))
     {
         CollisionObject[] entities = GetClosestTwoX(ObjOnY(Globals.currWorld.levels[Globals.currWorld.currLevel].entities, GetCollisionBox().Center.Y), GetCollisionBox().Center.X);
         if (lastDirRight)
         {
             if (entities[1] != null && !CollisionEngine.CollisionCheck(Globals.currWorld.levels[Globals.currWorld.currLevel].platforms, new Segment(new Vector2(GetCollisionBox().Center.X, GetCollisionBox().Center.Y), new Vector2(entities[1].GetCollisionBox().Center.X, entities[1].GetCollisionBox().Center.Y))))
             {
                 ((Entity)entities[1]).GetHit(damage);
             }
         }
         else
         {
             if (entities[0] != null && !CollisionEngine.CollisionCheck(Globals.currWorld.levels[Globals.currWorld.currLevel].platforms, new Segment(new Vector2(GetCollisionBox().Center.X, GetCollisionBox().Center.Y), new Vector2(entities[0].GetCollisionBox().Center.X, entities[0].GetCollisionBox().Center.Y))))
             {
                 ((Entity)entities[0]).GetHit(damage);
             }
         }
     }
 }
예제 #3
0
 /// <summary>
 /// Determines what the AI will do based on wether the player is on view and where he is on the platform.
 /// </summary>
 public void ComputeInput()
 {
     if (VisionBox().Intersects(((CollisionObject)Globals.currWorld.hero).GetCollisionBox()) || VisionBox().Contains(((CollisionObject)Globals.currWorld.hero).GetCollisionBox()) || ((CollisionObject)Globals.currWorld.hero).GetCollisionBox().Contains(VisionBox()))
     {
         if (!CollisionEngine.CollisionCheck(Globals.currWorld.levels[Globals.currWorld.currLevel].platforms, new Segment(new Vector2(GetCollisionBox().Center.X, GetCollisionBox().Top), new Vector2(Globals.currWorld.hero.GetCollisionBox().Center.X, Globals.currWorld.hero.GetCollisionBox().Top))))
         {
             if (!isAttacking)
             {
                 viewingDistance *= 2;
             }
             if (pos.X > Globals.currWorld.hero.pos.X)
             {
                 lastDirRight = false;
             }
             else
             {
                 lastDirRight = true;
             }
             Attack();
             vector      = Vector2.Zero;
             isAttacking = true;
         }
     }
     else
     {
         if (isAttacking)
         {
             viewingDistance /= 2;
         }
         isAttacking      = false;
         attackingCounter = new TimeSpan(0, 0, 0, 1, 250);
     }
     if (!isAttacking)
     {
         if (physicsVector.Y > 0.1f)
         {
             walkingSegment = null;
         }
         else
         {
             if (walkingSegment != null)
             {
                 if (Math.Sign(physicsVector.X) != Math.Sign(goingTo.X - pos.X) && Math.Sign(physicsVector.X) != 0 && Math.Abs(physicsVector.X) > 0.5)
                 {
                     if (goingTo == walkingSegment.defPoint1)
                     {
                         goingTo = walkingSegment.defPoint2;
                     }
                     else
                     {
                         goingTo = walkingSegment.defPoint1;
                     }
                 }
                 if (Math.Abs(goingTo.X - pos.X) < dims.X)
                 {
                     if (goingTo == walkingSegment.defPoint1)
                     {
                         goingTo = walkingSegment.defPoint2;
                     }
                     else
                     {
                         goingTo = walkingSegment.defPoint1;
                     }
                 }
                 if (Math.Sign(goingTo.X - pos.X) < 0)
                 {
                     if (vector.X > -speed)
                     {
                         vector.X += Math.Sign(goingTo.X - pos.X) * walkingAccelaration;
                     }
                 }
                 else
                 {
                     if (vector.X < speed)
                     {
                         vector.X += Math.Sign(goingTo.X - pos.X) * walkingAccelaration;
                     }
                 }
             }
             else
             {
                 FindNewWalkingSegment();
                 if (walkingSegment != null)
                 {
                     if (lastDirRight)
                     {
                         if (walkingSegment.defPoint1.X > walkingSegment.defPoint2.X)
                         {
                             goingTo = walkingSegment.defPoint1;
                         }
                         else
                         {
                             goingTo = walkingSegment.defPoint2;
                         }
                     }
                     else
                     {
                         if (walkingSegment.defPoint1.X > walkingSegment.defPoint2.X)
                         {
                             goingTo = walkingSegment.defPoint2;
                         }
                         else
                         {
                             goingTo = walkingSegment.defPoint1;
                         }
                     }
                 }
             }
         }
     }
 }