Archived

This topic is now archived and is closed to further replies.

Starwind8748

I need help with my whack - a - mole game

Recommended Posts

Its not really whack - a - mole, its more like shoot the hampster that pops up then shoot it so they explode. I got to the point where they randomly pop up in 12 different holes, and if you click on them, they''ll blow up. But I''m having a problem with clicking on them when using the GetMouseClick(); Here''s some code.
  

for (int i = 0; i < 20; i++)     // 20 hampsters will pop up

{
    // Random stuff here chooses hole

    // Draws Hampster there

    // Plays a little sound

    
    Pause (2000);   // Pause for two seconds 

    screen.GetMouseClick();
  
    if (certain conditions)
    {
         // shows blow up animation

    }
}

  
So essentially, what I want to do is give the person two seconds to click on the hampster before it goes somewhere else. I''ve tried putting the Pause() in different locations but it still didn''t work. I also tried using the WaitMouseClick(), but this gives the user infinite time to blow the hampster up. Any suggestions? BTW, I like hampsters.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I''m guessing you''re using VB to program this, but here''s something that may help. You''re looking for the mouse click inside the mouse pop-up routine. You may want to pull the mouse-click operation out of that function entirely, and set it up as an event handler. This way, when the user clicks the mouse on any part of the screen, at any time, you do 2 checks.

1. Is the ''critter'' visible?
2. Do the mouse coordinates match the critter coordinates?
If so.... Blam.

Anyway, that may help... Good Luck

Share this post


Link to post
Share on other sites
Event handler:
A function that detects specified "events" and does something about them.
A mouse-click event handler would be any algorithm or function that checks whether the mouse was or is being clicked. The problem with your code as it is is that it''s waiting 2 seconds without detecting anything, and only then looking for mouse clicks, so if the player clicks during those 2 seconds their click is lost (at least this is the way it should work). Here''s one suggestion:
At the point where you have the pause and the getmouseclick, put a while loop, like so:

int finished, c;
while(!finished)
{
screen.GetMouseClick();
if(mouse was clicked)
finished = 1;
(some sort of delay function to wait 1 millisecond)();
c++;
if(c == 2000)
finished = 1;
}

This might be a little too complicated; for instance you could just use the exit keyword if the mouse was clicked and test for (c < 2000) in the while loop.
BTW, are you using the MFC classes?

Twilight Dragon
Win32 API Expert
www.freewebz.com/j-world

Share this post


Link to post
Share on other sites