예제 #1
0
파일: Director.cs 프로젝트: zx8326123/LGame
        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);
        }
예제 #2
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;
        }
예제 #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 void SetLocation(LObject objToBePositioned, float atp_W,
				float atp_H, float obj_X, float obj_Y, float obj_XW, float obj_YH,
				Position position) {
			switch (position) {
			case Position.CENTER:
				objToBePositioned.SetX((obj_XW / 2f) - atp_W / 2f);
				objToBePositioned.SetY((obj_YH / 2f) - atp_H / 2f);
				break;
			case Position.SAME:
				objToBePositioned.SetLocation(obj_X, obj_Y);
				break;
			case Position.LEFT:
				objToBePositioned.SetLocation(obj_X, obj_YH / 2f - atp_H / 2f);
				break;
			case Position.TOP_LEFT:
				objToBePositioned.SetLocation(obj_X, obj_YH - atp_H);
				break;
			case Position.TOP_LEFT_CENTER:
				objToBePositioned.SetLocation(obj_X - atp_W / 2f, obj_YH - atp_H
						/ 2f);
				break;
			case Position.TOP_RIGHT:
				objToBePositioned.SetLocation(obj_XW - atp_W, obj_YH - atp_H);
				break;
			case Position.TOP_RIGHT_CENTER:
				objToBePositioned.SetLocation(obj_XW - atp_W / 2f, obj_YH - atp_H
						/ 2f);
				break;
			case Position.TOP_CENTER:
				objToBePositioned.SetLocation(obj_XW / 2f - atp_W / 2f, obj_YH
						- atp_H);
				break;
			case Position.BOTTOM_LEFT:
				objToBePositioned.SetLocation(obj_X, obj_Y);
				break;
			case Position.BOTTOM_LEFT_CENTER:
				objToBePositioned.SetLocation(obj_X - atp_W / 2f, obj_Y - atp_H
						/ 2f);
				break;
			case Position.BOTTOM_RIGHT:
				objToBePositioned.SetLocation(obj_XW - atp_W, obj_Y);
				break;
			case Position.BOTTOM_RIGHT_CENTER:
				objToBePositioned.SetLocation(obj_XW - atp_W / 2f, obj_Y - atp_H
						/ 2f);
				break;
			case Position.BOTTOM_CENTER:
				objToBePositioned.SetLocation(obj_XW / 2f - atp_W / 2f, obj_Y);
				break;
			case Position.RIGHT_CENTER:
				objToBePositioned.SetLocation(obj_XW - atp_W, obj_YH / 2f - atp_H
						/ 2f);
				break;
			default:
				objToBePositioned.SetLocation(objToBePositioned.GetX(),
						objToBePositioned.GetY());
				break;
			}
		}
예제 #5
0
파일: Director.cs 프로젝트: zx8326123/LGame
        private static void SetLocation(LObject objToBePositioned, float atp_W,
                                        float atp_H, float obj_X, float obj_Y, float obj_XW, float obj_YH,
                                        Position position)
        {
            switch (position)
            {
            case Position.CENTER:
                objToBePositioned.SetX((obj_XW / 2f) - atp_W / 2f);
                objToBePositioned.SetY((obj_YH / 2f) - atp_H / 2f);
                break;

            case Position.SAME:
                objToBePositioned.SetLocation(obj_X, obj_Y);
                break;

            case Position.LEFT:
                objToBePositioned.SetLocation(obj_X, obj_YH / 2f - atp_H / 2f);
                break;

            case Position.TOP_LEFT:
                objToBePositioned.SetLocation(obj_X, obj_YH - atp_H);
                break;

            case Position.TOP_LEFT_CENTER:
                objToBePositioned.SetLocation(obj_X - atp_W / 2f, obj_YH - atp_H
                                              / 2f);
                break;

            case Position.TOP_RIGHT:
                objToBePositioned.SetLocation(obj_XW - atp_W, obj_YH - atp_H);
                break;

            case Position.TOP_RIGHT_CENTER:
                objToBePositioned.SetLocation(obj_XW - atp_W / 2f, obj_YH - atp_H
                                              / 2f);
                break;

            case Position.TOP_CENTER:
                objToBePositioned.SetLocation(obj_XW / 2f - atp_W / 2f, obj_YH
                                              - atp_H);
                break;

            case Position.BOTTOM_LEFT:
                objToBePositioned.SetLocation(obj_X, obj_Y);
                break;

            case Position.BOTTOM_LEFT_CENTER:
                objToBePositioned.SetLocation(obj_X - atp_W / 2f, obj_Y - atp_H
                                              / 2f);
                break;

            case Position.BOTTOM_RIGHT:
                objToBePositioned.SetLocation(obj_XW - atp_W, obj_Y);
                break;

            case Position.BOTTOM_RIGHT_CENTER:
                objToBePositioned.SetLocation(obj_XW - atp_W / 2f, obj_Y - atp_H
                                              / 2f);
                break;

            case Position.BOTTOM_CENTER:
                objToBePositioned.SetLocation(obj_XW / 2f - atp_W / 2f, obj_Y);
                break;

            case Position.RIGHT_CENTER:
                objToBePositioned.SetLocation(obj_XW - atp_W, obj_YH / 2f - atp_H
                                              / 2f);
                break;

            default:
                objToBePositioned.SetLocation(objToBePositioned.GetX(),
                                              objToBePositioned.GetY());
                break;
            }
        }