Making the water splash in the Platform module

baardbi

Well-known member
Here is a tutorial on how to make the water splash when then player hits the surface, and how to make bubbles when the player is under water.

PS #1! Having a lot of splashing and bubbles in your game will cause a bit of slowdown.
PS #2! Using game objects for this is an expensive way to make effects, since you only have 16 game objects total.

Prerequisites for this tutorial:
- Basic understanding of NESmaker
- Knowledge about Game Objects and Tile Types
- Very basic understandig of ASM scripts

THE WATER SPLASH
watersplash.png


1. First we need to decide which Game Object we will use as the splash. In this example I will use game object 8 (the default is Effect 0)

2. Give it a name so it's easy to identify it:

watersplash2.png


3. Make the animation of the splash. I use 6 frames in this example (it might be too much if you want a lot of game objects with big graphics)

watersplash3.png


4. Set a bounding box on your game object. Use the entire box as the bounding box:

watersplash4.png


5. In the Object Details window of the game object (under the tab Actions) set the following:

- Animation speed
- End Animation -> DestroyMe
- Ignore Gravity

watersplash5.png


6. Create a new ASM file called WaterSplash.asm (or whatever you like). Save it in the TileScripts folder of your game.

C:\Users\baardbi\Desktop\WaterSplashGame\GameEngineData\Routines\Basic\ModuleScripts\TileScripts\SimplePlatformer

Code:
;Water splash

CPX player1_object
BNE +
    LDA tileX
    AND #%11110000
    STA temp
    
    LDA tileY
    AND #%11110000
    SEC
    SBC #$08 ;Adjust the splash to the top of the water tile
    STA temp1

    CreateObject temp, temp1, #$08, #$00, currentNametable ;Game Object 08 is the water splash
    ;PlaySound #SND_SPLASH
+

7. Assign this file to the Tile Collision of your choice (I use Tile 11 in this example)

watersplash6.png


8. In Project Settings go to Project Labels and give a name to your new Tile type:

watersplash7.png


9. You can now create a new tile (asset) which will be the water surface:

watersplash8.png


Every time the player comes in contact with this tile a new game object (your water splash animation) will be created on the tile the player collided with.


THE WATER BUBBLES
watersplash9.png


Making bubbles when the player is under water is exactly the same process as above. The only difference is a slightly different code for the WaterBubbles.asm file:

Code:
;;Water bubbles

LDX player1_object
LDA Object_x_hi,x
STA temp
LDA Object_y_hi,x
STA temp1
    
CreateObject temp, temp1, #$09, #$00, currentNametable
    
;LDA #$20
;STA GRAVITY_LO

In this example I use game object 9 for the water bubbles and Tile type 12 (see number 7 under The Water Splash tutorial).

Now you can make a new tile (asset) that acts as water. The bubbles (game objects) will be created constantly when the player collides with a water tile.

That's it!


A big thank you to Dale Coop for showing me how to get the position of the tiles the player collides with.

If you find any errors in this tutorial please let me know. Good luck making water effects in your game.
 

NeoBenj

Member
Nice tutorial, thank you.

Also, another way to treat FX, is to regroup All effects of the same sprite size (8x8, 16x16 etc) in 1 ID and just require to spawn the right FX by indicating which animation step to play.

Example:
Rename #$08 as "Water stuffs"
Water Splash = #$08, #$00
Bubbles = #$08, #$04 (so you can still animate your watersplash with animation 0, 1, 2, 3. And bubbles with animation 4,5,6,7).
Doing so, you saved 1 slot in your GameObjects!

As long are it is the same object type (Enemy, Weapon, Collectible), try to regroup your player ingredient together.
It works well, I regrouped all my FX including player death under only 1 ID. :)
 

NeoBenj

Member
Also if you need bubble and splash only in one part of your game (like 1 water specific world), you could also treat your waterslash and bubbles sprites as MonsterObject instead of GameObject.
So you can actually free your character sprite sheet, and include your water FX on the monster sprite sheet of that specific level.
My advice would be to keep as PlayerObject only sprites that can be displayed in any screen of your game (usually, projectiles, generic collectibles, generic FX, HUD elements, etc).
Otherwise you will shortly completely fill your character sheet. ;)
 

dale_coop

Moderator
Staff member
Yeah, NeoBenj is right... when your game becomes big, you need to factor the objects (use 1 object for different things, using different gfx animations. and like NeoBenj 1 object for death objects, I have 1 monster object for 8 different NPCs, 1 for the overworld decoration effets....)
 
Thanks baardbi!
Cool effect!
And you get waterphysics for free from the slowdown.
I had to change the tile-script a little to get it to work. I guess it was not created for 4.5.9?
sharing it here:

Code:
;Water splash
CPX player1_object
BNE +notPlayer
                    TXA
                    PHA
                    TYA
                    PHA
                        LDX player1_object
                        LDA Object_x_hi,x
                        CLC
                        ADC #$04
                        STA tempA
                        
                    LDA Object_screen,x
                    ADC #$00
                    STA tempD
                    
                        LDA Object_y_hi,x
                        SEC
                        SBC #$08 ;Adjust the splash to the top of the water tile
                        STA tempB
                        
                     LDA Object_direction,x
                     AND #%00000111
                     STA tempC
                    CreateObjectOnScreen tempA, tempB, #$08, #$00, tempD
                        ;;; x, y, object, starting action.
                        ;;; and now with that object, copy the player's
                        ;;; direction and start it moving that way.
                                            
                        
                    TXA
                    PLA
                    TAY
                    PLA
                    TAX
                        
    ;PlaySound #SND_SPLASH
+notPlayer:
 

baardbi

Well-known member
Thanks baardbi!
Cool effect!
And you get waterphysics for free from the slowdown.
I had to change the tile-script a little to get it to work. I guess it was not created for 4.5.9?
sharing it here:

Code:
;Water splash
CPX player1_object
BNE +notPlayer
                    TXA
                    PHA
                    TYA
                    PHA
                        LDX player1_object
                        LDA Object_x_hi,x
                        CLC
                        ADC #$04
                        STA tempA
                       
                    LDA Object_screen,x
                    ADC #$00
                    STA tempD
                   
                        LDA Object_y_hi,x
                        SEC
                        SBC #$08 ;Adjust the splash to the top of the water tile
                        STA tempB
                       
                     LDA Object_direction,x
                     AND #%00000111
                     STA tempC
                    CreateObjectOnScreen tempA, tempB, #$08, #$00, tempD
                        ;;; x, y, object, starting action.
                        ;;; and now with that object, copy the player's
                        ;;; direction and start it moving that way.
                                           
                       
                    TXA
                    PLA
                    TAY
                    PLA
                    TAX
                       
    ;PlaySound #SND_SPLASH
+notPlayer:
Yes. You are correct. It was made for 4.1.5. Thanks for adding the update to 4.5.9.
 

TheRetroBro

Active member
Thanks baardbi!
Cool effect!
And you get waterphysics for free from the slowdown.
I had to change the tile-script a little to get it to work. I guess it was not created for 4.5.9?
sharing it here:

Code:
;Water splash
CPX player1_object
BNE +notPlayer
                    TXA
                    PHA
                    TYA
                    PHA
                        LDX player1_object
                        LDA Object_x_hi,x
                        CLC
                        ADC #$04
                        STA tempA
                       
                    LDA Object_screen,x
                    ADC #$00
                    STA tempD
                   
                        LDA Object_y_hi,x
                        SEC
                        SBC #$08 ;Adjust the splash to the top of the water tile
                        STA tempB
                       
                     LDA Object_direction,x
                     AND #%00000111
                     STA tempC
                    CreateObjectOnScreen tempA, tempB, #$08, #$00, tempD
                        ;;; x, y, object, starting action.
                        ;;; and now with that object, copy the player's
                        ;;; direction and start it moving that way.
                                           
                       
                    TXA
                    PLA
                    TAY
                    PLA
                    TAX
                       
    ;PlaySound #SND_SPLASH
+notPlayer:
Here is a tutorial on how to make the water splash when then player hits the surface, and how to make bubbles when the player is under water.

PS #1! Having a lot of splashing and bubbles in your game will cause a bit of slowdown.
PS #2! Using game objects for this is an expensive way to make effects, since you only have 16 game objects total.

Prerequisites for this tutorial:
- Basic understanding of NESmaker
- Knowledge about Game Objects and Tile Types
- Very basic understandig of ASM scripts

THE WATER SPLASH
watersplash.png


1. First we need to decide which Game Object we will use as the splash. In this example I will use game object 8 (the default is Effect 0)

2. Give it a name so it's easy to identify it:

watersplash2.png


3. Make the animation of the splash. I use 6 frames in this example (it might be too much if you want a lot of game objects with big graphics)

watersplash3.png


4. Set a bounding box on your game object. Use the entire box as the bounding box:

watersplash4.png


5. In the Object Details window of the game object (under the tab Actions) set the following:

- Animation speed
- End Animation -> DestroyMe
- Ignore Gravity

watersplash5.png


6. Create a new ASM file called WaterSplash.asm (or whatever you like). Save it in the TileScripts folder of your game.

C:\Users\baardbi\Desktop\WaterSplashGame\GameEngineData\Routines\Basic\ModuleScripts\TileScripts\SimplePlatformer

Code:
;Water splash

CPX player1_object
BNE +
    LDA tileX
    AND #%11110000
    STA temp
   
    LDA tileY
    AND #%11110000
    SEC
    SBC #$08 ;Adjust the splash to the top of the water tile
    STA temp1

    CreateObject temp, temp1, #$08, #$00, currentNametable ;Game Object 08 is the water splash
    ;PlaySound #SND_SPLASH
+

7. Assign this file to the Tile Collision of your choice (I use Tile 11 in this example)

watersplash6.png


8. In Project Settings go to Project Labels and give a name to your new Tile type:

watersplash7.png


9. You can now create a new tile (asset) which will be the water surface:

watersplash8.png


Every time the player comes in contact with this tile a new game object (your water splash animation) will be created on the tile the player collided with.


THE WATER BUBBLES
watersplash9.png


Making bubbles when the player is under water is exactly the same process as above. The only difference is a slightly different code for the WaterBubbles.asm file:

Code:
;;Water bubbles

LDX player1_object
LDA Object_x_hi,x
STA temp
LDA Object_y_hi,x
STA temp1
   
CreateObject temp, temp1, #$09, #$00, currentNametable
   
;LDA #$20
;STA GRAVITY_LO

In this example I use game object 9 for the water bubbles and Tile type 12 (see number 7 under The Water Splash tutorial).

Now you can make a new tile (asset) that acts as water. The bubbles (game objects) will be created constantly when the player collides with a water tile.

That's it!


A big thank you to Dale Coop for showing me how to get the position of the tiles the player collides with.

If you find any errors in this tutorial please let me know. Good luck making water effects in your game.
my game takes place in the desert so now I need to find a reason to add wate lol
 

TheRetroBro

Active member
Here is a tutorial on how to make the water splash when then player hits the surface, and how to make bubbles when the player is under water.

PS #1! Having a lot of splashing and bubbles in your game will cause a bit of slowdown.
PS #2! Using game objects for this is an expensive way to make effects, since you only have 16 game objects total.

Prerequisites for this tutorial:
- Basic understanding of NESmaker
- Knowledge about Game Objects and Tile Types
- Very basic understandig of ASM scripts

THE WATER SPLASH
watersplash.png


1. First we need to decide which Game Object we will use as the splash. In this example I will use game object 8 (the default is Effect 0)

2. Give it a name so it's easy to identify it:

watersplash2.png


3. Make the animation of the splash. I use 6 frames in this example (it might be too much if you want a lot of game objects with big graphics)

watersplash3.png


4. Set a bounding box on your game object. Use the entire box as the bounding box:

watersplash4.png


5. In the Object Details window of the game object (under the tab Actions) set the following:

- Animation speed
- End Animation -> DestroyMe
- Ignore Gravity

watersplash5.png


6. Create a new ASM file called WaterSplash.asm (or whatever you like). Save it in the TileScripts folder of your game.

C:\Users\baardbi\Desktop\WaterSplashGame\GameEngineData\Routines\Basic\ModuleScripts\TileScripts\SimplePlatformer

Code:
;Water splash

CPX player1_object
BNE +
    LDA tileX
    AND #%11110000
    STA temp
  
    LDA tileY
    AND #%11110000
    SEC
    SBC #$08 ;Adjust the splash to the top of the water tile
    STA temp1

    CreateObject temp, temp1, #$08, #$00, currentNametable ;Game Object 08 is the water splash
    ;PlaySound #SND_SPLASH
+

7. Assign this file to the Tile Collision of your choice (I use Tile 11 in this example)

watersplash6.png


8. In Project Settings go to Project Labels and give a name to your new Tile type:

watersplash7.png


9. You can now create a new tile (asset) which will be the water surface:

watersplash8.png


Every time the player comes in contact with this tile a new game object (your water splash animation) will be created on the tile the player collided with.


THE WATER BUBBLES
watersplash9.png


Making bubbles when the player is under water is exactly the same process as above. The only difference is a slightly different code for the WaterBubbles.asm file:

Code:
;;Water bubbles

LDX player1_object
LDA Object_x_hi,x
STA temp
LDA Object_y_hi,x
STA temp1
  
CreateObject temp, temp1, #$09, #$00, currentNametable
  
;LDA #$20
;STA GRAVITY_LO

In this example I use game object 9 for the water bubbles and Tile type 12 (see number 7 under The Water Splash tutorial).

Now you can make a new tile (asset) that acts as water. The bubbles (game objects) will be created constantly when the player collides with a water tile.

That's it!


A big thank you to Dale Coop for showing me how to get the position of the tiles the player collides with.

If you find any errors in this tutorial please let me know. Good luck making water effects in your game.
hmmm everything works except when the object is created it makes multiple of my objects (splah object)
 
Last edited:

TheRetroBro

Active member

TheRetroBro

Active member
Also important to note. If you adjust the splash to appear at -5 and put your "splash tile" above your empty walkable tile (water ) or solid tile (ground) this code works as a puddle splash or jump into water splash.
 
Top Bottom