Originally Posted by
asdfarkangel
Now I want to use the mouse to shoot. This would be like when the user presses the left mouse button. I get the position of the cursor and calculate the coordinates from it. Easy right? Not for me
First problem: How do I make the program to basicly do nothing just wait until the user presses the mouse button? I tried simple loops but it didn't really care about I had already pressed the button it just stayed there in a never ending loop.
Ok, first lets address your mouse issue. You want to make sure that you are using local variables to store your mouse state and check those for updates. You should have something like the following...
Code:
var
MouseX, MouseY: Integer; // mouse screen location
MouseBtnLeft, MouseBtnMiddle, MouseBtnRight: Boolean; // true = Button pressed
With these you can store your mouse values when you run the function to check your mouse state update. You want to update these values EACH TIME your game goes through your main game loop. And it would also be advisable to do all of your user input at the very beginning of your main loop as well. Now you have to make sure that each time you check for your mouse state, you do so AFTER you update your mouse state variables. If you don't then you'll be reading the old state values and your input will act funny. This part is important.
You game's input code in your main loop should something roughtly like this...
Code:
// --- begin user input ---
{Update Mouse State variables}
// Left Mouse Button
if (Left mouse button pressed) then
begin
if (mouse where you need it) then
{Do whatever you need your game to do...}
end;
// Right Mouse Button
if (Right mouse button pressed) then
begin
if (mouse where you need it) then
{Do whatever you need your game to do...}
end;
// --- end user input ---
Hopefully that helps. I unfortunately had to rewrite it so I hope I didn't miss anything critical. So for the graphics I'll pop bakc and give it another read over and see if I can help out.
Bookmarks