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.

Newcomers AppGameKit Corner / Jumping and falling help

Author
Message
bszaronos
User Offline
Joined: 7th Jul 2017
Location:
Posted: 24th Jul 2017 15:34
Hello all,

I am trying to learn different methods for coding jumping and falling for a platform game.

So I have created a basic platform. I created a bunch of sprites as the ground level, a player sprite, and a block raised above the player. I have added a joystick and a button.
When the button is pressed the player moves up.

Is there a simple way have this player jump up and stay on the block, but if he moves off the block then fall down.
What I have done before is code everything by hand. If the sprite is in this position and jump button is pressed then put the sprite in this position.

I don't quite understand the physics parts of things yet. ( still just starting and learning ) so not sure if that would be easy.

+ Code Snippet

Thanks for any help with this. Just trying to learn different ways to do things

-Brian
Supertino
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 25th Jul 2017 10:32
Is my Pangemic platformer game in my signature what you're looking to achieve? if so in simple terms you need to be continually making the player fall (gravity) by increasing the Y position, if the feet touch a platform then one way (not the best) is to make him stop falling is to apply an equal decrease value to Y, there is some additional logic that needs to come into play so he doesn't clip through platforms etc. I use a custom hitbox object I apply to all objects in the game so I can detect which sides of which hitboxes collide and stop\offset as needed. I can maybe provide a quick example later this evening if you like.
bszaronos
User Offline
Joined: 7th Jul 2017
Location:
Posted: 25th Jul 2017 13:36
Supertino, That would be great if you could give an example. I am still in the beginning stages of learning AppGameKit, and I don't quite understand it all yet.
I am having fun learning though

-Brian
bszaronos
User Offline
Joined: 7th Jul 2017
Location:
Posted: 25th Jul 2017 19:03
So I fooled around with the test code. I came up with two different ways to fall off the edge.
one way way is to check the player x and y position to see if they are off the edge.
the second is to use two blank sprites, one on each side of the second level and detect via a sprite collision.

I tried using physics, but can't seem to wrap my head around it. All I am able to do is have the player spin.

+ Code Snippet


-Brian
Supertino
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 25th Jul 2017 23:08 Edited at: 25th Jul 2017 23:16
hope this helps, knocked this up in about half an hour (still new to AGK), it uses my own hitbox functions, in practice you'd apply sprites to the hit box coords etc.



Paste this into a new project and it should run
+ Code Snippet

.
Supertino
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 25th Jul 2017 23:10 Edited at: 25th Jul 2017 23:16
not sure why my last reply is has messed up formatting like that?!

[edit] this one too, seems forums are knackered.
bszaronos
User Offline
Joined: 7th Jul 2017
Location:
Posted: 26th Jul 2017 00:24
Thank you, Lots of good stuff in there.
So you are not using the built in physics from AGK. You are setting up a velocity and gravity via variables to apply to the player.

It's gonna take me a while to go through and figure out everything, again thank you.
I like the level_data idea, didn't think of that.

Is there a benefit to using functions rather than gosub's. I haven't gotten to the point of using functions yet. I have added files like moveplayer.agc and then just call a gosub moveplayer.


-Brian

blink0k
4
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 26th Jul 2017 01:22
I made up a little demo of how i would implement platform physics. I use getspritecollision() but you could just as easily use the position of the sprite and a map to determine collision.
What it demonstrates is very rudimentary jump/fall physics by using a gravity variable.
See the attached project. Hope it helps

Attachments

Login to view attachments

Login to post a reply

Server time is: 2017-07-26 02:48:26
Your offset time is: 2017-07-26 02:48:26