コード例 #1
0
 static void MoveY(Ihn ihn, Entity entity, ComponentPosition pos, ComponentVelocity velocity)
 {
     pos.Y += velocity.Y;
     if (CollisionHelper.Colliding(ihn, entity))
     {
         pos.Y -= velocity.Y;
         int runs = 0;
         while (!CollisionHelper.Colliding(ihn, entity) && runs < Math.Abs(velocity.Y) + 2)
         {
             runs++;
             pos.Y += velocity.Y > 0 ? 1 : -1;
         }
         pos.Y -= velocity.Y > 0 ? 1 : -1;
     }
 }
コード例 #2
0
 /// <summary>
 /// Gets the boundries of an entity
 /// </summary>
 /// <param name="entity">Entity to get bounds for</param>
 /// <param name="pos">Position of the entity</param>
 /// <param name="x">outs the x coord to this</param>
 /// <param name="y">outs the y coord to this</param>
 /// <param name="w">outs the width to this</param>
 /// <param name="h">outs the height to this</param>
 public static void GetBounds(Entity entity, ComponentPosition pos, out float x, out float y, out int w, out int h)
 {
     x = pos.X;
     y = pos.Y;
     w = 0;
     h = 0;
     if (entity.HasComp <ComponentAABB>())
     {
         var aabb = entity.GetComp <ComponentAABB>();
         x = aabb.X;
         y = aabb.Y;
         w = aabb.Width;
         h = aabb.Height;
     }
     else if (entity.HasComp <ComponentTopDownEightDirSprite>())
     {
         var spr = entity.GetComp <ComponentTopDownEightDirSprite>();
         x -= Rsc.Load <Texture2D>(spr.Texture).Width / 8;
         y -= Rsc.Load <Texture2D>(spr.Texture).Height / 4;
         w  = Rsc.Load <Texture2D>(spr.Texture).Width / 4;
         h  = Rsc.Load <Texture2D>(spr.Texture).Height / 2;
     }
     else if (entity.HasComp <ComponentSize>())
     {
         w = entity.GetComp <ComponentSize>().Width;
         h = entity.GetComp <ComponentSize>().Height;
     }
     else if (entity.HasComp <ComponentSprite>())
     {
         var spr = entity.GetComp <ComponentSprite>();
         x -= spr.Origin.X;
         y -= spr.Origin.Y;
         w  = Rsc.Load <Texture2D>(spr.Texture).Width;
         h  = Rsc.Load <Texture2D>(spr.Texture).Height;
     }
 }