Java Programming: Let's Build a Zombie Game #2

  Рет қаралды 28,545

RealTutsGML

RealTutsGML

Күн бұрын

Find Source Code and Courses www.codingmade...
in this tutorial we're creating the OOP (Object Oriented Programming) system for our zombie game! We start by creating our ID enumeration, GameObject parent class and the Handler class to update and render all of the GameObjects in our game. If you have any questions please feel free to comment below.
Twitter ► / realtutsgml
Google+ ► www.google.com/...
Have fun learning!
• Java Programming: Let'...

Пікірлер: 114
@RealTutsGML
@RealTutsGML 5 жыл бұрын
Hey guys! It's absolutely crazy to me that it's been over a year since this video went up. I'll be uploading a video next week on what happened and what I've been doing. Thank you to everybody for your support while I've been gone and I'm definitely not dead. -Zack
@PROJECTJoza100
@PROJECTJoza100 5 жыл бұрын
Happy to see you back. Good luck with whatever u've been doing!
@jovanjankovic
@jovanjankovic 5 жыл бұрын
Sooooooo happy to know you are coming back. Waiting for new video :)
@PROJECTJoza100
@PROJECTJoza100 5 жыл бұрын
7 months man. It feels like this was yesterday, but you arent here.. Atleast keeping us updated wpuld be better than dissapearing.. Edit: So you back?
@alainperez8579
@alainperez8579 5 жыл бұрын
come back my friend you can still make some money
@PROJECTJoza100
@PROJECTJoza100 6 жыл бұрын
rip
@MonaLisaOnGanja
@MonaLisaOnGanja 6 жыл бұрын
hey when are u going to upload ep 3??Plzz make as soon as possible
@raminote5726
@raminote5726 5 жыл бұрын
ONE YEAR ! One year without news, without a single post on social media ! Did he die ?
@raminote5726
@raminote5726 5 жыл бұрын
Oooh he didn't ! :o
@marceliwanicki2843
@marceliwanicki2843 6 жыл бұрын
Hey men, are you going to continue this series? I hope so, I really liked your past videos.
@MikeA-ri5pz
@MikeA-ri5pz 6 жыл бұрын
Are there going to be more videos??
@tweaxslp1557
@tweaxslp1557 6 жыл бұрын
where are the other epidsodes? :(
@PROJECTJoza100
@PROJECTJoza100 6 жыл бұрын
He is gone again :(
@RealTutsGML
@RealTutsGML 6 жыл бұрын
Thanks for watching! I'm having a blast building this game with you guys. I've also been adjusting my microphone setup, how does it sound for you? Thanks! -Zack
@TJPlaysNow
@TJPlaysNow 6 жыл бұрын
How long until the next video comes out?
@matthewchansavage3699
@matthewchansavage3699 6 жыл бұрын
Please make part 3 soon!
@maeve4004
@maeve4004 6 жыл бұрын
I second the above!
@PROJECTJoza100
@PROJECTJoza100 6 жыл бұрын
are u back soon?
@thecow4242
@thecow4242 6 жыл бұрын
Where did you go?
@epicgameplay7420
@epicgameplay7420 5 жыл бұрын
Did he die :c
@crew575
@crew575 6 жыл бұрын
I see that you are using in every game series the same systems. So I recommend you to make some new episodes where you will develop a game engine where be included things like input, game loop, some render methods, resource loader or sound. And after you can just use this Engine to make a new series. Because old viewers can be bored watching the same content. But your videos are amazing, thank you
@RealTutsGML
@RealTutsGML 6 жыл бұрын
Thanks a pretty good idea, I'd love to skip past these parts if I could, but I can't if somebody is new to this way of building the game. -Zack
@crew575
@crew575 6 жыл бұрын
RealTutsGML I suppose that you can link them to your game engine series and in current tutorial teach them more how to use this game engine and tell more things about game logic and mathematics that is used in..
@Roccatin
@Roccatin 5 жыл бұрын
aww, wanted to start this project, but I am glad that I've checked the number of episodes.
@ermir_skg5696
@ermir_skg5696 3 жыл бұрын
well now u can
@steliostb3120
@steliostb3120 5 жыл бұрын
why use a for loop when you can just create an array list and stream().filter() ? EDIT: for example, you could use: public void tickObjects() { objects.stream().filter(object -> object.isTick()).forEach(object -> object.onTick()); } this is a way easier and faster way to go through lists
@BrainExplosion1000
@BrainExplosion1000 5 жыл бұрын
Next episode
@MG-rn3jt
@MG-rn3jt 4 жыл бұрын
Rather use ArrayList instead of LinkedList
@shorakie5068
@shorakie5068 6 жыл бұрын
wont you continue
@gamemusicmeltingpot2192
@gamemusicmeltingpot2192 5 жыл бұрын
Duuude where you disappear off to?
@dgml007
@dgml007 5 жыл бұрын
UPDATE: Zack is back! The Coding Made Simple website is back again but...it doesn't recognize the user login details. Also, Zack's previous email contact is a no go.
@birutabatuta
@birutabatuta 5 жыл бұрын
I need the source code. Does anyone have?
@gamemusicmeltingpot2192
@gamemusicmeltingpot2192 6 жыл бұрын
I've been optimizing the game loop, and this is the version of the game loop that I think runs better. It makes it so that if the game is too processing heavy then the ticks and updates wont fall behind too much and only performs the most recent ticks and renders which helps in removing lag. You will notice that game laggs a lot when there are too many objects as the game becomes a bigger project. Also limits the fps to 60 so that it doesnt heat up the cpu too much : public void run() { long lastTime = System.nanoTime(); double amountOfTicks = 60.0; //NUMBER OF TICKS / SECOND double amountOfUpdates = 60.0; //FPS double ns = 1000000000 / amountOfTicks; //FIND THE NUMBER OF NANO SECONDS AFTER WHICH TICK HAPPENS double fp = 1000000000 / amountOfUpdates; //FIND THE NUMBER OF NANO SECONDS AFTER WHICH UPDATE HAPPENS double delta = 0, delta2 = 0; long timer = System.currentTimeMillis(); int frames = 0; int updates = 0; while(running){ long now = System.nanoTime(); delta += (now - lastTime) / ns; //WHEN CHANGE IN NANOSECONDS delta2 += (now - lastTime) / fp; //BETWEEN 2 INSTANCES IS AS LARGE AS THE TICK AND UPDATE INTERVAL lastTime = now; if(delta > 5) delta = 3; //IF IT FALLS BEHIND TOO MUCH IT SKIPS TICKS INSTEAD OF LAGGING while(delta >= 1){ //IT MAKES THE TICK tick(); updates++; delta--; } if(delta2 > 3) delta2 = 1; //IF IT FALLS BEHIND TOO MUCH IT ONLY DRAWS THE LATEST FRAME while(delta2 >= 1){ //AND THE UPDATE render(); frames++; delta2--; } //SHOW FPS AND TICKS AFTER EVERY SECOND if(System.currentTimeMillis() - timer > 1000){ timer += 1000; window.frame.setTitle("GAME " + frames + "FPS "+ updates +"TICKS"); frames = 0; updates = 0; } } }
@hossumquat
@hossumquat 5 жыл бұрын
Cool to see you are understanding what's going on in the game loop for the most part. However you really should only do one render per loop of while(running). If you look at what you're doing, you rendering multiple times, but since you aren't doing any tick() between renders, you are really just rendering the exact same image over and over. What is the point of that, right? So don't worry about the delta2 stuff, just render() once, and that will take constant time to do. If you find things are lagging behind too much, the best solution really is to adjust the amountOfTicks to something a bit lower, so you aren't doing as many tick() loops during a single game loop. This, however, can throw a lot of things off if you assumed some fixed amount of ticks per second. This brings up a nice lesson is design, though. Rather than designing your code to work on velocities and such using some unit per tick value, instead use a unit per second value (seconds are always seconds, can't change the universe after all). So instead of saying something like velX = 5; which would be 5 pixels per tick, you'd use something more like velX = 300 / TPS; with TPS being ticks per second (same as amountOfTicks above), and you'd probably want to make this a global constant instead of a local variable inside the run() method. Then you can change TPS to different values but still have object velocities be consistent. If rendering is what is slowing everything down then you probably want to start using a better graphics library instead of awt. Hope that all made sense to you.
@denisnasibullin7779
@denisnasibullin7779 6 жыл бұрын
I would be very happy if you did the games on the jbox2d engine. It can be an arcade like Angry Birds or platformer or physical puzzle with physical objects. Dear developers, put like if you want too
@zinsy23
@zinsy23 6 жыл бұрын
Happy 7th birthday to your channel! I remembered because my birthday is also the same day!
@jovanjankovic
@jovanjankovic 5 жыл бұрын
1 year passed without updates. No videos on youtube. Did he left youtube or something serius happened in real life. If you know why he isn't uploading please comment. Hope he will upload soon.
@danielchaffey7400
@danielchaffey7400 6 жыл бұрын
When is the Next video coming?
@matthewchansavage3699
@matthewchansavage3699 6 жыл бұрын
idk what's taking him so long... is he on vacation or something?
@dgml007
@dgml007 6 жыл бұрын
Zack, your website is "temporarily disabled" and I can't access your courses. Any ideas of when it will be back online?
@MathIsVeryCooliful
@MathIsVeryCooliful 6 жыл бұрын
Big fan of the java game dev series. Why do you bother with game IDs to differentiate gameObjects. Can't you just check if the game object is a instance of a player or enemy.
@RealTutsGML
@RealTutsGML 6 жыл бұрын
Thanks! How do you go about checking an instance of a GameObject in a different class? Let's say I want to add a keyboard event to only the player. Run me through the loop without using an ID system and I'll give it a try. -Zack
@MathIsVeryCooliful
@MathIsVeryCooliful 6 жыл бұрын
This code works for me. I modified one of your past Java game tutorials. This is all in the KeyInput class. public void keyPressed(KeyEvent p){ int key = p.getKeyCode(); for(int i = 0;i
@hossumquat
@hossumquat 5 жыл бұрын
I think an even simpler solution is to just have one player object (since you only have one player), instead of making it one object in a big mess of objects. For example you could have: class Handler { Player player; EnemyObject LinkedList enemies; } You can still have both Player and EnemyObject derived from GameObject. This will simplify the code, which is good for beginners to help understand what code is doing. And you always know that player is a Player object and enemies is a list of EnemyObjects. No need to worry about ENUM and type checking, though you may want to use an ENUM for different enemy types, where their type dictates how they look (render) and how they behave primarily. You also have more control over when the player gets rendered. You may want the player to be rendered on top of everything else, so you'd render the player after everything else. Also: public void keyPressed(KeyEvent p) { int key = p.getKeyCode(); playerInput(player, key, true); }
@TJPlaysNow
@TJPlaysNow 6 жыл бұрын
I don't see a point in the ID system, you have an abstract class, you could just setup a getId() method that just returns a set int or something, there is no need for an interface to be created for such a small thing when you can use any other method that doesn't require an extra file. You're on the right track to doing things good, but at the same time there are somethings that you need to change to be good. I really hope you implement some lambda usage sooner or later too just because the way they work adds a nice feel to the way a program runs in total. Will be waiting to see what comes next though
@RealTutsGML
@RealTutsGML 6 жыл бұрын
The ID system is made to make things so much easier. Who wants to keep track of player = 1 and block = 2 and bullet = 3, etc. Creating a simple ID system that has 4 lines of code to call ID.Player makes it much easier to understand the entire ID process. This also makes it much easier for scale, especially If you have something over 10-100 unique GameObjects in your game. I believe adding one extra file is much better than organizing a set of integers to equal a certain GameObject... you'll need an entire spread sheet to keep track. Thanks for watching and I encourage you to keep commenting if you feel like something could be made better. -Zack
@TJPlaysNow
@TJPlaysNow 6 жыл бұрын
I mean, sure but maybe whatever is causing you to figure out what the id of the object is outside of the object, inject it into the object and don't worry about it ever. Also, id's are usually used in cases where you never have two of the same, soo eh, also who said it has to be an int, it could be a string as the name :P but yea, will keep watching, I do like to see the take on different ways to do things
@TJPlaysNow
@TJPlaysNow 6 жыл бұрын
There's something I totally overlooked, instead of using an ID you could do an if (gameObject instanceof PlayerObject) {} and forget about the whole id thing if you have to mess with the object's special variables outside of the objects class, although you may still wanna think about bringing it all into the class, this is a nice work around to using an ID type
@FriendlyCube
@FriendlyCube 6 жыл бұрын
I wanted to thank you ! Your videos allowed me to develop my end of study project (2 years ago). Do you plan to make games multiplayer with socket gestion (UDP)? You do a very good job. Continuous like this :) !!
@RealTutsGML
@RealTutsGML 6 жыл бұрын
Thanks for watching! Right now I don't plan on turning this into a multiplayer game. -Zack
@TJPlaysNow
@TJPlaysNow 6 жыл бұрын
May I suggest, using a library such as SimpleNet to create very easy to use mutliplayer code? github.com/jhg023/SimpleNet
@jonatan1244
@jonatan1244 5 жыл бұрын
Whenever you write accesor like just to get x, someone in the world just dies..
@NepNepYT
@NepNepYT 3 жыл бұрын
17:16 lines 9 10 15 and 16 had underlines and idk how to fix it.
@RodrigoMatela
@RodrigoMatela 5 жыл бұрын
Hey man, could u please do, when u have time, a PipeMania game? It would be very good! Thanks
@xriccardo1831
@xriccardo1831 6 жыл бұрын
is Kill Java Programming a good book?
@itays7774
@itays7774 6 жыл бұрын
What are the benefits of a LinkedList over an ArrayList?
@HasNoName69
@HasNoName69 6 жыл бұрын
www.javatpoint.com/difference-between-arraylist-and-linkedlist 3 seconds of searching
@davidpoirierfilms
@davidpoirierfilms 6 жыл бұрын
Fr0d0B2g0sz But only one second of asking. Itay found a faster way.
@PROJECTJoza100
@PROJECTJoza100 6 жыл бұрын
Where did you dissapear?
@d.h.k.c8113
@d.h.k.c8113 5 жыл бұрын
... bro, I get that being in the same market as Heartbeast and Shaun Spalding can be depressing, but retiring from public life to raise goats in Southern Sudan is not the answer dude. And that beard doesn't look good. So, shave it off, divorce Ku'Lau'Pey'Ka'Pey from the Wuwok tribe, and do more tutorials for free in a thankless consistent manner for us. Because it's your duty. NoOoWw. ... but seriously, hope you got a 5-figure a year coding gig at a triple a and you're happy af cos that would totally be an excuse no one would give you shit for.
@davidpoirierfilms
@davidpoirierfilms 6 жыл бұрын
I’ve started my approach in a way very similar to how you are doing it here. Being the noob that I am, I’ve hit a roadblock because can’t wrap my head around building a structure that allows the objects to talk and react to each other. Please continue with this series. I am eager to see how you make it all come together in a way that makes sense. If you can get me over this mountain, it may change my life and career.
@Ordelos
@Ordelos 4 жыл бұрын
so why do i need the enum ? I dont get it yet
@manasbansal7946
@manasbansal7946 6 жыл бұрын
Instead of the getID() thing, you can do : if (Player instanceof GameObject) . Which is the same thing using "instanceof" keyword.
@DrFizzyQuizzler
@DrFizzyQuizzler 6 жыл бұрын
Can using java swing like this allow you to scale the game up to 1080p? Or bigger. All the tutorials I see online show the game as 800x600 resolutions, or do I need lwjgl to achieve higher resolutions?
@zandermcg968
@zandermcg968 6 жыл бұрын
Hello! I recently found out about your GameMaker Studio Online game tutorials, but then I realized that you haven't uploaded a video about that in a very long while. As I am currently learning about making a GMS online game with your videos, I couldn't help but wonder if you will ever do one again. If you will, please let me know so I can know for sure I can learn more than just the current videos. Thanks!
@PROJECTJoza100
@PROJECTJoza100 6 жыл бұрын
Also adding velocity to the x and y should be done in the gameobject class in a move() method or something. Not seperately in every other object
@palamut_14
@palamut_14 3 жыл бұрын
perfect perfect perfect %100 perfect
@오재화-d6l
@오재화-d6l 5 жыл бұрын
Did i just wasted my time lol
@nikomew5208
@nikomew5208 6 жыл бұрын
You taught me alot! Thanks!
@NepaliChoice
@NepaliChoice 6 жыл бұрын
bro when will be the next episode of this game? sorry i am new here and waiting for more episode.
@PROJECTJoza100
@PROJECTJoza100 5 жыл бұрын
He already has pretty good tutorial series on the channel, so thats all i can tell u..
@gruxx6603
@gruxx6603 6 жыл бұрын
Hey Zack, do you think that you will start a java based tower defense programming project one day?
@coolrash
@coolrash 6 жыл бұрын
make continue plss
@Styx_man
@Styx_man 5 жыл бұрын
I'm curious, why you still using awt and not JavaFX, for example?
@morenora1
@morenora1 6 жыл бұрын
Hi, thanxs for this, it's very helpful and I learn a lot. When are u releasing #3??
@adolfjohnduke
@adolfjohnduke 6 жыл бұрын
great video, your work always inspires me , do yo planning to do some tutorial of lights, shaders, etc?
@oliverbryan6083
@oliverbryan6083 5 жыл бұрын
More videos please??
@thorep
@thorep 5 жыл бұрын
Where is episode 3?
@ibitoyefeyisara3006
@ibitoyefeyisara3006 6 жыл бұрын
Is there a way this code could be made to work(port) for/to android?
@PROJECTJoza100
@PROJECTJoza100 6 жыл бұрын
This will become opengl later right?
@raminote5726
@raminote5726 6 жыл бұрын
why would it ?
@PROJECTJoza100
@PROJECTJoza100 6 жыл бұрын
Venakiel he said i thinl
@matt_huesman
@matt_huesman 5 жыл бұрын
Please come back your videos are so helpful. Where are you?!
@mihajlostamenkovic69
@mihajlostamenkovic69 5 жыл бұрын
At least inform us why you left come on dude this ain't cool at all.
@methitic9806
@methitic9806 5 жыл бұрын
His website is also down, and his last tweets on Twitter are as old as this video, so maybe he had an accident or something
@bot-ep1dk
@bot-ep1dk 5 жыл бұрын
@@methitic9806 He's still alive, check his Facebook lol
@dmitryveretelnyk8540
@dmitryveretelnyk8540 6 жыл бұрын
Hey, dude, I am waiting for next tutor))))
@jindrichkus3187
@jindrichkus3187 6 жыл бұрын
This is great tutorial. When will be next part?
@jtagames4670
@jtagames4670 5 жыл бұрын
hay forma de que subas los videos traducidos a español? saludos desde argentina
@Kage1128
@Kage1128 6 жыл бұрын
where are the source codes???? they are nowhere to be found
@scaraks
@scaraks 3 жыл бұрын
122nd
@rajatmohanjan
@rajatmohanjan 6 жыл бұрын
Please post the next videos of this series loved it till here
@snaxman
@snaxman 5 жыл бұрын
pls post the next part!!! great series
@nicxzoe4life123
@nicxzoe4life123 5 жыл бұрын
Will you continue this series?
@PROJECTJoza100
@PROJECTJoza100 6 жыл бұрын
Let me point one mistake. Pls notice me. In the Player class. Dont take in the ID in the constructor, but instead just put it in the super constructor. The same for the rest of the objects. They should already have set ids u dont have to set them again
@RealTutsGML
@RealTutsGML 6 жыл бұрын
Hey, I do have them in the super constructor when we create the child class. Just remember that every GameObject can be something different. i.e. Player, Block, Bullet, Zombie, Flowers, etc. How can we ID them initially in the GameObject class without knowing what they actually are yet? -Zack
@PROJECTJoza100
@PROJECTJoza100 6 жыл бұрын
sry i didnt see the answer. We are supposed to ID them in the class of the object. In The Player class we should ID that it is a player. in the player constructor it would be like this: player constructor (location){ super (location, PLAYERID); } and not: player consturctor (location, id){ super (location, id); } that way in every class that extends gameobject. i didnt type it out like in code. it was just to demonstrate it
@uselessone994
@uselessone994 6 жыл бұрын
Can you use jCreator or jGrasp on this
@vortex5244
@vortex5244 5 жыл бұрын
man where are the other vids? :(
@HasNoName69
@HasNoName69 5 жыл бұрын
It is really hard to tell you guys but... Zack passed away 3 months ago.
@PROJECTJoza100
@PROJECTJoza100 5 жыл бұрын
Source?
@HasNoName69
@HasNoName69 5 жыл бұрын
@@annie_the_great No, i am not.
@HasNoName69
@HasNoName69 5 жыл бұрын
@@PROJECTJoza100 I am his cousin. I was at the funeral like 6 months ago.
@PROJECTJoza100
@PROJECTJoza100 5 жыл бұрын
@@HasNoName69 you are not his cousin, you are a troll. In the previous comment, you said he passed away 3 months away, but u went to funeral 6 months ago? We aint dumb stop trolling pls
@HasNoName69
@HasNoName69 5 жыл бұрын
@@PROJECTJoza100 I wrote this post almost 3 months ago. 3+3 equals 6. Quit programming, dude. Its not for u.
@boltgreywing1718
@boltgreywing1718 5 жыл бұрын
Hey Realtutgml I was wondering if you could help me with a coding project? I like to build a new java game that is very simplistic. The game flips a coin where the user bets on heads or tails. If it comes up on their the side they bet on they win coins. If the lose then the coins that they bet get subtracted. However font text will need to be displayed on screen. Also there should be message box to prompt for the users name. Said users name should be displayed during the betting process. I lack the confidence to do this on my own and I feel I need the help of others. I gladly appreciate your help in this.
@crew575
@crew575 5 жыл бұрын
Do you believe that someone is going to help you? Yes you are right. This game is very simple so i can help you if you want.
@boltgreywing1718
@boltgreywing1718 5 жыл бұрын
@@crew575My appologies for not responding right away. I got a bit busy. However I still could use the help though and I would appreciate that very much.
Java Programming: Let's Build a Zombie Game #3
10:39
RealTutsGML
Рет қаралды 11 М.
Java Programming: Let's Build a Game #9
28:23
RealTutsGML
Рет қаралды 89 М.
Nastya and balloon challenge
00:23
Nastya
Рет қаралды 68 МЛН
Brawl Stars Edit😈📕
00:15
Kan Andrey
Рет қаралды 57 МЛН
Becoming No Boilerplate: My Journey
9:00
No Boilerplate
Рет қаралды 865
Java Collections Explained (with examples)
10:39
Visual Computer Science
Рет қаралды 85 М.
Being Competent With Coding Is More Fun
11:13
TheVimeagen
Рет қаралды 82 М.
Java Programming: Let's Build a Zombie Game #1
17:09
RealTutsGML
Рет қаралды 63 М.
Object-Oriented Programming is Bad
44:35
Brian Will
Рет қаралды 2,3 МЛН
WHY IS THE HEAP SO SLOW?
17:53
Core Dumped
Рет қаралды 226 М.
What is the Java Job delusion?
12:23
Stefan Mischook
Рет қаралды 123 М.
NEVER Memorize Vocabulary in a New Language - Use Artificial Immersion
10:04
GOLUREMI LANGUAGES
Рет қаралды 4,6 М.
Faster than Rust and C++: the PERFECT hash table
33:52
strager
Рет қаралды 574 М.
The Flaws of Inheritance
10:01
CodeAesthetic
Рет қаралды 945 М.