Java Tutorial How to Develop Game In Java ( Snake Game )

preview_player
Показать описание


Udemy Courses

Java Game Development Tutorial. In this Video You will learn step by step how to Develop Snake Game in Java.

Facebook Group:

Assets:

Solve Programming Practice Problems (Java):

Brick Breaker Game in JAVA:
Рекомендации по теме
Комментарии
Автор

Just a tip... When u set up the enemyXPos and enemyYPos i would say its easier to use an ArrayList that you fill by adding in a way like this...

for(int i = 0;i < frameWidth/25;i++){
enemyXPos.add(25 + ( 25 * i));
}
and the same for the other just using the Height.
this way you dont have to sit writing an entire numberDataBase. But a great video and thank oyou for the help.

albinwarme
Автор

For anyone that is also having issues placing the assets folder outside of the source folder and getting it to load in NetBeans, here is what I did while I was clicking around:

Instead of dragging the individual images into the project file, click the files tab at the top left where you see "Project, Files, Services." You could drag the files individually here right under the project main folder (mine is Snake2D), but I just took the entire assets folder and dropped it in under the main folder. Doing it this way, your code will need to also include the assets directory, so it'll look like this:

titleImage = new

I spent 3 hours trying to figure that out. :/

mlowe
Автор

Develop Brick Breaker Game with JAVA.
Practice Java by solving small programming questions:

AwaisMirza
Автор

For the people that know of the huge game bugs where if the snake head collides with itself, you can still move your snake by pressing the keys and it will break out of it and the game will continue, as well as the bug where if you press the space bar at any time during the game, your score will reset.

Don't worry, I fixed both bugs on my own and I wanted to share it with anyone who is frustrated and wants an answer to these problems.

Firstly, create another boolean variable called "isRunning" and set it to true. In your ActionListener method, put an if statement at the top, before all of the key direction code, and simply put an if statement checking if isPlaying is true and put the ending curly brace right at the bottom of all the key direction code, just before the repaint function. This will ensure that the directions will only be calculated if the isPlaying variable is true.

Now, in your code where the snake collides with itself, change the "isPlaying" boolean variable to false. So when the snake collides with itself now, you won't be able to move out of the position but you will notice that the snake's head is still moving.

To fix this, use that same isPlaying boolean variable and put an if Statement at the first point in the method where you set your key presses, and DON'T add it to the SPACE key event. This method determines the position of the head depending on the key pressed. The if check will check if the isPlaying variable is true, and if it is, which it won't be when the snake collides with itself, calculate the head direction based on the key pressed. Now the head won't move either and you won't be able to do anything when the game ends. Perfect.

finally, the space bar bug fix.

Just add another if check again but ONLY and I mean ONLY, as this is important... Only add this if check to the space key event code and nothing else. Instead of checking if the isPlaying variable is true, now check if it is FALSE. What will this do? Well, it's fairly obvious but this means that the space bar can only be pressed while the game isn't running. So now the game runs and your score will never reset, no matter how many times you press the space bar.

Really sorry for this essay. It's a lot of information to take in, but if you have any trouble still, I will be sure to help you if you're stuck. Happy coding!

EnlightenedSprite
Автор

i have little comment on improvement that when you code function press space to restart you need to set all the value of 2 arrays snakeXLength and snakeYLength to 0 otherwise when you restart the game if you go to the area you die the previous round you will trigger game over again. Anywway great video man, i made my day, keep up the good work and thank you very much for this.

binhduongpham
Автор

Mirza, thank you very much for the crystal clear explanation. For those having problems uploading images into the game, I got it by giving the whole path to the file where they are located: i.e
titleImage = new
I'm using Eclipse on Windows OS.

franm.e.
Автор

Great tutorial! I had to pause a lot but I just finished the game. Thanks for this awesome tutorial. My advise would be that you take an extra second to quickly repeat the logic of the code just written before moving to the next step. (i.e  type constant variable here goes variable...we do this because..)

harold
Автор

This was 8 months ago but I appreciate it. It's gotten me into speed. Thank you!

zapatazapata
Автор

for timer function to start
import javax.swing.Timer;
and remove other packages having Timer class.

sukritakhauri
Автор

33:17 you dont need to add the other directions as false, since they will just remain unchanged, theres no need to say theyre false if thats already initiated

Tokyo_Pessi
Автор

Congratulations for this game development video tutorial series!!!! Snake is really a cool game and it was very nice building it step-by-step and after that enjoying it, because it's so fun!! Your explanations were simple and very easy to understand, so it was a understandable and easy-to-follow tutorial series, especially for the fact that all the videos were put together over here in a single video! So the idea was great, the videos were very well made, and we are expecting other videos on game development because it is such a wonderful Universe! Keep up the good work! ☺☺🙏🙏👏👏🥳🥳

worldofelectronicsandprogr
Автор

For everyone who encounters the same problem as me: between part 2 and 3 some code has been added above the class which wasn't explained but you do need to import those items.

treentje
Автор

Amazing You are the man FROM which I become software developer

karunsarin-abouteverything
Автор

Very helpful video. The only thing i found that could use some work is that there is a glitch at the end. Once you reach the game over screen, you can continue to move if you use the arrow keys. I know this video is 4 years old, but just thought i'd say it since i didnt see anyone else say it

Steven.Z
Автор

There's a lot of Indian guys in YouTube! Nothing wrong with that, I am just surprised of the amount of Indian YouTubers

sudoalex
Автор

BEST VIDEO EVER AND YOU DID HARD WORK...I MADE MY FIRST SNAKE GAME FROM THIS VIDEO AND I SUCCEED, YOU TAUGHT ME WELL>>>HOPE YOU WILL CONTINUE THIS HARD WORK IN FUTURE :)

NarendraYadav-eqeg
Автор

Awesome! Thanks! I made it with IntelliJ

imaeolbutnotso
Автор

This code really works for teaching this code sir

JAYASHRITMSEC
Автор

Bro, to access the assets we need to have access permisions right?

ubaldosanjuansanjuan
Автор

Amazing video. Great instructions and understandable english. Every single step was shown clearly.

armanpapa
visit shbcf.ru