Exemplo n.º 1
0
    public override bool IsIntersect(Object2D geometry, float epsilon = 0)
    {
        if (geometry is LineSegment2D)
        {
            LineSegment2D otherLine = (LineSegment2D)geometry;

            // 두 object2D가 서로 다른 좌표계를 가지므로 global 좌표계로 통일
            Vector2 p1 = transform.TransformPoint(this.p1), p2 = transform.TransformPoint(this.p2);
            Vector2 p3 = otherLine.transform.TransformPoint(otherLine.p1), p4 = otherLine.transform.TransformPoint(otherLine.p2);

            float under = (p4.y - p3.y) * (p2.x - p1.x) - (p4.x - p3.x) * (p2.y - p1.y);

            if (under == 0)
            {
                return(false);
            }

            float t = ((p4.x - p3.x) * (p1.y - p3.y) - (p4.y - p3.y) * (p1.x - p3.x)) / under; // this line
            float s = ((p2.x - p1.x) * (p1.y - p3.y) - (p2.y - p1.y) * (p1.x - p3.x)) / under; // other line

            if (t < 0.0 || t > 1.0 || s < 0.0 || s > 1.0)
            {
                return(false);
            }

            return(true);
        }
        else
        {
            throw new System.NotImplementedException();
        }
    }
    public (Redirector.GainType, float) RealMove(Object2D realUser, Redirector.GainType type, float degree)
    {
        Transform2D realUserTransform = realUser.transform;
        float       appliedGain       = 0;

        switch (type)
        {
        case Redirector.GainType.Translation:
            realUser.Translate(realUserTransform.forward * degree * Time.fixedDeltaTime, Space.World);
            break;

        case Redirector.GainType.Rotation:
            realUser.Rotate(degree * Time.fixedDeltaTime);
            break;

        case Redirector.GainType.Curvature:
            realUser.Translate(realUserTransform.forward * deltaPosition.magnitude * Time.fixedDeltaTime, Space.World);
            realUser.Rotate(degree * Time.fixedDeltaTime);
            break;

        default:
            break;
        }

        return(type, appliedGain);
    }
Exemplo n.º 3
0
 public ControlsGameState()
 {
     controls = new Object2D("Controls");
     black    = new Object2D("black");
     timer    = 0;
     fader    = 0;
 }
Exemplo n.º 4
0
 public Stamina()
 {
     backGround = new Object2D("HUD\\Stamina\\Exhausted Empty Stamina");
     exhaustedBar = new Object2D("HUD\\Stamina\\Exhausted Full Stamina");
     fullBar = new Object2D("HUD\\Stamina\\Full Stamina");
     position = new Vector2(20, 20);
 }
Exemplo n.º 5
0
    //public Redirector(RedirectedUnit redirectedUnit) {
    //    this.redirectedUnit = redirectedUnit;
    //}

    //public void SetReferences(RedirectedUnit redirectedUnit) {
    //    this.redirectedUnit = redirectedUnit;
    //}

    public virtual (GainType, float) ApplyRedirection(Object2D realUser, Vector2 deltaPosition, float deltaRotation)
    {
        float    degree = 0;
        GainType type   = GainType.Undefined;

        return(type, degree);
    }
        protected override double CalculateFitResult(Object2D objectToPlace, int widthLeftInShelf, int shelfLevel, int shelfHeight, int containerWidth, int ContainerHeight)
        {
            // Don't fit (container height)
            if (objectToPlace.Height + shelfLevel > ContainerHeight)
            {
                return(Double.MaxValue);
            }
            // Don't fit (shelf height)
            else if (objectToPlace.Height > shelfHeight && shelfHeight != 0)
            {
                return(Double.MaxValue);
            }
            // Don't fit (width)
            else if (objectToPlace.Width > widthLeftInShelf)
            {
                return(Double.MaxValue);
            }
            else
            {
                int availableArea, availableHeight;

                if (shelfHeight == 0)
                {
                    availableHeight = ContainerHeight - shelfLevel;
                }
                else
                {
                    availableHeight = shelfHeight;
                }

                availableArea = availableHeight * widthLeftInShelf;

                return((double)(1 / (availableArea / objectToPlace.Area)));
            }
        }
Exemplo n.º 7
0
        public override void start()
        {
            GameObject objLayer = UIMgr.CreateLayer(layerNo);

            if (objLayer == null)
            {
                return;
            }

            objLayer.transform.parent.gameObject.SetActive(true);
            objLayer.SetActive(true);

            Object2D   info   = UIMgr.GetItemInfo(itemID);
            GameObject objPic = null;

            if (info != null)
            {
                objPic = info.gameObject;
            }
            else
            {
                objPic      = UIMgr.CreatePic(objLayer);
                objPic.name = itemID;
            }

            Object2D picShow = objPic.GetComponent <Object2D>();

            picShow.AddAction(this);

            this.isEnd = true;
        }
Exemplo n.º 8
0
    public override bool IsIntersect(Object2D geometry, float epsilon = 0)
    {
        if (geometry is LineSegment2D)
        {
            LineSegment2D line           = (LineSegment2D)geometry;
            int           numOfIntersect = 0;

            for (int i = 0; i < vertices.Count; i++)
            {
                LineSegment2D boundary = new LineSegment2D(vertices[i], vertices[(i + 1) % 4], transform);

                //Vector2 result;
                if (boundary.IsIntersect(line))
                {
                    numOfIntersect += 1;
                }
            }

            if (numOfIntersect == 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
        else
        {
            throw new System.NotImplementedException();
        }
    }
Exemplo n.º 9
0
        private void ShowToken(Random random, BattleToken token, Object2D parent, int index)
        {
            var tokenObj = new BattleTokenView(token);

            Tokens[token.Index] = tokenObj;
            Layer.AddObject(tokenObj);

            var x = (float)random.NextDouble() * 2 - 1;
            var y = (float)random.NextDouble() * 2 - 1;

            tokenObj.Position = coordinateConverter.Convert(new Vector2DF(x, y));

            var profileObj = new ProfileCardView(token, headerFont, planeFont);

            Profiles[token.Index] = profileObj;
            parent.AddChild(profileObj, ChildManagementMode.Disposal | ChildManagementMode.RegistrationToLayer,
                            ChildTransformingMode.All);

            var sizeX = 160.0f;
            var px    = (index % 2) * (sizeX + 4);
            var py    = (index / 2) * (sizeX * 1.61805f + 4);

            profileObj.Position = new Vector2DF(-px, -py) - new Vector2DF(sizeX, sizeX * 1.61805f);

            var scale = sizeX / profileObj.CardSize.X;

            profileObj.Scale = new Vector2DF(scale, scale);
        }
 public ControlsGameState()
 {
     controls = new Object2D("Controls");
     black = new Object2D("black");
     timer = 0;
     fader = 0;
 }
Exemplo n.º 11
0
    public static void SyncDirection(Object2D virtualUser, Object2D realUser, Vector2 virtualTargetDirection, Vector2 realTargetDirection) // 회전 오차로 인한 시뮬레이션 정확도 저하를 막기 위해 Direction을 동기화 시켜줌
    {
        if (virtualTargetDirection.magnitude > 1)
        {
            virtualTargetDirection = virtualTargetDirection.normalized;
        }
        if (realTargetDirection.magnitude > 1)
        {
            realTargetDirection = realTargetDirection.normalized;
        }

        //Debug.Log(string.Format("Before virtualUser.transform: {0}", virtualUser.transform));

        virtualUser.transform.forward = virtualTargetDirection;
        realUser.transform.forward    = realTargetDirection;

        //Debug.Log(string.Format("After virtualUser.transform.forward: {0}", virtualUser.transform));

        if (virtualUser.gameObject != null)
        {
            virtualUser.gameObject.transform.forward = Utility.Cast2Dto3D(virtualTargetDirection);
        }
        if (realUser.gameObject != null)
        {
            realUser.gameObject.transform.forward = Utility.Cast2Dto3D(realTargetDirection);
        }
    }
Exemplo n.º 12
0
    public override bool IsIntersect(Object2D geometry, float epsilon = 0)
    {
        if (geometry is Circle2D)
        {
            Circle2D other         = (Circle2D)geometry;
            Vector2  otherPosition = other.transform.position;
            Vector2  thisPosition  = this.transform.position;
            float    otherRadius   = other.GetRadius();

            if (Mathf.Abs(Vector2.Distance(thisPosition, otherPosition) - (otherRadius + this.radius)) < epsilon) // 차이가 epsilon 만큼이라면 intersect 했다고 판단
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        else if (geometry is Polygon2D)
        {
            throw new System.NotImplementedException();
        }
        else if (geometry is LineSegment2D)
        {
            throw new System.NotImplementedException();
        }
        else
        {
            throw new System.NotImplementedException();
        }
    }
    public PauseScreenState()
    {
        //Add a background image
        background = new Object2D("Notes\\Note blank", 0);
        gameObjects.Add(background);

        //Add text: paused
        paused = new Object2D("Menu Buttons\\Paused");
        gameObjects.Add(paused);

        //Add a resume button
        continueButton = new Button("Menu Buttons\\Menu button Continue", 0);
        gameObjects.Add(continueButton);

        //Add a mouse-over continue button
        continueButtonMouseOver = new Button("Menu Buttons\\Menu button Continue MouseOver", 0);
        gameObjects.Add(continueButtonMouseOver);
        continueButtonMouseOver.Visible = false;

        //Add an exit button
        exitButton = new Button("Menu Buttons\\Menu button Exit", 0);
        gameObjects.Add(exitButton);

        //Add a mouse-over exit button
        exitButtonMouseOver = new Button("Menu Buttons\\Menu button Exit MouseOver", 0);
        gameObjects.Add(exitButtonMouseOver);
        exitButtonMouseOver.Visible = false;
    }
 public BeginGameState()
 {
     logo = new Object2D("FancyPandaLogo");
     timer = 0;
     fader = 0;
     fader2 = 0;
 }
Exemplo n.º 15
0
 public void CopyTo(Object2D other)
 {
     other.Guid = Guid;
     other.Name = Name;
     other.PrefabName = PrefabName;
     other.Position = Position;
 }
Exemplo n.º 16
0
 public BeginGameState()
 {
     logo   = new Object2D("FancyPandaLogo");
     timer  = 0;
     fader  = 0;
     fader2 = 0;
 }
Exemplo n.º 17
0
        public void Ins()
        {
            Object2D Obj = Presets.Load(LinkedObject.ObjectName);

            Obj.Position = new Vector2(Rand.RandomFloat(0, Screen.Resolution.X), Rand.RandomFloat(0, Screen.Resolution.Y));
            UI.AddWindow.Dispose(true);
        }
    public PauseScreenState()
    {
        //Add a background image
        background = new Object2D("Notes\\Note blank", 0);
        gameObjects.Add(background);

        //Add text: paused
        paused = new Object2D("Menu Buttons\\Paused");
        gameObjects.Add(paused);

        //Add a resume button
        continueButton = new Button("Menu Buttons\\Menu button Continue", 0);
        gameObjects.Add(continueButton);

        //Add a mouse-over continue button
        continueButtonMouseOver = new Button("Menu Buttons\\Menu button Continue MouseOver", 0);
        gameObjects.Add(continueButtonMouseOver);
        continueButtonMouseOver.Visible = false;

        //Add an exit button
        exitButton = new Button("Menu Buttons\\Menu button Exit", 0);
        gameObjects.Add(exitButton);

        //Add a mouse-over exit button
        exitButtonMouseOver = new Button("Menu Buttons\\Menu button Exit MouseOver", 0);
        gameObjects.Add(exitButtonMouseOver);
        exitButtonMouseOver.Visible = false;
    }
Exemplo n.º 19
0
        public override void start()
        {
            //Debug.Log("Run Action : " + actID + " " + this.name);

            GameObject objLayer = UIMgr.CreateLayer(layer);

            if (objLayer == null)
            {
                return;
            }
            objLayer.SetActive(true);

            if (string.IsNullOrEmpty(assetID))
            {
                return;
            }

            Object2D   info   = UIMgr.GetItemInfo(itemID);
            GameObject objPic = null;

            if (info != null)
            {
                objPic = info.gameObject;
            }
            else
            {
                objPic      = UIMgr.CreatePic(objLayer);
                objPic.name = itemID;
            }

            info.AddAction(this);

            this.isEnd = true;
        }
Exemplo n.º 20
0
 public Stamina()
 {
     backGround   = new Object2D("HUD\\Stamina\\Exhausted Empty Stamina");
     exhaustedBar = new Object2D("HUD\\Stamina\\Exhausted Full Stamina");
     fullBar      = new Object2D("HUD\\Stamina\\Full Stamina");
     position     = new Vector2(20, 20);
 }
Exemplo n.º 21
0
    public GameOverState()
    {
        //Add the background sprite
        background = new Object2D("Menu Buttons\\Blood", 0);
        gameObjects.Add(background);

        //Add text: game over
        gameOver = new Object2D("Menu Buttons\\GameOver");
        gameObjects.Add(gameOver);

        //add a continue button
        continueButton = new Button("Menu Buttons\\Menu button Continue", 0);
        gameObjects.Add(continueButton);

        //Add a mouse-over continue button
        continueButtonMouseOver = new Button("Menu Buttons\\Menu button Continue MouseOver", 0);
        gameObjects.Add(continueButtonMouseOver);
        continueButtonMouseOver.Visible = false;

        //add an exit button
        exitButton = new Button("Menu Buttons\\Menu button Exit", 0);
        gameObjects.Add(exitButton);

        //Add a mouse-over exit button
        exitButtonMouseOver = new Button("Menu Buttons\\Menu button Exit MouseOver", 0);
        gameObjects.Add(exitButtonMouseOver);
        exitButtonMouseOver.Visible = false;
    }
    public GameOverState()
    {
        //Add the background sprite
        background = new Object2D("Menu Buttons\\Blood", 0);
        gameObjects.Add(background);

        //Add text: game over
        gameOver = new Object2D("Menu Buttons\\GameOver");
        gameObjects.Add(gameOver);

        //add a continue button
        continueButton = new Button("Menu Buttons\\Menu button Continue", 0);
        gameObjects.Add(continueButton);

        //Add a mouse-over continue button
        continueButtonMouseOver = new Button("Menu Buttons\\Menu button Continue MouseOver", 0);
        gameObjects.Add(continueButtonMouseOver);
        continueButtonMouseOver.Visible = false;

        //add an exit button
        exitButton = new Button("Menu Buttons\\Menu button Exit", 0);
        gameObjects.Add(exitButton);

        //Add a mouse-over exit button
        exitButtonMouseOver = new Button("Menu Buttons\\Menu button Exit MouseOver", 0);
        gameObjects.Add(exitButtonMouseOver);
        exitButtonMouseOver.Visible = false;
    }
Exemplo n.º 23
0
        public override void start()
        {
            Object2D info = UIMgr.GetItemInfo(itemID);

            EventTrigger trigger = info.gameObject.GetComponent <EventTrigger>();

            trigger.enabled = false;
        }
Exemplo n.º 24
0
 /// <summary>
 /// ウィンドウにオブジェクトを追加する
 /// </summary>
 /// <param name="object_2d"> 追加するオブジェクト </param>
 public void AddObject(Object2D object_2d)
 {
     AddChild(
         object_2d,
         ChildManagementMode.RegistrationToLayer,
         ChildTransformingMode.Position
         );
 }
 public void SyncPosition(Object2D virtualUser, Vector2 virtualTargetPosition)
 {
     virtualUser.transform.localPosition = virtualTargetPosition;
     if (virtualUser.gameObject != null)
     {
         virtualUser.gameObject.transform.localPosition = Utility.Cast2Dto3D(virtualTargetPosition);
     }
 }
Exemplo n.º 26
0
        public void PlaceNewObject(Object2D theObject, Position2D position)
        {
            LastPlacedObject = (PlaceObject(theObject, position)) as PlacedObject2D;

            MakeSkylineUnavailable(LastPlacedObject);

            CreateSkylineAtopObject(LastPlacedObject);
        }
Exemplo n.º 27
0
 public static void Save(string stage, Object2D obj)
 {
     var s = JsonConvert.SerializeObject(obj, Formatting.Indented, settings);
     var fp = GetDirectoryPath(stage);
     if (!Directory.Exists(fp)) {
         Directory.CreateDirectory(fp);
     }
     Serializer.SaveToFile(GetFilePath(stage, obj), s);
 }
Exemplo n.º 28
0
    public string ApplyUserReset(Object2D realUser, Object2D virtualUser, Vector2 resetDirection)
    {
        //float ratio = 2;
        float rotationSpeed = 60.0f;

        if (isFirst)
        {
            initialAngle       = Vector2.SignedAngle(realUser.transform.forward, resetDirection);
            realTargetRotation = Matrix3x3.CreateRotation(initialAngle) * realUser.transform.forward;

            //virtualTargetRotation = Matrix3x3.CreateRotation(ratio * targetAngle) * virtualUser.transform.forward; freeze-turn when user reset
            isFirst = false;

            maxRotTime = Mathf.Abs(initialAngle) / rotationSpeed;
            //Debug.Log(maxRotTime);
            remainRotTime = 0;
        }

        float realAngle = Vector2.SignedAngle(realUser.transform.forward, realTargetRotation);

        if (remainRotTime < maxRotTime)
        {
            //Debug.Log(remainRotTime);
            realUser.Rotate(Mathf.Sign(initialAngle) * rotationSpeed * Time.fixedDeltaTime);
            //virtualUser.Rotate(ratio * rotationSpeed * Time.fixedDeltaTime);
            remainRotTime += Time.fixedDeltaTime;
        }
        else
        {
            SyncDirection(realUser, resetDirection);
            //Debug.Log("SYNC");

            //Utility.SyncDirection(virtualUser, realUser, virtualTargetRotation, realTargetRotation);

            //realUser.transform.position = realUser.transform.position + realUser.transform.forward * 0.1f;
            //if (realUser.gameObject != null) realUser.gameObject.transform.position = Utility.Cast2Dto3D(realUser.transform.position);

            //Utility.SyncPosition(virtualUser, realUser, virtualUser.transform.localPosition, newRealPosition);
            //bool isNeedReset = NeedWallReset(realUser, realSpace);

            //Debug.Log(virtualUser.transform);
            //Debug.Log(realUser.transform);
            ////Debug.Log(virtualUser.gameObject.transform.localPosition);
            ////Debug.Log(realUser.gameObject.transform.localPosition);
            //Debug.Log(isNeedReset);

            //realUser.transform.position = realUser.transform.position + realUser.transform.forward * 0.1f; // 다시 리셋 상태에 빠지는 것을 방지
            isFirst = true;
            return("DONE");
            //episode.DeleteTarget();
            //isFirst = true;
            //isFirst2 = true;
        }

        return("NOT_YET");
    }
Exemplo n.º 29
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            pon3            = new Object2D(Content.Load <Texture2D>("text"));
            pon3.position.X = graphics.PreferredBackBufferWidth / 2;
            pon3.position.Y = graphics.PreferredBackBufferHeight / 2;

            tempRenderTarget = new RenderTarget2D(GraphicsDevice, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
            tempText         = new Texture2D(GraphicsDevice, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
        }
Exemplo n.º 30
0
 public static void HideItem(string itemName)
 {
     if (!string.IsNullOrEmpty(itemName))
     {
         Object2D info = GetItemInfo(itemName);
         if (info != null)
         {
             DestroyObj(info.gameObject);
         }
     }
 }
Exemplo n.º 31
0
        public void Explode(Object2D explodable, Texture2D explosion)
        {
            var exp = new Explosion(explosion, explodable)
            {
                Scale = new Vector2(0.25f, 0.25f)
            };

            exp.Position = Position;
            exp.CenterOrigin();

            ComponentManegment.Instance.Dispose(this);
        }
Exemplo n.º 32
0
        public override void Execute(ObjectSet originalObjects)
        {
            Position2D positionToPlace = null;

            ShelfContainer2D selectedContainer = containers.First() as ShelfContainer2D;

            selectedContainer.AddShelf();

            ShelfSubContainer2D selectedShelf = selectedContainer.TopShelf as ShelfSubContainer2D;

            var objectsCopy = originalObjects.ToObjectList();

            while (objectsCopy.Any())
            {
                Object2D selectedObject = objectsCopy.First() as Object2D;

                for (int i = 0; positionToPlace == null; i++)
                {
                    selectedContainer = containers[i] as ShelfContainer2D;

                    for (int j = 0; positionToPlace == null; j++)
                    {
                        selectedShelf = selectedContainer.Subcontainers[j] as ShelfSubContainer2D;

                        if (selectedObject.Width + selectedShelf.LastPlacedObject.X2 <= selectedContainer.Width &&
                            ((j == selectedContainer.Subcontainers.Count - 1 && selectedObject.Height + selectedShelf.Y <= selectedContainer.Height) ||
                             j != selectedContainer.Subcontainers.Count - 1 && selectedObject.Height < selectedShelf.Height))
                        {
                            positionToPlace = new Position2D(selectedShelf.LastPlacedObject.X2, selectedShelf.Y);
                        }
                        else if (selectedObject.Height + selectedShelf.Y > selectedContainer.Height && i == containers.Count - 1 && j == selectedContainer.Subcontainers.Count - 1)
                        {
                            AddContainer();
                            (containers.Last() as ShelfContainer2D).AddShelf();
                            break;
                        }
                        else if (selectedObject.Height + selectedShelf.Y > selectedContainer.Height && j == selectedContainer.Subcontainers.Count - 1)
                        {
                            break;
                        }
                        else if (selectedObject.Width + selectedShelf.LastPlacedObject.X2 > selectedContainer.Width && j == selectedContainer.Subcontainers.Count - 1)
                        {
                            selectedContainer.AddShelf();
                        }
                    }
                }

                objectsCopy.Remove(selectedObject);
                selectedShelf.LastPlacedObject = selectedContainer.PlaceObject(selectedObject, positionToPlace) as PlacedObject2D;
                positionToPlace = null;
            }
        }
Exemplo n.º 33
0
        public override void Execute(ObjectSet originalObjects)
        {
            double         bestFittingQuality = Double.MaxValue;
            double         localFittingQuality;
            PlacedObject2D newPlacedObject;
            Position2D     positionToPlace = null;

            GuillotineCutContainer2D selectedContainer = containers.First() as GuillotineCutContainer2D;

            GuillotineCutSubcontainer2D selectedSubcontainer = selectedContainer.Subcontainers.First() as GuillotineCutSubcontainer2D;

            var objectsCopy = originalObjects.ToObjectList();

            while (objectsCopy.Any())
            {
                Object2D selectedObject = objectsCopy.First() as Object2D;


                foreach (GuillotineCutContainer2D container in containers)
                {
                    foreach (GuillotineCutSubcontainer2D subcontainer in container.Subcontainers)
                    {
                        if (FittingStrategy.ValidateObjectPlacement(selectedObject, subcontainer))
                        {
                            localFittingQuality = FittingStrategy.CalculateFittingQuality(selectedObject, subcontainer);
                            if (localFittingQuality < bestFittingQuality)
                            {
                                bestFittingQuality   = localFittingQuality;
                                selectedContainer    = container;
                                selectedSubcontainer = subcontainer;
                                positionToPlace      = subcontainer.Position;
                            }
                        }
                    }
                }
                if (positionToPlace == null)
                {
                    AddContainer();

                    selectedContainer    = containers.Last() as GuillotineCutContainer2D;
                    selectedSubcontainer = selectedContainer.Subcontainers.Last() as GuillotineCutSubcontainer2D;
                    positionToPlace      = selectedSubcontainer.Position;
                }


                objectsCopy.Remove(selectedObject);
                newPlacedObject = selectedContainer.PlaceObject(selectedObject, positionToPlace) as PlacedObject2D;
                selectedContainer.SplitSubcontainer(selectedSubcontainer, newPlacedObject);
                positionToPlace    = null;
                bestFittingQuality = Double.MaxValue;
            }
        }
    public void SyncDirection(Object2D virtualUser, Vector2 virtualTargetDirection)
    {
        if (virtualTargetDirection.magnitude > 1)
        {
            virtualTargetDirection = virtualTargetDirection.normalized;
        }

        virtualUser.transform.forward = virtualTargetDirection;
        if (virtualUser.gameObject != null)
        {
            virtualUser.gameObject.transform.forward = Utility.Cast2Dto3D(virtualTargetDirection);
        }
    }
Exemplo n.º 35
0
    public Space2D(Object2D space, List <Object2D> obstacles)
    {
        if (space is Polygon2D) // TODO: 부모와 자식 클래스 형변환이 올바르게 되도록 정리
        {
            this.space = new Polygon2D((Polygon2D)space);
        }
        else
        {
            this.space = new Object2D(space);
        }

        this.obstacles = new List <Object2D>(obstacles);
    }
Exemplo n.º 36
0
    public void SyncDirection(Object2D realUser, Vector2 realTargetDirection)
    {
        if (realTargetDirection.magnitude > 1)
        {
            realTargetDirection = realTargetDirection.normalized;
        }

        realUser.transform.forward = realTargetDirection;
        if (realUser.gameObject != null)
        {
            realUser.gameObject.transform.forward = Utility.Cast2Dto3D(realTargetDirection);
        }
    }
        public override void Execute(ObjectSet originalObjects)
        {
            double bestFitResult = Double.MaxValue;
            double currentFitResult;

            int selectedFitContainerIndex = 0;

            Position2D positionToPlace = null;

            SkylineContainer2D selectedContainer = containers.First() as SkylineContainer2D;

            var objectsCopy = originalObjects.ToObjectList();

            while (objectsCopy.Any())
            {
                Object2D selectedObject = objectsCopy.First() as Object2D;

                for (int i = 0; i < containers.Count; i++)
                {
                    currentFitResult = FindBestFitWithinContainer(containers[i] as SkylineContainer2D, selectedObject, bestFitResult, ref positionToPlace);

                    if (currentFitResult < bestFitResult)
                    {
                        bestFitResult             = currentFitResult;
                        selectedFitContainerIndex = i;
                        break;
                    }
                }

                // Object not placed, create new container, place object bottom-left
                if (positionToPlace == null)
                {
                    AddContainer();

                    selectedContainer = containers.Last() as SkylineContainer2D;

                    positionToPlace = new Position2D(0, 0);
                }
                else
                {
                    selectedContainer = containers[selectedFitContainerIndex] as SkylineContainer2D;
                }

                objectsCopy.Remove(selectedObject);
                selectedContainer.PlaceNewObject(selectedObject, positionToPlace);
                selectedFitContainerIndex = 0;
                bestFitResult             = Double.MaxValue;
                positionToPlace           = null;
            }
        }
    public TitleScreenState()
    {
        level = new Level();
        level.player = new Player(new Vector3(200, 200f, 200));

        foreach (Sound sound in MusicPlayer.Music)
        {
            sound.PlaySound();
        }

        //Add title
        title = new Object2D("Menu Buttons\\Chased");
        gameObjects.Add(title);

        //Add a continue button
        continueButton = new Button("Menu Buttons\\Menu button Continue", 0);
        gameObjects.Add(continueButton);

        //Add a mouse-over continue button
        continueButtonMouseOver = new Button("Menu Buttons\\Menu button Continue MouseOver", 0);
        gameObjects.Add(continueButtonMouseOver);
        continueButtonMouseOver.Visible = false;

        //Add a new game button
        newGameButton = new Button("Menu Buttons\\Menu button NewGame", 0);
        gameObjects.Add(newGameButton);

        //Add a mouse-over new game button
        newGameButtonMouseOver = new Button("Menu Buttons\\Menu button NewGame MouseOver", 0);
        gameObjects.Add(newGameButtonMouseOver);
        newGameButtonMouseOver.Visible = false;

        //Add an exit button
        exitButton = new Button("Menu Buttons\\Menu button Exit", 0);
        gameObjects.Add(exitButton);

        //Add a mouse-over exit button
        exitButtonMouseOver = new Button("Menu Buttons\\Menu button Exit MouseOver", 0);
        gameObjects.Add(exitButtonMouseOver);
        exitButtonMouseOver.Visible = false;

        part = 0;
    }
    public void OpenEditorFor(Object2D obj)
    {
        if (current) {
            Destroy(current);
        }

        if(obj != null) {
            var editor = GameObjectUtil.GetResourceInstance(Object2DEditorBasePrefab);

            if (Object2DEditorMap.Instance.HasTypeFor(obj.GetType())) {
                editor.AddComponent(Object2DEditorMap.Instance.GetTypeFor(obj.GetType()));
            }

            foreach(var initObj in editor.GetInterfacesInChildren<IInitializable<Object2D>>()) {
                initObj.Initialize(obj);
            }

            Debug.Log(MainCanvas.main);
            Debug.Log(editor);
            MainCanvas.main.Add(editor.transform);

            current = editor;
        }
    }
 public void Delete(Object2D obj)
 {
     DeleteAt(obj.Position);
 }
Exemplo n.º 41
0
        public void Serialize(Object2D obj)
        {
            byte[] data = Encoding.ASCII.GetBytes(obj.ObjectFile.PadRight(80, '\0'));
            writer.Write(data);

            Serialize(obj.ObjectPosition);
            Serialize(obj.ObjectRotation);

            writer.Write(new byte[24]);
        }
Exemplo n.º 42
0
 protected static string GetFilePath(string stage, Object2D obj)
 {
     return GetFilePath(stage, obj.Guid);
 }
Exemplo n.º 43
0
 /// <summary>
 /// Collision of object2D with pixels
 /// </summary>
 /// <param name="obj2D">The object to check collision with</param>
 /// <returns>True if it collides, false if it doesn't</returns>
 public bool CollidesWith(Object2D obj2D)
 {
     if (!this.Visible || !obj2D.Visible || !BoundingBox.Intersects(obj2D.BoundingBox))
             return false;
         Rectangle b = Collision.Intersection(BoundingBox, obj2D.BoundingBox);
         for(int x = 0; x<b.Width; x++)
             for(int y = 0; y<b.Height; y++)
             {
                 int thisx = b.X - (int)(GlobalPosition.X - origin.X) + x;
                 int thisy = b.Y - (int)(GlobalPosition.Y - origin.Y) + y;
                 int objx = b.X - (int)(obj2D.GlobalPosition.X - obj2D.origin.X) + x;
                 int objy = b.Y - (int)(obj2D.GlobalPosition.Y - obj2D.origin.Y) + y;
                 if (SpriteSheet.GetPixelColor(thisx, thisy).A != 0 && obj2D.spriteSheet.GetPixelColor(objx, objy).A != 0)
                     return true;
             }
         return false;
 }
Exemplo n.º 44
0
 public void Serialize(Object2D obj)
 {
     writer.WriteElementString("filename", obj.ObjectFile);
     writer.WriteStartElement("position");
     Serialize(obj.ObjectPosition);
     writer.WriteEndElement();
     writer.WriteStartElement("rotation");
     Serialize(obj.ObjectRotation);
     writer.WriteEndElement();
 }
Exemplo n.º 45
0
 public static void Delete(string stage, Object2D obj)
 {
     if (File.Exists(GetFilePath(stage, obj))) {
         File.Delete(GetFilePath(stage, obj));
     }
 }
 public void Save(Object2D obj)
 {
     Object2DLoader.Save(_stage, obj);
 }
    public void Place(Object2D obj)
    {
        var pos = GetGridPosition(obj.Position);
        DeleteAt(pos);

        resources[pos] = ConstructObject2DInstance(obj);
    }
Exemplo n.º 48
0
 public void Arrange(Object2D objectToPosition, Microsoft.Xna.Framework.Rectangle container)
 {
     throw new NotImplementedException();
 }
    GameObject ConstructObject2DInstance(Object2D obj)
    {
        var baseObject = GameObjectUtil.GetResourceInstance(Object2DBasePrefab);
        baseObject.GetOrAddComponent<Object2DComponent>().Initialize(obj);
        baseObject.transform.position = GetWorldPosition(GetGridPosition(obj.Position));
        baseObject.name = string.Format("{0} ({1})", obj.Name, obj.GetType());

        var graphicObject = GameObjectUtil.GetResourceInstance(Object2DPrefabsDirectory + obj.PrefabName);
        graphicObject.transform.SetParent(baseObject.transform);
        graphicObject.transform.localPosition = Vector3.zero;

        //if (obj is IHasTrigger) {
        //    var c = baseObject.AddComponent<BoxCollider2D>();
        //    c.isTrigger = true;
        //}

        if (obj is IHasCollider) {
            graphicObject.AddComponent<BoxCollider2D>();
        }

        if (Object2DBehaviourMap.Instance.HasTypeFor(obj.GetType())) {
            baseObject.AddComponent(Object2DBehaviourMap.Instance.GetTypeFor(obj.GetType()));
        }

        foreach (var i in baseObject.GetInterfacesInChildren<IInitializable<Object2D>>()) {
            i.Initialize(obj);
        }

        return baseObject;
    }
Exemplo n.º 50
0
        public void Arrange(Object2D objectToPosition, Microsoft.Xna.Framework.Rectangle container, int typeOfLayout)
        {
            Rectangle tmp = objectToPosition.Bound;
            switch ((RelativePosition)typeOfLayout)
            {
                case RelativePosition.TOP_LEFT:
                    tmp.Location= new Point(container.X,container.Y);
                    break;
                case RelativePosition.TOP_CENTER:
                    tmp.Location = new Point((int)midh(tmp, container), container.Y);
                    break;
                case RelativePosition.TOP_RIGHT:
                    tmp.Location = new Point((int)right(tmp,container), container.Y);
                    break;

                case RelativePosition.CENTER_LEFT:
                    tmp.Location = new Point(container.X, (int)midv(tmp, container));
                    break;
                case RelativePosition.MIDDLE:
                    tmp.Location = new Point((int)midh(tmp,container), (int)midv(tmp,container));
                    break;
                case RelativePosition.CENTER_RIGHT:
                    tmp.Location = new Point((int)right(tmp,container), (int)midv(tmp, container));
                    break;

                case RelativePosition.BOTTOM_LEFT:
                    tmp.Location = new Point(container.X, (int)bot(tmp,container));
                    break;
                case RelativePosition.BOTTOM_CENTER:
                    tmp.Location = new Point((int)midh(tmp, container), (int)bot(tmp,container));
                    break;
                case RelativePosition.BOTTOM_RIGHT:
                    tmp.Location = new Point((int)right(tmp, container), (int)bot(tmp,container));
                    break;

                case RelativePosition.BORDER_LEFT_TOP_LEFT:
                    tmp.Location = new Point(container.X - tmp.Width,container.Y);
                    break;
                case RelativePosition.BORDER_LEFT_CENTER_LEFT:
                    tmp.Location = new Point(container.X - tmp.Width, (int)midv(tmp,container));
                    break;
                case RelativePosition.BORDER_LEFT_BOTTOM_LEFT:
                    tmp.Location = new Point(container.X - tmp.Width, (int)bot(tmp,container));
                    break;
                case RelativePosition.BORDER_LEFT_TOP_CENTER:
                    tmp.Location = new Point(container.X - tmp.Width/2, container.Y);
                    break;
                case RelativePosition.BORDER_LEFT_CENTER_CENTER:
                    tmp.Location = new Point(container.X - tmp.Width/2, (int)midv(tmp, container));
                    break;
                case RelativePosition.BORDER_LEFT_BOTTOM_CENTER:
                    tmp.Location = new Point(container.X - tmp.Width/2, (int)bot(tmp,container));
                    break;

                case RelativePosition.BORDER_RIGHT_TOP_RIGHT:
                    tmp.Location = new Point(container.X + container.Width, container.Y);
                    break;
                case RelativePosition.BORDER_RIGHT_CENTER_RIGHT:
                    tmp.Location = new Point(container.X + container.Width, (int)midv(tmp,container));
                    break;
                case RelativePosition.BORDER_RIGHT_BOTTOM_RIGHT:
                    tmp.Location = new Point(container.X + container.Width, (int)bot(tmp,container));
                    break;
                case RelativePosition.BORDER_RIGHT_TOP_CENTER:
                    tmp.Location = new Point(container.X + container.Width - tmp.Width/2, container.Y);
                    break;
                case RelativePosition.BORDER_RIGHT_CENTER_CENTER:
                    tmp.Location = new Point(container.X + container.Width - tmp.Width/2, (int)midv(tmp, container));
                    break;
                case RelativePosition.BORDER_RIGHT_BOTTOM_CENTER:
                    tmp.Location = new Point(container.X + container.Width - tmp.Width/2, (int)bot(tmp, container));
                    break;

                case RelativePosition.BORDER_TOP_TOP_LEFT:
                    tmp.Location = new Point(container.X , container.Y - tmp.Height);
                    break;
                case RelativePosition.BORDER_TOP_TOP_CENTER:
                    tmp.Location = new Point((int)midh(tmp,container) , container.Y - tmp.Height);
                    break;
                case RelativePosition.BORDER_TOP_TOP_RIGHT:
                    tmp.Location = new Point((int)right(tmp,container), container.Y - tmp.Height);
                    break;

                case RelativePosition.BORDER_TOP_CENTER_LEFT:
                    tmp.Location = new Point(container.X, container.Y - tmp.Height/2);
                    break;
                case RelativePosition.BORDER_TOP_CENTER_CENTER:
                    tmp.Location = new Point((int)midh(tmp, container), container.Y - tmp.Height/2);
                    break;
                case RelativePosition.BORDER_TOP_CENTER_RIGHT:
                    tmp.Location = new Point((int)right(tmp, container), container.Y - tmp.Height/2);
                    break;

                case RelativePosition.BORDER_BOTTOM_BOTTOM_LEFT:
                    tmp.Location = new Point(container.X,(int)bot(tmp,container)+tmp.Height);
                    break;
                case RelativePosition.BORDER_BOTTOM_BOTTOM_CENTER:
                    tmp.Location = new Point((int)midh(tmp,container), (int)bot(tmp, container) + tmp.Height);
                    break;
                case RelativePosition.BORDER_BOTTOM_BOTTOM_RIGHT:
                    tmp.Location = new Point((int)right(tmp,container), (int)bot(tmp, container) + tmp.Height);
                    break;

                case RelativePosition.BORDER_BOTTOM_CENTER_LEFT:
                    tmp.Location = new Point(container.X,(int)bot(tmp,container)+tmp.Height/2);
                    break;
                case RelativePosition.BORDER_BOTTOM_CENTER_CENTER:
                    tmp.Location = new Point((int)midh(tmp,container),(int)bot(tmp,container)+tmp.Height/2);
                    break;
                case RelativePosition.BORDER_BOTTOM_CENTER_RIGHT:
                    tmp.Location = new Point((int)right(tmp,container),(int)bot(tmp,container)+tmp.Height/2);
                    break;
                default: break;
            }
            objectToPosition.Bound = tmp;
        }
 public void Create(Object2D obj)
 {
     Place(obj);
     Save(obj);
 }
 public EndGameState()
 {
     black = new Object2D("black");
     fader = 0;
     gunShotSound = false;
 }