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.

AppGameKit Classic Chat / Angles, maths and relative positions?

Author
Message
Fluorescent
FPSC Reloaded TGC Backer
19
Years of Service
User Offline
Joined: 1st Aug 2005
Location: Stockholm, Sweden
Posted: 25th Jul 2017 17:05
The game character can move up, down, left, right in a grid. One space at a time. I handle this by checking if there has been a key press or change in the joystick axis. Then set the variables DX or DY to either 1 or -1. So DX = -1 and DY = 0, walk left one position. DX = 0, DY = 1, walk down one position. Then check for obstacles and so on and so forth.

Now I want to add the ability to click with the mouse, or on a touch screen to move the character. Based on the same rules, so I need to figure out how PointerX and PointerY relates to the player position and set DX or DY to 1 or -1. But only on of them, both should not be able to be set at once. I've tried by doing this


It seems like a sort of promising start, but not great, the angles don't quite line up. Any suggestions?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 25th Jul 2017 18:39 Edited at: 25th Jul 2017 18:55
like this?
AGK (Steam) V2017.07.19 : Windows 10 Pro 64 Bit : AMD (17.4.4) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 25th Jul 2017 20:00 Edited at: 25th Jul 2017 21:16
For this I would opt for a grid x,y co-ordinates system, I started coding a simple example and got a little bit carried away lol.

http://parttimecode.16mb.com/Grid/Grid_Movement.html

EDIT: cleaned up my code (made more modular) and added keyboard movement, fixed an error with out-of-bounds array index if trying to move outside grid
Fluorescent
FPSC Reloaded TGC Backer
19
Years of Service
User Offline
Joined: 1st Aug 2005
Location: Stockholm, Sweden
Posted: 26th Jul 2017 17:37
Thank you for your suggestions, here is how I decided to solve it eventually. I think it will work well once I add sprites with arrows as cursor so the player can see what direction the player character will move when clicking.

Login to post a reply

Server time is: 2024-09-30 05:21:22
Your offset time is: 2024-09-30 05:21:22