Ep. 124: Integrating the Event System - Game Programming

The Cherno · Intermediate ·10y ago

Key Takeaways

The Cherno integrates an event system into the Rain game project, utilizing event-driven programming and object-oriented design principles to handle user input and game logic. The video covers the implementation of event listeners, event dispatchers, and layer stacks to manage game events.

Full Transcript

hey what's up guys My Name Is AO and welcome to episode 124 of game programming so last time we finished up the UI and the buttons and whatnot and we actually had our own image inside the button this little kind of uh thing here and we did some image brightness stuff and whatever and we've got a pretty good setup going on for the UI right now um up to the point where I can pretty much call it complete um except for the fact that when we clicked over on this panel uh it actually uh continued to shoot of course we put in something to stop that over here and that was this if Mouse getex is greater than 660 than whatever we put on we put in this whole system um to stop that and whatnot but I asked you guys if you wanted me to do it properly you know basically by converting this into like a kind of layered uh game with with layers and with events um and you guys said yes so I made a standalone video for that um it's called like event system and dispatcher or something I don't know it's called but it's there'll be a link to that video in the description so I highly recommend you watch that video before you go ahead and watch this one because that one is going to explain how the entire advance system works okay um and that video of course will be kind of the preface to this video because in this video all we're going to do is we're going to kind of copy the code from that other video from that example that I made and integrated into uh into rain so that's kind of the idea okay um speaking of which this game is called rain so we should have we probably have some kind of rain effects going on I think I I think that'll be good so if you guys want to see that just leave a comment below and um and and and we'll get we'll get around to that uh but anyway so I when I said copy I literally meant copy because I've got B basically both folders open right now and I'm going to be copying them so layers we want right cuz that has like our base kind of layer configuration and we want events we don't really need core this is from the other video by the way um and this is also on GitHub uh but um yeah we don't really need core but we do want events and layers so I'm just going to copy that and we can actually just put it right on into here okay layers I'm actually going to move into Graphics though that's the only change I'm going to make if we come back here right click hit refresh or we can hit F5 as well with that selected uh we will see our new code in the um in the project so we've got like a bunch of errors here which is fine um so we have to basically uh reconfigure all this stuff event list now we going reimport that event we should probably just go through every file right now fix up the package declarations if you have your mouse over the error and select a change package declaration to well that one then uh it should uh it should work out lovely all right and yes this will take a bit of time unfortunately um uh Mouse press Mouse so this is just for Mouse events so far we we'll hook in some key events and whatnot in the future uh so we're kind of making some uh engine changes here that are probably going to be for the better because as I said as I told you guys I want to kind of take this game to the next level and I want to make it a game that we can pretty much release like as in we want to meet that quality uh so that's what um that's why I'm doing all this stuff so let's see uh what do we need to import right now we want to import what are we trying to import though would be good if it told me cuz I don't know so event type is probably what we want um not spawn we shouldn't need that yeah there we go not sure why e clipse was asking us for that I'm just hitting control shift o by the way to bring up that organized Imports dialog all right is that it that's it okay cool no no more errors so let's integrate everything to use layers so the way this is going to work is we're going to basically uh go to our level class right now and we're going to make it so that level uh extends layer okay because level is going to be a layer um we don't really have a layer stack right now but we'll set that up in a minute so uh that'll be in our game class it looks like so anyway you can see nothing's basically changed uh if I actually go into layer though I want to see what kind of stuff we have in layer that we should be overriding so there's on update there's on render so I'll change these to render an update to match our kind of convention um on event I guess I will just leave as on event cuzz if I change it to event that just looks kind of weird public for event uh we'll we'll leave it as on event Okay cool so if we go render we want screen screen of course to be in here instead of Graphics G uh and update I think is pretty much the same cool so now we should be getting one way to check is if you look at this you should be seeing um this is the player you you should be seeing where's update you should be seeing like a green arrow that just basically uh is a Clips telling you that you're overriding something and you should see the same for render if you don't like for example we don't uh that's a problem so that's because our render method takes in like X scroll and Y scroll which is a bit weird so let's not make it do that let's quickly just make a public void set scroll because I'm pretty sure we've got something like that anyway way don't we X scroll y scroll do we not have that apparently not well we do now so we'll make a private int X scroll y scroll this game really needs some refactoring to be honest obviously it's been three years since I started it so I do things a lot differently now but um I'm a much better programmer now than I was back then but anyway regardless of that we will continue going on with this stuff okay so and I'll I'll kind of I guess slowly over time we'll be refactoring this stuff I'm not going to spend like 10 episodes an hour rewriting everything or anything like that but we're going to kind of just slowly gradually you know little things like this uh just kind of uh changing it up a bit so basically all that's all that's changed is uh we just have to call one extra method here there we go okay and let's just double check the game is still working as expected and it is great so now let's close all these event classes now we need to hook up our event system uh into our kind of window class which is really just this class because you can see that we're doing everything like adding key listeners adding Mouse listeners uh and all of that stuff yeah uh into here um you know the frames for example we're doing all that stuff uh in this class so that's why we have to kind of make it work with that so what we're going to do is um let's see so we've got the layer so we'll have to make a layer stack so private list layer uh we call it layer stack equals new array list layer and I'll import that make sure you import the one that's in util not awt we're not looking for the uh GUI version of list we're looking for the actual data structure um so layer stack is our layer stack which great um so every time we we add a layer let's make a uh let's just quickly make a public void add layer layer layer layer stack. add layer okay um so what we'll do is we've got a key list already that's our keyboard and we've got our Mouse so if we actually uh if if you guys were to go back to the other video and see how it worked all we did is we kind of we uh essentially made an event um and when we made an event uh we um we kind of we called an onevent method which basically looped through everything uh and handled it okay so what I'm going to do is this I'm going to make it so that uh game actually implements um an EV the event listener which might be a bit weird because layers by the way do that as you can see the reason I'm doing this is because I'm going to actually uh make it so that Mouse requires uh when we make the mouse public um so basically we don't really need any of this to be static anymore uh but when we make this we're going to make it so that uh this takes in an event listener because we want to hook up this mouse into an event listener because the event listener is where it's going to send all the events right hopefully this is making sense uh so public event listener uh event event listener all right we'll hook this up uh and then when we have all this we'll we'll have to uh we'll have to basically sort them out uh there so we'll add this um and we'll add the listeners all right so let's quickly set it up for the mouse right uh we're kind of going to so we we are changing this system I'll still keep the static stuff around just in case we need them but I'll probably start uh changing the up to be honest so when we move we want to create a new Mouse uh move event Mouse moved event uh E.G X E.G Y and dragged is false and then what we want to do is by the event listener is here we're going to call event listener do on event uh with the event here all right pretty simple stuff um so this obviously needs to implement on event I'll pop it right over here public V on Event Event Event okay because what this is going to do is just basically uh send it down the layer stack now events go down to layer stack in reverse order so what we need to do is we need to say 4 in I equals uh basically the the last uh thing in the layer stack which will be layer stack dot um get oh rather layer sorry layer stack do size minus one that's the last element I is greater than or equal to zero so it goes all the way to the beginning of layer stack and then IUS minus okay so that's basically going to iterate through the layer stack but in Reverse so from the from the from the end to the beginning rather than from the beginning to the end um so uh all we have to do here is say layer stack. getet I do onevent because obviously whoops because obviously every uh layer is an event listener okay cool anyway so now we should be getting events so if we go into like um say the level uh you you would see that the level um so the level extends the layout so we need to uh basically override that on event method I think we just did that no we didn't so we've got St where's update we'll do it right after update how about that public void on event okay now this is where the events get received so basically what we usually want to do is just uh basically raise that event for every single uh entity okay and then the entity can choose what to do with the event okay we definitely don't want to block events or anything like that in this case uh but that's kind of how it works right now so anyway there is two different things that I should mention though in the event thing there's an event listener and there's an event handler okay an event handler is something that actually handles the event this returns a bullying and this had this could stop the dispatcher from taking place but remember we we we're not really talking about this we're not really talking about the event dispatcher right now at all it's not actually a thing an event dispatcher is something that you use to just dispatch events when you're actually inside an onevent thing okay that's that's all you do that's kind of the Endo solution right we're kind of still in the middle of things because level really probably won't do too much with on event but we do want to send it to things like the player okay uh so that being said um yeah like the player is actually a really good example of where we want to send events to like we probably don't want to send um uh events to entities for example that wouldn't really make too much sense we could do that though right we could do that in situations where we want the enemies to react to players event which is a bit weird like you might not do that it doesn't really make too much sense to do that because events right now at least are just kind of user input style things in the future they could be anything they like literally anything but um right now they're just user input things so it doesn't make too much sense to do that but anyway we can get um I don't know why this is called get player if it turns a list should be called get players but anyway we can get the client player which is the current player um and we can send an event there because really again if we are talking about about a multiplayer scenario uh which is why we've got like the G client player here really the client player is the only one who raises events because right now events are input events and uh they get raised uh all they should get sent to the client player so what we'll do is we'll say get client player. onevent event so the player is going to implement the event listener interface which is going to add we're going to add that on event going to pop it right before update uh and there we go so now we can set up an event dispat and we can do things like shoot and whatnot when things happen which is great so if we go back to Mouse real quick I'm just going to finish um making events for everything so drags is going to be the same but with true uh Mouse uh pressed is going to be Mouse pressed event okay and I believe that just takes in uh in in bulling so uh sorry it doesn't take in pull in takes in in in int so the button I think is first let's see the button is first and then the coordinates so we'll take in the button which is e do get button and then we'll take in the things this is actually additional information as well uh I mean we did have it before you would have to call two methods you would have to call the get mouse button and the get uh X and get y but now we kind of have it all all in that event which is nice uh and released of course we'll do the exact same thing except it's going to be a mouse released event okay I think that's it isn't it that sounds like it's it you know we would have other events such as Focus lost Focus uh what's the of focus lost Focus focused I don't know anyway Focus lost Focus gained whatever um you could uh we would have events for that if we had Focus listeners as well that's another common thing to do in Java and in games in general but um yeah we could raise events for that as well okay cool anyway um so now that we've done that we should be able to capture events uh already in um in the uh player class already okay the final thing we haven't done is set up a proper rendering system for events so right now we have this level. set scroll stuff and we kind of do this stuff level. render shouldn't this shouldn't be called anymore okay what should happen is this is where we render layers okay so we'll basically say for each layer layer stack. size I will basically just call layer stack. gei do render screen okay and then when we make the level up the top here uh we'll actually or we so where we do the we set it to level spawn whatever we just we'll just basically say add layer level okay and we don't need to update anymore either so I'm going to copy this I'm going to say update layers here uh and we're basically just going to change this to update okay done so if we if we run the game now we should hopefully be at the same situation as we are now and we are which is good um so now we need to change uh the only thing we need to change is we need to see first of all if players get events correctly so if we go to player uh the best way to see any of this really is just to print out the current event so if we just print out the event we'll get the name of the event you can see we get ton of mouse moved events we get uh Mouse press Mouse release events when we actually press and release like uh over here for example press released right uh we get all that stuff which is good uh so it's working that's basically the main thing this is where event dispatcher comes in so we're going to say event dispatcher um dispatcher equals new event dispatcher event okay and now what we're going to do is we're going to basically write a bunch of events for all these things so public void on Mouse move do we don't really need to handle that too much do we really we just want Mouse pressed so Mouse pressed event e uh and we want Mouse released I think that's probably about it to be honest okay we'll import those these should be bullings by the way uh okay and we'll just return false right now okay cool so so what we what we want to do right now is just call uh dispatcher do dispatch uh the type will be event. type do uh Mass press right the handle for that is going to be a Lambda um and it's going to be uh just a mouse press event we're going to cast it to that um and and what was I calling I was calling the on Mouse pressed method so on Mouse pressed e is that the syntax I don't even know too many semicolons first of all uh that's what I meant I think or is that what I meant I haven't written lambdas in Java in a while that's what I meant I think this is great oh okay that was right I just have to change my pressure compliance to j8 well guys looks like we're finally making switch into Java 8 um okay cannot redeclare uh is it just it's that isn't it is it okay I'm going to quickly uh see what I did before because I don't do lambdas in Java too often uh where where would I have done that I would have done that in example layer in the other project ah close so Event Event okay we run M to cool that was close all right so we've got the mouse pressed event and now we'll do the M Mouse released event um released event okay and uh now we should have everything working pretty well uh what's wrong with you I wonder yeah you totally should be there uh did I screw up on Mouse released yeah it's not a thing okay cool there we go so lambdas are just basically a a shorter way of writing um like an an inner class basically so the alternative would have been to do something like new event handler and then call like you know return on Mouse pressed event that's exactly the same code okay uh and then you have to cast it yeah that's the same thing except our system is way cooler all right cool there we go um so now that we've done that uh we should be able to basically handle all that stuff pretty easily um so we've got this get button fire rate stuff so update shooting is kind of something that we don't really need to do anymore okay because now we can uh handle this stuff in the event system so if I literally cut this update shooting and put it onto on Mouse pressed um so uh you know we'll just return false or whatever if that's the case we don't need to do the get button anymore this this comes from the event now so it's going to be E.G button equals we'll do like mouse event do button one I guess I was hoping for something like left button but I guess we get what we get uh that's the left Mouse button right I hope so button one whatever that means what do that even equal to one okay so that's the same thing as what we had before excuse me me okay so fire rate yeah we got that stuff going on um now if this happens we might want to return true okay that means that we've totally handled the event whoops we've totally handled the event um and we don't want anyone else to handle it anymore okay uh otherwise we'll just return false okay cool um and if this happens we can yeah we can return false pretty much straight away we probably don't even have to do that anymore to be honest Okay cool so I'll get rid of see masse released really doesn't even need to be a thing anymore um it probably doesn't at least so we'll get rid of update shooting uh we can get rid of it here and if we launch this we should still be able to shoot and as you can see we can um however I don't think we can hold the mouse down anymore looks like we can only uh we can't kind of leave it press we have to keep clicking on it uh which is a bit annoying um so what do we have before let's see so first of all it looks like that event isn't going to get raised as long as the mouse is pressed only when it gets pressed okay so the way that you can uh do something like that is pretty simple we basically [Music] um we basically have something in player that's like private bullying shooting false uh if um let's see where are we uh so on Mouse press if this is true we simply set shooting equal to True uh over here if the button is the correct button and we release it we'll set uh shooting equal to false and we'll return true um and uh that should be about it so now this code which is really the the the the juicy part uh we can basically just put into the update uh loop so we can we'll still we can still have something like update shooting or something um private void update shooting uh and of course uh we can say that if not shooting return okay there we go so if we run that uh we should be able to shoot and as you can see we totally can and we're shooting a lot shooting very quickly um and I assume that that's because of that fire rate so uh one thing we should say is that oh yeah we definitely don't want to be shooting so this and fire rate stuff don't really care about that uh we could say something like uh if fire rate so shooting or fire rate is uh greater than zero then we return we don't really need to be doing anything like that okay and then we've got our back we're back to our kind of uh old self with the event system Okay cool so anyway uh that's pretty much going to wrap up this episode I don't want to make this one too long but that is kind of the beginning of the refactoring for wow those Imports crazy that's basically the beginning of the refactoring for the um event system uh next time we're going to refactor the UI stuff um so what I mean by that is we've got the UI buttons and UI panels really which we're going to have event listeners um and of course we're going to be able to block events based on uh where like you know basically whether or not the event happened on that certain layer and whatnot and we're going to transform uh UI panels and the entire UI manager system into basically a UI layer so we'll ring up that concept and overall it should be definitely pretty cool now uh if you guys do enjoy this series then the best way to support it would be on patreon so I do have a patreon account it's patreon.com Theo here it is right over here you can uh essentially pledge uh a given amount and uh the the best thing you can you can really do is pledge $5 or more because if you do you'll get access to all of the source code for this game programming series on GitHub via private repository so you'll have all of the code for this game programming series as well as um as well as uh all the differences between commits because every episode I make a new commit and you'll be able to compare the difference of what I've changed uh episode per episode uh which is pretty cool I think so anyway if you're interested in that you can of course click the link in in the description and support me on patreon that all that also ensures that I make more videos as well which is always a good thing um but other than that if you did enjoy uh hit the like button and I will see you guys next time as we continue uh making rain goodbye [Music]

Original Description

Events Video ► https://www.youtube.com/watch?v=yD47_hq75q0 Source Code ► https://www.patreon.com/thecherno Twitter ► http://www.twitter.com/thecherno Stream ► http://www.twitch.tv/thecherno Website ► http://www.thecherno.com Facebook ► http://www.facebook.com/thecherno Want more? You can help out by supporting me on Patreon! https://www.patreon.com/thecherno ------------------------------------------------------------------------------------------------- In this video: - How to make a game - How to implement an event system ------------------------------------------------------------------------------------------------- Website: http://www.thecherno.com Twitter: http://www.twitter.com/thecherno Facebook: http://www.facebook.com/thecherno Subreddit: http://www.reddit.com/r/thecherno/ Steam Group: http://www.steamcommunity.com/groups/thecherno ------------------------------------------------------------------------------------------------- Outro music is by Approaching Nirvana: http://www.youtube.com/approachingnirvana
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from The Cherno · The Cherno · 0 of 60

← Previous Next →
1 3D Game Programming - Episode 1 - Window
3D Game Programming - Episode 1 - Window
The Cherno
2 3D Game Programming - Episode 2 - Game Loop
3D Game Programming - Episode 2 - Game Loop
The Cherno
3 3D Game Programming - Episode 3 - Arrays
3D Game Programming - Episode 3 - Arrays
The Cherno
4 3D Game Programming - Episode 4 - Drawing Pixels!
3D Game Programming - Episode 4 - Drawing Pixels!
The Cherno
5 3D Game Programming - Episode 4.5 - How Rendering Works
3D Game Programming - Episode 4.5 - How Rendering Works
The Cherno
6 3D Game Programming - Episode 5 - Playing with Pixels!
3D Game Programming - Episode 5 - Playing with Pixels!
The Cherno
7 3D Game Programming - Episode 6 - Performance Boosting
3D Game Programming - Episode 6 - Performance Boosting
The Cherno
8 3D Game Programming - Episode 7 - FPS Counter
3D Game Programming - Episode 7 - FPS Counter
The Cherno
9 3D Game Programming - Episode 8 - Alpha Support and More
3D Game Programming - Episode 8 - Alpha Support and More
The Cherno
10 3D Game Programming - Episode 9 - Beginning 3D
3D Game Programming - Episode 9 - Beginning 3D
The Cherno
11 3D Game Programming - Episode 10 - Floors and Animation
3D Game Programming - Episode 10 - Floors and Animation
The Cherno
12 3D Game Programming - Episode 11 - Rotation
3D Game Programming - Episode 11 - Rotation
The Cherno
13 3D Game Programming - Episode 12 - User Input
3D Game Programming - Episode 12 - User Input
The Cherno
14 3D Game Programming - Episode 13 - Render Distance Limiter!
3D Game Programming - Episode 13 - Render Distance Limiter!
The Cherno
15 3D Game Programming - Episode 14 - Basic Mouse Movement
3D Game Programming - Episode 14 - Basic Mouse Movement
The Cherno
16 3D Game Programming - Episode 15 - Textures + More!
3D Game Programming - Episode 15 - Textures + More!
The Cherno
17 3D Game Programming - Episode 16 - Walking, Crouching, Sprinting + More
3D Game Programming - Episode 16 - Walking, Crouching, Sprinting + More
The Cherno
18 3D Game Programming - Episode 16.5 - Exporting Runnable Jars
3D Game Programming - Episode 16.5 - Exporting Runnable Jars
The Cherno
19 3D Game Programming - Episode 17 - Small Adjustments + Birthday!
3D Game Programming - Episode 17 - Small Adjustments + Birthday!
The Cherno
20 3D Game Programming - Episode 17.5 - Creating an Applet
3D Game Programming - Episode 17.5 - Creating an Applet
The Cherno
21 3D Game Programming - Episode 18 - The Beginning of Walls
3D Game Programming - Episode 18 - The Beginning of Walls
The Cherno
22 3D Game Programming - Episode 18.1 - A Few More Things
3D Game Programming - Episode 18.1 - A Few More Things
The Cherno
23 Episode 18.5 - Creating an EXE File in Java
Episode 18.5 - Creating an EXE File in Java
The Cherno
24 3D Game Programming - Episode 19 - Rendering Walls
3D Game Programming - Episode 19 - Rendering Walls
The Cherno
25 3D Game Programming - Episode 20 - Continuing Walls, Fixing Bugs, and Managing Crashes
3D Game Programming - Episode 20 - Continuing Walls, Fixing Bugs, and Managing Crashes
The Cherno
26 3D Game Programming - Episode 21 - Texturing Walls, Fixing Clipping, and Fixing the Mouse
3D Game Programming - Episode 21 - Texturing Walls, Fixing Clipping, and Fixing the Mouse
The Cherno
27 3D Game Programming - Episode 22 - Random Level Generator + Properly Fixing Clipping
3D Game Programming - Episode 22 - Random Level Generator + Properly Fixing Clipping
The Cherno
28 3D Game Programming - Episode 23 - Graphical User Interface (GUI) Launcher
3D Game Programming - Episode 23 - Graphical User Interface (GUI) Launcher
The Cherno
29 3D Game Programming - Episode 24 - Making Our Launcher Work
3D Game Programming - Episode 24 - Making Our Launcher Work
The Cherno
30 3D Game Programming - Episode 25 - Writing and Reading Files
3D Game Programming - Episode 25 - Writing and Reading Files
The Cherno
31 3D Game Programming - Episode 26 - Custom Resolutions
3D Game Programming - Episode 26 - Custom Resolutions
The Cherno
32 3D Game Programming - Episode 27 - Decorating the Launcher
3D Game Programming - Episode 27 - Decorating the Launcher
The Cherno
33 3D Game Programming - Episode 28 - Continuing our Custom Launcher!
3D Game Programming - Episode 28 - Continuing our Custom Launcher!
The Cherno
34 3D Game Programming - Episode 29 - Launching The Game
3D Game Programming - Episode 29 - Launching The Game
The Cherno
35 3D Game Programming - Episode 30 - Colour Processing In-Depth
3D Game Programming - Episode 30 - Colour Processing In-Depth
The Cherno
36 3D Game Programming - Episode 31 - Sprites!
3D Game Programming - Episode 31 - Sprites!
The Cherno
37 3D Game Programming - Episode 32 - Sprite Mapping
3D Game Programming - Episode 32 - Sprite Mapping
The Cherno
38 3D Game Programming - Episode 33 - High Resolution Rendering
3D Game Programming - Episode 33 - High Resolution Rendering
The Cherno
39 3D Game Programming - Episode 34 - Entities
3D Game Programming - Episode 34 - Entities
The Cherno
40 Genesis - My Game for Ludum Dare 24
Genesis - My Game for Ludum Dare 24
The Cherno
41 Vlog + Ludum Dare Results
Vlog + Ludum Dare Results
The Cherno
42 Game Programming - Episode 1 - Resolution
Game Programming - Episode 1 - Resolution
The Cherno
43 Game Programming - Episode 2 - Threads
Game Programming - Episode 2 - Threads
The Cherno
44 Game Programming - Episode 3 - Game Loop
Game Programming - Episode 3 - Game Loop
The Cherno
45 Game Programming - Episode 4 - Window
Game Programming - Episode 4 - Window
The Cherno
46 Episode 5 - Buffer Strategy
Episode 5 - Buffer Strategy
The Cherno
47 Game Programming - Episode 6 - Graphics Initialized
Game Programming - Episode 6 - Graphics Initialized
The Cherno
48 Game Programming - Episode 7 - Buffered Image and Rasters
Game Programming - Episode 7 - Buffered Image and Rasters
The Cherno
49 Game Programming - Episode 8 - The Screen Class
Game Programming - Episode 8 - The Screen Class
The Cherno
50 Game Programming - Episode 9 - Rendering Pixels
Game Programming - Episode 9 - Rendering Pixels
The Cherno
51 Game Programming - Episode 10 - Clearing the Screen
Game Programming - Episode 10 - Clearing the Screen
The Cherno
52 Game Programming - Episode 11 - "Out of Bounds, Baby!"
Game Programming - Episode 11 - "Out of Bounds, Baby!"
The Cherno
53 Game Programming - Episode 12 - Negative Bounds
Game Programming - Episode 12 - Negative Bounds
The Cherno
54 Game Programming - Episode 13 - Timer
Game Programming - Episode 13 - Timer
The Cherno
55 Game Programming - Episode 14 - FPS Counter
Game Programming - Episode 14 - FPS Counter
The Cherno
56 Episode 15 - Tiles
Episode 15 - Tiles
The Cherno
57 Game Programming - Episode 16 - The Map
Game Programming - Episode 16 - The Map
The Cherno
58 The Walls 2 - Minecraft PvP Survival Map
The Walls 2 - Minecraft PvP Survival Map
The Cherno
59 Game Programming - Episode 17 - Key Input
Game Programming - Episode 17 - Key Input
The Cherno
60 Game Programming - Episode 18 - Controlling The Map
Game Programming - Episode 18 - Controlling The Map
The Cherno

This video teaches how to integrate an event system into a game project, using event-driven programming and object-oriented design principles. The event system is used to handle user input and game logic, making the game more responsive and interactive. By following the steps outlined in the video, viewers can learn how to design and implement event-driven systems, utilize event listeners and dispatchers, and manage game events using layer stacks.

Key Takeaways
  1. Copy code from a standalone video into the Rain game project
  2. Integrate event system and dispatcher into the game
  3. Add layers to the game configuration
  4. Reconfigure package declarations and import necessary classes
  5. Hook in Mouse events and key events
  6. Make Level class extend Layer class
  7. Override on update, on render, and on event methods in Layer class
  8. Create a layer stack in Game class
  9. Add layers to layer stack
  10. Integrate event system into Game class
💡 The event system is a crucial component of game development, allowing for more responsive and interactive gameplay. By utilizing event-driven programming and object-oriented design principles, developers can create more efficient and scalable game architectures.
Up next
George Hotz | Programming | tinygrad, starting on CLOUD=1 | Part 2
george hotz archive
Watch →