Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


Mathematical Genius Required


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-30-2009, 10:50 PM
Senior Member
 
Join Date: Mar 2008
Posts: 196
Default Mathematical Genius Required

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.
Attached Images
File Type: gif click.GIF (2.0 KB, 13 views)
Reply With Quote
  #2 (permalink)  
Old 03-30-2009, 11:34 PM
LineCutter's Avatar
Senior Member
 
Join Date: May 2007
Location: Daarsit
Posts: 143
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Assuming that you know where the middle of the screen (Form.height/2 etc) is then you know the 45 degree lines run at x=y, x=-y, y=-x & -y=-x.

So if (screentap x value) minus (screen centre x value) is positive but > than the absolute value of y then the move is east. Ror x being negative the move is west. After that, if (Screen tap y) - (Screen centre y) is positive then the move is north (You've already excluded it being E or W) & a negative value is south.
Note that taps on the lines go N or S (You could change the default, or simply view this as a way to irritate indecisive players).

The coding (if then statements nested) should be straight forward, although you might want to read the help file for Abs().
Reply With Quote
  #3 (permalink)  
Old 03-30-2009, 11:37 PM
Newbie
 
Join Date: Mar 2009
Posts: 1
Default

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.
Reply With Quote
  #4 (permalink)  
Old 03-31-2009, 09:13 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 3,357
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

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
Reply With Quote
  #5 (permalink)  
Old 03-31-2009, 12:00 PM
Senior Member
 
Join Date: Mar 2008
Posts: 196
Default

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.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT. The time now is 02:41 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0