 Welcome to simple Java game library, which is made for beginners with Tokyo ed tech. That is me Today I want to introduce you to something. I've been working on I think it's finally in a state where I could share it with people and you might be able to actually use it for something useful I call it the simple Java game library So I'm gonna talk to you about what this is you can probably guess from the title I'm gonna show you how to download it. It's really easy. I'm gonna show you a little sample game I'm still working on but it kind of demonstrates the power of this particular simple Java game library and I hope you get started and show you some of the classes and things that you can use to make some games so Simple Java game library is as the name indicates it is a Library for making simple 2d games in Java. I wrote it for my students you is Basically really I think really aimed at beginners something that they can understand even with just kind of basic Java knowledge and Java and Java coding knowledge so to download it you just go to my github and It is wine and 1 0 0 4 and I'll put a link down below and you'll see actually go to this page. You'll see Projects simple Python game library. Don't get the wrong one You'll see simple Java game library and touring machine Emulator that of course could change depending on when you watch this video So I'm gonna go to simple Java game library and you'll see here where it says code I'm gonna click download zip And it will download. It's about 7.4 megabytes. I think seven of those megabytes are actually just an audio file, but Yeah, yeah, so I've downloaded it. You'll see simple Java game library and I'm gonna double-click that to Open it. I'm gonna extract it now again I'm running Linux, you know what you see will be compared different depending on if you're running what Mac or Windows I've tested on Mac, but I haven't tested it on Windows yet. So Windows people let me know how it goes So but it's Java so it should work so I'm gonna go into simple Java game library and The Java files here. There's a few of them. There's SJ GL. That's the actual main library There's the sound class sound sprite class There is a label class and there is a demo game as well And there is a template. I'm gonna show you how to use those here shortly Let me show you this demo game. This will kind of give you an idea of what this can do and The idea here is to make this as simple as possible for beginners to You know start getting used to making simple games So this is the demo game and it is 112 lines long basically it's just it's just the beginning of a side-scrolling shooter So I'm gonna go ahead and hit compile and I'm running genie now It automatically compiles all of the files in the directory for me I'm gonna go ahead and execute it and you should see It's on the box really bring it up. Okay, so you can see I Got a little background See this basically shows you everything that this can do we got sounds. We've got sprites. We've got labels where we can print text and Yeah, that's it. We got a screen. Let me close that for you it's a little loud and So this is included in in the file right now probably rearrange things later I just want to get this out. I was really excited to share this with the world So let me go ahead and open up the template So you'll see template dot job. So if I open that up and basically it's got some comments here So if you run this you'll see it's basically one two three four five six actually basically five lines of code if I compile this and I run it it puts Basically it puts up a blank window Okay, now that should be 1024 by 768 I think that's the default but you can control that completely so you can see here We are able to set the background color using the built-in AWT colors So again, one of the things I wanted to do with this was to introduce my students to how Java works But avoid some of the complexity of you know how game programming works with you know You know asynchronous timers and things like that. I'll show you some of that a little bit probably So let's try. Let's try green. Just see how that goes. So I'm gonna compile it again And I'm gonna run it and hopefully we will see a now a green screen very very exciting I'll put that back to black Okay, so Basically what happens is you create a new game object And that game object has several methods and things that you can use One of one of which of course is set background color Now speaking of sprites, which are 2d game objects We have background sprites which basically you know shown in the background and don't interact They don't collide with anything. They're just there for You know really background So in the previous example you saw, you know, you saw the background so to create a background sprite you need to Create a sprite and give it a name. So for example, let's let's go ahead and do the background there. So background image And it's a new sprite and I'm gonna put that at 00 which is the top left part of the screen and let me just copy that because I forget what exactly what I called it Now one of the things I did to make this easy for my students Especially today's students who are not very good at file management Was just make it work so that everything is in the same folder. So as long as This is in the same folder. It should work. So you'll see You know background 1024768 jpeg and now if I compile that and run it You won't see anything Okay, it's missing and the reason is that creating it's one step, but we actually have to add it to The the game and say the game engine or whatever you want to call it So game dot add background sprite and then in this case this sprite is called background image So I compile that and run it again. I Should see my nice little background and I forgot where I got this image from what it's in the commit where I actually Committed that to my repo here. So you see got a nice little background so far. So good Yeah, then we can now go ahead and create a sprite for like our game objects. So let's go ahead and create the player Is that what I wanted? Yeah, so Player and that's gonna be a new sprite and in this case what I do is I I'm gonna put the sprite in on the left side of the screen It's 0x and the screen. I think by default is seven six eight. So 350 well say 360 let's put it around 360 on the y and I think I called it. What did I call? I'll see if I called a player that PNG so We'll run it and see what happens. Do you feel lucky? Okay, okay, it did compile it is running and I Forgot to add it to the game sprites. So notice. I'm adding background sprites and I'm adding Regular like to the game game sprites Again, these do not interact. They're just for there for the background It could be moving clouds. It could be anything moving in the background the game will render them first So the active sprites will be printed in front The background sprites will be printed or renders to say in the background. So let's go ahead and try that again. I guess my Okay, and we don't see anything here Because sprite name is not correct player All right, let's try that again So you probably see this pattern. So you create the object and then you add it Okay, and now you can see there is the player object so let's go ahead and move it so For this game to work Again, it's trying to keep this as simple as humanly possible for my students So we basically set up our game here. We create the game object We can set the background color adds a background sprites at our game sprites You know, I'll talk about sounds in a minute's labels And then we have a wild true loop, which is basically our game is going to run Okay, so that's where our game code is gonna go So I'm just gonna go ahead and kind of scroll down through here without not doing everything You know on live this is just kind of an introduction. So you'll see here. It says deal with key presses so I'm just gonna go ahead and copy that and I'll explain what that does here in a second So paste that in there so you'll see here that Currently there is a way of getting the current key that is pressed So it's game and get key again trying to keep it as simple as possible We have object dot method something that my students are you know It all levels can really understand and then we have various key events And these are just straight out of the standard Java key event class So vk underscore up vk underscore down and what that does is it sets our dy and dx of our Sprite so run that Or compiles you say I'm gonna run it now when I press the up arrow My sprite goes up and when I press it it goes down Okay, so and again this this will run faster. It's running slowly because I'm doing the screen recording I'm surprised. It's this small though. That's the thing Maybe my screen resolution is a lot bigger than I thought it was So Where are we at there? Okay, so you can see how we can get some keyboard input That's in there. Now if I open up the sprite class Sprite class has quite a few things going on there and eventually once I get this fully set up I will do a proper explanation some proper it's some proper documentation, but You know, the sprite has an x-coordinate a y-coordinate the top left not the center It has a dx and dy which is the speed that it moves Left and right and up and down. It also has a heading you are able to rotate the sprites And you can actually have it rotate, you know automatically just just like it's moving It's rotating it in place or you can actually set the heading directly We have a couple default sizes And there's some stuff here to deal with you know Lots of stuff to deal with you know hitting the hitting borders What are you doing hit the boundary do you bounce do you warp around do you stop? You can change is it visible? There's all kinds of all kinds of different things we can do Again, I'm not gonna go through everything. It's just you know kind of give you an idea of You know what each class does and there's all kinds of stuff you can rotate you do all the kind of normal Kind of cool stuff you do you can obviously do Collisions there's something that's colliding and kind of go from there Let's see here a couple other Classes in here. We want to take a look at sounds so if you want to create a sound It's sound and you give it a name So let's go ahead and So BGM so that's background music and this is one of the limitations because I wanted to keep this easy To download and cross-platform and just very simple to deal with I had to I only use the built-in Java classes So you are limited to basically wave files, so you can't do MP3's you have to convert them Yeah, it was a conscious decision to keep it simple And also I wanted the students my students to be able to actually look at the code and kind of see how it's working and then another thing I did here to keep it simple is BGM dot play if you want to play a sound and What's what makes this work really well is each sound can only play once at a time I should say so if You know if you're playing it and it's already playing it won't play it will ignore that second play until it's done So that's why the background music keeps playing because of the loop that it's in Okay, so that's a background music playing and that will go You know that will keep playing for us in the background again key here was keeping it simple as possible Labels are pretty simple to use as well. So I might say here, you know score a label and I will say score you start the game to zero and we'll put that 512 and we'll put it down about 50 and see what happens there and then also don't forget We need to add the label to the game So the game like library takes care of you know all the rendering and all that sort of stuff for you label space Yeah, normally my tutorials are I wouldn't call this a tutorial. It's kind of an introduction, but Yeah, I just wanted to get this out. It's something I've been working on. I'm really happy with so Should see here the score is zero and we can you know set that to any XY You know the game engine basically takes care of all the rendering for you so Again, I wanted to keep this as simple as humanly possible for Beginners so you know add a background image Add a add a sprite add a sound play it add a label You know just it's you know, just you know, I see all these game engines that are supposedly good for beginners They are not good for real beginners They they're just far too complex wait. There's way too much presumed knowledge that Most students just don't have At the early stages of their learning and so that is why I created this So, let me just kind of go through show you a couple quick things in some of the code to kind of give you an idea So the actual library itself. It isn't that long It's only a few hundred lines like 370 lines give or take and there is some rudimentary support for mouse as well I got some of the basic code from this website here. I didn't know how to do a lot of these things I've been working on this for about a month and Finally got a few things working that were kind of causing some problems and but as a user You don't really need to look at this But it is here if you're curious how all of this stuff works and that was one of the other things I really wanted to The students to be able to do is to look at this and say oh, I can kind of see how that works I mean, you see there's still some testing code in there This this is it very much a work in progress, but again, I think it's at a point where you know You can actually do some things with it one of the things Yeah, I had a problem earlier with it But I fixed that literally this morning was it would just crash when you had too many sprites on the screen So let me go ahead and add from 30 to 300 enemies And I'll show you how that works Now it's gonna be slow because I'm doing the screen recording, but on my desktop computer. It runs pretty smoothly So I can shoot so this is 300 different sprites going on the screen just pretty cool and It's working I think pretty well, I don't have a particularly powerful laptop or anything Let's see if we get 3,000. Let's just see what happens That might crash. We'll see Okay, well still making sprites, I think Yeah, if you see this part down here, this this is when there's a It's the system's kind of overloaded. That's what I fixed today Every time that happened it used to crash but now now all the sprites are created So now I've got 3,000 sprites on this running at the same time well 3,002 if you count the player So I think that's a pretty impressive Tally to get 3,000 sprites running on a you know, five-year-old laptop not his Linux So it does run a little bit faster, but Anyway, so that was that's kind of it. You know, you can kind of take a look at the Demo code you can see here how collisions work You know, there's quite a lot going on here, but it's not super challenging. There's some Code here for mouse clicks to test that But there's no mouse clicking in this game, but it's pretty simple It's pretty straightforward, you know, create your game objects. You can change the frames per second set your background color When we do a background sprite create some sprites, you know, I have a missile in the game, obviously you know create some random enemies and There's an explosion sound. There's a background music sounds you saw earlier and there's a label so Yeah, and then so like, you know things like, you know, if the missile if the missile collides with the sprites So in this pick your game if that sprite is You know, it's gonna be an enemy it can't survive itself. It doesn't register So you'll see explosion dot play so it'll play that explosion sound and then we can remove sprites from the game that was part of what I got fixed this morning and Yeah, so Yeah, hope and it was a little quick and wasn't really a tutorial per se But hopefully that's enough to get you started playing with it if you're interested if you have any questions, you know Drop me a message down below You know, I'm like said, I'm really happy with this I'm gonna actually I started actually using it with my students a couple weeks ago an early version But now it's really to a point where I can actually do some interesting stuff with it But I just wanted to get them exposed to it and just so they have the basic idea how these things work So anyway, that is that I think I covered everything Yeah, so the main classes SJ GL sprites sound and Label so I think with this engine you can make basically, you know, a lot of classic 2d games You do a platformer. There's there's a gravity thing that's built in and you know, it's it needs some work But there's quite a lot that you can do with it. So Thanks for watching. I know it was quick, but I just want to get this out there Like I said, I'm really excited a little bit proud of this to be honest I think it's it's gonna really change I think the way I approach teaching Java to some of my students and you know students that have done some Java They can apply what they learn students that are learning Java You'll give them something kind of cool and visual to do rather than just a bunch of boring old text Anyway, thanks for watching. Keep on coding