   Placing Buildings in an RTS
  Hi everyone,I am working on a simple 2D RTS style game, and everything was working great until I tried adding the buildings. I can make the building sprite follow the mouse, and go away when you right click, but I can't figure out how to place the building on the map. I've tried several different ways, and none of them seem to work.Is there a good tutorial or article on how to do something like this? Do you know a good way to do it that you would be willing to share, or even some pointers in the right direction?Any help would be greatly appreciated.   
  Can you tell us the ways you tried? Its not really a hard thing, come up with a plan and then execute it.Eg. You could make it so when you select the building it shows the building under your mouse and then when you left click to place it it gets the coordinates of the mouse click and then draws the object using a function or however you want it. Pseudo Idea CodeonClick:Get Mouse CoordinatesDraw building at Coordinates.So pretty much if you click on a location and you have a building selected to be built then it shows that builidng at the location you clicked.Theres much better ways to do this but thats by far the simplest way you could do it, I think.   ;  How do you order units around?  Just do that, but instead of telling units to move there, place a building there   ;  Before, I tried something like:Each building has an x and a y variable as well as a finalX and finalY variable.1. Get mouse position using GetCursorPos and ScreenToClient2. If the user clicked on the button for the building, draw the building at the mouse position3. If the user clicked again, set the finalX and finalY variables to the posidion of the cursor4. Draw the building at (finalX, finalY)I don't have the code at the moment, it's at school, but it was something along those lines.The building would never stay at the location that the mouse was clicked at, it always kept following the mouse.   ;  Are you using directx, SDL, pascal?are you drawing to a surface, are you using a game engine?We need a little more information from you.If you are using directx7 you could just blt the location onto your off screen surface containing your game world or something like that.   ;  At school I am using the CMU graphics library, but I also want to know how to do it using DirectX (which I am using at home).I am not using a game engine.   ;  Whatever you use to draw things, the concepts stay the same. Now, putting down a building in a RTS game is much more than just drawing a sprite at a certain position. How do you represent the underlying logic? Did you write a Building class or something similar already? How do you represent the world? How do you check if a given location is valid (e.g. nothing is obstructing the building site)?Once these things are sorted out, making sure that a building is displayed is much easier: you've already got the logic in place, all that's left is drawing a sprite at that location. Remember, the sprite is not the building, but the building is represented on screen by a sprite.   ;  I'm sure this is not the best way, but you could:0. Create a vector to store your buildings1. Create a mouse class that serves as the mouse pointer2. Have this class contain different sprites for each building, as well as a default cursor image3. Hide the real cursor and load the default cursor at the same location as the real one4. When the user clicks on the building button, set the cursor's image to the image of the building5. When the user clicks on the map, set tue building's x and y to the x and y of the cursor, push the building onto the vector and set the cursor's image to the default image6. Loop through the vector and draw each building7. Make sure to free any memory you may have allocated when the program exitsHope this helps, and again, this probably isn't the best way to do this but it works for me.   ;  Ok, I got it to work using Alatar's suggestion, thanks a lot guys!!   