Making Realistic 2D Dynamic Water (Waves) in GameMaker Studio 1.4 & 2 (Springs and Elasticity #2) HD

03.05.2018
Learn how to code 2D dynamic water using GameMaker Studio 1.4 or 2! This lesson will build off concepts I taught in my Intro to Springs and Elasticity video, so I’d recommend watching that first if you haven’t already. You can watch Part 1 here: https://www.youtube.com/watch?v=vewwP8Od_7s Source code » https://github.com/zbanack/TSE-dynamic-water Twitter » https://twitter.com/thestepevent Facebook » https://www.facebook.com/thestepevent Zack Banack » https://zackbanack.com Just like in Part 1, I’d like to give a huge shoutout to Michael Hoffman for his original C# and XNA tutorial on this very subject, which I’m using as a foundation for this Springs series. Check out his article: https://gamedevelopment.tutsplus.com/tutorials/make-a-splash-with-dynamic-2d-water-effects--gamedev-236 Rough transcript: The dynamic water we’re coding won’t follow the real-world physics of liquids. But it’s a great effect that can add polish and bring some life to your games. You can replace static bodies of water, or at least their surfaces, with this. In part 1, we went over how to code and interact with springs independently. That is, the movement of one spring won’t affect adjacent springs. You can think of our dynamic water as just a bunch of springs, side by side. But connected, almost. When I displace one spring, neighboring springs are also displaced. The closer a spring to the manipulated spring, the more movement. Further away, and we get less. Next we just replace springs with “columns”, or trapezoids. And give it some nice coloring. Bam, water! And I’m going to be tackling the code in three distinct parts. First, I want to program a series of springs, side by side, and draw them in the room. Second, we’ll “link” the springs together. And lastly, we’ll make it look pretty. When it comes to defining variables, first, we should know the dimensions of our body of water. We’ll call bodyWidth the width of the body, and bodyHeight the height of the body. bodyX and bodyY define the (x, y) coordinates of the top-left corner of the body in the room. So, the bottom-right corner of the body of water would be bodyX + bodyWidth, bodyY + bodyHeight. Last time, we coded obj_spring. Each instance of obj_spring acted as an individual spring. We could iterate over adjacent instances of a spring object and achieve the dynamic water effect. But it’s easier for us to create multiple springs inside of one all-encompassing body-of-water object. So, we need to figure out how many “columns”, or springs, this body of water will contain. Here’s each column drawn in an alternating color. Too few columns and the effect isn’t as really noticeable. Too many columns and the splashes are going to feel, uh, lumpy? There isn’t a “correct” number of columns to use. It depends on what effect you’re going for and how large your body of water is. I personally like 1 column every 64-96px. So, for this body I’ve decided columns = 10. columnWidth, the variable assigned to the w

Похожие видео

Показать еще