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 / [SOLVED] movement vector based on getpointer help

Author
Message
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 8th Jun 2016 00:21
Ide like to get a movement amount based on how far/fast the mouse cursor has been moved in a particular

What I have it randomly scrolls blocks in direction depending on the mouse pointer
(I'm thinking that the sprites I'm using are more background and the main game sprite stays stationary in the centre of the screen)



The idea is to just swipe with the mouse the direction you want to go and continuously move in that direction that part seems to be working what I figure there should be some sort of speed factor
so if you swiped slower then you would effectively slow down. not sure if the idea is just crazy or i am and the only way to stop would be collide.

fubar

The author of this post has marked a post as an answer.

Go to answer

fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 8th Jun 2016 04:34
This might give more of an idea of what I'm doing




fubar
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 8th Jun 2016 12:20
Ive given up on the thrust factor and still very much playing around and please forgive the sprites they're only test sprites
but the following ive got working so far with modifications to the code listed need to change the large ships as they're just off google images but you can see parallax scrolling with bullets etc
The other ship came from one of the additional graphics packs with AGK

hope the video works


Its a bit tricky using finger drag for continues movement but that's what I like so much about programming for the phone, there is so many ways to use selection
and movement and personally I don't like using a virtual joystick with a touchscreen


I still need to make use of sprite offsets but I was having problems with them at the beginning so that will be a last thing I do when I tidy up the code
fubar
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 8th Jun 2016 12:42 Edited at: 8th Jun 2016 12:45
This post has been marked by the post author as the answer.
You could just do a square root based on your pointer location and ship, like work out the differences on each axis, then calculate the distance, and adjust for minimum and maximum thrust.

Like:



So you'd have spd#, which is the distance from the pointer to the ship - how that actually converts to velocity depends on your own scales, maybe divide by the screens actual width to allow for different resolutions.

Also, it might be worth storing the ships X and Y velocity, and adjusting them to match the desired velocity, so the actual velocity increases or decreases gradually. This would let you have some inertia and make movement a little more dynamic - like skidding around a bit, drifting around corners, move in a direction and turn and fire while still moving.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 8th Jun 2016 13:07
That's exactly what I was looking for Van B thanks
fubar
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 8th Jun 2016 14:08
I also added a velocity factor like you suggested and makes it much more controllable thanks again
I hope this post also helps other people as ive found using this method now that ive ironed out the bugs quite a
a good way of controlling movement
fubar
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 11th Jun 2016 02:10
not sure if anyone is interested in seeing what I have now but il share the video just in case.
I'm thinking of releasing full source code afterwards



This should show the acceleration and thrust factor suggested by "Van B"

fubar
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 11th Jun 2016 10:20
it looks good. interesting control method. is there some AI for the enemy ships?
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 11th Jun 2016 20:43
Thanks blinkOk

The mothership in Centre doesn't do much atm and is just used to spawn the enemy fighters
There is also 4 spacestations top left, top right, bottom left, bottom right not seen in this video
Each enemy fighter points and moves towards your ship keeping a certain distance
The enemy fighters have an acceleration and thrust factor too not as fast as players ship tho
The players ship I'm thinking of modifying it to shoot forward and backward as I want the enemy fighters to shoot aswell
The mothership and space stations have hitpoints so they take several hits to die

my thinking the player has to destroy all space stations and the mothership in order to progress to next level

that's the plan but open to different suggestions
fubar
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 11th Jun 2016 20:53
The following is how I get a speed and acceleration of the enemy fighters its very similar to the way I do with the player ship



The following are functions I used





fubar
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 23rd Jun 2016 10:54
Well I had a break and got back to some coding. The code is very messy at the moment and needs allot of documenting but here is the full code so far for those interested.



designing levels is the next step but here is the map file so any help or suggestions here would be greatly recieved



youl note I still have not added sound but here is the video so far



If anyone is interested the media can be downloaded here
http://users.tpg.com.au/subarpk/media.rar

The developer of the green sprites are compliments of the Millionvector
http://millionthvector.blogspot.com.au/p/free-sprites.html
fubar
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 27th Jun 2016 00:20
Fixed some bugs and added 4 types of levels
not much different in each level so far apart from hitpoint changes and the colours of the enemy ships



http://users.tpg.com.au/subarpk/media.rar
not sure what people actually think but i atleast like the movement as i hate virtual joysticks on phones
fubar
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 27th Jun 2016 12:03
and for those that are too lazy to copy and paste the Source code and download media
I figured ide test the html5 commands out and got a working version at the following link

http://users.tpg.com.au/subarpk/HTML5/SpaceShooter.html

Still no rules image yet
just move the mouse
will adventually have a rules image with scoring etc


I also am awaiting for facebook to approve it to test it under facebook as I went through the facebook requirements

fubar
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 26th Jul 2016 11:11 Edited at: 12th Apr 2018 20:51
Should be the last and final post of this one



the last bit just fixes the level wave and end of game graphics under windows no idea why it doesn't show on all android phones or under html but works fine under windows
stops the brief flash of the wave appearing at top of screen prior to its movement changes which was source I got out of the forums so I don't deserve credit for that
fubar

Login to post a reply

Server time is: 2024-11-25 03:44:41
Your offset time is: 2024-11-25 03:44:41