Bug Hunting
Before we step out to the unsafe areas of the game we really need to know where our dot is and more impotently between what two dots is our game. In this video we start exploring the logic involved in finding the two points that are between our dot but more then that we focus on finding the pixel perfect data for our first points we found earlier.
Video Transcript
00:00So we were back in the beginning point where we already set up those initial corner points.
00:05The next step after this before we start adding new corners, because we already have the new corners.
00:10The new corners are that trailing point, are that what we called it our path.
00:16Our path is the new corners that are going to be.
00:19If we look at our example, our path is this new path that needs to be integrated in whatever is already there.
00:24So the best next step that we need to do is we need to create some sort of function
00:28that will tell us between what two dots are we right now.
00:32So let's see how we can make this happen.
00:34Not going to be too easy, but we're going to give it a roll.
00:37First of all, we're going to try to figure out where do we want to first time check for that.
00:42First time we want to check for that is basically when a status changes.
00:46That's when it starts and that status changes and that is when it ends.
00:50But when it starts is probably the perfect scenario, the perfect place where we want to set this,
00:54because this is the place where it will only happen once.
00:57It happens whenever we're stepping into an unsafe terrain.
01:01Whenever we step into an unsafe terrain, we want to store the starting line.
01:06And to do that, I'm going to create here another variable.
01:09I'm going to call this a private var.
01:12It's going to be an O line.
01:15It's going to be an object.
01:18Now this O line object, I'm just going to make sure that I have in my,
01:22I'm going to just create a new line, just a new object, an empty object.
01:26Now, the new line, what is it going to have?
01:29That O line is going to have, and if we go back right here into that place in our enter frame where we were just at,
01:35what it's going to contain is going to contain a few things.
01:38It's going to contain, in the beginning it's going to contain two dots.
01:41But we're going to see later on that those two dots are not enough.
01:44We're going to start with two dots, but what we're going to be missing also is the direction where we're going towards.
01:49We're just going to see, which is basically if we're going up or we're going sideways,
01:53to make it easier for us to decrypt how to actually work with it,
01:57to know if we care about the Y when we're searching for the dot,
02:00or we care about the X when we're searching for the dot.
02:03All right.
02:04So first of all, the best thing for us to do next is to create a function that would actually return that value.
02:09So in the beginning, I'm just going to throw it right into the stage.
02:12It's just going to be a trace.
02:14I'm just going to call a function that's going to get line,
02:21and it's going to accept the point, and that point is going to be our dot.
02:25Our point is going to be our dot X and our dot Y.
02:29And for now, we're going to just trace something out,
02:33but we're going to sort that out in a couple of minutes after we get all our ducks in a row.
02:37All right.
02:39So a good step out of here.
02:41We're going to start creating that function.
02:44Private function, get line.
02:49It has an X.
02:53Why aren't we sending a point like we're doing with all the rest?
02:56Because we could send the dot and just treat it as a point, I believe.
03:01Or is our dot a point? No.
03:03Our dot is not a point.
03:05Our dot is a shape.
03:06All right.
03:07So we'll just create a new point,
03:08because it seems cleaner with all the different points that we've been creating.
03:11New point, because everything here is points.
03:15All right.
03:16So we're sending a new point based on the points of our dot.
03:20And our new line, we could get here our current point,
03:22our new point, which is a point.
03:27For now, we're not going to return anything.
03:29The next step for us really is using that current list of corners that we have,
03:34cycling through those corners to find out what is the line
03:40that holds the information that's most needed for us.
03:43Before we do that, we want to make sure,
03:45I'm just going to trace here out our corners,
03:47and I'm going to trace out our point.
03:50And the reason I'm doing that is because I want to make sure
03:53that we actually have a correlation.
03:55Let's see what that means.
03:56So first of all, first trace is going to be our corners.
04:00Our second trace is going to be our new point
04:02that we're going to search for that point.
04:04Now, last step here that I want to make sure,
04:06I just want to get rid of any other traces so they're not in our way.
04:09Let me just make sure that they're all deleted.
04:12There we go.
04:13So everything was deleted.
04:14If we run our application now, obviously, again,
04:16it's going to happen only once because it's in that area
04:18that we've just created.
04:20Beautiful.
04:21So first of all, we could see that when we're looking at this,
04:23we could already see that we're close,
04:25but we're not close enough.
04:26That our point is at 477, while our real point is at 480.
04:32Now, the reason to that is simple.
04:35Because when we created our corners,
04:37when we created our shape,
04:39when we created our rectangle, if I could find it,
04:41we gave it a line style of four.
04:44Now, with that line style of four,
04:45because we set our stage to take the full stage height
04:48and stage width, we actually created a shape
04:51that was a little bit bigger than our stage, actually.
04:54Because what happens when,
04:55and let me just show it to you in a sample here
04:57that's more visual.
04:59Now, if I create a new square,
05:01and notice where my point is with my mouse,
05:05and when I'm creating the shape,
05:06notice how the shape just grows a little bit, right?
05:10Now, if I created a dot that's four points wide,
05:13such as we did with our application,
05:17and let me just create here another square,
05:20and I'm going to give it four points.
05:22When I create a point that's four points,
05:24notice what happens.
05:25First of all, create that shape.
05:26You'll notice that our shape becomes bigger
05:29on both directions by how much?
05:31By two pixels in every direction.
05:34That gives us our cube basically telling us
05:36that it's half the size in both directions.
05:39So our line, the bigger our line becomes,
05:42the more space it takes from the two different directions.
05:45So basically when we created our shape
05:47inside of our application,
05:48our line here is two pixels wide.
05:50If our application was wider,
05:52we'd be able to see four pixels, but it's not.
05:56Okay?
05:57So what we want to do is we want to make sure
05:59that we're taking into account,
06:01and if you run this just for a second
06:03just to see the numbers again,
06:04if we take it, we have to take into account
06:07that we had those four pixels divided by two,
06:09which is two pixels.
06:10So that brings us at 479.
06:13And then we're missing that one new pixel
06:15that we just moved,
06:16because we just stepped out of the save zone.
06:18So those are the three missing pixels
06:20that we needed to account for.
06:22So probably the easiest way, first of all,
06:25we want to make sure that maybe we don't store
06:28this information the way it is right now right here.
06:31Maybe we want to store the values a little bit more tighter
06:34where we'll have your two-two,
06:36and maybe this is going to be instead of 320,
06:38it will be 318.
06:41Now, let's see how we're going to do this.
06:43First of all, before we even solve the second problem,
06:45first of all, we create another private constant.
06:48That constant is going to be our line width.
06:56It's going to be an integer.
06:57It has the value four.
06:58We're not really changing anything.
07:00All I'm going to do is going to go to that line,
07:02make sure that that line now gets that value
07:04instead of getting a direct number.
07:06Now, drawing the rectangle is not changing.
07:09Only thing that's going to change now
07:10is instead of adding 00,
07:13instead of adding the right values,
07:14I'm going to subtract half of the line width each time.
07:17So I'm just going to create a temporary variable here.
07:20So this is going to be, let's call this line,
07:24or let's call it LW for line width,
07:27and it's going to be an integer.
07:28Well, it has to be a number.
07:31It has to be a number.
07:32Well, let's make it an integer
07:34because the thing is that we have to make sure,
07:36if we ever put your value that's not an integer,
07:38it would mess everything up.
07:40Not only not an integer,
07:41it has to be two, four, six, eight,
07:44and so on and so forth.
07:45But because we already know it,
07:47we're going to make sure that there's only those type of values
07:49because if we put any other type of value,
07:51this logic is not going to work
07:53because we're not working with a number.
07:55All right, so that is our integer.
07:57We're going to take that line width,
07:58divide it by two, not by three,
08:01and then we could take our line width,
08:04and we could start from that point
08:07instead of zero, zero.
08:08We want to start from that two, two.
08:10We're going to take it from the stage with minus two,
08:13two, two, and the same thing here.
08:17So basically, I'm just adding two to the beginning,
08:20subtracting two from the end.
08:25All right, and if we run our applications just one more time,
08:28now when we get that value,
08:30we'll see that our numbers are getting much, much closer.
08:32The only point that's still missing
08:37is making sure that this value
08:39will actually store the number
08:41just before we change our direction.
