Java Programming: Let’s Build a Game #12

[ad_1]
Produce your own Java game from scratch with this very simple, yet very powerful course available right now

In this video we add a pause menu and a difficulty screen! 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


Posted

in

by

Tags:

Comments

37 responses to “Java Programming: Let’s Build a Game #12”

  1. David Joel Avatar

    for those of you who get errors when clicking play, in the tick method on the Game class where it says

    if (!paused) {
    hud.tick();
    spawner.tick();
    handler.tick();

    if (HUD.HEALTH <= 0) {
    HUD.HEALTH = 100;
    gameState = STATE.End;
    handler.clearEnemys();
    for (int i = 0; i < 20; i++) {
    handler.addObject(new MenuParticle(r.nextInt(WIDTH), r.nextInt(HEIGHT), ID.MenuParticle, handler));
    }
    }
    }

    change the pause at the top to if (!(paused)) {

  2. TheBrohman Avatar

    I keep getting this error when trying to do Hard difficulty, aswell as every now and then on normal diff
    "Exception in thread "Thread-2" java.lang.NullPointerException
    at java.util.LinkedList.node(Unknown Source)
    at java.util.LinkedList.get(Unknown Source)
    at me.TheBrohman.Game.utils.Handler.render(Handler.java:23)
    at me.TheBrohman.Game.core.Game.render(Game.java:158)
    at me.TheBrohman.Game.core.Game.run(Game.java:111)
    at java.lang.Thread.run(Unknown Source)"

  3. Legend Of Hero Avatar

    I have issue with my menu particle. They freezed when I moved my "handler.tick();" to "if(gameState == STATE.Game)" and "else if(gameState == STATE.Menu || gameState == STATE.End)" Help me please……..

    This is my coding:

    private void tick(){  if(gameState == STATE.Game) {
       if(!paused) {
        hud.tick();
              spawner.tick();
              handler.tick();
             
         
              if(HUD.HEALTH <= 0) {
           HUD.HEALTH = 100;
           gameState = STATE.End;
           handler.clearEnemys();
           for(int i = 0; i < 20; i++) {
         handler.addObject(new MenuParticle(r.nextInt(WIDTH),r.nextInt(HEIGHT), ID.MenuParticle, handler));
        }
           
              }
             
      }else if(gameState == STATE.Menu || gameState == STATE.End) {
            menu.tick();
            handler.tick();
           
            }
       }
     }

  4. Dr.Z Avatar

    2:26 How is this?

    if (key == KeyEvent.VK_P) Game.paused = !Game.paused;

    a lot better and easier 🙂

  5. MrBearcat82 Avatar

    having an issue my menu particles freeze after following this. I only did the pause button

  6. Aldo Gonzalez Avatar

    In hard mode, my Hard Enemy does not have wall collision and simply passes through them. Someone please help me fix this.

  7. BENIK TOON Avatar

    Exception in thread "Thread-2" java.lang.NullPointerException

  8. Max Hoffmeyer Avatar

    Hi guys! First of all thank you RealTutsGML for a great series of tutorials. I've never coded before and then started on this tutorial a week ago… now I'm SO hooked! haha

    I think I've fixed the glitch on the HardEnemies! Instead of "if(velY<0)" try "if(y<=0)". Same goes for x.

    Explanation: We are not interested in changing the velocity of the HardEnemy, when the velocity is below a specific speed. We are interested in changing the velocity if the rectangle hits the border. And since we have four borders and we want both velX & velY to be random each time it leaves a border, we gotta set specific algorithms for each border (including the x = 0 and the y = 0 ones).

    Hope this helps!

  9. CheezyPig Avatar

    I get a java null pointer exception

    at java.util.LinkedList.node(Unknown Source)
    at java.util.LinkedList.get(Unknown Source)
    at me.Rave.main.Handler.render(Handler.java:19)
    at me.Rave.main.Game.render(Game.java:139)
    at me.Rave.main.Game.run(Game.java:91)
    at java.lang.Thread.run(Unknown Source)

  10. Gurkensohn Avatar

    Thank you so much! With your help I made a snake game 🙂

  11. ShivGames Avatar

    +RealTutsGML how did you get eclipse theme pls reply

  12. daveshn Avatar

    Having problems with all menu buttons. When I click, the button that would be in that location on the next screen is immediately clicked.

    Ex: If I press play on the menu, it immediately clicks again and normal mode starts playing. The same thing happens with the back button on the Help menu.

    I've used Thread.sleep to slow the program down, but that didn't stop it from happening, but did confirm that the right menus do proceed the clicks, but the input clicks anyway.

  13. Mortifix Avatar

    Hi +RealTutsGML. I am not sure what I was doing wrong, but for some reason the PAUSED was still showing up when I hit P in the menu even though it didn't actually pause anything. For this I just added an IF statement to only draw PAUSED if gameState == STATE.Game. This seemed to work until I would start a new game and it would start paused. I went over the code like 4 or 5 times but I couldn't find what I was doing different. So I changed

    if(key == KeyEvent.VK_P)
    {
    if(game.gameState == STATE.Game);
    {
    if(Game.paused) Game.paused = false;
    else Game.paused = true;
    }
    }

    to

    if(key == KeyEvent.VK_P && game.gameState == STATE.Game)
    {
    if(Game.paused) Game.paused = false;
    else Game.paused = true;
    }

    This seems to have resolved the issue. Can you tell me why this was not working? This is what my tick method looks like in Game.

    private void tick()
    {
    if(gameState == STATE.Game)
    {
    if(!paused)
    {
    hud.tick();
    spawner.tick();
    handler.tick();
    if(HUD.HEALTH <= 0)
    {
    HUD.HEALTH = 100;
    gameState = STATE.End;
    handler.clearEnemys();
    for(int i = 0; i < 10; i++)
    {
    handler.addObject(new MenuParticle(r.nextInt(WIDTH – 50), r.nextInt(HEIGHT – 50), ID.MenuParticle, handler));
    }
    }
    }
    }
    else if(gameState == STATE.Menu || gameState == STATE.Help || gameState == STATE.End || gameState == STATE.Select)
    {
    menu.tick();
    handler.tick();
    }
    }

    This is render:

    if(paused){
    g.setColor(Color.white);
    g.drawString("PAUSED", 100, 100);
    }

  14. zdenda Avatar

    Yeah, "-(something)*-1" is so much cooler than "(something)". Magic!

  15. Wolf Films Avatar

    erm… can't you just test what difficulty it was then add more damage?

  16. Janko Prorokovic Avatar

    why could it be that after following this video my 'back button for help' and 'try again' button stoped working ??

  17. Areej Shama Avatar

    why iam getting that error java.lang.NullPointerException every time i run?????????????

  18. Tudor Lechintan Avatar

    if(key == KeyEvent.VK_P) Game.paused = (Game.paused)? false : true;

  19. Randy Wolf Avatar

    what program are you using

  20. Dominik Haider Avatar

    love your tutorials! keep up the good work!

  21. Pilbaran00b Avatar

    Hey man! Ive been watching your Java game tutorials and I love them.. But im having some issues with both the Trail and EnemyBossBullet classes.

    Ive copied my code exactly like yours but when I try to add the trail into the handler with this line:

    handler.addObject(new Trail((int)x, (int)y, enemyColour, xSize, ySize, 0.08f, ID.Trail, handler));

    I allways crash with an error:

    Exception in thread "Thread-2" java.util.ConcurrentModificationException
    at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:966)
    at java.util.LinkedList$ListItr.next(LinkedList.java:888)
    at com.firstgame.main.Handler.tick(Handler.java:12)
    at com.firstgame.main.Game.tick(Game.java:132)
    at com.firstgame.main.Game.run(Game.java:100)
    at java.lang.Thread.run(Thread.java:745)

    no matter what I do, I cant fix this.. please help!

  22. Connor McReynolds Avatar

    You should put up a class on Udemy. I'd pay for it

  23. adrian villareal Avatar

    what programming book do you use for java games?

  24. Computer Boy Avatar

    Pls give me download

  25. Khanh Moriaty Avatar

    You can simplify the "pause" part by writing "paused=!paused;"

  26. Games Master5 Avatar

    i get an error. I know what u said about the order of the code and nothing is working. My error is: java.lang.NullPointerException
    at Main.Game.tick(Game.java:98)
    at Main.Game.run(Game.java:76)
    at java.lang.Thread.run(Unknown Source)

    on line 98 is tick(); in the game loop and on line 76 its spawner.tick(); inside tick method. ive use try and catch round spawer.tick and it still doesnt work! anyone know y?

  27. Games Master5 Avatar

    If i wanted to give the player an image i have made, how do i do that?

  28. Jesse Smith Avatar

    You talked about adding upgrades and save high score to this series. Are you still going to do that? That would be great.

  29. Ceri Westcott Avatar

    instead of watching Netflix or that I ended up watching these. 2nd year comp sci undergrade. cannot wait til exams are over to start my own game via these tuts.

    is that also a razer black widow i hear?

  30. Jack Gogvail Avatar

    Please make a tutorial for textures

  31. Alberto Barbosa Avatar

    Please make a tutorial for adding textures

  32. chowchowsonic Avatar

    Are you going to do a tutorial for adding textures?

  33. DoctorWhoFan967 Avatar

    Could you continue this series?

  34. finlay gaming Avatar

    can someone give me a paste bin link for it

  35. Ben Kelcher Avatar

    how do i export this as a jar file

  36. Jordan Camilletti Avatar

    For some reason if I try to run my code it gives me 'Error: Could not find or load main class src.main.GameMain' could you help me please?

  37. TennisSlayer Avatar

    Can you keep making these videos? These are really helpful bro.

Leave a Reply

Your email address will not be published. Required fields are marked *