Java Programming: Let's Build a Game #5

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


Have fun learning!

In this video we take care of full on collision within our game and also a particle trail effect. If you have any questions then be sure to leave a comment or contact me on twitter; realtutsgml. If you learned something then be sure to leave a like, comment, and favorite.

Have you ever wanted to create games? Have you ever gotten fed up with it being to difficult? Well now is the time to thank me and possibly subscribe because you have just found the channel for you! Game Maker Tutorials, Java Game Programming, Unity3D Tutorials, Batch, C++ and much much more! This is the channel for you, the one stop shop for an exploration of your hidden talent as a game developer. Unleash your potential and go wild with imagination when you finally figure out how to make any game you want!

Visit CodingMadeSimple for more exclusive tutorials and get the help you need to succeed as your very own indie game developer!

Follow me on twitter for exclusive content and interaction with me!

Follow me on Google+ to keep updated with all of my tutorials

Game Maker Studio: Programming
Game Maker Studio: Tutorial
Java Programming
Game Programming
Game Tutorial
Programming Tutorial

Рекомендации по теме
Комментарии
Автор

It's literally the best feeling when you fix an annoying bug in your code.

daemon
Автор

Tipp: Add handler to the constructor of GameObject, and have it do
this.handler=handler;
handler.addObject(this) ;
That way you don't have to add every object to the handler yourself with "handler.addObject(New Player(x, y, etc))", instead you can just use "new Player(x, y, etc)" and it will automatically add itself to the handler.

robinvik
Автор

"I hope that makes sense." That was by far the clearest explanation anyone could provide on the matter, lol. Love the tutorials, very easy to follow. Great job!

irubberduck
Автор

For anyone having trouble with key inputs, (pressing multiple keys at once causes the player to stop moving in the correct direction) here are the correct functions for the KeyInput class

public void keyPressed(KeyEvent e) {
int key = e.getKeyCode();

for(int i = 0; i < handler.object.size(); i++) {
GameObject tempObject = handler.object.get(i);

if(tempObject.getId() == ID.Player) {
//key events for player

if(key == KeyEvent.VK_W)
if(key == KeyEvent.VK_A)
if(key == KeyEvent.VK_S)
if(key == KeyEvent.VK_D)
tempObject.setVelY(Game.clamp(tempObject.getVelY(), -5, 5));
tempObject.setVelX(Game.clamp(tempObject.getVelX(), -5, 5));
}
}

if(key == KeyEvent.VK_ESCAPE) System.exit(1);
}

public void keyReleased(KeyEvent e){
int key = e.getKeyCode();

for(int i = 0; i < handler.object.size(); i++) {
GameObject tempObject = handler.object.get(i);

if(tempObject.getId() == ID.Player) {
//key events for player

if(key == KeyEvent.VK_W)
if(key == KeyEvent.VK_A)
if(key == KeyEvent.VK_S)
if(key == KeyEvent.VK_D)
tempObject.setVelY(Game.clamp(tempObject.getVelY(), -5, 5));
tempObject.setVelX(Game.clamp(tempObject.getVelX(), -5, 5));
}
}

}

youraveragejoe
Автор

Seeing things starting to feel alive is amazing (in a way words cannot fully explain). Thank you so much for this tutorial, I should have started a long time ago.

SetGacia
Автор

Trying to keep up with the furious typing is actually really fun to do

woah
Автор

also if u did not understand the tick method here it is:



public void tick() {
//alpha AKA the transparency is 1 and life is what we set in parameters and if it is less then 1
//(if it's not then it's just going to not show the trail going to the else statement)
//then it's going to keep on subtracting from life so the transparency is slowly going to fade
//and then it's also going to reach the else statement if it's faded so when the alpha = 0

if(alpha > life){
alpha -= (life);
}

else{
handler.removeObject(this);
}

}

codebitcookie
Автор

🔥From this cool project I found out that I will not use for-each loops anymore. And here is why:

I tried using a for-each loop in Handler class when looping thru the LinkedList objects (instead of the standard for-loop as for(int i = 0; ...) as shown in this tutorial).

My loop code was:

for(GameObject go : objects) {
GameObject tempObject = go;
tempObject.tick();
}

This enhanced for-loop worked well UNTIL we added in BasicEnemy class tick() method a line:

handler.addObject(new Trail(x, y

With this ☝ line I got a
(If intrested, you may try it by yourself).
It took me a while to figure out why!

The reason of that exception is due to LinkedList iterator interface which in its next() method calls checksForComodification() method which checks if modCount equals to expectedModCount.

This code ☝ checks whether the LinkedList (or ArrayList) was updated in its size while being looped thru, and it doesn't allow that kind of update.
And as far as we exactly update our LinkedList in the Handler class for enemy object trailing ... it's not possible to use for-each looping. 📯

Whereas the standard for loop works perfect!

✨Conclusion: do not use for-each loops with Collections if there is a chance of their modifying (adding or removing objects) while looping thru them!

Кукусик-еэ
Автор

This is the best resource I've found for Java game creation.
It's extremely helpful for my college level Java class!
Thanks for this. Your videos are great and you do an excellent job of explaining things.

jimmyrustles
Автор

Totally been using these videos for an FBLA State competition learning tool!

XXBearcat
Автор

if you get a change your enhanced loop to the one he's using

felix.__k
Автор

Making Your Trail 1 less than the size of the object makes a really coll commet effect

oomphgordon
Автор

I'm understanding these methods now... slowly but surely...

hernandopenados
Автор

ok so im pretty new to this whole programming thing, and I managed to set the ID of the trail to BasicEnemy. This caused a collision issue where the trail was colliding with the enemy square due to the nature of the collision method and how it loops through the whole object list. I was able to locate and remedy the issue after about 10 minutes, and it felt so damn good.

skuul
Автор

Using graphics2D transparency your fps drops a lot.I recommend using diferent images or use pixel manipulation changing manually your RGB values ;)

Also instead of creating new objects in every update, create only once at your inicialization and then update like this this:

for(int i = trail.lenght-1; i > 0; i--){
   trail[i].x = trail[i-1].x;
  trail[i].y = trail[i-1].y;
}

and then at position 0 of the array you move.

guigrillo
Автор

Could you do a tutorial on random dungeon generation? That would be awesome.

Thegenfy
Автор

Can you explain what is actually going on inside of the 'trail' class? What does alpha mean? AlphaComposite? Etc.

bryangomez
Автор

12:58 IMG_1081 is this (and more photos like this) a selfie? You been pumping bro?

Zeriver
Автор

If someone is still watching this series (like me) and getting an error like:
Exception in thread "Thread-0"

Try this: object = new CopyOnWriteArrayList<>();
Instead of this: LinkedList<GameObject> object = new LinkedList <>();

on your BasicEnemy class. This method worked for me!

barsailles
Автор

I don t know anything about programming and I still wached this video instead of doing my homework

someonelol