This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

A good way to code water?

A good way to code water?
by on (#39385)
Hey again. I've been toying with ideas and let me explain my ideas:

Basically, I have a tile with a property of Water and when the player enters it, I want him to change to a swimming state. Basically, for the movement I setup a variable called Environment and then that uses pointer on whether to use GroundMovement or WaterMovement during the control read.

But the main problem I seem to have is coming up with a good way on how to make the transition from air to water. Right now it's kind of messy in that it looks at what tile you moved into and then sets Environment based on that. It's also possible when you briefly swim up to exit water, but move back down you'll be considered in air for a moment while in a water tile.

So, my thought process was to eliminate the whole "check what you moved into" and replace it with some check at the beginning to see what kind of tile you are mostly overlapping...

Does this sound reasonable or is it overcomplicating yet again?

by on (#39390)
If all of the water is at the same level (that is, a straight line), like in Sonic games, it would just be easier to indicate the level of the water in a variable and check the player against that instead of tiles. This would make changing the water level easy (apart from the graphics at least).

But even if you have many pools of water at different heights, you could still just have a point in the middle of your character (like, close to the waist) collide with the tiles. Well, it doesn't need to be the waist, just pick a pixel at the proper height in your character to be the threshold.

by on (#39398)
Yeah, basically what I'd do is have all sorts of different tile types, and do different things based on what tile the player collides with. Obviously, the word "collide" just means what tile an object enters. So when a player enters a "water" tile, make them go into swimming mode.

by on (#39399)
Celius wrote:
So when a player enters a "water" tile, make them go into swimming mode.

But I think this was his problem in the first place. You certainly don't want to enter swimming mode if only the feet of the character entered in contact with the water. So, if the character is 32 pixels tall, you could have a special check for water tiles at pixel 15 or 16, to make sure swimming mode is only activated when more than half of the player is into the water.

by on (#39400)
Well, I was basically thinking that, like you were saying a collision point on the waist line. It would certainly not be practical to enter swimming mode when the player is only foot-deep in water.

by on (#39410)
Castlevania : Dawn of Sorrow (the game I'm playing a lot these days) have the main character walk slower when only a part of him is in water, and have him swim when he's entierely in water. Also the gravity should be lowered because water puts the hero high and this counters the real gravity. In reality for an human the gravity is nullified because the density of an human is close to the density of water, but most video games seems to assume the human is heavier than water and still falls down.