Пример #1
0
		private static Vector2f CreateOrigin(LObject o, Origin origin) {
			Vector2f v = new Vector2f(o.X(), o.Y());
			switch (origin) {
			case Origin.CENTER:
				v.Set(o.GetWidth() / 2f, o.GetHeight() / 2f);
				return v;
			case Origin.TOP_LEFT:
				v.Set(0.0f, o.GetHeight());
				return v;
			case Origin.TOP_RIGHT:
				v.Set(o.GetWidth(), o.GetHeight());
				return v;
			case Origin.BOTTOM_LEFT:
				v.Set(0.0f, 0.0f);
				return v;
			case Origin.BOTTOM_RIGHT:
				v.Set(o.GetWidth(), 0.0f);
				return v;
			case Origin.LEFT_CENTER:
				v.Set(0.0f, o.GetHeight() / 2f);
				return v;
			case Origin.TOP_CENTER:
				v.Set(o.GetWidth() / 2f, o.GetHeight());
				return v;
			case Origin.BOTTOM_CENTER:
				v.Set(o.GetWidth() / 2f, 0.0f);
				return v;
			case Origin.RIGHT_CENTER:
				v.Set(o.GetWidth(), o.GetHeight() / 2f);
				return v;
			default:
				return v;
			}
		}
Пример #2
0
        public static void SetPoisiton(LObject objToBePositioned, float x, float y,
                                       float width, float height, Position position)
        {
            float atp_W  = objToBePositioned.GetWidth();
            float atp_H  = objToBePositioned.GetHeight();
            float obj_X  = x;
            float obj_Y  = y;
            float obj_XW = width + obj_X;
            float obj_YH = height + obj_Y;

            SetLocation(objToBePositioned, atp_W, atp_H, obj_X, obj_Y, obj_XW,
                        obj_YH, position);
        }
Пример #3
0
        public static void SetPoisiton(LObject objToBePositioned,
                                       LObject objStable, Position position)
        {
            float atp_W  = objToBePositioned.GetWidth();
            float atp_H  = objToBePositioned.GetHeight();
            float obj_X  = objStable.GetX();
            float obj_Y  = objStable.GetY();
            float obj_XW = objStable.GetWidth() + obj_X;
            float obj_YH = objStable.GetHeight() + obj_Y;

            SetLocation(objToBePositioned, atp_W, atp_H, obj_X, obj_Y, obj_XW,
                        obj_YH, position);
        }
Пример #4
0
        private static Vector2f CreateOrigin(LObject o, Origin origin)
        {
            Vector2f v = new Vector2f(o.X(), o.Y());

            switch (origin)
            {
            case Origin.CENTER:
                v.Set(o.GetWidth() / 2f, o.GetHeight() / 2f);
                return(v);

            case Origin.TOP_LEFT:
                v.Set(0.0f, o.GetHeight());
                return(v);

            case Origin.TOP_RIGHT:
                v.Set(o.GetWidth(), o.GetHeight());
                return(v);

            case Origin.BOTTOM_LEFT:
                v.Set(0.0f, 0.0f);
                return(v);

            case Origin.BOTTOM_RIGHT:
                v.Set(o.GetWidth(), 0.0f);
                return(v);

            case Origin.LEFT_CENTER:
                v.Set(0.0f, o.GetHeight() / 2f);
                return(v);

            case Origin.TOP_CENTER:
                v.Set(o.GetWidth() / 2f, o.GetHeight());
                return(v);

            case Origin.BOTTOM_CENTER:
                v.Set(o.GetWidth() / 2f, 0.0f);
                return(v);

            case Origin.RIGHT_CENTER:
                v.Set(o.GetWidth(), o.GetHeight() / 2f);
                return(v);

            default:
                return(v);
            }
        }
Пример #5
0
 public static void BottomOn(LObject obj0, int w, int h)
 {
     obj0.SetLocation(w / 2 - obj0.GetWidth() / 2,
                      h - obj0.GetHeight());
 }
Пример #6
0
 public static void RightOn(LObject obj0, int w, int h)
 {
     obj0.SetLocation(w - obj0.GetWidth(), h / 2 - obj0.GetHeight()
                      / 2);
 }
Пример #7
0
 public static void LeftOn(LObject obj0, int w, int h)
 {
     obj0.SetLocation(0, h / 2 - obj0.GetHeight() / 2);
 }
Пример #8
0
 public static void CenterOn(LObject obj0, int w, int h)
 {
     obj0.SetLocation(w / 2 - obj0.GetWidth() / 2,
                      h / 2 - obj0.GetHeight() / 2);
 }
Пример #9
0
 public static void BottomOn(LObject obj0, int w, int h)
 {
     obj0.SetLocation(w / 2 - obj0.GetWidth() / 2,
             h - obj0.GetHeight());
 }
Пример #10
0
 public static void RightOn(LObject obj0, int w, int h)
 {
     obj0.SetLocation(w - obj0.GetWidth(), h / 2 - obj0.GetHeight()
             / 2);
 }
Пример #11
0
 public static void LeftOn(LObject obj0, int w, int h)
 {
     obj0.SetLocation(0, h / 2 - obj0.GetHeight() / 2);
 }
Пример #12
0
 public static void CenterOn(LObject obj0, int w, int h)
 {
     obj0.SetLocation(w / 2 - obj0.GetWidth() / 2,
             h / 2 - obj0.GetHeight() / 2);
 }
Пример #13
0
        public Vector2f GetTileCollision(LObject o, float newX, float newY)
        {
            newX = MathUtils.Ceil(newX);
            newY = MathUtils.Ceil(newY);

            float fromX = MathUtils.Min(o.GetX(), newX);
            float fromY = MathUtils.Min(o.GetY(), newY);
            float toX = MathUtils.Max(o.GetX(), newX);
            float toY = MathUtils.Max(o.GetY(), newY);

            int fromTileX = field.PixelsToTilesWidth(fromX);
            int fromTileY = field.PixelsToTilesHeight(fromY);
            int toTileX = field.PixelsToTilesWidth(toX + o.GetWidth() - 1f);
            int toTileY = field.PixelsToTilesHeight(toY + o.GetHeight() - 1f);

            for (int x = fromTileX; x <= toTileX; x++)
            {
                for (int y = fromTileY; y <= toTileY; y++)
                {
                    if ((x < 0) || (x >= this.GetWidth()))
                    {
                        return new Vector2f(x, y);
                    }
                    if ((y < 0) || (y >= this.GetHeight()))
                    {
                        return new Vector2f(x, y);
                    }

                    if (this.IsHit(x, y))
                    {
                        return new Vector2f(x, y);
                    }
                }
            }

            return null;
        }
Пример #14
0
		public static void SetPoisiton(LObject objToBePositioned, float x, float y,
				float width, float height, Position position) {
			float atp_W = objToBePositioned.GetWidth();
			float atp_H = objToBePositioned.GetHeight();
			float obj_X = x;
			float obj_Y = y;
			float obj_XW = width + obj_X;
			float obj_YH = height + obj_Y;
			SetLocation(objToBePositioned, atp_W, atp_H, obj_X, obj_Y, obj_XW,
					obj_YH, position);
		}
Пример #15
0
		public static void SetPoisiton(LObject objToBePositioned,
				LObject objStable, Position position) {
			float atp_W = objToBePositioned.GetWidth();
			float atp_H = objToBePositioned.GetHeight();
			float obj_X = objStable.GetX();
			float obj_Y = objStable.GetY();
			float obj_XW = objStable.GetWidth() + obj_X;
			float obj_YH = objStable.GetHeight() + obj_Y;
			SetLocation(objToBePositioned, atp_W, atp_H, obj_X, obj_Y, obj_XW,
					obj_YH, position);
		}