Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:04,660 --> 00:00:09,790
So it always surprises me how successful some really simple games like this can be my son absolutely
2
00:00:09,790 --> 00:00:11,490
loves playing this sort of game on his iPod.
3
00:00:11,680 --> 00:00:15,550
And this is entirely based at this stage on addition and subtraction.
4
00:00:15,550 --> 00:00:18,580
So even with these simple mechanics we can have a lot of fun.
5
00:00:18,580 --> 00:00:23,530
So let's dive in and start with the very basics of mathematics addition and subtraction so you in the
6
00:00:27,530 --> 00:00:32,930
Okay guys let's get moving let's get on with addition and subtraction the very starting point now look
7
00:00:32,930 --> 00:00:36,620
I'm not going to keep you too long with this because it's simple stuff but there are a few gotchas with
8
00:00:36,620 --> 00:00:39,010
regards to game development that I want to show you about.
9
00:00:39,200 --> 00:00:43,010
So throughout this course we're going to be using something that I'm going to call the number line as
10
00:00:43,040 --> 00:00:44,180
a starting point.
11
00:00:44,180 --> 00:00:47,400
So that's just a line in space I'm drawing here.
12
00:00:47,450 --> 00:00:47,740
All right.
13
00:00:47,750 --> 00:00:52,730
And then we're going to imagine to start with that we have a zero point maybe on the left hand side
14
00:00:52,730 --> 00:00:52,850
here.
15
00:00:52,880 --> 00:00:56,690
So this is just a line that represents numbers and this guy here is zero.
16
00:00:57,110 --> 00:01:03,380
So as our numbers progressed we've got one and then maybe two and then maybe three and then maybe four.
17
00:01:03,580 --> 00:01:03,980
OK.
18
00:01:04,010 --> 00:01:09,830
Now addition is simply moving to the right on this number line like so each time we add one we're doing
19
00:01:09,830 --> 00:01:10,070
this.
20
00:01:10,070 --> 00:01:14,040
If we were to add four we would be doing this nice and simple.
21
00:01:14,840 --> 00:01:16,250
So that's addition what is subtraction.
22
00:01:16,400 --> 00:01:18,650
Well subtraction is moving left.
23
00:01:18,650 --> 00:01:23,780
So maybe I use a different color for subtraction perhaps a gain a green if we were to take four and
24
00:01:23,780 --> 00:01:25,460
subtract two we get down to two.
25
00:01:25,890 --> 00:01:26,150
OK.
26
00:01:26,150 --> 00:01:30,510
And if we were to subtract take one and subtract one we get down to zero.
27
00:01:30,530 --> 00:01:31,300
Very simple.
28
00:01:31,940 --> 00:01:36,860
So the other option that we have here is to have a negative values on the number of lines.
29
00:01:36,860 --> 00:01:38,470
Let's take a little look at how that would work.
30
00:01:38,630 --> 00:01:40,220
So we can have a very similar number line.
31
00:01:40,220 --> 00:01:46,200
But this time let's imagine that this number line the zero is shifted across and that we have zero here.
32
00:01:46,680 --> 00:01:46,970
All right.
33
00:01:46,970 --> 00:01:48,060
Right in the middle there.
34
00:01:48,060 --> 00:01:50,780
Let's say now we can play with things called negative numbers.
35
00:01:50,770 --> 00:01:58,370
So if I have maybe 0 1 sheep or two sheep or three sheep and I want to take away a certain number of
36
00:01:58,370 --> 00:02:03,520
sheep then if you said hey you've got two sheep give me three.
37
00:02:03,620 --> 00:02:07,250
We would end up back here at a number that we're going to call minus one.
38
00:02:07,250 --> 00:02:08,950
So negative numbers.
39
00:02:08,990 --> 00:02:09,860
All right super simple.
40
00:02:09,860 --> 00:02:13,160
That's all I'm going to say about the number line for the moment for you.
41
00:02:13,760 --> 00:02:22,670
So what we need to think about when we're using a game engine with numbers is a few things.
42
00:02:22,670 --> 00:02:24,420
Firstly we want to look at overflow limit.
43
00:02:24,440 --> 00:02:29,390
So if I pop here this is an older version of Unity game engine and it doesn't matter it's the same in
44
00:02:29,390 --> 00:02:31,460
a lot of languages and I start with a big number.
45
00:02:31,460 --> 00:02:33,300
Now I've chosen this number for a reason.
46
00:02:33,440 --> 00:02:35,440
This is we'll find out later.
47
00:02:35,570 --> 00:02:37,160
A 32 bit integer.
48
00:02:37,280 --> 00:02:42,020
So this means the total size that this can be is just over 2 billion.
49
00:02:42,020 --> 00:02:46,580
So I've set them under just under its limits and then I've just got a thing that's going to print out
50
00:02:46,580 --> 00:02:48,650
the number and then keep updating it.
51
00:02:48,650 --> 00:02:50,270
So let's just look at that happening.
52
00:02:50,270 --> 00:02:51,880
So I come along I hit play.
53
00:02:51,890 --> 00:02:56,570
We go to the console and look what happens if we scroll back in the console the number goes up and up
54
00:02:56,570 --> 00:03:01,480
and up and up and then eventually hook ups suddenly goes negative.
55
00:03:01,480 --> 00:03:01,890
Mm hmm.
56
00:03:02,300 --> 00:03:04,040
So we'll find out what's going on there.
57
00:03:04,040 --> 00:03:07,090
At another stage in the course when we look at the floating point representation.
58
00:03:07,160 --> 00:03:12,980
But what you need to understand is that one of the gotchas on a computer is the idea that you have limits
59
00:03:13,100 --> 00:03:14,230
of a number.
60
00:03:14,230 --> 00:03:19,850
And it may not fail nicely you may end up with it going from 2 billion to minus 2 billion when your
61
00:03:19,850 --> 00:03:22,330
code said to do is to add what's so big got you.
62
00:03:22,330 --> 00:03:28,250
There are other things we need to look at is the idea that when we're placing things together on a computer
63
00:03:28,460 --> 00:03:30,860
we're not necessarily dealing with the same time.
64
00:03:30,890 --> 00:03:35,660
We may have on one side of this we may have a hole number somewhere else we may have a decimal number
65
00:03:35,660 --> 00:03:40,460
so we need to be a little bit careful of that plus operators on computers tend to do lots of different
66
00:03:40,460 --> 00:03:45,980
things and you sometimes need to hover over them or look in your documentation to find out exactly what
67
00:03:46,070 --> 00:03:48,350
your your thing is doing on machines day.
68
00:03:48,640 --> 00:03:53,240
And the other thing to say about addition and subtraction is it can be done in any order so addition
69
00:03:53,240 --> 00:03:57,480
can be done in any order one plus two equals two plus one.
70
00:03:57,500 --> 00:04:01,660
The same thing they both equal three when it comes to subtraction.
71
00:04:01,670 --> 00:04:07,790
They can't be done in any order one minus two does not equal and I'm going to use that symbol there
72
00:04:07,820 --> 00:04:13,840
which is an equals with a cross rate does not equal to minus one because one minus two is minus one
73
00:04:13,850 --> 00:04:18,580
as we saw before and that does not equal to two minus one which is one.
74
00:04:18,590 --> 00:04:19,000
All right.
75
00:04:19,070 --> 00:04:21,350
So be careful of the order of subtraction.
76
00:04:21,350 --> 00:04:26,300
Understand that you could blow your limits on a computer of what is possible in terms of the range of
77
00:04:26,300 --> 00:04:30,290
the numbers you're dealing with and be a little bit careful those plus operators because I can catch
78
00:04:30,290 --> 00:04:34,370
you out they might do things you're not expecting that's enough on addition of subtraction for now let's
79
00:04:34,370 --> 00:04:35,270
dive into the next lecture.
7940
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.