
-----------------------------------
TheHobbit
Fri Jan 02, 2009 12:24 am

Simple Solution Required , help :)
-----------------------------------
hey guys 
so i've got a little problem, and i need a solution

im making a game where the user is going to be clicking 'icons' ( pictures )  to score points, after getting all my icons , mousevents  nad other stuff working, i realized that its gona be super hard, because the only place the user clicks which the computer will recognize is the top corner 

so, say i want the user to click anywhere on this square to score a point: 
   
   []

the only reference point the program recognizes is the top corner. now, i COULD program so that if the user clicks any pixel within the area of the square it works, but that would be like, a 100 if statements. 

can someone give me a simple solution as to how to go about this problem ? im thinking of somehow using getArea and such, but honestly im kind've stumped. any ideas would be helpful

thanks :)

-----------------------------------
Tony
Fri Jan 02, 2009 1:06 am

Re: Simple Solution Required , help :)
-----------------------------------
i COULD program so that if the user clicks any pixel within the area of the square it works, but that would be like, a 100 if statements.
I'm glad that you've recognized that this sounds wrong (if you could imagine, some people actually go ahead with such "solutions").

Though I'm not sure what 100 if statements you could be thinking of. Can you describe, in any language of your choice (including English!) how you can know if a given point is inside a square?

-----------------------------------
TheHobbit
Sat Jan 03, 2009 1:06 pm

Re: Simple Solution Required , help :)
-----------------------------------
err 
im thinking of figuring out the area of the square, say its a 5 x 5 square, so theres about 25 pixels inside of it. 
( the ' 100 if statements' would be like, every one of those pixels, so it'd be 25 if statements in this case, which is still rather pointless ) 

OR

i could set some sort of a range from the origin ? 
like er
( say origin is 0,0 , and the square is 5 pixels in length ) 

"if the  0 < xPos < 5  && if 0 < y < 5 , make click work"      < math&english

in java if staments i could say

if ( mouseXPos 