Object Interaction - How to Make a 2D Game in Java #8

Поделиться
HTML-код
  • Опубликовано: 20 сен 2024

Комментарии • 225

  • @aarushigiri7103
    @aarushigiri7103 2 года назад +13

    excuse me i need help i'm getting an error message and im not able to move my character anymore

    • @aarushigiri7103
      @aarushigiri7103 2 года назад +4

      as soon as i try to move my character i get this error messaage:
      Exception in thread "Thread-0" java.lang.NullPointerException: Cannot read field "solidArea" because "this.gp.obj[i]" is null
      at pptrialgame2/main.CollisionChecker.checkObject(CollisionChecker.java:98)
      at pptrialgame2/entity.Player.update(Player.java:83)
      at pptrialgame2/main.GamePanel.update(GamePanel.java:96)
      at pptrialgame2/main.GamePanel.run(GamePanel.java:83)
      at java.base/java.lang.Thread.run(Thread.java:833)

    • @RyiSnow
      @RyiSnow  2 года назад

      The message indicates the program is trying to read an empty object. Did you instantiate objects in the AssetSetter? Also, did you add the condition "if(gp.obj[i] != null)" when you check object collision?

    • @aarushigiri7103
      @aarushigiri7103 2 года назад

      @@RyiSnow i think i did... can i send my code to you through mail? im sorry im new to coding so im making a lot of mistakes TT^TT

    • @RyiSnow
      @RyiSnow  2 года назад

      Did you check if object is null or not when you draw objects in the paintComponent method?

    • @aarushigiri7103
      @aarushigiri7103 2 года назад

      @@RyiSnow yuppp it is null

  • @streetfashiontv9149
    @streetfashiontv9149 2 года назад +30

    Hi Ryi I really appreciate the time and effort you put into these tutorials as nobody is doing this for tile games in any language let alone java with the level of precision, stylistic elements and conceptual information that you provide. There is only one other programmer a C++ guy called Javid but he is a PhD and has built a game engine etc. Anyways I'm happy to see programmers who are passionate about Java and promoting game development in the language which I think it doesn't get enough credit especially when you consider that some of the greatest games were built in Java. I look forward to playing your game when it is released on Steam. Keep up the good work.

    • @RyiSnow
      @RyiSnow  2 года назад +11

      Yeah it's a bit sad that not many people make games from scratch any more. In any case, I'm enjoying this and good to know that you are as well.

  • @natzos6372
    @natzos6372 Год назад +4

    I always have to laugh at your reaction when you misspell things! I always see it beforehand and anticipate for you to realize :D

  • @jimmyjakes1823
    @jimmyjakes1823 3 месяца назад +2

    To summarize the data flow for all the new classes, methods, etc, in the last couple videos:
    -Create a SuperObject class which sets up the default rectangle hitbox the items use and implements the draw() method that determines where the item is in on the world map in relation to the player and whether it's in view of the camera before sending it to be drawn.
    -Create individual item classes (Key, Door, etc.) which load images and can set collision properties that are unique to each item
    -Create an AssetSetter class that uses the setObject() method to determine what type of item will appear on the world map and where it will appear. These objects and their position are held in an array of SuperObject classes that is instantiated GamePanel.
    -Create a setupGame() method in GamePanel class which calls the setObject() method from AssetSetter class. We call the setupGame() method from Main so that it places the items on the world map before calling the startGameThread() method in GamePanel.
    -GamePanel class calls the draw() method from SuperClass so the items are drawn above the world map and below the player sprite in its paintComponent() method. It calls the draw() method in SuperClass using a for loop so that all the different items in the obj array are drawn on the world map in their unique place.
    -The checkObject() method in the CollisionChecker class is called from within the update() method in the Player class. It determines whether the player hitbox collides with the hitbox of an item on the map using the intersects() method from the Rectangle class. If returns an index value for the item collided with which is used for further processing.
    -The pickupObject() method is called later in the update() method of the Player class. It is passed the index value returned from the checkObject() method. In the code in this video, we use the index value to determine when the player picks up keys and if they have a key to open doors.

  • @yashuchiha99
    @yashuchiha99 5 месяцев назад +3

    reached episode 8, i am really enjoying . Lets goo

  • @botondkohanec2906
    @botondkohanec2906 Год назад +2

    You are not horrible, you are awesome!

  • @WarrenBainesMusic
    @WarrenBainesMusic 2 года назад +8

    Firstly, absolutely love this tutorial, easily one of the best Java tutorials out there, really appreciate that you take the time to explain many concepts. I'm at the part where we are testing for object collision, and for some reason I'm not getting the console text output over objects like the key, but rather on a blank vertical line of grass near the second door! Any ideas where I'm going wrong?

    • @RyiSnow
      @RyiSnow  2 года назад +1

      Glad you liked the video. That sounds like collision is triggered at a wrong spot. Probably something is wrong in checkObject method. Can I see your CollisionChecker class? Then maybe I can find out why. You can paste your code here.

    • @WarrenBainesMusic
      @WarrenBainesMusic 2 года назад

      @@RyiSnow I did post the code however I spotted the error (after days of searching for it!), in the checkObject method, I had put entity.solidArea.y = entity.worldX + entity.solidArea.y; , and that reference to worldX should've been worldY. Feels so good when you fix errors like that.

    • @RyiSnow
      @RyiSnow  2 года назад

      @@WarrenBainesMusic You mean you posted the code but got deleted? It happens from time to time. Anyways, good to know it was solved!

  • @forte2265
    @forte2265 2 года назад +2

    great job again! really appreciate these videos to go back to while i work

  • @nadinewalter-lang9333
    @nadinewalter-lang9333 4 месяца назад

    you're legend in doing tutorials!

  • @wither_scout1468
    @wither_scout1468 2 года назад +1

    Thank you as always for these videos. I really appreciate it :)

  • @solarcubing7504
    @solarcubing7504 2 года назад +7

    I have done something different but pretty cool with the doors rather than setting it to null I added in another bool value + an image the boolValue is needs key and the image is open door basically if the needsKey value is set to true when the door is collided with then it goes to see if the player has a key and then if the player does it sets the collision to false and the image to the open door

    • @TheMemeSheep11
      @TheMemeSheep11 Год назад

      Could you please show me your code on how you did this. I am trying to implement it myself but I am having trouble.

  • @LouShunt
    @LouShunt 2 года назад +10

    Hey great video ! I use your video to great my own "game engine" so I can reuse the code to make another game quickly. I will love to see a tutorial on particule and window management (like full screen, resize window, etc).

    • @RyiSnow
      @RyiSnow  2 года назад +5

      Cool! Yeah, separating a part of your code and stock them as your own tools/libraries is a great idea (especially when you repeat the same thing in every project) and it often makes your work a lot easier. I found creating tools is as fun as making games (I realized that when I made my 2D tile editor). I hope your engine will turn out good!

    • @unbroken-hunter
      @unbroken-hunter 2 года назад +1

      @@Gabriel-mh7ek hey! So does this tool allow you to make a map using your png’s (like a normal tile editor), then get it in text format? If so, how did you do it because I’m looking for something like that :D

  • @tranminhquang7368
    @tranminhquang7368 2 года назад +2

    Great
    I hope to see a video of your enemy soon

  • @adnan2734
    @adnan2734 Год назад

    thanks for all videos, learning is ertertaining and informative :) You are legend.

  • @lim0nplays45
    @lim0nplays45 3 месяца назад

    This is awesome! I'm can only pickup the bottom key atm but I'll make it work

  • @termite1737
    @termite1737 2 года назад +2

    just cmt to beat RUclips's algorithm :))). Keep going!!!

  • @dominiktworek6455
    @dominiktworek6455 Год назад +1

    Oooh, amazing tutorial, ofc we could implement some OOP patterns like state, builder etc. but i will do it in my own projects. Maybe in future parts you do, but i didnt get there yet.
    I spend last half year on lerning java and thats amazing how this all puzzles fits together.
    Do you guys also fight with debugging? In here insted of index = i; in checkObject method i wrote return i;
    It took me 2h to figureout how to fix it. Whats amazing is that I take 10min break and then I fix it instantly.

  • @donavenbruce4407
    @donavenbruce4407 Год назад +3

    Hello, i have a question, when my player touches to far to a structure its glitched and gets stuck and cant leave. any ideas let me know.

  • @AlexanderHL1919
    @AlexanderHL1919 5 месяцев назад

    Awesome series!

  • @NikitaBomba112
    @NikitaBomba112 Год назад +1

    Thanks you so much for this video!

  • @cedricsahaghian1605
    @cedricsahaghian1605 Год назад

    I'm really enjoying your tutorials!

  • @zakarianaji6584
    @zakarianaji6584 4 месяца назад

    good! you do not need to add or subtract speed in order to determine the player coordinates in switch, because they are already defined in player class.

  • @nemdoom
    @nemdoom Месяц назад

    Lovely course ^_^

  • @worldofelectronicsandprogr1128
    @worldofelectronicsandprogr1128 2 месяца назад

    Hi! I have a question: do you have a C or C++ background? :)

  • @holmdev
    @holmdev 2 года назад +3

    I make it work with points to , in my game you can get points from apple and Carrots. thanks for a good video :)

    • @RyiSnow
      @RyiSnow  2 года назад +3

      That's so cool! I just love when people use my code and make something their original :D Keep up the good work and thank you for letting me know!

    • @holmdev
      @holmdev 2 года назад +1

      @@RyiSnow know i´m making some panel to have inventory in the top of the game, But also to see how many points you got, now you can only see it in the terminal.

    • @RyiSnow
      @RyiSnow  2 года назад +3

      You can draw text on the screen with Graphics2D's drawString method so maybe you want to try that :) On-screen text will be featured in Part 10!

    • @holmdev
      @holmdev 2 года назад +1

      @@RyiSnow im gone test that
      thanks

  • @lucastucker2783
    @lucastucker2783 9 месяцев назад

    I think at 15:18 you can check if the entity is a player without passing the boolean parameter to the 'checkObject' function. You could have simply done:
    if(entity instanceof Player)
    {
    index = i;
    }

    • @NguyenNam-yj1sg
      @NguyenNam-yj1sg 9 месяцев назад

      thanks, I had a bug and I used your code and it worked 🥰

  • @billthompson4393
    @billthompson4393 2 года назад +1

    ik I'm late, but my character is getting stuck in the door when you don't have a key. Any help?

    • @kingkangiv1615
      @kingkangiv1615 Год назад

      Been a long while, but by any chance did you find a fix for this?
      Fixed it! The speed modifiers were being called after the if statement in the switch.

  • @deborahlawani5539
    @deborahlawani5539 21 день назад

    Hey i have an issue, when i try to run my code, my door collides if i don't pick up any key, but then even if i pick up a key i still can't pass through the door.
    And when i pick up all three all my doors disappear before i get to it

  • @kirtiprajapati9935
    @kirtiprajapati9935 Год назад +1

    My game player isn't picking the objects at the end of program

  • @harllemalves1590
    @harllemalves1590 2 года назад +1

    Hi, thanks for the videos, i implemented a Interface that have a method called executeAction() to implement in objects and avoid switch

  • @SlothfulSage285
    @SlothfulSage285 2 года назад

    Enjoyed it!

  • @LawrenceDiaz-fj5vz
    @LawrenceDiaz-fj5vz 4 месяца назад

    I think i have a problem, its that when i move all the objecs are teleported to the very top of the screen

  • @tardii_dah_gr8211
    @tardii_dah_gr8211 2 года назад +1

    Hi Ryi I've followed up to this far however I don't know why my player is unable to interact with keys as well as the doors not performing any collision what do you think I.ve done something wrong or did i forget something or maybe made a mistake in a class the only thing I see that I'm is a scope above of the return command.

    • @RyiSnow
      @RyiSnow  2 года назад

      May I see your CollisionChecker class? You can paste it here.

  • @luciuscouto4592
    @luciuscouto4592 2 года назад +1

    Excuse me, how could I implement the tile collision system on objects?

  • @ackoly_dude4495
    @ackoly_dude4495 Месяц назад

    @RyiSnow
    im sorry for pining you but..
    IM COMPLETLY STUCK HERE!
    whenever i load the game i walk through the doors... i can pick up keys and open doors but when i dont have keys i just walk through and the doors dont disappear
    Update 2:
    i restarted my work from scratch and i did it alL by hand without the help of chatgpt
    and my current problem is that keys are not being currently displayed at first it was working but there was one key only being displayed but now there are none once i tried moving the code somewhere else.. What do you think the problem is? the problem is in player class picKUpObjects and i dont know what to do so i could fix this code

  • @soneli4669
    @soneli4669 Год назад

    You're the best!!

  • @thangduong1107
    @thangduong1107 2 года назад +1

    wow thank you

  • @notmakhan
    @notmakhan Год назад

    there's something wrong with my map. when i move my player downward there are only some tiles and then black background starts showing moreover my pickup object method isnt working. i have checked it several times but i still cant figure out

  • @jarrodmcevoy
    @jarrodmcevoy 2 года назад

    Amazing video!!!!

  • @SomeCoderYT
    @SomeCoderYT 6 месяцев назад +2

    Whenever i try to move, i get this error message:Exception in thread "Thread-0" java.lang.ArrayIndexOutOfBoundsException: Index 68 out of bounds for length 50
    at CollisionChecker.CheckTile(CollisionChecker.java:39)
    at Player.update(Player.java:73)
    at GamePanel.update(GamePanel.java:117)
    at GamePanel.run(GamePanel.java:99)
    at java.base/java.lang.Thread.run(Thread.java:1583)

  • @josueronquillocassagne6911
    @josueronquillocassagne6911 Год назад +1

    Hi. Thanks for the tutoriales, I have a problem, My door isn't Solid, I can walk over it, I don't know why the code is the same, any idea for why it's happening that?

    • @kaleforlife6390
      @kaleforlife6390 4 месяца назад

      bro has w rizz perchance? check the sigma base and see if any gyatts are getting fanum taxed

  • @MetinCloup
    @MetinCloup 2 года назад +2

    good video

  • @MyshaeA24
    @MyshaeA24 2 года назад +1

    My object collision doesn't print the message “up, down… collision!”. I am trying to get to 14:15 in the video, can you help me?
    I usually never make comments and I've been able to solve all the problems by myself until now. I have tried so many things like re-watching this video and the previous one, and I re-checked my work around 5-6 different times.
    Also: Ryu if you are actually reading this, thank you! This series is SO awesome and helpful! I'm sorry I had to bring up my problem, but that aside I will try to keep following along :)

    • @RyiSnow
      @RyiSnow  2 года назад +1

      No worries. Can I see your SuperObject, Player and CollisionChecker class? You can paste them here.

    • @MyshaeA24
      @MyshaeA24 2 года назад

      Player:
      _____________________________________________________________________________________________
      package entity;
      import java.awt.image.BufferedImage;
      import java.awt.Graphics2D;
      import java.awt.Rectangle;
      import java.io.IOException;
      import javax.imageio.ImageIO;
      import java.awt.Color;
      import main.GamePanel;
      import main.KeyHandler;
      public class Player extends Entity{
      GamePanel gp;
      KeyHandler keyH;

      public final int screenX;
      public final int screenY;
      int hasKey = 0;

      public Player(GamePanel gp, KeyHandler keyH) {
      this.gp = gp;
      this.keyH = keyH;

      screenX = gp.screenWidth/2 - (gp.tileSize/2);
      screenY = gp.screenHeight/2 - (gp.tileSize/2);

      solidArea = new Rectangle();
      solidArea.x = 8;
      solidArea.y = 16;
      solidAreaDefaultX = solidArea.x;
      solidAreaDefaultY = solidArea.y;
      solidArea.width = 32;
      solidArea.height = 30;

      setDefaultValues();
      getPlayerImage();
      }
      public void setDefaultValues() {

      worldX = gp.tileSize * 23;
      worldY = gp.tileSize * 21;
      speed = 4;
      // speed = gp.worldWidth/600;

      direction = "down";
      }
      public void getPlayerImage() {

      try {

      up1 = ImageIO.read(getClass().getResourceAsStream("/player/boy_up_1.png"));
      up2 = ImageIO.read(getClass().getResourceAsStream("/player/boy_up_2.png"));
      down1 = ImageIO.read(getClass().getResourceAsStream("/player/boy_down_1.png"));
      down2 = ImageIO.read(getClass().getResourceAsStream("/player/boy_down_2.png"));
      left1 = ImageIO.read(getClass().getResourceAsStream("/player/boy_left_1.png"));
      left2 = ImageIO.read(getClass().getResourceAsStream("/player/boy_left_2.png"));
      right1 = ImageIO.read(getClass().getResourceAsStream("/player/boy_right_1.png"));
      right2 = ImageIO.read(getClass().getResourceAsStream("/player/boy_right_2.png"));

      }catch(IOException e) {
      e.printStackTrace();
      }
      }
      public void update() {

      if(keyH.upPressed == true || keyH.downPressed == true ||
      keyH.leftPressed == true || keyH.rightPressed == true) {

      if (keyH.upPressed == true) {
      direction = "up";
      }
      else if(keyH.downPressed == true) {
      direction = "down";
      }
      else if (keyH.leftPressed == true) {
      direction = "left";
      }
      else if (keyH.rightPressed == true) {
      direction = "right";
      }

      // CHECK TILE COLLISION
      collisionOn = false;
      gp.cChecker.checkTile(this);

      // CHECK OBJECT COLLISION
      int objIndex = gp.cChecker.checkObject(this, true);
      pickUpObject(objIndex);


      // IF COLLISION IS FALSE, PLAYER CAN MOVE
      if(collisionOn == false) {
      switch(direction) {
      case "up":worldY -= speed;break;
      case "down":worldY += speed;break;
      case "left":worldX -= speed;break;
      case "right":worldX += speed;break;
      }
      }

      spriteCounter++;
      if(spriteCounter > 12) {
      if(spriteNum == 1) {
      spriteNum = 2;
      }
      else if(spriteNum == 2) {
      spriteNum = 1;
      }
      spriteCounter = 0;
      }
      }
      }
      public void pickUpObject(int i) {

      if(i != 999) {

      String objectName = gp.obj[i].name;

      switch(objectName) {
      case "Key":
      gp.playSE(1);
      hasKey++;
      gp.obj[i] = null;
      System.out.println("Has:" + hasKey);
      break;
      case "Door":
      if(hasKey > 0) {
      gp.playSE(3);
      gp.obj[i] = null;
      hasKey--;
      }
      System.out.println("Key: " + hasKey);
      break;
      case "Boots":
      gp.playSE(2);
      speed += 1;
      gp.obj[i] = null;
      break;
      }
      }
      }

      public void draw(Graphics2D g2) {

      // g2.setColor(Color.white);
      // g2.fillRect(x, y, gp.tileSize, gp.tileSize);

      BufferedImage image = null;

      switch(direction) {
      case "up":
      if (spriteNum == 1) {
      image = up1;
      }
      if (spriteNum == 2) {
      image = up2;
      }
      break;
      case "down":
      if (spriteNum == 1) {
      image = down1;
      }
      if (spriteNum == 2) {
      image = down2;
      }
      break;
      case "left":
      if (spriteNum == 1) {
      image = left1;
      }
      if (spriteNum == 2) {
      image = left2;
      }
      break;
      case "right":
      if (spriteNum == 1) {
      image = right1;
      }
      if (spriteNum == 2) {
      image = right2;
      }
      break;
      }
      g2.drawImage(image, screenX, screenY, gp.tileSize, gp.tileSize, null);

      }
      }
      _____________________________________________________________________________________________

    • @MyshaeA24
      @MyshaeA24 2 года назад

      SuperObject:
      __________________________________________________________________________________________________________________
      package object;
      import java.awt.Graphics2D;
      import java.awt.Rectangle;
      import java.awt.image.BufferedImage;
      import main.GamePanel;
      public class SuperObject {
      public BufferedImage image;
      public String name;
      public boolean collision = false;
      public int worldX, worldY;
      public Rectangle solidArea = new Rectangle(0, 0, 48, 48);
      public int solidAreaDefaultX = 0;
      public int solidAreaDefaultY = 0;

      public void draw(Graphics2D g2, GamePanel gp) {

      int screenX = worldX - gp.player.worldX + gp.player.screenX;
      int screenY = worldY - gp.player.worldY + gp.player.screenY;

      if (worldX + gp.tileSize > gp.player.worldX - gp.player.screenX &&
      worldX - gp.tileSize < gp.player.worldX + gp.player.screenX &&
      worldY + gp.tileSize> gp.player.worldY - gp.player.screenY &&
      worldY - gp.tileSize< gp.player.worldY + gp.player.screenY) {

      g2.drawImage(image, screenX, screenY, gp.tileSize, gp.tileSize, null);
      }
      }
      }
      __________________________________________________________________________________________________________________

    • @RyiSnow
      @RyiSnow  2 года назад

      Can you provide CollisionChecker too?

    • @MyshaeA24
      @MyshaeA24 2 года назад

      ​@@RyiSnow The code wasn't working in the comments for some reason, so here's a link to the google doc with the info (hopefully this works):
      docs.google.com/document/d/10LaUFJ9s7t6COYnin0psqkPZNIExLjU2jELysEOfAT4/edit?usp=sharing

  • @droidlycodes
    @droidlycodes 2 года назад

    HEELLLLPPP :) Hey so this is amazing, I even had to make my own Rectangle class for this method to work... Curious though, when my player interacts with the door for example if the player faces up or down when moving the collision is detected and the player is able to walk away perfectly fine. BUTTT when the door is placed on a horizontal plain so x axis the player gets stuck on the door and walks overtop. I'll keep looking at the code but I'm not seeing where or why this occurs.

    • @dash8497
      @dash8497 2 года назад +1

      why would you make your own rectangle class?

    • @droidlycodes
      @droidlycodes 2 года назад

      @@dash8497 I am using Android Studio! the default class is different for AS!

  • @lexhex69ao35
    @lexhex69ao35 4 месяца назад

    What is the difference between entity and object x and y? Isn't it the same thing ?

  • @arian.a4181
    @arian.a4181 2 года назад +1

    im here:)

  • @dash8497
    @dash8497 2 года назад

    13:47 You obviously know what youre talking about, but you often say "parse this Player class" which is technically wrong. We only parse the pointer of the current instance of the class. Could be misleading for people who dont know the difference.

  • @progress2171
    @progress2171 Год назад +1

    Isn't it better to check if entity intersects with object outside of the switch ?

    • @freshie94
      @freshie94 10 месяцев назад

      I noticed that too, I think it's written like this because the checkTile method contains direction specific information in the if checks, but checkObject doesn't have that, so it's easier to just check after the switch ends. It's a small difference, but it does add to readability.

    • @kaleforlife6390
      @kaleforlife6390 4 месяца назад

      bro has w rizz perchance? check the sigma base and see if any gyatts are getting fanum taxedbro has w rizz perchance? check the sigma base and see if any gyatts are getting fanum taxedbro has w rizz perchance? check the sigma base and see if any gyatts are getting fanum taxedbro has w rizz perchance? check the sigma base and see if any gyatts are getting fanum taxedbro has w rizz perchance? check the sigma base and see if any gyatts are getting fanum taxedbro has w rizz perchance? check the sigma base and see if any gyatts are getting fanum taxedbro has w rizz perchance? check the sigma base and see if any gyatts are getting fanum taxedbro has w rizz perchance? check the sigma base and see if any gyatts are getting fanum taxed

  • @clovercandii
    @clovercandii 2 года назад +1

    hello, thank you for this tutorial! when you are checking the first result i do not get the message "up/down/etc collision!" when touching key or door, and my door isn't solid either. Do you know what happened? please let me know if i should paste some code here

    • @clovercandii
      @clovercandii 2 года назад +2

      the only things i changed were what intellij suggested to me ("enhanced switch statements") like this:
      switch(entity.direction) {
      case "up":
      entity.solidArea.y -= entity.speed;
      if (entity.solidArea.intersects(gp.obj[i].solidArea)) {
      System.out.println("up collision!");
      }
      break;
      case "down":
      entity.solidArea.y += entity.speed;
      if (entity.solidArea.intersects(gp.obj[i].solidArea)) {
      System.out.println("down collision!");
      }
      break;
      case "left":
      entity.solidArea.x -= entity.speed;
      if (entity.solidArea.intersects(gp.obj[i].solidArea)) {
      System.out.println("left collision!");
      }
      break;
      case "right":
      entity.solidArea.x += entity.speed;
      if (entity.solidArea.intersects(gp.obj[i].solidArea)) {
      System.out.println("right collision!");
      }
      break;
      }
      to
      switch (entity.direction) {
      case "up" -> {
      entity.solidArea.y -= entity.speed;
      if (entity.solidArea.intersects(gp.obj[i].solidArea)) {
      System.out.println("up collision!");
      }
      }
      case "down" -> {
      entity.solidArea.y += entity.speed;
      if (entity.solidArea.intersects(gp.obj[i].solidArea)) {
      System.out.println("down collision!");
      }
      }
      case "left" -> {
      entity.solidArea.x -= entity.speed;
      if (entity.solidArea.intersects(gp.obj[i].solidArea)) {
      System.out.println("left collision!");
      }
      }
      case "right" -> {
      entity.solidArea.x += entity.speed;
      if (entity.solidArea.intersects(gp.obj[i].solidArea)) {
      System.out.println("right collision!");
      }
      }
      }
      and i didnt think things like that could impact the games functioning (switching it back didnt change anything either, still no "up collision!").

    • @clovercandii
      @clovercandii 2 года назад

      now that i went through the video again, i realized i was missing an int counter2 = 0, maybe that is what went wrong? i went through your last video as well and cannot find where you put the int counter2, could you please tell me what video it is in? sorry for the trouble, thank you so much again for this tutorial, it is very clear and simple to follow through.

    • @RyiSnow
      @RyiSnow  2 года назад

      Don't worry about the counter2. That is for setting the player character in standstill position after he stopped moving. I doubt it's related with your issue (check part 10+ video if you are curious).
      Could you paste your CollisionChecker class here? Then I will take a look.

    • @clovercandii
      @clovercandii 2 года назад

      i figured it out; i think i accidentally typed gp.obj[i].solidArea.x twice by accident. thank you for letting me know about the counter2!

  • @konstandinosdimitriou2301
    @konstandinosdimitriou2301 2 года назад +1

    can you make a home screen for the game with the option to resize the game to different resolutions ??

    • @droidlycodes
      @droidlycodes 2 года назад

      You can make a separate class for this navigate to that class first then navigate to the game (Main class) from the home screen on PLAY button clicked ;). Hope this opens your mind I'm developing this game for Android currently, a little harder but I know sort of what I'm doing :)

  • @truarrogancex
    @truarrogancex Год назад

    1:50 it's alright man I think it's funny

  • @cameronsmith1807
    @cameronsmith1807 2 года назад

    I have a string.hash code(); error because of objectName is null. How do I fix this

  • @elysiayeo5423
    @elysiayeo5423 2 года назад

    Hi, thank you so much for this tutorial! I would like to know how can I allow more spawning of the objects after all the objects have been collected?

    • @droidlycodes
      @droidlycodes 2 года назад

      I just played with this today, you'd want a redraw method after a set time for the object or objects you want to redraw and place them in maybe .random locations on the screen for the player to collect at any time :).. I haven't tested the random placement part yet but you'd want a void to make sure the item doesn't get placed in the boarder for example!!

  • @muhamadzulfikarfikri9482
    @muhamadzulfikarfikri9482 2 года назад +1

    i implement the diagonal movement, but yeah im stuck because when the player was interact with object that have collision value true the player just stuck, i think its because the for loop while getting the object. i hope i found the solution asap

    • @zapallito1286
      @zapallito1286 10 месяцев назад

      did u get the solution? im having the same problem
      here

  • @ferry6700
    @ferry6700 Год назад

    Hi Ryi, I need help
    I able to detect and make the object going null , I check using
    System.out.println(gp.obj[i]);
    gp.obj[i] = null;
    System.out.println(gp.obj[i]);
    but the image keep there not gone, what do you think Should I check?

    • @ferry6700
      @ferry6700 Год назад

      after I check at the game actually the key is disappeared, but only one and specific one key

    • @ferry6700
      @ferry6700 Год назад

      ahh my bad :D
      I typo
      if(player == true) {
      index = 1;
      }
      it should be
      if(player == true) {
      index = i;
      }
      that's why only object number one that always disappear XD

  • @2MSTennis
    @2MSTennis 2 года назад

    Thank you Ry again so much! When you get a chance I’d like to ask because my character goes to the door and gets stuck!

  • @JavierYturriaga
    @JavierYturriaga Год назад

    can anyone help? I am at the end, I can get the player to pick up the key, key increases by one, but then I go down to the door and it does nothing it just stays there.. I have all the same code so I don't know why it's doing this...

  • @anitaanonym7307
    @anitaanonym7307 Год назад

    Hello, i need help. When i touch a object, it doesnt write " up collision"(or "down collision", "right collision" or left "collision").

  • @wc7276
    @wc7276 2 года назад +1

    HI Ryi, is it possible to post a tutorial on players shooting projectiles like bullets? I'm kind of lost on how to do it

    • @RyiSnow
      @RyiSnow  2 года назад +3

      You can create bullets as Entity. Since I've received a couple of similar requests, I might squeeze a video at some point.

    • @wc7276
      @wc7276 2 года назад

      @@RyiSnow Ohh ok, thanks !

    • @RyiSnow
      @RyiSnow  2 года назад +3

      If you're interested, this is a fireball demo that I recently posted on my twitter. The fireball was created as Entity.
      twitter.com/RyiSnow2017/status/1484146787980308480

    • @wc7276
      @wc7276 2 года назад +1

      @@RyiSnow Wow it looks so cool ! Would love your tutorial on this !

    • @wc7276
      @wc7276 2 года назад

      @@RyiSnow Hi RyiSnow, Can I ask, the way you create bullets is, first of all, create a child class called bullet which extends the entity class ? Then I also need to call the bullet class on the player and gamepanel class ?
      I just need a direction and some ideas so I can work on it.
      I know that the bullet class needs X and Y axis, so I will be using worldX and WorldY.
      for the direction, I will be using the player direction

  • @furbos3278
    @furbos3278 Год назад +1

    Can you please help me, I don't understand why it's not working. I got this message : Exception in thread "Thread-0" java.lang.NullPointerException: Cannot read field "name" because "this.gp.obj[i]" is null
    at entity.Player.pickUpObject(Player.java:144)
    at entity.Player.update(Player.java:106)
    at main.gamePanel.update(gamePanel.java:108)
    at main.gamePanel.run(gamePanel.java:89)
    at java.base/java.lang.Thread.run(Thread.java:1623)

    • @RyiSnow
      @RyiSnow  Год назад

      Check the line 144 in the Player class! That's where something went wrong.

  • @MrLoser-ks2xn
    @MrLoser-ks2xn 2 года назад

    Thanks!

  • @normalercarl
    @normalercarl Год назад

    i am invested.

  • @kotziajohnnemesis9415
    @kotziajohnnemesis9415 2 года назад

    Hello and your videos are awesome anyways i have a problem with the two up map keys the game stops and the error says about the key that goes to null because they are already null for some reason (The Down key works correctly)

    • @kaleforlife6390
      @kaleforlife6390 4 месяца назад

      bro has w rizz perchance? check the sigma base and see if any gyatts are getting fanum taxed

  • @quentin4516
    @quentin4516 2 года назад +1

    Anyone have a fix for when not having any key's, you can still pass through doors?

    • @quentin4516
      @quentin4516 2 года назад

      nvm lol i got it

    • @sachmandhaliwal4618
      @sachmandhaliwal4618 2 года назад +1

      @@quentin4516 if you dont mind me asking what did you fix? I am having the same problem

    • @quentin4516
      @quentin4516 2 года назад

      @@sachmandhaliwal4618 I forgot, but I would check your player collision

  • @RisingCookie13
    @RisingCookie13 2 года назад

    Update! in one of the next 1-2 videos, it will deleted^^ :P
    until now, the GamePanel's properties
    public final int worldWidth = tileSize * maxWorldCol; and
    public final int worldHeight = tileSize * maxWorldRow; were not used,..
    Is there something I have overseen, or will this come yet ^^' :P ..but I will see anyways :D
    this is so much fun to learn, and to create individually

  • @harounjaafar6918
    @harounjaafar6918 Год назад

    but whit zoominout the man move how can i fix it?

  • @diegofourstage
    @diegofourstage 2 года назад

    Hello, i do not getting collision, the keys disappear, but collision no happen

    • @foolian712
      @foolian712 2 месяца назад

      you are getting the collision if the keys are disappearing, because they disappear if your player collides with them

  • @MarkJohnFamisan
    @MarkJohnFamisan Год назад

    help my character can still pass through objects

  • @vosquz
    @vosquz Год назад

    for some reason, even though I defined the i variable as an int it still tells me I need to make it an integer, and i know this video is years old, but thanks for the videos in general!

    • @freshie94
      @freshie94 10 месяцев назад

      Are you using all lowercase? like "for(int i = 0....)" ?

  • @gabrielwalker4062
    @gabrielwalker4062 2 года назад

    Hey im having issues with my code not placing more than 1 object, for instance, I want to draw the door and the key but It only draws number 0 in the array (in this case only the door is being drawn)

    • @RyiSnow
      @RyiSnow  2 года назад

      Did you assign a different index to your key?

    • @gabrielwalker4062
      @gabrielwalker4062 2 года назад

      @@RyiSnow yes, my door is on [0] of the array, and the key is assigned to [1], but it only displays [0]. Everything else works perfectly though.

    • @RyiSnow
      @RyiSnow  2 года назад

      Try adding this line after g2.drawImage in the SuperObject: System.out.println(name + " is displayed");
      And check if "Key is displayed" is printed out on the console when the key is visible on the screen. If the text is printed out, the object is rendered but somehow the image is invisible so maybe something is wrong with your image. If the text is not printed out, the program is not drawing the key object so maybe something is wrong with your object array or the for loop to draw them.

    • @gabrielwalker4062
      @gabrielwalker4062 2 года назад

      Yup its says that both are being displayed but only the door is being shown. Will check on it

    • @gabrielwalker4062
      @gabrielwalker4062 2 года назад

      @@RyiSnow I made a bunch of other assets in the array and no matter how much I add, only the number 0 in the array is ever shown no matter the image/object. It says in the terminal that all of them are displaying but its not showing on the screen.

  • @fonzafeytt6644
    @fonzafeytt6644 2 года назад

    RyiSnow, I keep getting this error when I try to run my movement, I get a null pointer error
    Exception in thread "Thread-0" java.lang.NullPointerException: Cannot read field "solidArea" because "this.gp.obj[i]" is null
    at main.CollisionChecker.checkObject(CollisionChecker.java:74)
    at entity.Player.update(Player.java:88)
    at main.GamePanel.update(GamePanel.java:98)
    at main.GamePanel.run(GamePanel.java:82)
    at java.base/java.lang.Thread.run(Thread.java:833)

    • @fonzafeytt6644
      @fonzafeytt6644 2 года назад

      it's an error at
      gp.obj[i].solidArea.x = gp.obj[i].solidAreaDefaultX;
      gp.obj[i].solidArea.y = gp.obj[i].solidAreaDefaultY;

    • @fonzafeytt6644
      @fonzafeytt6644 2 года назад

      i fixed it

    • @CanePazzoHD
      @CanePazzoHD 2 года назад

      @@fonzafeytt6644 how?

    • @helioktt
      @helioktt 2 года назад +2

      entity.solidArea.x = entity.solidAreaDefaultX;
      entity.solidArea.y = entity.solidAreaDefaultY;
      gp.obj[i].solidArea.x = gp.obj[i].solidAreaDefaultX;
      gp.obj[i].solidArea.y = gp.obj[i].solidAreaDefaultY;
      These need to be inside of
      if (gp.obj[i] != null)
      Probably you've placed outside of it.
      move the 4 lines to fix it.

    • @RandomHandle-r2q
      @RandomHandle-r2q 2 года назад

      @@helioktt You have no idea how much this helps. Thank you thank you!

  • @maryamhussein8116
    @maryamhussein8116 2 года назад

    intersects don't work!! Help :(

  • @np.figwig8771
    @np.figwig8771 2 года назад

    Why am I getting this when I tried to move my character?
    Exception in thread "Thread-0" java.lang.ArrayIndexOutOfBoundsException: Index 168 out of bounds for length 50
    at my2dgame.CollisionChecker.checkTile(CollisionChecker.java:54)
    at entity.Player.update(Player.java:86)
    at my2dgame.GamePanel.update(GamePanel.java:101)
    at my2dgame.GamePanel.run(GamePanel.java:76)
    at java.base/java.lang.Thread.run(Thread.java:831)
    I can't seem to fix it. can anybody help?????

    • @RyiSnow
      @RyiSnow  2 года назад

      Looks like one of the index (col or row) for the mapTileNum is getting a number which is beyond the array's boundary (50). That is not supposed to happen so I think some calculation is not correct.

    • @pokeminestwodios
      @pokeminestwodios 2 года назад

      I'm having the same issue. Did you ever figure this out?

    • @abikyoukan2
      @abikyoukan2 Год назад +1

      having the same issue here. cant seem to fix it at all

    • @apro8723
      @apro8723 9 месяцев назад

      HOW TO FIX????@@RyiSnow

    • @alexholst8138
      @alexholst8138 7 месяцев назад

      @@apro8723 Don't know if this is relevant anymore or not, but I think it might be because of the statement:
      entity.solidArea.x = entity.worldX + entity.solidArea.x inside of the checkObject()-method in CollisionChecker.
      If you don't reset the value of the rectangles values like he does in 12:20 it will make the rectangle bigger than the map at some point - which would then give you an error since the array's boundary is only as big as the world (thus you get an array out of bounds exception).

  • @udaybhokre591
    @udaybhokre591 2 года назад

    The door doesn't open when I have more than 0 keys

    • @law3922
      @law3922 Год назад

      I had a similar problem.
      It was because I had written "Door" as "door" in the pickUpObject method

  • @kirtiprajapati9935
    @kirtiprajapati9935 Год назад

    It's showing FPS:60

    • @deborahlawani5539
      @deborahlawani5539 22 дня назад

      In your game panel class, you have to remove the System.out.println("FPS:" + drawCount);

  • @Spluli
    @Spluli Год назад +1

    CODE in Answers

    • @Spluli
      @Spluli Год назад

      CODE Player:
      package entityFolder;
      import java.awt.*;
      import java.awt.image.BufferedImage;
      import javax.imageio.ImageIO;
      import main.GamePanel;
      import main.KeyHandler;
      public class Player extends Entity {
      GamePanel gp;
      KeyHandler keyH;
      public final int screenX ;
      public final int screenY ;
      int hasKey = 0;
      public Player(GamePanel gp, KeyHandler keyH) {
      this.gp = gp;
      this.keyH = keyH;
      screenX = gp.screenWidth/2 - (gp.tileSize/2);
      screenY= gp.screenHeight/2 - (gp.tileSize/2);
      solidArea = new Rectangle();
      solidArea.x = 8;
      solidArea.y = 16;
      solidAreaDefaultX = solidArea.x;
      solidAreaDefaultY = solidArea.y;
      solidArea.width = 32;
      solidArea.height = 32;

      setDefaultValues();
      getPlayerImage();
      }
      public void setDefaultValues() {
      worldX = gp.tileSize * 23;
      worldY = gp.tileSize * 21;
      speed = 4;
      direction = "down";
      }
      public void getPlayerImage() {
      try {
      up1 =
      ImageIO.read(
      getClass().getResourceAsStream("../res/player/boy_up_1.png")
      );
      up2 =
      ImageIO.read(
      getClass().getResourceAsStream("../res/player/boy_up_2.png")
      );
      down1 =
      ImageIO.read(
      getClass().getResourceAsStream("../res/player/boy_down_1.png")
      );
      down2 =
      ImageIO.read(
      getClass().getResourceAsStream("../res/player/boy_down_2.png")
      );
      left1 =
      ImageIO.read(
      getClass().getResourceAsStream("../res/player/boy_left_1.png")
      );
      left2 =
      ImageIO.read(
      getClass().getResourceAsStream("../res/player/boy_left_2.png")
      );
      right1 =
      ImageIO.read(
      getClass().getResourceAsStream("../res/player/boy_right_1.png")
      );
      right2 =
      ImageIO.read(
      getClass().getResourceAsStream("../res/player/boy_right_2.png")
      );
      } catch (Exception e) {
      e.printStackTrace();
      }
      }
      public void update() {
      if (
      keyH.upPressed == true ||
      keyH.downPressed == true ||
      keyH.leftPressed == true ||
      keyH.rightPressed == true
      ) {
      if (keyH.upPressed == true) {
      direction = "up";

      } else if (keyH.downPressed == true) {
      direction = "down";

      } else if (keyH.rightPressed == true) {
      direction = "right";
      ;
      } else if (keyH.leftPressed == true) {
      direction = "left";

      }
      // CHECK TILE COLLISION
      collisionOn = false;
      gp.cChecker.checkTile(this);
      // CHECK OBJEKT COLLISION
      int objIndex = gp.cChecker.checkObject(this, true);
      pickUpObject(objIndex);
      // IF COLLISION = FALSE, PLAYER CAN MOVE
      if(collisionOn == false){
      switch(direction){
      case "up" : worldY -= speed; break;
      case "down" : worldY += speed; break;
      case "right": worldX += speed; break;
      case "left" : worldX -= speed; break;
      }
      }
      spriteCounter++;
      if (spriteCounter > 10) {
      if (spriteNum == 1) {
      spriteNum = 2;
      } else if (spriteNum == 2) {
      spriteNum = 1;
      }
      spriteCounter = 0;
      }
      }
      }
      public void pickUpObject(int i){
      if(i != 999){
      String objectName = gp.obj[i].name;
      switch(objectName){
      case "Key" : hasKey++; gp.obj[i] = null; break;
      case "Door" : if(hasKey > 0){gp.obj[i] = null;hasKey--;} break;
      // case "Boots": speed += 3; gp.obj[i] = null; break;



      }
      }
      }
      public void draw(Graphics2D g2) {
      // g2.setColor(Color.WHITE);
      // g2.fillRect(x, y, gp.tileSize, gp.tileSize);
      BufferedImage image = null;
      switch (direction) {
      case "up":
      if (spriteNum == 1) {
      image = up1;
      }
      if (spriteNum == 2) {
      image = up2;
      }
      break;
      case "down":
      if (spriteNum == 1) {
      image = down1;
      }
      if (spriteNum == 2) {
      image = down2;
      }
      break;
      case "right":
      if (spriteNum == 1) {
      image = right1;
      }
      if (spriteNum == 2) {
      image = right2;
      }
      break;
      case "left":
      if (spriteNum == 1) {
      image = left1;
      }
      if (spriteNum == 2) {
      image = left2;
      }
      break;
      }
      g2.drawImage(image, screenX, screenY, gp.tileSize, gp.tileSize, null);
      }
      }

    • @Spluli
      @Spluli Год назад

      CODE Super Obj:
      package objects;
      import java.awt.image.BufferedImage;
      import main.GamePanel;
      import java.awt.*;
      public class SuperObject {

      public BufferedImage image;
      public String name;
      public boolean collision = false;
      public int worldX , worldY;
      public Rectangle solidArea = new Rectangle(0,0,48,48);
      public int solidAreaDefaultX = 0;
      public int solidAreaDefaultY = 0;
      public void draw(Graphics2D g2, GamePanel gp){
      int screenX = worldX - gp.player.worldX + gp.player.screenX;
      int screenY = worldY - gp.player.worldY + gp.player.screenY;
      if( worldX + gp.tileSize > gp.player.worldX - gp.player.screenX &&
      worldX - gp.tileSize < gp.player.worldX + gp.player.screenX &&
      worldY + gp.tileSize > gp.player.worldY - gp.player.screenY &&
      worldY - gp.tileSize < gp.player.worldY + gp.player.screenY //
      ){
      g2.drawImage(image, screenX, screenY, gp.tileSize, gp.tileSize, null);
      }
      }
      }

  • @vivitronthereal4298
    @vivitronthereal4298 2 года назад

    Hey RyiSnow I fixed the first error. But now whenever i run the game and try to move, I get a null pointer.

    • @vivitronthereal4298
      @vivitronthereal4298 2 года назад

      Exception in thread "Thread-0" java.lang.NullPointerException: Cannot read field "solidArea" because "this.gp.obj[i]" is null
      at Main.CollisionDetection.checkObject(CollisionDetection.java:79)
      at entity.Player.update(Player.java:89)
      at Main.GamePanel.update(GamePanel.java:97)
      at Main.GamePanel.run(GamePanel.java:72)
      at java.base/java.lang.Thread.run(Thread.java:831)

    • @RyiSnow
      @RyiSnow  2 года назад

      Did you instantiate the object? Also, did you add the line "if(gp.obj[i] != null)"? NullPointerException error occurs when program tries to refer to an instance but it was empty (null).

    • @vivitronthereal4298
      @vivitronthereal4298 2 года назад

      @@RyiSnow Yes I did add if(gp.obj[i] != null).

    • @vivitronthereal4298
      @vivitronthereal4298 2 года назад

      @@RyiSnow Still doesn't work

  • @Entity_The_Demon
    @Entity_The_Demon Год назад

    "imagine not putting your own twists to a game a youtuber has a tutorial on" -me

  • @jamesconwell2767
    @jamesconwell2767 2 года назад +1

    Algorithm comment

  • @woodswoody5553
    @woodswoody5553 2 года назад +1

    Exception in thread "Thread-0" java.lang.NullPointerException: Cannot read field "solidArea" because "this.gp.obj[i]" is null
    at main.CollisionChecker.checkObject(CollisionChecker.java:116)
    at entity.Player.update(Player.java:107)
    at main.GamePanel.update(GamePanel.java:155)
    at main.GamePanel.run(GamePanel.java:137)
    at java.base/java.lang.Thread.run(Thread.java:833)

    • @helioktt
      @helioktt 2 года назад +1

      entity.solidArea.x = entity.solidAreaDefaultX;
      entity.solidArea.y = entity.solidAreaDefaultY;
      gp.obj[i].solidArea.x = gp.obj[i].solidAreaDefaultX;
      gp.obj[i].solidArea.y = gp.obj[i].solidAreaDefaultY;
      These need to be inside of
      if (gp.obj[i] != null)
      Probably you've placed outside of it.
      move the 4 lines to fix it.

    • @anasfaisal4581
      @anasfaisal4581 Месяц назад

      @@helioktt Broooooo you don't know how many moths i took to figure this issue out!!!!! i thank you very much!!!

  • @dahoodgnome
    @dahoodgnome Год назад +2

    I'm having a small issue when checking the object collision. After I add the line: { int objIndex = gp.cChecker.checkObject(this, true); } into the update method inside of the Player class, all of my assets (chests, keys, and doors) disappear from the game. Omitting this line makes them reappear, but I don't see that as fixing the problem lol. I am getting a warning about the objIndex stating that its value is never used, only option it gives to remedy is to remove it all together. and again, I don't see that as a solution.
    I'm going to continue trying to figure this out. If anyone has any input or ideas of where I so obviously made a mistake, that would be much appreciated. 😁 I will update with my solution when it comes to me.
    So that took 5 minutes. I mistakenly used the = instead of the + when setting the positions of gp.obj[i]. I really need to pay a little more attention to detail!

  • @vivitronthereal4298
    @vivitronthereal4298 2 года назад +1

    Hey RyiSnow!! I love your videos so much. For some reason im getting an error on " gp.obj[i].solidArea.x = gp.obj[i].solidAreaDefaultX;
    gp.obj[i].solidArea.y = gp.obj[i].solidAreaDefaultY;" Anything im doing wrong?

    • @vivitronthereal4298
      @vivitronthereal4298 2 года назад

      It says "solidAreaDefaultX cannot be resolved or is not a field"

    • @RyiSnow
      @RyiSnow  2 года назад

      May I see your CollisionChecker class?

    • @vivitronthereal4298
      @vivitronthereal4298 2 года назад

      @@RyiSnow It wont let me send it

    • @RyiSnow
      @RyiSnow  2 года назад +1

      Did you create those two variables in SuperObject class?

    • @vivitronthereal4298
      @vivitronthereal4298 2 года назад

      @@RyiSnow omg i didnt

  • @coolfactor1796
    @coolfactor1796 2 года назад +1

    Exception in thread "Thread-0" java.lang.ArrayIndexOutOfBoundsException: Index 184 out of bounds for length 50
    at main.CollisionChecker.checkTile(CollisionChecker.java:36)
    at entity.Player.update(Player.java:93)
    at main.GamePanel.update(GamePanel.java:150)
    at main.GamePanel.run(GamePanel.java:137)
    at java.base/java.lang.Thread.run(Thread.java:831)
    how can I fix this?

    • @dgarrard100
      @dgarrard100 Год назад

      -I managed to fix a similar error by removing the lines "entity.solidArea.y -= entity.speed" etc. in the "checkObject" method's switch statement. I'm not sure if that'll cause more problems down the line or not, though.-
      Update: I believe this actually did cause a problem where I would become unable to move when touching any collidable object (except doors I had the key to).
      I ended up restarting this program from scratch, and now I'm not getting the error. I'm still not sure what caused the error in the first place; I would recommend just rewriting the method from scratch, and if that doesn't work, rewriting the class from scratch.

    • @coolfactor1796
      @coolfactor1796 Год назад

      @@dgarrard100 thx for your answer

    • @abikyoukan2
      @abikyoukan2 Год назад

      damn im having the exact same problem here and its quite weird because this error happens when I try to move ingame. very strange

  • @rafaelroriz6622
    @rafaelroriz6622 2 года назад

    Hey, great video. Im having a problem, and I need some help. All my objects are being placed at the top of the map when I add this line "int objindex = gp.cChecker.checkObject(this, true);" in the player class. What could it be ? I could send you my code if needed.

    • @RyiSnow
      @RyiSnow  2 года назад

      Maybe you haven't set their worldX and worldY?

    • @rafaelroriz6622
      @rafaelroriz6622 2 года назад

      @@RyiSnow yeah it was that. Thanks.

  • @kn0x690
    @kn0x690 Год назад

    Hello, I tried your method the collision of object and the player is perfectly fine and return the right object index however when I set null value in obj[] from pickUpObject method
    I got this error
    Exception in thread "Thread-4" java.lang.NullPointerException
    at main.Collision.checkObject(Collision.java:138)
    at entity.Player.updatePos(Player.java:163)
    at entity.Player.update(Player.java:84)
    at main.GameLoop.update(GameLoop.java:39)
    at main.GameLoop.run(GameLoop.java:66)
    at java.lang.Thread.run(Thread.java:745)

    • @kn0x690
      @kn0x690 Год назад

      and I want to add animation to object how can I do that?

    • @kn0x690
      @kn0x690 Год назад

      I fixed the issue but how about animation?

  • @hydrogennetwork
    @hydrogennetwork 8 месяцев назад

    help i'm getting an error and i can't move it after
    Exception in thread "Thread-0" java.lang.NullPointerException: Cannot read field "name" because "this.gp.obj[i]" is null
    at entity.Player.pickUpObject(Player.java:117)
    at entity.Player.update(Player.java:81)
    at main.GamePanel.update(GamePanel.java:88)
    at main.GamePanel.run(GamePanel.java:74)
    at java.base/java.lang.Thread.run(Thread.java:1583)

    • @RyiSnow
      @RyiSnow  8 месяцев назад

      Looks like you're trying to read an empty object at line 117. There should be a reason for that so I suggest you look into that.

    • @hydrogennetwork
      @hydrogennetwork 8 месяцев назад

      i looked into it like a bajillion times and just checked again but it doesn't help

    • @hydrogennetwork
      @hydrogennetwork 8 месяцев назад

      nevermind it's fixed thanks for the help anyway

    • @hydrogennetwork
      @hydrogennetwork 8 месяцев назад

      nevermind again its still there

    • @hydrogennetwork
      @hydrogennetwork 8 месяцев назад

      ​ @RyiSnow it's been 14 hours

  • @shoukopubgm9109
    @shoukopubgm9109 Год назад

    Exception in thread "Thread-0" java.lang.NullPointerException: Cannot read field "solidArea" because "this.gp.obj[i]" is null
    at Bohol/My2Dgame.CollisionChecker.checkObject(CollisionChecker.java:111)
    at Bohol/entity.Player.update(Player.java:92)
    at Bohol/My2Dgame.GamePanel.update(GamePanel.java:130)
    at Bohol/My2Dgame.GamePanel.run(GamePanel.java:115)
    at java.base/java.lang.Thread.run(Thread.java:833)
    can u help me this this why it's not working? these are seem to be the problem

    • @freshie94
      @freshie94 10 месяцев назад

      Hmm, when you are setting your objects' image, do you have the correct file path? I think it should be /objects/key.png" for instance. What IDE are you using? In some IDE's like IntelliJ that I'm using, you have to right click the res folder and Mark directory as - Resources Root. As he explained in an earlier video, / at the beginning means it goes from root, meaning the project folder, into res, and then it checks the folders from there.

  • @coolfactor1796
    @coolfactor1796 2 года назад

    i need help because i have this error meesage and i am not able to move the charackter Exception in thread "Thread-0" java.lang.NullPointerException: Cannot invoke "java.lang.Integer.intValue()" because "entity.solidAreaDefaultY" is null
    at main.CollisionChecker.checkObjekt(CollisionChecker.java:108)
    at entity.Player.update(Player.java:100)
    at main.GamePanel.update(GamePanel.java:150)
    at main.GamePanel.run(GamePanel.java:137)
    at java.base/java.lang.Thread.run(Thread.java:831)

    • @coolfactor1796
      @coolfactor1796 2 года назад

      I place this highe : entity.solidArea.x = entity.solidAreaDefaultX;
      entity.solidArea.y = entity.solidAreaDefaultY;
      gp.obj[i].solidArea.x = gp.obj[i].solidAreaDefaultX;
      gp.obj[i].solidArea.y = gp.obj[i].solidAreaDefaultY;
      and optain this error message:
      Exception in thread "Thread-0" java.lang.ArrayIndexOutOfBoundsException: Index 184 out of bounds for length 50
      at main.CollisionChecker.checkTile(CollisionChecker.java:28)
      at entity.Player.update(Player.java:93)
      at main.GamePanel.update(GamePanel.java:150)
      at main.GamePanel.run(GamePanel.java:137)
      at java.base/java.lang.Thread.run(Thread.java:831)

    • @RyiSnow
      @RyiSnow  2 года назад

      Did you instantiate the solidArea in Entity?

    • @coolfactor1796
      @coolfactor1796 2 года назад

      @@RyiSnow hi thx for your help i fixed the problem (i wrote AreaDefaultX= areay;

    • @abikyoukan2
      @abikyoukan2 Год назад

      @@coolfactor1796 where did you put this?

  • @Anarkiados
    @Anarkiados Год назад +1

    Hello, and huge thanks for your amazing tutorials Ryi!
    I'm encountering an error the moment my character touches the Key Object (I've added what's in each line to the error message below):
    Exception in thread "Thread-0" java.lang.NullPointerException: Cannot invoke "String.hashCode()" because "" is null
    at entity.Player.pickUpObject(Player.java:123)

    • @RyiSnow
      @RyiSnow  Год назад

      Check the pinned comment!

    • @Anarkiados
      @Anarkiados Год назад

      @@RyiSnow I did, trust me! It didn't help and I'm getting a different sort of error: "Cannot invoke "String.hashCode()" because "" is null"
      I've tried moving brackets, I've gone through this video and the previous one to try and see where I go wrong but I simply cannot find what I'm doing wrong D:

    • @RyiSnow
      @RyiSnow  Год назад

      Can I see your pickUpObject method?

    • @Anarkiados
      @Anarkiados Год назад

      @@RyiSnow
      public void pickUpObject(int i) {
      if(i != 999) {
      String objectName = gp.obj[i].name;
      switch(objectName) {
      case "Key":
      hasKey++;
      gp.obj[i] = null;
      System.out.println("Key:"+hasKey);
      break;
      case "Door":
      if(hasKey > 0) {
      gp.obj[i] = null;
      hasKey--;
      }
      System.out.println("Key:"+hasKey);
      break;
      }
      }
      }

    • @Anarkiados
      @Anarkiados Год назад

      @@RyiSnow
      int objIndex = gp.cChecker.checkObject(this, true);
      pickUpObject(objIndex);

  • @RandomHandle-r2q
    @RandomHandle-r2q 2 года назад

    If someone could help me with this that would be great. I have been debugging my code for 2 days now... And I still can not solve this error I am getting to the console.
    Exception in thread "Thread-0" java.lang.NullPointerException: Cannot read field "solidArea" because "this.gp.obj[i]" is null
    at main.CollisionChecker.checkObject(CollisionChecker.java:119)
    at entity.Player.update(Player.java:100)
    at main.GamePanel.update(GamePanel.java:98)
    at main.GamePanel.run(GamePanel.java:82)
    I am not the best at coding, so this might be a really simple error, and I am just not understanding it. So please let me know if anyone else is having this problem and how they fixed it please.

    • @RyiSnow
      @RyiSnow  2 года назад

      Did you instantiate the solidArea in SuperObject?

    • @RandomHandle-r2q
      @RandomHandle-r2q 2 года назад

      @@RyiSnow I did. The problem was I placed a block of code just a bracket off lol