Have different gravity on specific screen types (4.5.9)

baardbi

Well-known member
Here's a tutorial for making levels with different gravity on specific screens based on screenType.

This can for example be used to make underwater levels or space type levels.

PS! This tutorial is made for platform type games.

1.
Make a backup of doHandlePhysics_PlatformBase.asm
It's located in ...\BASE_4_5\Game\MOD_PlatformerBase\Subroutines

2.
Comment out the lines about gravity. It's somewhere around line 475

;MAX_FALL_SPEED = #$04
;GRAVITY_LO = #$40
;GRAVITY_HI = #$00

3.
Then add user variables for every one of those constants

gravityConst.PNG

4.
Then remove the # in front of the references to gravity (somewhere around line 710)

ADC GRAVITY_LO
STA Object_v_speed_lo,x
LDA Object_v_speed_hi,x
ADC GRAVITY_HI
STA Object_v_speed_hi,x

LDA Object_v_speed_hi,x
CMP MAX_FALL_SPEED

Just to be sure, we're talking about these three values:

GRAVITY_LO
GRAVITY_HI
MAX_FALL_SPEED

5.
Make a backup of extraScreenLoad_PlatformBase.asm
It's located in ...\BASE_4_5\Game\MOD_PlatformerBase\Game

6.
At the end of the extraScreenLoad_PlatformBase.asm file put this:

LDA screenType
CMP #$01 ;;;; This is the screen type for special gravity
BEQ +specialGravity

JMP +finishedGravityCheck

+specialGravity:

LDA #$02
STA MAX_FALL_SPEED
LDA #$20
STA GRAVITY_LO
LDA #$00
STA GRAVITY_HI

+finishedGravityCheck:

7.
Set screen type to 1 on the screens you want special gravity on. The default here is 1 but can of course be changed.

8.
You should now have screens with low gravity. You can experiment with different values for MAX_FALL_SPEED, GRAVITY_LO and GRAVITY_HI for a different effect.


Let me know if something in this tutorial isn't working.
 
@baardbi this was gold! thank you!
i implemeted it as my gravity change for swimming so it works on my swiming action step! very simple way of doing it!

my doHandlePhysics_PlatformBase.asm looks like this
Code:
            LDA Object_v_speed_lo,x
            CLC
            ADC GRAVITY_LO
            STA Object_v_speed_lo,x
            LDA Object_v_speed_hi,x
            ADC GRAVITY_HI
            STA Object_v_speed_hi,x
            
                LDA Object_v_speed_hi,x
                CMP MAX_FALL_SPEED
                BNE notOverFallSpeed
                    ;; is at least max fall speed.
                    LDA #$00
                    STA Object_v_speed_lo,x
                notOverFallSpeed:
                
            GetActionStep #$00
            CMP #$06
            BEQ +SWIM

            JMP +finishedGravityCheck

            +SWIM:

            LDA #$01
            STA MAX_FALL_SPEED
            LDA #$10
            STA GRAVITY_LO
            LDA #$00
            STA GRAVITY_HI

+finishedGravityCheck:
    
    JMP doneWithGravity
 

baardbi

Well-known member
@baardbi this was gold! thank you!
i implemeted it as my gravity change for swimming so it works on my swiming action step! very simple way of doing it!

my doHandlePhysics_PlatformBase.asm looks like this
Code:
            LDA Object_v_speed_lo,x
            CLC
            ADC GRAVITY_LO
            STA Object_v_speed_lo,x
            LDA Object_v_speed_hi,x
            ADC GRAVITY_HI
            STA Object_v_speed_hi,x
           
                LDA Object_v_speed_hi,x
                CMP MAX_FALL_SPEED
                BNE notOverFallSpeed
                    ;; is at least max fall speed.
                    LDA #$00
                    STA Object_v_speed_lo,x
                notOverFallSpeed:
               
            GetActionStep #$00
            CMP #$06
            BEQ +SWIM

            JMP +finishedGravityCheck

            +SWIM:

            LDA #$01
            STA MAX_FALL_SPEED
            LDA #$10
            STA GRAVITY_LO
            LDA #$00
            STA GRAVITY_HI

+finishedGravityCheck:
   
    JMP doneWithGravity
Cool! You're welcome. Glad to be of help.
 

cramske

Member
I think Im confused now. I am using a combination of scripts. I am a newbie. I would love to do this.
Im using arcade platformer and adventure basescripts. my dohandlePhysics is Arcade platformer and my extra screen load is Adventure base.. ?
Maybe I am doing this wrong?
 

baardbi

Well-known member
I think Im confused now. I am using a combination of scripts. I am a newbie. I would love to do this.
Im using arcade platformer and adventure basescripts. my dohandlePhysics is Arcade platformer and my extra screen load is Adventure base.. ?
Maybe I am doing this wrong?
Sorry. I haven't used those modules much lately. I'm guessing the arcade platformer would be pretty similar. The big thing here is changing the constants to variables. I'll have to look more into those modules you're using, but unfortunately I'm super busy trying to finish Nosey Joe at the moment. I'll let you know if I find out something that can be of any help to you.
 

Ahrevival

New member
Hi @baardbi . This is great. I have it working. Quick one - I have Screen 5 as the special gravity screen. Is there a way to load a special action as default for those screen types? I'd like the player to be swimming on these parts. I tried to follow others on here - but nothing is working. Thanks.
 

baardbi

Well-known member
Hi @baardbi . This is great. I have it working. Quick one - I have Screen 5 as the special gravity screen. Is there a way to load a special action as default for those screen types? I'd like the player to be swimming on these parts. I tried to follow others on here - but nothing is working. Thanks.
You could do that. However it would just change back to walking as soon as you move left or right because the input scripts change the action step. So you would have to both change the action step in (for example) the extraScreenLoad script as well as modify the input scripts. Another way to do this is to have more than one set of game object graphics in your game. I have a tutorial for that. It's a bit cumbersome to set up, but it would probably be the best way to do it. That way you don't have to worry about accidentally changing action steps.

 

Ahrevival

New member
Thanks. I tried the other tutorial based on this post. The swimming tutorial by CalFlyheight. But, my player just gets stuck in the middle of the screen and can't move.
 

baardbi

Well-known member
Thanks. I tried the other tutorial based on this post. The swimming tutorial by CalFlyheight. But, my player just gets stuck in the middle of the screen and can't move.
Oh. Interesting. I haven't seen that one. I'll take a look.
 
Top Bottom