CalFlyheight
Member
So i made my player be able to jump in the water and swim about and then jump back out and go back to normal physics.
View: https://youtu.be/KvIPM1aNJZo
this takes up 2 tiles and a very small amount of code in the physics and a couple of input scripts.
im using action step #$06 as my swimming animation so thats what will be checked for these scripts
like usual make backups of existing scripts you are working on.
lets start with the doHandlePhysics_PlatfromBase.asm
here we are going to do somethings that @baardbi has already worked out for us.
follow steps 1, 2,3 and 4
then we will edit the doHandlePhysics scricpt just after the 3 variables mentioned
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
with code like this
this will use the swim action step to switch to swim physics and use normal gravity if no swimming.
you could make a whole bunch of gravity changes depending on situations if you wanted.
Now the tiles.
i made a swimtile.asm and assigned it to tile 13
this will switch to swim action and reboot a little gravity switch when falling.
next is a return action tile.
mine is set to tile 14 returnaction.asm
this tile is placed above the swim tile so that when jumping out of the water it goes to jumping #$02 and normal gravity.
0D swim
0E return
lastly we need to make A button in this case cause a jump while in swim state.
so the input script jump_throughPlat.asm will need a tweak around line 24 to check action step #$06
next is changeActionToMoving_unlessJumping.asm
we r just adding in the CMP #$06 part to each of these scripts to allow movement to change for swimming.
next is changeActionToStop_unlessJumping.asm
again just to clarify we are just adding the
GetActionStep temp
CMP #$06
BNE +notSwim
RTS
+notSwim
stuff to whatever you input script already has
lastly is stopMoving.asm
thats about it. obviously it will need adapting for individual games but this will give a good start.
good luck nesmakers!
this takes up 2 tiles and a very small amount of code in the physics and a couple of input scripts.
im using action step #$06 as my swimming animation so thats what will be checked for these scripts
like usual make backups of existing scripts you are working on.
lets start with the doHandlePhysics_PlatfromBase.asm
here we are going to do somethings that @baardbi has already worked out for us.
Have different gravity on specific screen types (4.5.9)
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...
www.nesmakers.com
then we will edit the doHandlePhysics scricpt just after the 3 variables mentioned
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
with code like this
Code:
notOverFallSpeed:
GetActionStep #$00
CMP #$06
BEQ SWIM
LDA #$40
STA GRAVITY_LO
LDA #$00
STA GRAVITY_HI
LDA #$04
STA MAX_FALL_SPEED
JMP doneWithGravity
SWIM:
LDA #$90
STA GRAVITY_LO
JMP doneWithGravity
isSolidSoLand:
this will use the swim action step to switch to swim physics and use normal gravity if no swimming.
you could make a whole bunch of gravity changes depending on situations if you wanted.
Now the tiles.
i made a swimtile.asm and assigned it to tile 13
Code:
;;;;SWIM:;;;;;;;;;;;
GetActionStep #$00
CMP #$06
BEQ +skip
CPX player1_object
BNE +skip
ChangeActionStep #$00, #$06
LDA Object_v_speed_hi,x
LDA #$01
STA MAX_FALL_SPEED
STA Object_v_speed_hi,x
+skip:
RTS
next is a return action tile.
mine is set to tile 14 returnaction.asm
Code:
;; return from swim
CPX player1_object
BNE +skip
ChangeActionStep #$00, #$02
+skip:
RTS
0D swim
0E return
lastly we need to make A button in this case cause a jump while in swim state.
so the input script jump_throughPlat.asm will need a tweak around line 24 to check action step #$06
Code:
;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Only can jump if the place below feet is free.
SwitchBank #$1C
LDY Object_type,x
LDA ObjectBboxTop,y
CLC
ADC ObjectHeight,y
sta temp2
LDA Object_x_hi,x
CLC
ADC ObjectBboxLeft,y
STA temp
JSR getPointColTable
LDA Object_y_hi,x
CLC
ADC #$02
CLC
ADC temp2
STA temp1
GetActionStep #$00
CMP #$06
BNE +checkMore
JMP +doJump
+checkMore
CheckCollisionPoint temp, temp1, #$01, tempA ;; check below feet to see if it is solid.
next is changeActionToMoving_unlessJumping.asm
Code:
TXA
STA temp ;; assumes the object we want to move is in x.
GetActionStep temp
CMP #$07
BNE +notHurt
RTS
+notHurt
CMP #$02 ;; the state of your jump animation
BNE +notJumping
RTS
+notJumping
CMP #$06
BNE +notSwim
RTS
+notSwim
ChangeActionStep temp, #$01 ;; assumes that "walk" is in action 1
;arg0 = what object?
;arg1 = what behavior?
;+
RTS
next is changeActionToStop_unlessJumping.asm
Code:
TXA
STA temp ;; assumes the object we want to move is in x.
;;; It is possible that we are pressing multiple directions, and let go of one of them.
;;; If this happens, we would have our behavior change to stop, even though we'd continue to move.
;;; What we need to do is checkt o see if the relevant dpad buttons are pressed. If any buttons
;;; are pressed that would counter the change to a stop action upon release, we need to skip the
;;; change to stop action.
;GetActionStep temp
;CMP #$07
;BNE +notHurt
; RTS
LDA controllerNumber_hold
;BNE weAreCheckingCOntroller2
;; we are checking controller 1.
LDA gamepad
AND #%11110000
BEQ changeToStop_NoDpadPressed
RTS
;weAreCheckingCOntroller2:
;LDA gamepad2
;AND #%11110000
;BEQ changeToStop_NoDpadPressed
;RTS
changeToStop_NoDpadPressed:
GetActionStep temp
CMP #$06
BNE +notSwim
RTS
+notSwim
ChangeActionStep temp, #$00 ;; assumes that "walk" is in action 1
;arg0 = what object?
;arg1 = what behavior?
RTS
GetActionStep temp
CMP #$06
BNE +notSwim
RTS
+notSwim
stuff to whatever you input script already has
lastly is stopMoving.asm
Code:
;;;;
TXA
STA temp ;; assumes the object we want to move is in x.
StopMoving temp, #$FF, #$00
TXA
STA temp ;; assumes the object we want to move is in x.
GetActionStep temp
CMP #$07
BNE +notHurt
RTS
+notHurt
CMP #$06
BNE +notSwim
RTS
+notSwim
ChangeActionStep #$00, #$00
RTS
good luck nesmakers!