![]() |
|
|||||||
| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
| Questions & Help Needed Post any question regarding Basic4ppc. |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hello there,
I am making an "old school text based game" where you move a character around the screen. I dont really want to use the device's hardware keys but instead to use the stylus on the screen and where you click on the screen determines where your "character" moves in the maze (North, East, South, West) (imagine Pacman type game). My dilemma is, does anyone know of a smart piece of code or function which will return a "N" or "E" or "W" or "S" depending where they click on the screen (using for example Form1.MouseDown(X,Y)? An example "320x200" area screen and clickable "trinagled area" points and return values can be seen in the attached click.GIF. Does anyone know a calculable formula for translating X,Y of the four areas highlighted into the N E W S returns for my app? Thank you. |
|
|||
|
I think that only applies when the screen is a square. Following badkarma's example, you'll have to deal with the slopes of the lines (i.e. y=(200/320)*x etc.) which makes it slightly less straightforward.
My approach would be to consider the 2 diagonals: - Diagonal 1: y = (height/width) * x - Diagonal 2: y = height - ((height/width) * x) And check whether the clicked position is: - Above diagonal 1 and 2 => North - Above diagonal 1 and below diagonal 2 => West etc. Last edited by Upquark : 03-30-2009 at 11:43 PM. |
|
||||
|
I think this does it although I haven't run it so it could well fail. Assuming the detection rectangle has co-ordinates (XL,YL), (XR,YR)
Code:
mousex = mousex - XL mousey = mousey - YL X = XR - XL Y = YR - YL pos = 0 if mousey > mousex*Y/X then pos = 1 ' 0 is S or W, 1 is N or E if mousex > (Y - mousey)*X/Y then pos = pos + 2 ' 0 is N or W, 2 is S or E ... ' pos 0 = W, 1 = N, 2 = S, 3 = E |
|
|||
|
Thank you all for your time taken for your replies, hints and tips, and formulas, I really do appreciate it.
I now have it working and have put the example here... Detecting Zone tap regions North East West South Once again, many thanks for your time, I'm not the best with formulas for maths ![]() Cheers Steve Last edited by badkarma : 03-31-2009 at 07:21 PM. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Files Required to be loaded on Mobile Device | johnpc | Questions & Help Needed | 1 | 03-04-2009 03:07 PM |
| Evaluating mathematical expressions | Erel | Code Samples & Tips | 0 | 06-10-2007 06:56 AM |