1
00:00:00,150 --> 00:00:06,420
Is it going so far so in the last lesson, we identified a problem because we can move off of our grid

2
00:00:06,840 --> 00:00:12,000
and we need to set the boundaries that the player needs to stay within our game area, otherwise it

3
00:00:12,000 --> 00:00:13,520
could go pretty much anywhere.

4
00:00:13,530 --> 00:00:15,480
So we need to set those restrictions.

5
00:00:15,840 --> 00:00:17,160
That's what I'm going to do in this lesson.

6
00:00:17,370 --> 00:00:22,050
So opening up where we handle our key press, so setting a condition.

7
00:00:22,050 --> 00:00:28,170
So checking to see if the player pressed left and if they did, then we're checking the value of box

8
00:00:28,170 --> 00:00:28,530
X.

9
00:00:28,770 --> 00:00:35,820
So this is the variable within box where we're tracking the position of X and we're checking to see

10
00:00:35,820 --> 00:00:38,210
if it's larger than game area.

11
00:00:38,430 --> 00:00:42,210
And remember, we got that bounding client bounding rectangle value.

12
00:00:42,400 --> 00:00:43,880
So that's the game area left.

13
00:00:43,890 --> 00:00:48,330
So making sure that if we're going left, we're not outside of the left area.

14
00:00:48,360 --> 00:00:53,460
So now, even if I press left, we're not doing anything because we're not able to move left anymore

15
00:00:53,940 --> 00:00:55,830
and we've got to do the same thing for right.

16
00:00:56,250 --> 00:01:03,660
So the same idea here where we're taking the value of box X and we going to make sure that the value

17
00:01:03,660 --> 00:01:06,510
of X is less than we got to do.

18
00:01:06,510 --> 00:01:10,440
Some little bit of calculation here because we can do game area.

19
00:01:10,680 --> 00:01:11,480
Right.

20
00:01:11,610 --> 00:01:16,340
But what that's going to do is it's not going to actually account for the width.

21
00:01:16,350 --> 00:01:21,240
So if we can still go over, but we can't go over too much, so we can still go out of balance, we

22
00:01:21,240 --> 00:01:22,800
want to still restrict that.

23
00:01:22,810 --> 00:01:28,030
So we've got a little bit more calculating and lucky for us, we can get the width of our box elements.

24
00:01:28,030 --> 00:01:34,860
So clearing that out, we've got our box object and we can see that we can get the offset width of that,

25
00:01:35,040 --> 00:01:37,770
which is of course, one hundred, because that's how wide it is.

26
00:01:38,010 --> 00:01:41,010
And we try to keep it, of course, dynamic as possible.

27
00:01:41,190 --> 00:01:44,040
So subtracting the value of box.

28
00:01:45,090 --> 00:01:50,160
Offset with should account for that ability to go one more over.

29
00:01:50,520 --> 00:01:56,130
So now we are restricting it to that boundary area so that we can't go off of the edge and we need to

30
00:01:56,130 --> 00:01:59,370
do the same thing for down and as well as up.

31
00:01:59,670 --> 00:02:08,670
So taking down, checking to see if this time we're using box, why is less then and we're using that

32
00:02:08,670 --> 00:02:11,930
same game area and it's going to be game area bottom.

33
00:02:12,270 --> 00:02:13,170
So let's try that out.

34
00:02:13,190 --> 00:02:15,320
So refresh and going down.

35
00:02:15,780 --> 00:02:20,940
So we see we had the same problem here that we can go past what the bottom areas and we need to make

36
00:02:20,940 --> 00:02:24,480
that same adjustment accounting for the height of the box.

37
00:02:25,620 --> 00:02:32,850
So add in some extra brackets there and we're going to subtract the value of box and offset height this

38
00:02:32,850 --> 00:02:33,120
time.

39
00:02:33,750 --> 00:02:38,010
So that will account for the height of the box and we'll just make sure that it works.

40
00:02:38,550 --> 00:02:44,450
So now we can't go below 17 and we've got one last one to take care of and that's the up.

41
00:02:45,090 --> 00:02:52,230
So checking to see if box Y is greater than game area top.

42
00:02:53,200 --> 00:02:58,780
And try that one more time, so I can't go up, I can't go out of bounds and exactly what we want to

43
00:02:58,780 --> 00:03:02,290
be able to do and we see that we're still tracking the squares properly.

44
00:03:02,470 --> 00:03:08,710
So that's going to be essential in the upcoming lesson where we start activating our books in order

45
00:03:08,710 --> 00:03:11,570
to navigate to to in order to score within this game.

46
00:03:12,010 --> 00:03:19,390
So go ahead and add the boundaries into your project so that you can't the player can't exit out of

47
00:03:19,390 --> 00:03:22,330
or get out of bounds of our gameplay area.

48
00:03:22,840 --> 00:03:27,610
And coming up next, we're going to add in our active object that we need to pursue.
