Exemplo n.º 1
0
 /// <summary>
 /// Collisions the specified entity.
 /// </summary>
 /// <param name="player">The player.</param>
 /// <param name="npc">The NPC.</param>
 /// <returns></returns>
 public static bool collision(Player player, NPC npc)
 {
     if (npc.visible) {
         if (npc.attacking) //Waarom controleren op collision als ie toch stilstaat...
         {
             TimeSpan hitTimePassed = DateTime.Now - npc.lastHit;
             if (hitTimePassed.TotalMilliseconds >= npc.definition.attackSpeed)
             {
                 if (player.electricWallTimer > 0)
                 {
                     npc.hit(new Hit(npc, player, player.Damage));
                 }
                 player.hit(new Hit(player, npc, GameWorld.random.Next(1, npc.Damage)));
                 npc.lastHit = DateTime.Now;
             }
             return true;
         }
         GifAnimation mainTexture = npc.definition.mainTexture;
         Rectangle npcRectangle = new Rectangle(npc.getX(), npc.getY(), mainTexture.Width, mainTexture.Height);
         Rectangle wallRectangle = new Rectangle(player.Wall.getX(), player.Wall.getY(), player.Wall.definition.mainTexture.Width, player.Wall.definition.mainTexture.Height);
         if (intersects(npcRectangle, wallRectangle) && (npc.getX() >= (player.Wall.getX() + player.Wall.definition.mainTexture.Width / 2) - npc.definition.mainTexture.Width))
         {
             Matrix npcMatrix = Matrix.CreateTranslation(npc.getX(), npc.getY(), 0);
             Matrix wallMatrix = Matrix.CreateTranslation(player.Wall.getX(), player.Wall.getY(), 0);
             Vector2 collision = texturesCollide(player.Wall.definition.pixels, wallMatrix, npc.definition.pixels, npcMatrix);
             if (collision.X != -1 && collision.Y != -1)
             {
                 TimeSpan hitTimePassed = DateTime.Now - npc.lastHit;
                 if (hitTimePassed.TotalMilliseconds >= npc.definition.attackSpeed)
                 {
                     if (player.electricWallTimer > 0)
                     {
                         npc.hit(new Hit(npc, player, player.Damage));
                     }
                     player.hit(new Hit(player, npc, GameWorld.random.Next(1, npc.Damage)));
                     npc.attacking = true;
                     npc.lastHit = DateTime.Now;
                 }
                 return true;
             }
         }
     }
     return false;
 }