User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Game Development section within the Software Development category of DaniWeb, a massive community of 426,660 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,521 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Game Development advertiser: Programming Forums
Views: 767 | Replies: 2
Reply
Join Date: Jan 2008
Location: USA East Cost
Posts: 389
Reputation: CoolGamer48 is on a distinguished road 
Rep Power: 1
Solved Threads: 37
CoolGamer48's Avatar
CoolGamer48 CoolGamer48 is offline Offline
Posting Whiz

Help Check to see if a mouse click missed an object

  #1  
Feb 22nd, 2008
I've been trying to code a catch me game (for anyone who doesn't know: a game with a ball that randomly jumps around the screen - the goal is to click the ball before it moves, and not to miss it). I've got the clicks part down. You can click on the ball and you get points. When I try to add punishment for missing - it won't work. Either every click is a miss - no matter what - or no click is a miss. I'm using this code:

A member of the object class
	int miss(cursor* mycursor)
	{
		if((mycursor->X() < x || mycursor->X() > x+width || mycursor->Y() < y || mycursor->Y() > y+height) && MouseButton(0))
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}

part of the code in a GameRun() function (target is an object of class cursor):
if(myball.click(&target))
		{
			hits++;
			jump_delay--;
			jump_timer = GetTickCount();
			myball.RandomJump(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
		}
		if(myball.miss(&target))
		{
			MessageBox(hwnd,"GAME OVER","CatchMe",MB_OK);
			PostMessage(hwnd,WM_DESTROY,0,0);
		}

Does the code look okay? I've gone over it tons of times - and I can't find anything wrong.
I'm a student. If my statements seem too absolute, feel free to coat them with "In my opinion..." or "I believe...".
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2006
Location: Deptford, London
Posts: 963
Reputation: MattEvans has a spectacular aura about MattEvans has a spectacular aura about 
Rep Power: 5
Solved Threads: 48
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Posting Shark

Re: Check to see if a mouse click missed an object

  #2  
Feb 22nd, 2008
As it looks; you're doing one test for the mouse click ( testing MouseButton(0); ) - this means the function 'miss' will only be true if the user clicks the mouse at the exact moment that the code is running. I would set up an event to wait for the mouseclick or do a time-locked loop to poll the mouse until a click occurs; and THEN test to see whether or not it's a hit.
Last edited by MattEvans : Feb 22nd, 2008 at 1:12 pm.
If it only works in Internet Explorer; it doesn't work.
Reply With Quote  
Join Date: Jan 2008
Location: USA East Cost
Posts: 389
Reputation: CoolGamer48 is on a distinguished road 
Rep Power: 1
Solved Threads: 37
CoolGamer48's Avatar
CoolGamer48 CoolGamer48 is offline Offline
Posting Whiz

Re: Check to see if a mouse click missed an object

  #3  
Feb 22nd, 2008
Originally Posted by MattEvans View Post
As it looks; you're doing one test for the mouse click ( testing MouseButton(0); ) - this means the function 'miss' will only be true if the user clicks the mouse at the exact moment that the code is running. I would set up an event to wait for the mouseclick or do a time-locked loop to poll the mouse until a click occurs; and THEN test to see whether or not it's a hit.


I think I found the problem - and I'm not really sure if it was what you were talking about.

I was checking to see if the button was down, not if it was just clicked. So whenever you clicked on the ball, it would move, leaving the mouse button down over space that is now empty.

I wrote some new functions to take into account the previous state of the mouse button, so that the function checked for a press, not just that the button was down. It now works,
I'm a student. If my statements seem too absolute, feel free to coat them with "In my opinion..." or "I believe...".
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Game Development Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the Game Development Forum

All times are GMT -4. The time now is 1:48 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC