Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.

Ads

#1 2016-06-12 14:17:16

8sync
New member
Registered: 2016-04-07
Posts: 4

Need help with platformer physics

Hi!
I'm currently learning GBDK and after few steps forward, now I'm on to make a simple platformer game.
And there's the problem.
I have no idea how to make a simple platformer physics code.
I tried to port https://scratch.mit.edu/projects/1236389/#editor ,but since there are no floats in GBDK, I'm kind of stuck.
Can somebody instruct me?


BTW, my first post on this forum. Hi, guys!

Last edited by 8sync (2016-06-13 13:44:07)

Offline

 

#2 2016-06-13 15:09:31

Xephyr
Member
From: France
Registered: 2015-02-26
Posts: 59

Re: Need help with platformer physics

You needs floats for "velocity*0.9" right?

Then why not simply do "(velocity*9)/10"? Of course it will gives you an approximation, but it's still better than nothing I guess.

Offline

 

#3 2016-06-13 19:02:52

rychan
Member
From: Paignton, Devon, UK
Registered: 2015-12-16
Posts: 103
Website

Re: Need help with platformer physics

okay, here's the method I use, maybe not the most efficient but hey, here we go:

Say you have to move the playersX co-ordinate but with an acceleration force. Create another variable, sayy a UINT8 calleed playersSubX.

Adjust the playerSubXt value based on force and whilst it is overcertain limits, constrain it then inc / dec the playerX variable.

This way you're not left with more processor intensive operators such as multiplication and division, just + and -

Hope this helps out smile

Offline

 

#4 2016-06-14 04:04:38

LuckyLights
Member
Registered: 2014-07-06
Posts: 20

Re: Need help with platformer physics

I would recommend to start with developing a game on PICO8 to get a fell for what you want to do. Doing GBDK games is not a great place to start game programming, lots of very techy stuff to keep in mind.
I will make my new gameboy game pandaland opensource once i am "done" https://twitter.com/LucasDuroj/status/7 … 3351050240 and you could have a look at that code by then. but I dont know when thats going to happen.

Offline

 

#5 2016-06-14 07:40:10

rychan
Member
From: Paignton, Devon, UK
Registered: 2015-12-16
Posts: 103
Website

Re: Need help with platformer physics

That is a nice looking game there LuckyLights! Keep us updated on how it comes along yeah?

Offline

 

#6 2016-06-14 11:02:59

8sync
New member
Registered: 2016-04-07
Posts: 4

Re: Need help with platformer physics

Thanks for answers.
I already figured out X-axis movement (moving with a little slide), but i'm still having problems with Y-axis movement(gravity).
I mean, the character accelerates during the fall, but there's another problem.
When the character accelerates, it needs to move more and more pixels per screen update.
And my code for detecting collision looks like this:

if(YouReTouchingOrBelowTheGround()==TRUE)
      STAHP();

It usually results in my character stuck in the floor.

Last edited by 8sync (2016-06-16 09:53:35)

Offline

 

#7 2016-06-14 11:55:37

rychan
Member
From: Paignton, Devon, UK
Registered: 2015-12-16
Posts: 103
Website

Re: Need help with platformer physics

2 ways to go about this. Either check the future position (before updating your sprite position) then adjust.

Orrr, make the maximum limit 1 or 2 pixels per collision check frame.

Offline

 

#8 2016-06-16 09:53:01

8sync
New member
Registered: 2016-04-07
Posts: 4

Re: Need help with platformer physics

Thanks guys, for solving my problem so quickly and effectively.
Everything works quite fine by now. No rocket science, but still.
It's nice to know, that (after many dead websites, which i had to search in archive.org) there's still an active forum, with many passionate people.

Offline

 

#9 2016-06-16 19:08:09

quangdx
New member
Registered: 2013-10-01
Posts: 8

Re: Need help with platformer physics

If your Character collides with the floor, you need to raise him up, pixel by pixel until they are no longer colliding.
A while loop should be good for that.

while(PlayerStuckInFloor==True){
YPosition=YPosition-1;
}

Offline

 

#10 2016-06-17 08:59:08

8sync
New member
Registered: 2016-04-07
Posts: 4

Re: Need help with platformer physics

I tried that, but it looked like the floor was giant trampoline.

Offline

 

#11 2016-06-19 18:38:20

quangdx
New member
Registered: 2013-10-01
Posts: 8

Re: Need help with platformer physics

The loop should happen before the next frame,
so you don't update the actual sprites positions until it's found it's resting place.

Game Loop {
Perform Game Logic
Move Characters
If inside floor, move them up until out of floor.
Update Sprites positions with Character values.
VBLANK
}

Hopefully that makes sense.

Offline

 

#12 2016-07-09 17:26:31

LuckyLights
Member
Registered: 2014-07-06
Posts: 20

Re: Need help with platformer physics

It's generally a good idea to have your ground/world in a lower resolution then your sprites. For instance if you use tiles as your ground they would probably be a deviation by 8. That way when you detect a collision with you ground you can safely assume that the correct y pos the closest div by 8, and its safe to move your sprites (as long as your moving less then 8px per frame) to that y pos.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson