 Hey everybody, my name is Seth, and I work at opensource.com. This is the website. Our mission statement at opensource.com is that we're trying to spread awareness of open source, telling people what it can do. And part of that is that open source has recently discovered that games exist, or gaming has discovered open source, whichever way you want to look at it. And so one of the things that people wanting to either get into games or who are in games and want to distribute to more than just one de facto platform is that they're trying to find a game engine. And there's a really neat little game engine called Love, L-O-V-E. It's really nice. Well, it's nifty. I won't say it's really nice because it won't blow your mind. It's a pretty basic game engine. It does exactly what you would expect a game engine to need to do. So it takes care of your pixels. It takes care of your sound. It takes care of keyboard input and mouse response, things like that. It's basically a fancy screen buffer. But the cool thing about it is that it installs on. It runs on pretty much all the platforms that you would expect. So Windows, Mac, Linux, Android is in progress. I mean, Android does work. There's some niceties that it lacks, such as opening a game from within the engine. There's no sort of file chooser. You have to launch the game in the engine from a file manager, which usually, by default, Android file managers don't know how to do. But they're working on that. And then iOS, technically, but apparently, in order to get it on iOS, you'd have to compile it. I don't know what you'd have to do, but it would be up to the user. So realistically, probably not. But it gets four out of those five major platforms. It is written in C++, I think I saw that. And it is controlled by Lua. And Lua is a really neat little programming language that you might think, well, why would I use Lua instead of the obvious choice of Python or something like that? And you could do that. Those are perfectly fine languages, Python, Java, whatever. But Lua is quite nice because it is a really small, that's not actually what I wanted to look at. It's a really small file. It's like a 200 kilobyte file, single file. And you drop that into your project and suddenly you have your whole programming language. So it's pretty manageable. The documentation is, it'll show you all the basic functions that you get. And it's, once again, just kind of, it's exactly what you'd expect a programming language to have. Love takes care of all the fancy stuff for a game. For instance, here's a quick sample of a game that was written in love with Lua. It's called Mr. Rescue. Kind of does all the stuff that you'd expect a game to do. So I'm just controlling it with the keyboard. It's got animations. It's got music. It's got menus, stuff like that. So you can make 2D games with love. And I kind of want to show you sort of the process of what that would look like. But we can't spend the time to make a Mr. Rescue. So what we will do is make a quick little sample application together right now. As you can see, to launch a love game in progress. So as you're developing, it's just a matter of typing in love, which you would have installed on your system. And then here, your current directory, your project directory. And this is what we'll build together. So this is just a quick little random number, pseudo random number generator. So if I click, it grabs a number and shows me visually what that number is. This will be about 30 lines of code. And it'll give you an idea of the process of making something with love. So we'll make a project directory. We'll call it my project. We'll go into that project directory. So love expects there to be a main.lua file. That's what it needs to see in order to launch. I mean, you can launch it without that, but it doesn't know what to do from there. So if we just create a main.lua file, okay. So nothing super fancy is required. You can just do sort of a function. Then the function that, let me make that a little bit bigger. The first function that love looks for is a load function. Now, if you didn't know this, you can always just kind of refer to the love documentation. They've got all the libraries and functions rather. It is a library. It's got all the functions that it gives you in their wiki in a really nicely laid out kind of practical format. It shows you examples of how to use each thing. So if you're completely new to this sort of thing, as long as you spend a little time learning the basics of lua, which isn't all that complex. And once you have that, you can basically look up the stuff that you need to do with love. And the basic structure of any game that you do within this little engine is you've got your load function, which is the stuff that love does when you first launch your game. So it'll do that once. And then you've got your draw function. It'll do that every tick, every millisecond that passes. It'll refresh the screen, well, not every millisecond, but as time passes, it will refresh your screen with whatever is in the draw function. And that's really actually all you need to start. So if you just wanna get something up on your screen with love, that's the skeleton of it. We can create things like a window and we can give that window a title. We can give it some dimensions. Now, we could type the dimensions in here manually, but in real life, we would probably make a variable for those things, which we'll do right now. And that way, if we need to change it later, we would have easy access to that. Yeah, so that should give us something. There we go, there's our window. So that's the love game engine at its most basic, is a window with pixels in it. If we go back to our code, we can change things within that window. For instance, we could say that we wanna maybe set a background color. Once again, if you didn't know that that function existed, you could look it up in the documentation. You might have to look around for it a little bit because you wouldn't even know that it was in, oh, it's not in graphics, is it? What did I type? Graphics, yeah, it is in graphics. So you wouldn't know it's in graphics and you'd have to find out what function it is that allows you to set your background color. But once you figure that out, it's easy enough to use. The colors are in RGB format, so that would be black. This would be white, which is very confusing to me coming from a video background as I do. Zero and one for colors makes no sense to me, so I generally just use fractions. So that would be R, G, and then if we wanted, let's do some, oops, blue, there's a blue screen. We'll set it kind of to a gray. So all of that just loads initially when you first start your game. If you want something to appear constantly for as long as the window is open, you need to do that in the draw function. And the most basic thing I guess that you could do is in the graphics function, which is let's do a printf. That'll just get some text on the screen. So we'll do, let's do click to roll because we want people to be able to click on our screen and get a random number. So we'll say click to roll. And then there's the positioning, which I've already sort of calculated so that we don't have to figure that out live during this presentation. But essentially I'm just setting the X and Y values for where this text will appear. And there it is, so way, way down there, really, really small. And that's just raw sort of text being printed to the screen. We can make that fancier by defining a font for it. And we only have to define the font once, so we would do that back up in the load function. So we'll say love, graphics, set new font. Problem is we don't actually have a font to point it to. We can make it a big font, but we don't have a font. So I happen to have a font set aside here, so I'll just copy from my previous folder the font. So now our project directory looks like this. It's got our main.lua file, which we're working in, and then it's got the font directory, which contains a couple of different open source fonts, actually one open source font in a couple of different formats. So we can just grab one of these, we'll grab this one maybe, paste that in there. And it'll need the path, so since we have it in the subdirectory, we'll include the subdirectory so that it knows where to look. There we go. Now we've got the same text being printed, but it's using the font variable that we've defined and it's rendering it with the font that we've included. So as long as you're using open source assets, it's pretty easy to make everything self-contained. You're not gonna get weird errors about how the font doesn't exist on the system or anything like that. You can just throw everything into your project directory, which is how love sees itself. So in the end, which I don't even know if we'll get to, but I mean, we'll get to the end, but I don't know if we'll be able to cover the packaging of a love game, but it's just a zip file. You zip up your project directory, you rename it to a .love file, and that's it, that's all you do. So that makes packaging super, super easy. All right, so next thing that we need is a graphic. And so once again, if we want something to be drawn on the screen, as long as the window is open, we need to put that into the draw function. So if we just do like love graphics, new image, and then once again, I don't have an image, so I've set some images aside here. I sort of pre-manufactured them and named them in a biological system. So I'll copy those from my sample project. There they are. That's our project directory. It's got all of our assets in it. So we can say, okay, this is gonna be image, and we'll just start with zero PNG because this will be the starting image. So it could be anything, it could be a splash screen, it could be whatever, but we'll start with an empty image. And the way that we'll do that, the way that we'll draw that is, that's wrong, is we'll draw our image that we want, and we have to kind of position it with numbers that I've pre-calculated. We don't have to do it here. And we get an error. Not sure what I did there. So let me, let me look at that. Love, graphics, draw, image, zero PNG. That's correct. This is what I did. So this is the starting image. So we're going to instantiate this as an image that exists in the load function. So that's telling love to load this graphic file as something. So we'll call it starting image right now. Well, we'll call it start. We'll call it splash because I've got something else that I want to use as start later. So there we go, image. Now of course, it doesn't do anything because we've got no logic in our program. And this is kind of the cool thing about love is that the way that you make objects, so love is a, or rather, Lua is a scripting language. It is not an object-oriented language. However, it uses something called tables which are just, it's a fancy term for an array. So if you're used to using arrays in a different programming language, this is the same concept, but a little bit simpler than probably the arrays that you're used to. So we'll create a table. Let's call it human. And now that's, so that's an empty global table that exists in our project. We can now use that array to dump new variables into and get variables out of. And it's really easy to do that. So if we just say human.img, for instance, equals this starter image that we want to use. Now in our previously empty table for human, we have a new field called image. And so we define that by simply creating it out of thin air. It doesn't have to be, it can be anything. We could call it image. We could call it splash. It doesn't matter. We're just making this stuff up and we're dumping it into our table. And then if we call it again here, then it'll know what image we're calling. So that's that. And we can do lots of different things. So we can do bullions. So we'll say, okay, is this the start of our program? We'll call it true. Yes, this is the very beginning of our program. We haven't done anything. Nothing's been clicked yet. So we'll say if human start is true, then we'll print this graphic. Else we'll do something else. Now the something else that we want to do is the logic part of the program. And so we can use a new function that exists in love. So this isn't something that we're making up. I mean, you can make up your own functions, but this one is again, it's defined in the documentation. And it is upon a mouse release. So mouse release will say that if we have a click and then it's been released, then we will set our human start variable now to false. So it's no longer the start of the game because now there's been an interaction. And then we can use Lua functions to do some of the stuff in the background that love wouldn't normally do. For instance, love doesn't have a random number generator because Lua already has that. So we can create a random seed up here in our start function. And this is all just pure Lua now. So this is the Lua math function. This is the Lua timekeeping system. We start the seed here in our load function once. And now we can invoke it later because we've got that seed running. And we can say, okay, well, take that random seed and pull out some number from one to six. Yeah, and then we can create a new variable. We'll call it pick for now. And we'll say that it's gonna be called image die.png, but we'll substitute the word die for whatever the random number that we generated ends up being. So this number here is gonna be used to generate the name of the image that we show in the window. And now we'll redefine human image, which we defined initially up in the load function as just a blank, the blank image. But now we're gonna use one of the images that has numbers assigned to it. And we'll do that using whatever happens to be in our pick variable right now, depending on how it's been created. So now, rather than, so in other words, if it's not the start of the game, there's been an interaction, then we don't wanna show the blank image. We wanna show the, I don't know. We wanna show the, that's all right. We wanna show the new image, which should be basically, it'll be the same place, and it'll be the same variable. We get different numbers. Well, we get, yeah, we get different pictures, rather. And we can do some niceties like, okay, well, instead of printing click to roll, we could just print the value of the human roll. And then we'll move this one up to the conditional where it's just the starting screen. And that's good because we have a couple of minutes to demonstrate how this works if we bundle it up. So this is the complete program for what we just witnessed. It's not that long. It is 32 lines, and I think, it's not even 32 lines really, it is 30 lines. I think it's one of those things that's pretty easy to follow, because you've got your initial function of your startup sequence, your init sequence, essentially, and then you've got your loop, and then you've got little exceptions of events that happen, and that's kind of how I think about it when structuring a game. So we'll save that. Here we are in a project directory. We can go back out and literally just zip this up. So if it's my project.love, I think I have to do that recursively. Yep. Now we've got a myproject.love, and then if I tell it to launch myproject.love, that didn't work. I know why. I'm not supposed to go back out of the project. Yeah. So we need to do a zip of, we'll still call it myproject.love. Actually, I think I'm gonna call it .zip first, and then I'll rename it, because if I recall correctly, it gets confused if I don't do that. So we're including all of our assets in the current directory. There we go. And now we've got myproject.zip. I'll rename that to myproject.love. So it's a single file that you can distribute to people. I think in the file system, it looks relatively pretty as long as you have love installed on the system. Yeah, there. So people, you know, ideally should be able, let me see if it works. If I double click on that, it just launches it. So it feels and sort of acts like a real application for your end users. They don't have to worry about what's inside of here. But if they want to know, then they can unzip it and actually look at it and see all the code. So that's assuming you're totally into open source. That's a good thing, because now your code is visible to others and they can learn from it or possibly help you port it to the latest version of love or whatever. So yeah, that's... And that same file, if I were to load that onto my phone, I could launch... I could open that up in love on my phone and it would work exactly the same. So it's kind of nice, because it's, yes, pretty portable. There are some other details about the way that tables work that I would like to talk about, but I'm not sure if it's really that important. Are there any questions? Possible, yes. Convenient, possibly not. So you wouldn't... You can compile love separately, obviously on its own. It is not that huge. It's basically a 60... I think it's 61 megabytes. And then you could drop that into your project and sort of shift that with your project, but then you'd have to sort of figure out how to get that to launch. So yeah, I mean, there are ways, but it's not super convenient to do it now. Any other questions? Yeah, I think that's it. That's good. Thanks a lot.