Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / 2d Birds Eye Veiw mouse movement math help.

Author
Message
Prep
20
Years of Service
User Offline
Joined: 17th Nov 2003
Location:
Posted: 29th Jan 2004 01:20
Basically i'm writing a small RPG (and I mean small) made for two players (if I somehow become a master of programming during the course of this i'll increase the player count but I seriously can't see that happening, but I think I can handle two players well enough) and currently I use keypad control which is bad, I really don't like it.

I want to use the mouse to move "the player" (well the sprites I use to make up a tile based BG truthfully) so I wrote the controls to be simple if MouseX > etc etc and it works "ok". The problem really is the threshholds between directions, I don't like it. (four rectangles at the edges basically)

My idea is to simpley divide the game area (640x480 not including GUIS) into 4 triangles (simply drawing an X from corner to corner). The problem is my math doesn't appear to have the answer to corrcetly Identifying the area the mouse is within.

So basically i'm asking if anyone could either give me a (or 4 seperate ifs) formula to work with or give me some advice on where to start with it.

I would be greatful for any help at all really.

Thanks in advance for any help.

To be no more, sad cure.
Avien Langley
20
Years of Service
User Offline
Joined: 29th Jan 2004
Location: State of Denial
Posted: 29th Jan 2004 19:00
I just got up so I'm too tired to think of the exact formulas you'd need to determine which triangle the mouse cursor is in, but here's a general method I'd recommend for simplifying the process:

First divide the screen into four rectangular quarters. Within each quarter, there are 2 possible triangles the cursor could be in, and each quadrant will be precisely cut in half by the two triangles it overlaps. Once you know which rectangular quadrant the mouse cursor is in, you only have 2 triangles you need to mess with. This might be easier than trying to come up with straight formulas to determine which of the 4 triangles the mouse cursor is in. Quick example:

` If mouse is in upper-left corner of the screen it could be
` in either the top or left triangle.
if mousex()<321 and mousey()<241
` This is where the code for determining whether the mouse is
` in the upper or left triangle goes. (The code I'm too tired to
` come up with right now.)
endif

` If mouse is in upper-right corner of the screen it could be
` in either the top or right triangle.
if mousex()>320 and mousey()<241
` Code for determining whether mouse goes in upper or left triangle
endif

` etc.

I don't know of how much help that will be, but I hope it at least gets you started. You need to figure out the relationship between the x and y coordinates of the edges of each triangle within each rectangular quadrant in order to determine which triangle the cursor is in. That could get a little tricky, particularly for the upper-right and lower-left quadrants. I wish you luck.
Prep
20
Years of Service
User Offline
Joined: 17th Nov 2003
Location:
Posted: 31st Jan 2004 03:21 Edited at: 31st Jan 2004 03:24
Thanks for the advice friend, I think it will be most handy, i'm going to have a crack at it over the weekend and see if I can come up with something.

If all goes badly I might do something like

]_ _[
]_ _[
]
_]_
_] [_
] [

I think that would be much simpler and not much worse, but i'll have ago with the triangles first.

Thanks again for the advice.

edit - ok my shape looks a lot nicer in the message box. Its a series of rectangles making a sort of step pyramid type thing.

To be no more, sad cure.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 31st Jan 2004 13:03
An X to connect corners? You got me totally confused.

"eureka" - Archimedes
Prep
20
Years of Service
User Offline
Joined: 17th Nov 2003
Location:
Posted: 31st Jan 2004 16:57
If you draw an X over the screen you end up with four triangles. I want to use these along with the second mouse button to determine direction for the player to move.

To be no more, sad cure.

Login to post a reply

Server time is: 2024-05-13 21:16:33
Your offset time is: 2024-05-13 21:16:33