Exemplo n.º 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
                {
                    Rectangle clip = new Rectangle(currentTile%3*size,currentTile/3*size,size,size);
                    tileMap.Set(y, x, new Tile(tileSheet,clip,Tile.SOLID_BLOCK));
                }
            }
        }
Exemplo n.º 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, null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            bg = this.Content.Load<Texture2D>("stage");
            lucasTxtr = this.Content.Load<Texture2D>("lucas");
            gridCell = this.Content.Load<Texture2D>("gridcell");
            tileSheet = this.Content.Load<Texture2D>("tileSheet");
            crosshair = this.Content.Load<Texture2D>("crosshair");
            window_backing = this.Content.Load<Texture2D>("color_backing");

            lucas = new Character(lucasTxtr);
            editor = new Editor(GraphicsDevice); //Initializes editor
            tileMap = new Map(GraphicsDevice,tileSheet);   //Initializes map
        }