2012年1月27日金曜日

How To Turn Water Into Ice Fast

how to turn water into ice fast

Dev Update 2: Fluids, Part 2

Another week and another update! It was a bit more difficult to stay motivated this week, and I've tried to figure out why that was. The two causes I've come up with was the fact that it was my second week working on the same game system (a little less exciting), and that two annoying glitches took up a lot of the development time. Despite this I managed to complete pretty much everything that was on my list at the start of the week, so I'd still consider it a success.

Wrapping Up Loose Ends

For those of you who are aware of my difficulties with infinite acid mentioned in last week's post, I'm happy to report that Multiply Infinitely has been vanquished! I spent a good chunk of time going over the code I had written last week to figure out what exactly was causing the issue. I deduced that it was triggered when lava was dropped into a pool of acid and water, but later found that it was possible for the acid to become infinite when water was dropped into it as well (only saw this happened once, it was impossible to reproduce after that). What's worse is that my code looked flawless. My frustration with it reached a boiling point so I decided to work on some of the new stuff that was planned for this week, and thankfully decided to add liquids to the pressure calculation done for the tile stability.

To my surprise, this had stopped working completely for some reason. After a bit more debugging I found that some of the pressure values were being set to 255. For the programmers among us, you've probably realized what the issue was. Without thinking I had changed the data type to bytes, which can hold a number from 0 to 255. You'll notice that I didn't list any negative values. When a byte becomes a negative, it automatically wraps around back to its max, which is 255.

While this still didn't tell me exactly why the value for acid was turning into a negative (they're only supposed to be have a value of 0-8), it did let me move on to the next items on my list: reactions between fluids.

Scientific-ish Reactions

The fluid system I implemented last week was just the first step of what I was trying to achieve with them. While they did add a little hint of life to the game, they didn't really do much beyond move around. This was fun to watch (for me at least), but there was nothing there that would force the player to stay on their tows as they moved around the world. With that in mind it was time to create as many ways for fluids to interact with each other and the environment as possible. What I completed was a good start, but something I'd still like to expand as the game progresses in development.

Below is a list of the different interactions/reactions that are in the game as of this week. The elements that get combined are listed at the beginning, with those at the end being the result of the reaction. It's actually how I have them listed in the code as well; there's something about programming that makes you want to turn everything into math. The 6 liquids currently in the game are: mud, lava, lava rock, water, ice, and acid. You'll notice that three of those are generally considered solids, but because they are not the size of a full tile and need to be able to move around (even if minimally), they use the same system as liquids do.


Whirlpool 4396508 KitchenAid Maytag Side-by-Side Refrigerator Water Filter, 1-Pack
Learn more

Mud OR Water + Dirt = Mud: I wanted a way for water to be able to break down dirt blocks found in the world. It just didn't make sense that they were treated exactly the same as solid stone blocks. Ideally the system would cause water to spread through dirt blocks and turn them into mud once enough liquid was within them, but this type of interaction isn't possible right now. Instead, I just gave mud and water a random chance to turn any dirt blocks around them into mud. This is one of the interactions I'll probably have to revisit later on, but it definitely forces the player to be aware of their surroundings. Whose to say there isn't water eating away at the dirt roof above them?

Steam + Solid Block Above = Water: You might remember this one from last week's video. Not much has changed since then, but I did make steam spread out and complete calculations a little faster. For those that aren't familiar with it, the system is supposed to simulate condensation that takes place. If there's a pool of lava in the floor below the result is an infinite system of reactions.

Water + Lava = Steam + Lava Rock: It was always my plan to have lava evaporate water when they met, but I felt like something should happen to lava as well. If you watch videos of flowing lava you'll often notice a dark layer appear at the top, especially when it meets with water. I decided that this would be a neat reaction to add to the game, one that could actually have consequences on gameplay. There wasn't time to implement it, but my plan right now is to allow the player and monsters to walk on lava rock. It would be interesting if the player had the option of emptying a pool of water into a pool of lava, giving them a short amount of time to cross

Water + Lava Rock = Steam: This wasn't implemented until after I had tested what a pool of water would do when mixed with lava. The result was that the water created a pool above the lava, even if there was a single layer of lava rock between them. While lava rock is cool compared to lava, it is not cool compared to water. The solution was adding a small chance for lava rock to evaporate a single unit of water. The solution was solved the problem rather elegantly, in my not-so-humble opinion.

Lava Rock + Lava = ???Lava Rock/Lava???: Referencing back to videos of flowing lava, you'll notice that even with a layer of cooled lava, there are times when it cracks and exposes the molten lava beneath. I wanted to mimic this without having to make provisions for lava rock to flow beneath the lava layer (remember that each liquid has a set "heaviness" which determines where it appears when liquids are layered). The solution I came up with is simple, and probably not all that accurate, but it gets the job done. If lava rock exists in a block with lava, there's a random chance for it to either turn into lava itself or cool some of the lava, turning it into another layer of lava rock. This also allows water to be exposed directly to lava at times even if there's a layer of lava rock covering everything.


GE GXRLQR Twist and Lock In-Line Refrigerator/Icemaker Replacement Filter
Learn more

Ice + Water = ???Ice/Water???: I won't go into a huge description for this interaction since it functions in the exact same way as when lava rock and lava are in the same tile. However, it would be good to note that I'm not really sure how ice will appear "naturally" in the game right now, if at all. Maybe I'll need to add a temperature stat for each world tile to determine if water should turn into ice? Another option is a freezing ability which can slow down enemies or turn water into ice. We'll just have to wait and see!

Ice + Lava = Water: This isn't all that interesting of a reaction. The only thing of note is that I didn't want ice to turn directly into steam, since, from my understanding, it has to melt into water before evaporating into steam. I'm not even sure why I'm talking about this since the reaction will still happen so quickly that you won't notice the difference unless you're looking for it. Anyway, moving right along…

Acidic Gas + Solid Block Above = Solid Block Weakened: The second type of gas currently in the game is acidic gas. It spreads a little slower than steam, but uses pretty much the same code otherwise. The interesting thing with acidic gas is that instead of using condensation, it weakens any solid blocks above it by reducing a single "tick" used for the stability calculation. The result is that blocks can now fall because of what's below them, rather than just what's above. In the future I'll probably add the ability for it to force the player to use their oxygen supply (just like being underwater, which isn't implemented either) and possibly damage them. Because it moves slower than steam it'll be in the players interest to get out of an acidic gas cloud as soon as possible, and watch out for any blocks that are falling from the sky.

Acid + Solid Block = Acidic Gas + Solid Block Destroyed: I really enjoyed creating this interaction since it's the most destructive. There's nothing quite like creating a bunch of acid, watching it run down a hill, pool up, and start eating away a hole through the world. Each time a block gets destroyed one unit of acid is lost as well, ensuring that it can't go on forever. On the other hand, the reaction does create a small amount of acidic gas, so you still have to keep an eye on the environment around you. At first the processes simply had a random chance to destroy a block, but I realized that it didn't make sense for acid to break down a huge boulder as quickly as a lump of dirt. I changed it to instead reduce the number of ticks the block had (just like acidic gas), eventually destroying the block.

Acid + Water OR Lava = Acidic Gas: Of all the interactions listed in this post, this is the one I'm the least sure about. I like the idea of acid and water creating acidic gas, but I don't know if it's scientifically correct in the least. The same applies for acid and lava mixing. I know there has to be some kind of reaction, but figuring out a reaction that's both fun gameplay wise and at resembles reality at least a little bit is important to me. In the end gameplay will always win, so whose to say acid and lava mixing won't create a huge explosion in some future build…


The Optimal Reaction

I did want to mention how the code for fluids and reactions is structured. You might remember from last week that liquids in the game have a specific order they're placed in, with the heaviest ones being on the bottom and the lightest at the top. Because of this the code needs to account for times when the heavier liquid moving into a tile will displace the lighter liquid that's already in it. To reduce calculations the heaviest liquid has to check every single liquid type that can be above it when it moves, while the lightest one doesn't have to check anything because there's nothing that it can displace. The result is that the heavier the liquid, the more calculations are required to move all the lighter liquids. There are 6 liquids in the game right now so that's quite a few calculations.

To help offset this I decided that every reaction that can take place between liquids should be calculated by the lighter liquid. For example, if water and lava are found on top of each other, lava will complete the calculation to move water upwards while water will complete the calculation to evaporate into steam. This means that reactions only have to be calculated by one liquid rather than both.

A Change in Stability

If you actually read the book I wrote above, you'll notice that I mentioned "block stability" a few times. I discussed it briefly in the very first post on the site, but haven't had reason to since then. That is until now. This week I changed how stability is calculated, and to be more accurate, how the strength of blocks is calculated. Each block has a certain amount of "pressure" placed on it, which is determined by a set of equations which boils down to "How much stuff is above it." That's a huge simplification, but it works for what I'm trying to explain right now. Along with the pressure placed on the block, each one also has a number of "ticks." The final bit of data calculated for every block is its strength, which is determined by whether or not it has a block next to it. If the pressure placed on a block is greater than the strength of the block, and there's no block beneath it, the block losses a tick. Once a block reaches 0 ticks, it falls to the ground. Again, big simplification, but you get the idea.

There are two things I changed this week. First, different blocks in the world have a different number of ticks. Instead of dirt and stone having the exact same chance of collapsing, dirt now has less of a chance. This is also used by the reactions I listed above, namely anything with the word "acid" in it. The more ticks a block has, the longer it takes it to fall. Another thing I changed was how strength is calculated. Before, the strength of a block was decided by whether or not it had a block to the left or right of it, with a value of 5 being given to each. This means that a block could have a maximum strength of 10 if there was a block to both the left and right. Like the tick value, it didn't take into account what type of block it was. I changed it so that instead of a generic value of 5, the strength value that's added to the block is determined by the number of ticks that block has. For example: if a block to the left has 3 ticks left, and a block to the right has 4 ticks left, the total strength of the block in the middle is 7. This allows for areas that were once unstable to start breaking down quickly if the conditions are right.


Extreme Makeover: Liquid Edition

While working on liquids for the Fluids, Part 1 update, I started realizing that the way they flowed just didn't look good. That said, it didn't seem bad enough to warrant devoting a huge amount of time to it. After feedback from a Redditor in /r/gamedev (my favorite subreddit!) , it was clear that it just wouldn't cut it. I threw a few ideas out, none of which I actually ended using. The biggest issue with the liquids was that they felt jittery if there was an uneven amount of them. This was caused by the code which made the fluids flow, so there was no simple fix to the problem that wouldn't stop it from working entirely. My goal ended up as follows: create a system that made the fluids appear even and calm when pooled up, without creating a situation where infinitely multiplying liquids was possible and without making a huge change to the code in place. This meant that each tile needed to calculate on its own, without needing to figure out what the average was for a huge pool of water.

After some thinking and iteration I decided that each fluid should have an "overflow" value attached to it. This value would only be added to tiles which had less liquid than their immediate neighbors to the left and right, creating the illusion that they were all equal. It seemed straightforward enough, but as with most things, that simply was not the case. The first tests that I did were promising: liquids kept flowing like they did before and would spread out until the top of the fluids looked even and calm. After a few more tests I realized that under certain conditions, liquids did not spread out all the way. Granted, it still looked better than it did before, but it didn't look perfect.

Trying to pinpoint those conditions is where I'm at now. I'm not sure if this is something I'll be able to do in the immediate future, but it's definitely planned. Along with this I'd like to change what the fluids look like when flowing downwards; instead of individual lines it would be better to represent them as water and mist mixed together. I don't know when I'll get to this, but it's added to the list!

Coming Next Week

The groundwork for weapons and player abilities!

After working on fluids for two weeks, I don't want to touch anything related to world generation or interaction this week. Seeing as this is a game, I thought it'd be good to start adding some fun things to play with. While these past two weeks were devoted to creating ways for the world to interact with itself and the player, this week I'll be focused on creating ways for the player to interact with the world. And come on now, who doesn't like blowing stuff up?!



These are our most popular posts: how to turn water into ice fast

Ready, Set, Fast: How Strategic Meal-Skipping Can Help You Lose ...

Its also supposed to make us less likely to binge on cookies and ice cream at night. Its sound ... (I did drink green tea and water throughout the day.) The periodic fast: If you survived the trial fast without breaking down and cleaning out the refrigerator, then you can try this. Simply do .... In the book, he gets into all the different fasting approaches he tried, including details of his exercise programs and his exact eating plans, as well as which ones could work best for you. read more

Drink Adequate Water for losing weight fast » ArticlePlusX ...

Your body will require more energy to vary the water into temperature thus burning more calories. It truly is however recommended that you mustnt have ice cold water great deal of thought as the fastest technique for losing weight. read more

Rocco DiSpiritos Valentines Day surf and turf cobbler for 2

Get More Followers Fast – Blast My Twitter Tools And Tips for Taking Your Twitter To The Extreme! Subscribe to our RSS ... So if youre looking for a romantic Valentines Day gift thats truly from the heart, why not give the best gift of all — a mouth -watering, healthy meal you make yourself? This weeks recipe is ... I did this by turning the pie into a cobbler, which means the crust is only on top. And my crust is made ... Set a bowl of ice water nearby. Submerge lobster in ... read more

Facts and figures

Hot water will turn into ice faster then cold water. Assuming current population growths remain constant: by the year 3550 the total human population will have the same mass as the earth; assuming the average person is 60 ... read more

Related Posts



0 コメント:

コメントを投稿