Example #1
0
        public void checkCollision()
        {
            bool collided = false;
            for (int i = 0; i < levelCreator.height; i++)
            {
                for (int j = 0; j < levelCreator.width; j++)
                {
                    LcTilePlace temp = levelCreator.tileArray[i,j];

                    if (temp.activeCol)
                    {
                        if (temp.bounds.checkPoint(pos))
                        {
                            collided = true;
                            if (temp != activeTile)
                            {
                                if (activeTile != null)
                                    activeTile.disable();
                                activeTile = temp;
                                activeTile.activate();
                            }
                        }
                    }
                }
            }
            if (activeTile != null)
            {
                if (!collided)
                {
                    activeTile.disable();
                    activeTile = null;
                }
            }

            collided = false;
            foreach(LcMenuTile m in levelCreator.menuTiles)
            {
                if (m.bounds.checkPoint(pos))
                {
                    collided = true;
                    if (m != activeMenuTile)
                    {
                        if (activeMenuTile != null)
                            activeMenuTile.disable();
                        activeMenuTile = m;
                        activeMenuTile.activate();
                    }
                }
            }
            if (activeMenuTile != null)
            {
                if (!collided)
                {
                    activeMenuTile.disable();
                    activeMenuTile = null;
                }
            }

            collided = false;
            foreach (LcGridModifier m in levelCreator.gridModifiers)
            {
                if (m.bounds.checkPoint(pos))
                {
                    collided = true;
                    if (m != activeGridModifier)
                    {
                        if (activeGridModifier != null)
                            activeGridModifier.disable();
                        activeGridModifier = m;
                        activeGridModifier.activate();
                    }
                }
            }
            if (activeGridModifier != null)
            {
                if (!collided)
                {
                    activeGridModifier.disable();
                    activeGridModifier = null;
                }
            }

            if(levelCreator.saveButton.bounds.checkPoint(pos))
            {
                levelCreator.saveButton.activate();

                if (Mouse.GetState().LeftButton == ButtonState.Pressed)
                    levelCreator.saveButton.onClick();
            }
            else
            {
                levelCreator.saveButton.disable();
            }

            collided = false;
            foreach (LcTextField t in levelCreator.textFields)
            {
                if (t.bounds.checkPoint(pos))
                {
                    collided = true;
                        activeText = t;
                }
            }
            if (activeText != null)
            {
                if (!collided)
                {
                    activeText = null;
                }
            }
        }
Example #2
0
        void onLeftHold()
        {
            if (holdType == 24)
                checkBasePlace();

            if (!dragging)
            {
                if (clickPos.X != pos.X || clickPos.Y != pos.Y)
                {
                    dragging = true;
                    if (selectedTile != null)
                    {
                        selectedTile.selected = false;
                        selectedTile = null;
                    }

                    if (activeTile != null)
                    {
                        if (activeTile.type != 60)
                        {
                            holdType = activeTile.type;
                            if (holdType == 24)
                                clearBase();
                            setTex();
                            if (!Keyboard.GetState().IsKeyDown(Keys.LeftAlt))
                            {
                                activeTile.setType(60);
                                swapDrag = true;
                                prevTile = activeTile;
                            }
                        }
                    }
                }
            }
        }
Example #3
0
        public void Update()
        {
            pos = Mouse.GetState().Position.ToVector2();
            checkCollision();

            if(Mouse.GetState().LeftButton == ButtonState.Pressed)
            {
                if (!leftClick)
                    onLeftClick();
                else
                {
                    onLeftHold();
                }
            }
            else
            {
                if (leftClick)
                    onLeftRelease();
            }

            if (Mouse.GetState().RightButton == ButtonState.Pressed)
            {
                if (!leftClick && !rightClick)
                    onRightClick();
            }
            else
            {
                if (rightClick)
                    rightClick = false;
            }

            if(selectedTile != null)
            {
                if(Keyboard.GetState().IsKeyDown(Keys.Back) || Keyboard.GetState().IsKeyDown(Keys.Delete))
                {
                    if (selectedTile.type == 24)
                    {
                        activeTile = selectedTile;
                        clearBase();
                        activeTile = null;
                    }
                    else
                        selectedTile.setType(60);

                    selectedTile.selected = false;
                    selectedTile = null;
                }
            }
        }
Example #4
0
        void onLeftClick()
        {
            leftClick = true;
            clickPos = pos;

            if(activeMenuTile != null)
            {
                holdType = activeMenuTile.type;
                setTex();
            }
            if(activeTile != null)
            {
                if(activeTile != selectedTile)
                {
                    if (selectedTile != null)
                        selectedTile.selected = false;
                }
                //activeTile.selected = true;
                selectedTile = activeTile;
                selectedTile.selected = true;
            }
            if(activeGridModifier != null)
            {
                activeGridModifier.onClick();
            }

            levelCreator.keyListener.setTextField(activeText);
        }
Example #5
0
        public void onClick()
        {
            switch(type)
            {
                default://x
                    if (add)
                    {
                        int oldWidth = lc.width;
                        lc.width++;

                        LcTilePlace[,] tempArray = new LcTilePlace[lc.height, lc.width];

                        Vector2 tempPos = lc.topPos;
                        for (int i = 0; i < lc.height; i++)
                        {
                            //tiles.Add(new List<LcTilePlace>());
                            tempPos.X = 90;
                            for (int j = 0; j < lc.width; j++)
                            {
                                if(j < oldWidth)
                                    tempArray[i, j] = lc.tileArray[i,j];
                                else
                                    tempArray[i, j] = new LcTilePlace(game, tempPos, new Vector2(j, i));
                                //                    tiles.ElementAt(i).Add(new LcTilePlace(game, tempPos));
                                tempPos.X += 30;
                            }
                            tempPos.Y += 30;
                        }
                        lc.tileArray = tempArray;
                    }
                    else
                    {
                        int oldWidth = lc.width;
                        if(lc.width > 1)
                            lc.width--;

                        LcTilePlace[,] tempArray = new LcTilePlace[lc.height, lc.width];

                        Vector2 tempPos = lc.topPos;
                        for (int i = 0; i < lc.height; i++)
                        {
                            //tiles.Add(new List<LcTilePlace>());
                            tempPos.X = 100;
                            for (int j = 0; j < lc.width; j++)
                            {
                                tempArray[i, j] = lc.tileArray[i, j];
                                tempPos.X += 30;
                            }
                            tempPos.Y += 30;
                        }
                        lc.tileArray = tempArray;
                    }
                    break;
                case 1://y
                    if (add)
                    {
                        int oldHeight = lc.height;
                        lc.height++;

                        LcTilePlace[,] tempArray = new LcTilePlace[lc.height, lc.width];

                        Vector2 tempPos = lc.topPos;
                        for (int i = 0; i < lc.height; i++)
                        {
                            //tiles.Add(new List<LcTilePlace>());
                            tempPos.X = 90;
                            for (int j = 0; j < lc.width; j++)
                            {
                                if(i < oldHeight)
                                    tempArray[i, j] = lc.tileArray[i, j];
                                else
                                    tempArray[i,j] = new LcTilePlace(game, tempPos, new Vector2(j,i));
                                tempPos.X += 30;
                            }
                            tempPos.Y += 30;
                        }
                        lc.tileArray = tempArray;
                    }
                    else
                    {
                        if(lc.height > 1)
                            lc.height--;

                        LcTilePlace[,] tempArray = new LcTilePlace[lc.height, lc.width];

                        Vector2 tempPos = lc.topPos;
                        for (int i = 0; i < lc.height; i++)
                        {
                            tempPos.X = 100;
                            for (int j = 0; j < lc.width; j++)
                            {
                                tempArray[i, j] = lc.tileArray[i, j];
                                tempPos.X += 30;
                            }
                            tempPos.Y += 30;
                        }
                        lc.tileArray = tempArray;
                    }
                    break;
            }
        }