1 00:00:15,185 --> 00:00:16,370 GUEST SPEAKER: You ready? 2 00:00:16,370 --> 00:00:22,070 The project that I chose to work on is a 2D puzzle game, 3 00:00:22,070 --> 00:00:25,460 and it's based on a puzzle version of Tetris 4 00:00:25,460 --> 00:00:27,830 that I've created over many years. 5 00:00:27,830 --> 00:00:30,840 I programmed in different formats. 6 00:00:30,840 --> 00:00:33,800 But I haven't figured out a good way to deploy it, 7 00:00:33,800 --> 00:00:37,850 so I thought maybe Unity would be a good option because it 8 00:00:37,850 --> 00:00:39,740 claims to be cross platform. 9 00:00:39,740 --> 00:00:44,540 So, anyway, so I'm a one-person project, and that's OK. 10 00:00:44,540 --> 00:00:46,900 It was a fascinating learning experience, 11 00:00:46,900 --> 00:00:49,460 and I made decent progress. 12 00:00:49,460 --> 00:00:52,140 The game that you're going to see is not very-- 13 00:00:52,140 --> 00:00:54,500 oh, something's wrong with it. 14 00:00:54,500 --> 00:00:57,230 The Canvas needs to get away from the playing board. 15 00:00:57,230 --> 00:00:59,540 Is there a way? 16 00:00:59,540 --> 00:01:03,390 Anyway, so the game is very low-end graphics. 17 00:01:03,390 --> 00:01:06,590 It's very bare bones, but conceptually, it's 18 00:01:06,590 --> 00:01:11,900 an implementation of Tetris, with the variation that only 19 00:01:11,900 --> 00:01:13,250 certain pieces are used. 20 00:01:13,250 --> 00:01:15,740 And it has a puzzle objective, so you could actually 21 00:01:15,740 --> 00:01:17,990 win the game or solve it. 22 00:01:17,990 --> 00:01:20,760 The objective is-- the simple objective is a wipeout-- 23 00:01:20,760 --> 00:01:22,610 where you want to clear the board exactly, 24 00:01:22,610 --> 00:01:25,010 so that the last piece clears all the row. 25 00:01:25,010 --> 00:01:27,810 Is everyone familiar with Tetris and the row-clearing mechanism 26 00:01:27,810 --> 00:01:29,240 [INAUDIBLE], I hope? 27 00:01:29,240 --> 00:01:32,775 So you'll see it and figure it out if you're not. 28 00:01:32,775 --> 00:01:34,140 If I can-- 29 00:01:34,140 --> 00:01:38,300 I knew I wanted to do a 2D game, grid-type puzzle 30 00:01:38,300 --> 00:01:40,250 because that's what I've been working on a lot 31 00:01:40,250 --> 00:01:43,160 is developing various ideas for logic puzzles 32 00:01:43,160 --> 00:01:44,720 that use 2D grids. 33 00:01:44,720 --> 00:01:47,660 And I thought Tetris might be too ambitious, 34 00:01:47,660 --> 00:01:49,730 so I was looking at the tutorials I 35 00:01:49,730 --> 00:01:50,900 found on Unity sites. 36 00:01:50,900 --> 00:01:52,900 There were some-- there was one for Minesweeper, 37 00:01:52,900 --> 00:01:54,441 so I was originally going to do that. 38 00:01:54,441 --> 00:01:57,390 But then when I found the Tetris tutorial, 39 00:01:57,390 --> 00:01:59,360 I said, oh, maybe I can go with this. 40 00:01:59,360 --> 00:02:03,770 My first step was to implement the Tetris tutorial-- 41 00:02:03,770 --> 00:02:05,660 implement the code from the Tetris tutorial, 42 00:02:05,660 --> 00:02:07,940 which that code was for a full Tetris 43 00:02:07,940 --> 00:02:11,550 game with a 10-wide board and all the pieces that 44 00:02:11,550 --> 00:02:12,860 are standard Tetris. 45 00:02:12,860 --> 00:02:14,960 But what I wanted is just a couple 46 00:02:14,960 --> 00:02:17,240 of pieces that work well for the wipe 47 00:02:17,240 --> 00:02:18,670 out games that I do-- the puzzles. 48 00:02:18,670 --> 00:02:20,420 So I just needed a T-piece and an L-piece, 49 00:02:20,420 --> 00:02:23,460 so that's all I implemented. 50 00:02:23,460 --> 00:02:27,020 So I adapted the Tetris code a lot. 51 00:02:27,020 --> 00:02:29,750 So let me just jump a bit and show you a quick demo 52 00:02:29,750 --> 00:02:32,054 if I could move my mouse. 53 00:02:32,054 --> 00:02:35,120 Oh, it's two screens. 54 00:02:35,120 --> 00:02:39,110 So before-- oh, yeah, the game is already going. 55 00:02:39,110 --> 00:02:42,140 So you can select which width you want. 56 00:02:42,140 --> 00:02:43,220 The board can be-- 57 00:02:43,220 --> 00:02:46,040 I'll show you how that moves-- 58 00:02:46,040 --> 00:02:47,870 the board can be seven-wide, or we'll 59 00:02:47,870 --> 00:02:50,810 start with five-wide because that's easier 60 00:02:50,810 --> 00:02:51,920 to finish the wipeout. 61 00:02:51,920 --> 00:02:54,530 10-wide is really slow. 62 00:02:54,530 --> 00:02:57,620 It's possible to play this wipeout game with wider boards, 63 00:02:57,620 --> 00:03:01,260 but it just takes so much longer, and it's tedious. 64 00:03:01,260 --> 00:03:03,260 So I find that five, six, and seven are the most 65 00:03:03,260 --> 00:03:05,900 fun and challenging levels, and the game 66 00:03:05,900 --> 00:03:07,000 can be very challenging. 67 00:03:07,000 --> 00:03:09,390 You need to learn patterns, as you'll see. 68 00:03:09,390 --> 00:03:12,010 So then you have the choice of three piece options, 69 00:03:12,010 --> 00:03:14,510 as either a T-piece, which I'll start with, 70 00:03:14,510 --> 00:03:19,220 or you can do an L-piece, or the T and L together, which 71 00:03:19,220 --> 00:03:22,130 under the current limitation, they're randomly chosen, 72 00:03:22,130 --> 00:03:23,720 which makes the game extremely hard 73 00:03:23,720 --> 00:03:26,850 because it's much easier to solve 74 00:03:26,850 --> 00:03:29,540 if you can plan ahead a little. 75 00:03:29,540 --> 00:03:31,370 Because you get to the point where-- 76 00:03:31,370 --> 00:03:32,750 well, I'm jumping ahead. 77 00:03:32,750 --> 00:03:35,840 So let's do the T-piece and show the game in action. 78 00:03:35,840 --> 00:03:37,200 So this is what it looks like. 79 00:03:37,200 --> 00:03:39,500 We start with a piece down at the bottom. 80 00:03:39,500 --> 00:03:42,850 It manually drops-- are my cursor keys going to work here? 81 00:03:42,850 --> 00:03:46,510 Yeah, so there's basically four-- 82 00:03:46,510 --> 00:03:48,740 the four arrow keys are used to control this. 83 00:03:48,740 --> 00:03:52,860 The pieces fall like in Tetris, so you can rotate. 84 00:03:52,860 --> 00:03:55,580 There is only one rotate, so right up arrow 85 00:03:55,580 --> 00:03:58,040 is rotate clockwise. 86 00:03:58,040 --> 00:04:00,620 And you could drop a piece, and then the rows clear. 87 00:04:00,620 --> 00:04:02,990 That's the Tetris mechanism. 88 00:04:02,990 --> 00:04:08,550 So now this takes a little longer to do a wipeout, 89 00:04:08,550 --> 00:04:10,230 but I'll show you the basic idea. 90 00:04:10,230 --> 00:04:12,770 The trick is that you learn patterns, 91 00:04:12,770 --> 00:04:14,670 so you'll start to see a pattern here. 92 00:04:14,670 --> 00:04:17,130 So I can clear that, and now I can 93 00:04:17,130 --> 00:04:19,120 clear a row by putting this. 94 00:04:19,120 --> 00:04:23,150 It takes four pieces to clear a row. 95 00:04:23,150 --> 00:04:26,610 So eight more pieces and I'll be down-- 96 00:04:26,610 --> 00:04:27,600 all but the white dots. 97 00:04:27,600 --> 00:04:31,655 So let's just plow through that, so you can see what happens. 98 00:04:32,185 --> 00:04:33,410 [LAUGHTER] 99 00:04:33,410 --> 00:04:35,270 One more. 100 00:04:35,270 --> 00:04:39,749 So it's-- you see the pattern, so part of what I think is fun 101 00:04:39,749 --> 00:04:41,540 about this game is learning these patterns. 102 00:04:41,540 --> 00:04:44,230 It's challenging to figure out how to learn pattern. 103 00:04:44,230 --> 00:04:46,270 There sort of like macros. 104 00:04:46,270 --> 00:04:46,925 Oh. 105 00:04:46,925 --> 00:04:47,424 [APPLAUSE] 106 00:04:47,424 --> 00:04:48,750 Look at that. 107 00:04:48,750 --> 00:04:51,000 Thank you. 108 00:04:51,000 --> 00:04:53,861 So let's just try one-- 109 00:04:53,861 --> 00:04:56,360 I don't know how much time I have, so I'll just do one more, 110 00:04:56,360 --> 00:04:58,610 so we can discuss what went into it. 111 00:04:58,610 --> 00:05:02,040 There were a number of steps forward in the learning 112 00:05:02,040 --> 00:05:02,540 experience. 113 00:05:02,540 --> 00:05:05,750 First, was implementing the Tetris game, modified 114 00:05:05,750 --> 00:05:08,720 to use only the two pieces, so I started with just the two 115 00:05:08,720 --> 00:05:10,960 pieces. 116 00:05:10,960 --> 00:05:15,810 And then, the next step, I wanted to set up 117 00:05:15,810 --> 00:05:17,610 controls to let me select. 118 00:05:17,610 --> 00:05:20,910 So the first thing I did was the width buttons-- 119 00:05:20,910 --> 00:05:21,760 to modify the width. 120 00:05:21,760 --> 00:05:23,343 There's just one thing that's control, 121 00:05:23,343 --> 00:05:30,120 which is the right border, as you saw it moves around. 122 00:05:30,120 --> 00:05:33,730 So learning to move that was my first learning experience. 123 00:05:33,730 --> 00:05:35,809 I was happy when I got that to work. 124 00:05:35,809 --> 00:05:37,350 And I had to figure out along the way 125 00:05:37,350 --> 00:05:39,480 how to make buttons work-- how to connect to them 126 00:05:39,480 --> 00:05:42,040 and run the scripts for buttons and things like that. 127 00:05:42,040 --> 00:05:45,570 It was very challenging, and I had never programmed in C# 128 00:05:45,570 --> 00:05:48,350 before, so that was a challenge in itself. 129 00:05:48,350 --> 00:05:51,750 But I made progress with that. 130 00:05:51,750 --> 00:05:54,440 Once I figured out buttons, I said, I'm running with buttons. 131 00:05:54,440 --> 00:05:56,950 I'm going to use buttons for all they're worth. 132 00:05:56,950 --> 00:05:59,640 So I try to do the Piece Selection buttons and then 133 00:05:59,640 --> 00:06:01,410 the Start buttons. 134 00:06:01,410 --> 00:06:03,540 And the Stop button doesn't quite work. 135 00:06:03,540 --> 00:06:06,930 It sort of works, but it seems to create something 136 00:06:06,930 --> 00:06:10,530 wrong in the data structure, so that when I run the next game, 137 00:06:10,530 --> 00:06:11,550 it crashes. 138 00:06:11,550 --> 00:06:14,880 So that's not good, so I avoid the Stop button now. 139 00:06:14,880 --> 00:06:19,290 So let me show you the six-wide board with the T-piece also. 140 00:06:19,290 --> 00:06:21,142 Maybe I should do the L-piece just 141 00:06:21,142 --> 00:06:23,100 to show you a different piece because I may not 142 00:06:23,100 --> 00:06:25,490 be able to get beyond this. 143 00:06:25,490 --> 00:06:33,254 So how do I want to do this? 144 00:06:33,254 --> 00:06:36,680 So, yeah, this will work. 145 00:06:36,680 --> 00:06:38,170 So one of the patterns you learn is 146 00:06:38,170 --> 00:06:40,240 that with two L-pieces together, you can 147 00:06:40,240 --> 00:06:42,530 make a two-by-four rectangle. 148 00:06:42,530 --> 00:06:44,620 So if I put this one down here, then the other 149 00:06:44,620 --> 00:06:46,720 completes the two-by-four rectangle. 150 00:06:46,720 --> 00:06:52,450 And that rectangle, you can see, fills in the remaining pieces, 151 00:06:52,450 --> 00:06:54,962 so that that wipes that one out. 152 00:06:54,962 --> 00:06:57,760 [APPLAUSE] 153 00:06:57,760 --> 00:06:59,402 And I won't have time to finish it, 154 00:06:59,402 --> 00:07:00,860 but I'll just show you what happens 155 00:07:00,860 --> 00:07:02,250 when have the end of pieces. 156 00:07:02,250 --> 00:07:04,690 Let's do it with, say, the five-wide board. 157 00:07:08,890 --> 00:07:13,090 So you see-- so we randomly get an L- or a T-piece now. 158 00:07:13,090 --> 00:07:15,700 And notice there's only one kind of L, 159 00:07:15,700 --> 00:07:21,040 which is the L L, not the reflected L. 160 00:07:21,040 --> 00:07:22,525 So how do I want to do this? 161 00:07:27,340 --> 00:07:31,030 So part of the problem here is that this L will not 162 00:07:31,030 --> 00:07:34,730 turn around to go in the other direction. 163 00:07:34,730 --> 00:07:41,060 Now if I'm fast, I can slip things in before it falls. 164 00:07:41,060 --> 00:07:43,210 [LAUGHTER] 165 00:07:43,210 --> 00:07:47,230 So I implemented the drop, so that it drops-- 166 00:07:47,230 --> 00:07:49,720 let me just get my piece ready-- 167 00:07:49,720 --> 00:07:51,010 I want it to go there. 168 00:07:51,010 --> 00:07:53,390 So it will drop, but not freeze the piece. 169 00:07:53,390 --> 00:07:58,610 So the code actually waits until there's a fall. 170 00:07:58,610 --> 00:08:00,490 You see that every second the piece 171 00:08:00,490 --> 00:08:03,940 tries to fall another step, and the piece 172 00:08:03,940 --> 00:08:07,000 freezes when it can't successfully fall 173 00:08:07,000 --> 00:08:09,690 in response to a fall action. 174 00:08:09,690 --> 00:08:12,310 So this isn't great. 175 00:08:12,310 --> 00:08:13,965 PROFESSOR: Anybody have any questions? 176 00:08:14,465 --> 00:08:16,590 GUEST SPEAKER: Yeah, you can start asking questions 177 00:08:16,590 --> 00:08:17,790 while I muck with this. 178 00:08:20,590 --> 00:08:21,090 Nope. 179 00:08:21,090 --> 00:08:22,360 AUDIENCE: Have you actually completed it 180 00:08:22,360 --> 00:08:23,560 with the RAM [INAUDIBLE]. 181 00:08:23,560 --> 00:08:25,690 GUEST SPEAKER: Oh, yeah, absolutely. 182 00:08:25,690 --> 00:08:29,250 It's just a little more tedious, like I said. 183 00:08:29,250 --> 00:08:32,220 It takes-- no, it's definitely doable. 184 00:08:32,220 --> 00:08:37,820 It just-- sometimes it takes multiple tries because-- 185 00:08:37,820 --> 00:08:38,919 here's a trick. 186 00:08:38,919 --> 00:08:41,309 Because I'm preparing for Ls. 187 00:08:41,309 --> 00:08:43,659 So I didn't get an L, but I could put a T in here. 188 00:08:43,659 --> 00:08:46,740 If I get an L next, good, then I could put this here. 189 00:08:46,740 --> 00:08:51,230 Now if I an L, I'll wipe out all those three rows. 190 00:08:51,230 --> 00:08:53,178 So I want to do things like that. 191 00:08:53,178 --> 00:08:54,402 [LAUGHTER] 192 00:08:54,402 --> 00:08:56,376 Let's see. 193 00:08:56,376 --> 00:09:05,200 There-- and this could work. 194 00:09:05,200 --> 00:09:06,641 I get another L. Nope-- 195 00:09:06,641 --> 00:09:07,140 didn't. 196 00:09:07,140 --> 00:09:09,670 So how do I want to do this? 197 00:09:09,670 --> 00:09:11,920 So you don't always get the piece 198 00:09:11,920 --> 00:09:15,478 you want, of course, because it's random. 199 00:09:15,478 --> 00:09:17,950 Let's see how this works. 200 00:09:17,950 --> 00:09:21,034 This will get it down to almost one row. 201 00:09:21,034 --> 00:09:24,240 [ARGH] 202 00:09:24,240 --> 00:09:24,930 Boo. 203 00:09:24,930 --> 00:09:29,260 I didn't want more L-pieces, but I have 204 00:09:29,260 --> 00:09:30,550 to decide what to do with it. 205 00:09:30,550 --> 00:09:33,960 I guess I'll just bite the bullet and do that. 206 00:09:33,960 --> 00:09:36,150 So now I'll try again. 207 00:09:36,150 --> 00:09:37,600 Yes, now if I-- 208 00:09:37,600 --> 00:09:41,480 whichever-- I'd prefer a T-piece now. 209 00:09:41,480 --> 00:09:42,975 So I can get it down to one cell. 210 00:09:42,975 --> 00:09:47,250 I'm close to a wipeout, but not what I wanted. 211 00:09:47,250 --> 00:09:49,230 If I can get a T-piece, so this is good. 212 00:09:49,230 --> 00:09:52,110 I like getting-- making the shape of a T-piece 213 00:09:52,110 --> 00:09:54,030 at the bottom because there is a way 214 00:09:54,030 --> 00:09:57,590 to win if I get the right pieces. 215 00:09:57,590 --> 00:10:03,393 So, L-- I need a T and an L. let's hope for an L next. 216 00:10:03,393 --> 00:10:03,976 AUDIENCE: Yay. 217 00:10:04,476 --> 00:10:06,341 GUEST SPEAKER: Yay. 218 00:10:06,341 --> 00:10:08,706 [APPLAUSE] 219 00:10:11,071 --> 00:10:14,130 So I think this is a fun game. 220 00:10:14,130 --> 00:10:16,331 What was this-- there was a second thing. 221 00:10:16,331 --> 00:10:18,220 The scripting was a big challenge, 222 00:10:18,220 --> 00:10:23,830 and learning to get the buttons to work properly. 223 00:10:23,830 --> 00:10:26,400 Oh, the text-- that's what I did last night. 224 00:10:26,400 --> 00:10:27,850 I figured out how to enable text. 225 00:10:27,850 --> 00:10:29,350 Someone gave me a hint that I wanted 226 00:10:29,350 --> 00:10:31,660 to set enable true or something. 227 00:10:31,660 --> 00:10:33,910 But it was very hard in one script 228 00:10:33,910 --> 00:10:35,260 that detected the wipeout. 229 00:10:35,260 --> 00:10:37,819 So I wrote the code last night to detect the wipeout 230 00:10:37,819 --> 00:10:39,360 by checking for all the rows cleared. 231 00:10:39,360 --> 00:10:44,240 There's a grid that's hidden behind this little matrix that 232 00:10:44,240 --> 00:10:46,720 holds blocks. 233 00:10:46,720 --> 00:10:51,460 And the script operates on that, and so I had the script 234 00:10:51,460 --> 00:10:54,144 that checks for the wipeout. 235 00:10:54,144 --> 00:10:55,560 And if it finds there's a wipeout, 236 00:10:55,560 --> 00:10:57,850 then it needs to call another script. 237 00:10:57,850 --> 00:11:02,770 Well, it basically needs to go tell the text to enable, 238 00:11:02,770 --> 00:11:03,730 so that you can see it. 239 00:11:03,730 --> 00:11:07,110 So I created the text and disabled it at the start, 240 00:11:07,110 --> 00:11:10,110 but then I needed to be able to programmatically, 241 00:11:10,110 --> 00:11:12,130 or in the script, turn it off and on, 242 00:11:12,130 --> 00:11:16,120 which these things sound simple, but they are not trivial 243 00:11:16,120 --> 00:11:17,620 when you're first encountering them. 244 00:11:17,620 --> 00:11:21,910 So I struggled-- doing googling-- looking for things 245 00:11:21,910 --> 00:11:25,640 like how to find an object. 246 00:11:25,640 --> 00:11:29,530 And so there's find object by type, 247 00:11:29,530 --> 00:11:32,230 and then there is the game object defined, 248 00:11:32,230 --> 00:11:35,480 which let's you find by name, which was very useful. 249 00:11:35,480 --> 00:11:38,540 So once I figured that out I could look up my-- 250 00:11:38,540 --> 00:11:41,050 I think it was a text object. 251 00:11:41,050 --> 00:11:44,204 I had a text object that I created, 252 00:11:44,204 --> 00:11:45,370 but that wasn't good enough. 253 00:11:45,370 --> 00:11:47,810 I needed to get the text component itself. 254 00:11:47,810 --> 00:11:49,870 So I had to call get component and figure out 255 00:11:49,870 --> 00:11:53,470 what kind of specifications to put after that to tell it 256 00:11:53,470 --> 00:11:55,030 what kind of component to find. 257 00:11:55,030 --> 00:11:56,140 The syntax was tricky. 258 00:11:56,140 --> 00:12:00,610 One website said you needed a dot before the angle bracket 259 00:12:00,610 --> 00:12:02,110 text and another one. 260 00:12:02,110 --> 00:12:04,180 But what worked was not having the dot there, 261 00:12:04,180 --> 00:12:07,760 so there's misinformation out there, or else Unity changed. 262 00:12:07,760 --> 00:12:10,090 I don't know, but, finally, I got it. 263 00:12:10,090 --> 00:12:11,810 And I thought there was a method called 264 00:12:11,810 --> 00:12:16,300 enable that I could say enable or disable, but turns out, 265 00:12:16,300 --> 00:12:17,120 it's a variable. 266 00:12:17,120 --> 00:12:19,570 It's a, I guess, a component variable, 267 00:12:19,570 --> 00:12:22,360 or something, that you can set to true or false. 268 00:12:22,360 --> 00:12:23,860 Finally, I figured it out, and I was 269 00:12:23,860 --> 00:12:28,930 able to get the congratulatory text to appear 270 00:12:28,930 --> 00:12:30,780 [APPLAUSE]