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
7
Years of Service
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.



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

-Brian
Supertino
7
Years of Service
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
7
Years of Service
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
7
Years of Service
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.




-Brian
Supertino
7
Years of Service
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


.
Supertino
7
Years of Service
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
7
Years of Service
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
Moderator
11
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
bszaronos
7
Years of Service
User Offline
Joined: 7th Jul 2017
Location:
Posted: 26th Jul 2017 03:53
Thanks Blink0k, I just downloaded the file, will check it out in the morning. Looks good though, just skimmed it real quick before bed.
But looks like everyone is doing the same thing, they are not using the built in physics functions, but instead using variables.

Thanks appreciate it

-Brian
Supertino
7
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 26th Jul 2017 08:54 Edited at: 26th Jul 2017 08:55
@ bszaronos you probably can use the built in Physics, not sure it's the best for a pixel perfect platformer though, I believe the game Briad used Box2D physics or similar, which I think is what AppGameKit uses? I am still new round here. As to functions vs gosubs, functions is the way to go, AppGameKit has nice write up on what functions can do for you, my example also uses Types which is something else you should get to grips with.
bszaronos
7
Years of Service
User Offline
Joined: 7th Jul 2017
Location:
Posted: 26th Jul 2017 17:21
So using my original example and taking bits from the examples ( still trying to wrap my head around the examples, but getting there )
I was able to get the player to move and jump on the blocks and even do a double jump, and fall off the block. This is way better then just coding the y position to subtract a set number.

Is there a simple way to detect if a collision only happens with the player bottom and the top of the 2nd level ?

Supertino
7
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 27th Jul 2017 13:38 Edited at: 27th Jul 2017 13:40
okay bszaronos I took your code and made changes so its more or less functional with feet, head and side collisions, for this method its best that the player sprite is smaller than the ground sprites, the order in which collision detects are done is also important with all x axis collision and movement done before y axis. hope this gets you going.



bszaronos
7
Years of Service
User Offline
Joined: 7th Jul 2017
Location:
Posted: 27th Jul 2017 14:25
I have to say that you guys are awesome. I am going to name my first child after both of you. She will not be happy, but this is the least I can do.

-Brian

Login to post a reply

Server time is: 2024-11-22 16:20:49
Your offset time is: 2024-11-22 16:20:49