Set() public method

public Set ( int y, int x, int currentTile ) : void
y int
x int
currentTile int
return void
Example #1
0
        public void Click(Vector2 cursorLoc, Map tileMap, Texture2D tileSheet)
        {
            KeyboardState keyState = Keyboard.GetState();
            int x = (int)(cursorLoc.X + 2) / size; //Why the +2? Because cursorLoc is modified by -2. Duh.
            int y = (int)(cursorLoc.Y + 2) / size; //Same goes for this.
            int tsWidth = tileSheet.Width / size; //The width of the tilesheet in tiles

            if (drag)
                editorPanel = new Vector2(x, y); //If dragging the editor panel, set its location to cursor location
            else
            {
                if ((x >= (int)editorPanel.X && x <= (int)editorPanel.X + tsWidth) && //Uhhmm...well basically this is checking if the crosshair
                    (y >= (int)editorPanel.Y && y <= (int)editorPanel.Y + tileSheet.Height / size) && //is within the editor panel, and the
                    keyState.IsKeyDown(Keys.Space))                                                   //spacebar is pressed
                {
                    currentTile = ((y - (int)editorPanel.Y) * tsWidth) + (x - (int)editorPanel.X); //Sets the current tile as a function of its location on the tilesheet (focus if you want to understand this one)
                }
                else if ((x >= (int)editorPanel.X && x <= (int)editorPanel.X + tsWidth) &&  //Same as the last one, only simpler. If the
                    (y == (int)editorPanel.Y - 1) && keyState.IsKeyDown(Keys.Space)) //crosshair is on the top of the editor window, allow user to drag
                {
                    drag = true;
                }
                else //User wants to change the tile
                {
                    tileMap.Set(y, x, currentTile);
                }
            }
        }
Example #2
0
        //Simplified version of the Click() method. Just erases the currently selected tile.
        public void Erase(Vector2 cursorLoc, Map tileMap)
        {
            int x = (int)(cursorLoc.X + 2) / size;
            int y = (int)(cursorLoc.Y + 2) / size;

            tileMap.Set(y, x, -1);
        }