Object Placement - How to Make a 2D Game in Java #7

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ต.ค. 2024

ความคิดเห็น • 130

  • @alialden1258
    @alialden1258 3 ปีที่แล้ว +46

    you are the best, been following this tutorial and I feel more and more confident about coding. Thank you for taking out time to make this series.

    • @RyiSnow
      @RyiSnow  3 ปีที่แล้ว +9

      That's great to hear! Thank you for the comment.

    • @akashmajji359
      @akashmajji359 7 หลายเดือนก่อน

      ​@@RyiSnow My screen is got black any idea

  • @crackrokmccaib
    @crackrokmccaib ปีที่แล้ว +8

    I hope more people find your channel. You are the absolute best person on TH-cam. I use what I learn here to make my own dungeon crawler game. I know it's completely different, but things like loading maps still help with making my mini-map. The concepts you provide are useful for other types of games.

  • @RodrigoMatela
    @RodrigoMatela 6 หลายเดือนก่อน +10

    A hint if someone was struggling like me. The project was running fine until this video. After i finish it, I tried to run the project but it gave me an error, saying that it couldnt find the Main Class, when previously it always could. Ive search for it throughout the whole internet and tried everything, clean project, change libraries, everything. But nothing worked. When i created a new project and put everything in there, the error persisted. Finally, i found the solution. It was that simple... In the new versions of the libraries, you cannot create the package "object". It was giving me conflict and the project could not run. Change it to objects or obj, or whatever you want. Cheers

    • @BartizeR
      @BartizeR 6 หลายเดือนก่อน +2

      bro you are the best.

    • @mayurchoksi5896
      @mayurchoksi5896 18 ชั่วโมงที่ผ่านมา

      saved my life

  • @brinklebros7136
    @brinklebros7136 7 หลายเดือนก่อน +5

    I took a break from this project for a bit to finish calc2 but im back, I wanna say again thank you so much for making this. I was curious what your background is, work and education? did you make this tutorial all off the top of your head, how much planning was involved how many iterations of this were there, were there other resources, consultations... I only say this bc it seems like an overwhelming feat for just one person to put this all together. thank you again RyiSnow!

  • @TheGrislyBear
    @TheGrislyBear 2 ปีที่แล้ว +6

    I'm developing my own game (different kind of game, but from scratch in Java). My journey would've been much easier had I been watching these videos over the course of the past year. These videos are top notch. Keep up the good work!

  • @andreas1903
    @andreas1903 2 ปีที่แล้ว +5

    found a hidden gems right here, this is exactly what i need when i tried to find some channels about creating games in java there's rarely seeing them uploading videos like this. Love it, best channel ever!

    • @andreas1903
      @andreas1903 2 ปีที่แล้ว

      ahhhh why are my comments always got auto deleted by youtube, i just want to send my error codes

  • @jamiebarr3118
    @jamiebarr3118 ปีที่แล้ว +3

    Thank you so much for all the time and energy you've invested into this series! I can't tell you how much this has helped guide me in making my own game. I always tried to code these features on my own first but when I didn't have a good method for getting things done, your in depth explanation was super helpful! Also, your videos are just really relaxing to watch, it makes coding a lot less stressful haha. Thanks from SF!

    • @RyiSnow
      @RyiSnow  ปีที่แล้ว +2

      That's great to hear!😄

    • @akashmajji359
      @akashmajji359 7 หลายเดือนก่อน

      @@RyiSnow My screen is got black

  • @DzwiekiOtchlani
    @DzwiekiOtchlani 3 ปีที่แล้ว +6

    素晴らしいチュートリアル。君の教えをありがとうございます。

    • @RyiSnow
      @RyiSnow  3 ปีที่แล้ว +4

      どういたしまして :)

    • @akashmajji359
      @akashmajji359 7 หลายเดือนก่อน

      @@RyiSnow My screen is got black

  • @droidlycodes
    @droidlycodes 2 ปีที่แล้ว +2

    This is great, best series yet! I'm developing this for Android so getting everything successfully working up to this point with my knowledge and yours has helped a lot! I would have never thought to use the methods I'm using for game development in this type of gaming! I can't wait to continue, you are a great teacher!

  • @nikolamiletic6991
    @nikolamiletic6991 2 วันที่ผ่านมา

    Thank you again for tutorials ^^
    When you try to explain something I just get it without any issues ^^ and that mean you are good teacher and you giving multiple ways how to write code I just love that and I rly appreciate!! Wish if everyone would explain stuff like you do!!!
    Question, do you have any plans to do some other languages like Javascript or PHP or maybe some other orr you explicitly doing Java ^^ ?

  • @DIABLOJOESTAR
    @DIABLOJOESTAR หลายเดือนก่อน +1

    ty bro youre such a big help hahahahha ive been following the step and create my own condition after i finish your tutorial

  • @nicorajala4881
    @nicorajala4881 3 ปีที่แล้ว +9

    Nice tutorials! Keep up the work! It would be really nice to see something like fullscreen mode or changing the screen resolution... You don't have to make it fullscreen, even the new super nintendos have somewhat of an fullscreen where they put the game in the center. So that would work really great too (and give some retro feel)

    • @RyiSnow
      @RyiSnow  3 ปีที่แล้ว +10

      Yeah I'd love to try this in the full screen too. Maybe I will try that once the game is complete. Thanks for the suggestion.

    • @akashmajji359
      @akashmajji359 7 หลายเดือนก่อน

      @@RyiSnow My screen is got black

  • @abikyoukan2
    @abikyoukan2 ปีที่แล้ว

    just wanna say thank you once again for these videos. been following them with my own details here and there and managed to finally complete this one with the collision detection. just had to change a couple of values, and add a couple of classes to my liking and its looking good. thank you!

  • @Ancientdrifter
    @Ancientdrifter ปีที่แล้ว +2

    I'm really enjoying this series. I'm having trouble with the objects not appearing in game. I can only see the one key rendered in game, a second or third will not appear. I cannot see the chest or door objects either. I've been going over the code multiple times, but I can't find any mistakes. Please help!

  • @edward265
    @edward265 3 ปีที่แล้ว +3

    Very nice. I want to learn how to build something like this from scratch.

  • @dhssjssjj1766
    @dhssjssjj1766 2 ปีที่แล้ว +1

    Thanks for your game tutorials man.

  • @razzlegazz
    @razzlegazz ปีที่แล้ว

    AH! I love this series! I'm trying to make something out of your tutorials but adding and diverting a lot to make a different game!
    QUESTION! How do you make different objects of different sizes? Also, how do you layer the sprites so objects and characters can be in front or behind them in certain conditions? (I've only watched till the sound portion of your tutorial since I'm also still composing my own music)

    • @WillBlanchard-go4qu
      @WillBlanchard-go4qu หลายเดือนก่อน

      You simply have to make a second modified draw method which can use the object's image size instead of the tileSize.
      For reference this line of code:
      graphics2D.drawImage(getObjectTexture(), screenX, screenY, gamePanel.getTILE_SIZE(), gamePanel.getTILE_SIZE(), null);
      takes 5 parameters (taken from the Graphics Class from java.awt):
      drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)
      All you need to do is add a width and height parameter to the object's constructor let's use an example from my game:
      //=======================
      // INSTANTIATE VARIABLES
      //=======================
      private int width, height;
      //=============
      // CONSTRUCTOR
      //=============
      public OBJ_Item(String specification, int width, int height) {
      this.setName(specification);
      this.width = width;
      this.height = height;
      try {
      setObjectTexture(ImageIO.read(Objects.requireNonNull(getClass().getResourceAsStream("/assets/textures/object/item/" + specification + ".png"))));
      } catch (IOException e) {
      Main.LOGGER.error("File IO error: One of the errors couldn't be found due to either reason |" + "
      " + "
      1. The image file name isn't spelled correctly"
      + "
      2. There is a type in the file path, most likely a missing / in front of the assets path");
      }//End of Try-Catch
      }//End of Constructor
      The logging thing is not required e.printStackTrace can be used, anyways now it's time to make a second version of the draw method overriding the one from your SuperObject inside of the OBJ_Item Class
      //============================================================================
      // OVERRIDDEN METHOD TO DRAW THE OBJECT ON THE SCREEN USING THE OBJECT'S SIZE
      //============================================================================
      @Override
      public void draw(Graphics2D graphics2D, GamePanel gamePanel) {
      int screenX = getWorldX() - gamePanel.getPlayer().getWorldX() + gamePanel.getPlayer().getScreenX();
      int screenY = getWorldY() - gamePanel.getPlayer().getWorldY() + gamePanel.getPlayer().getScreenY();
      //-------------------------------------------------------------------------------
      // THIS IF STATEMENT IMPROVES PERFORMANCE BY KEEPING OFF-SCREEN TILES NOT DRAWN
      //-------------------------------------------------------------------------------
      if (getWorldX() + gamePanel.getTILE_SIZE() > gamePanel.getPlayer().getWorldX() - gamePanel.getPlayer().getScreenX() &&
      getWorldX() - gamePanel.getTILE_SIZE() < gamePanel.getPlayer().getWorldX() + gamePanel.getPlayer().getScreenX() &&
      getWorldY() + gamePanel.getTILE_SIZE() > gamePanel.getPlayer().getWorldY() - gamePanel.getPlayer().getScreenY() &&
      getWorldY() - gamePanel.getTILE_SIZE() < gamePanel.getPlayer().getWorldY() + gamePanel.getPlayer().getScreenY()) {
      graphics2D.drawImage(getObjectTexture(), screenX, screenY, this.width, this.height, null);
      }//End of If Statement
      }//End of Overridden Method
      }//End of Class
      Now when you instantiate the object in the AssetSetter class you simply pass in the dimensions of the item. Hope this helps anyone else looking to do this

  • @monsty628
    @monsty628 2 ปีที่แล้ว +1

    Great tutorial as always, but I do have one question. I'm not sure if this will be covered later on so I'll just ask: When I want to add an object that is bigger than our tilesize (let's say a tree which is bigger than our player model so maybe 120x120px) how would I be able to do that? Do I need to create another SuperObject class for these objects? thanks for answering in advance and happy new year!~

    • @RyiSnow
      @RyiSnow  2 ปีที่แล้ว +3

      You don't really need to create another SuperObject. Instead you can scale images to different sizes. I have introduced a different scaling method in Part 11 and scaling to different sizes will be covered in Part 23 that I will upload in a few days. So yes, it will be covered.

  • @shortclipsatyt
    @shortclipsatyt 7 วันที่ผ่านมา

    00:05 Preparing object images and creating object classes.
    03:49 Implementing object key class and loading images in Java game
    06:22 Optimally managing object placement in the game for performance improvement
    09:01 Setting the object's world position and style
    11:58 Drawing objects on the screen using the draw method
    14:34 Drawing objects using the draw method in the super object class
    17:19 Creating and placing objects in the game
    19:54 Implementing object placement for keys, doors, and a chest in a 2D Java game.
    Crafted by Merlin AI.

  • @hggnomm
    @hggnomm ปีที่แล้ว

    I really enjoyed and enjoyed learning your series, but I was a little hesitant because I couldn't understand the logic of the game quickly. Were you like that before?

  • @michab2500
    @michab2500 2 ปีที่แล้ว +3

    Amazing tutorials! I got a question though: How would I implement a multi-tile object? Let's say I would like to draw a table and put something on it. I order for the object ON the table to look realistic, the table needs to cover two tiles (let's say half of the lower tile and half of the upper one). An option that would be possible is to create an Object for every part of the table (f.e. OBJ_UpperTable and OBJ_LowerTable) but that seems pretty ugly to me.
    I've seen people work with multiple layers so the table is implemented on another layer that works half like the tile layer and half like the object layer, but I wouldn't know how to implement that either 🤓 Anyway, I'd love some input! And as I said before: Absolutely amazing content! Keep it up :)

    • @RyiSnow
      @RyiSnow  2 ปีที่แล้ว +2

      I've never really tried it myself but I think you can draw multiple layered objects by creating another object array.
      Maybe something like this?
      // Bottom layer
      for(int i = 0; i < obj.length; i++) {
      if(obj[i] != null) {
      obj[i].draw(g2, this);
      }
      }
      // Second layer
      for(int i = 0; i < obj2.length; i++) {
      if(ob2j[i] != null) {
      ob2j[i].draw(g2, this);
      }
      }
      But if you increase the number of the objects, it might affect the game's performance. I'm not certain until I test it though. If you encounter some lags, drawing them as a background tile is probably better as most of the retro games do (such as A Link to the Past).

    • @michab2500
      @michab2500 2 ปีที่แล้ว +3

      @@RyiSnowThanks a lot for replying so quickly! I'll give it a shot and let you know how it worked out :)
      On another note: I read through the comment section of most of your videos in this series and it's honestly amazing how much time, care and effort you put into helping everyone out! I've rarely seen anything like it and I (and many others) appreciate it so much! I've been subscribed anyway, but I've also shared your channel with friends that might be interested. You really deserve to get those viewers! Anyway, I hope you're doing great and ye, happy holidays (soon) :)

    • @RyiSnow
      @RyiSnow  2 ปีที่แล้ว +5

      Thanks for the kind words! Replying to comments actually helps me to sort out/review my own knowledge. Also, I often get some nice ideas/suggestions from them so I think it's a win-win situation :)
      I hope your game will turn out nicely. Happy holidays to you too!

  • @maq.4280
    @maq.4280 9 หลายเดือนก่อน +1

    how to randomize object placements minding collision with e.g. water?

  • @happyburger23
    @happyburger23 ปีที่แล้ว +2

    I copied the tutorial exactly and am unsure why my objects aren't loading, and no errors are being thrown. Anyidea why that could be the case?

    • @HABIBMUHD92
      @HABIBMUHD92 ปีที่แล้ว

      Please try to run the game in debugger and see if the image path and draw method are okay. If not ensure your setObject() method has both world X and worldY. i accidentally used worldX only i faced the same issue as you. Hope this helps.
      public void setObject() {
      gp.obj[0] = new OBJ_Key();
      gp.obj[0].worldX = 23 * gp.tileSize;
      gp.obj[0].worldY = 7 * gp.tileSize;

      gp.obj[1] = new OBJ_Key();
      gp.obj[1].worldX = 23 * gp.tileSize;
      gp.obj[1].worldY = 40 * gp.tileSize;
      }

  • @NikitaBomba112
    @NikitaBomba112 2 ปีที่แล้ว +1

    Thanks you so much for this video!

  • @harounjaafar6918
    @harounjaafar6918 ปีที่แล้ว +1

    why whit the zoom the objects move how can i fix it please?

  • @zakarianaji6584
    @zakarianaji6584 5 หลายเดือนก่อน

    great work, thanks our friend !

  • @demiannecahiles9818
    @demiannecahiles9818 10 หลายเดือนก่อน

    Hello RyiSnow, I've been following your tutorial to create my final project, it's been very helpful but I've encountered a problem... The collisionchecker works fine but after trying to make the item disappear the code encounters an error

  • @BloxxingDinosaurus
    @BloxxingDinosaurus 6 หลายเดือนก่อน

    What do I do if I didn't want any camera scrolling? Instead of WorldX/Y and ScreenX/Y, I only have x and y, but I don't know how to initialize them for the draw method.
    My TileManager function basically looks like the one in video #4, not like the one in video #5.
    UPDATE: I fixed it, I just had to say
    public void draw(Graphics2D g, GamePanel gp) {
    int x = *this.x;*
    int y = *this.y;*
    g.drawImage(img, x, y, gp.tileSize, gp.tileSize, null);
    }

  • @SlothfulSage285
    @SlothfulSage285 2 ปีที่แล้ว

    Very good. Hope you are well.

  • @kevincolgan6651
    @kevincolgan6651 3 ปีที่แล้ว +1

    Great stuff thanks again

  • @lamrecode
    @lamrecode 5 หลายเดือนก่อน

    Tool for this : add obj to map(same tool create map), can you create ?

  • @erpresident1312
    @erpresident1312 ปีที่แล้ว

    Great video as always! But I I've been having a problem, the key does not print, it doesn't give any errors, it's like the key is not there I already tried printing the object without the for loop but it's still not there, can someone help please?

  • @ThanhNguyen-hq6ot
    @ThanhNguyen-hq6ot 6 หลายเดือนก่อน

    The collisionOn variable is not updated

  • @centice_
    @centice_ หลายเดือนก่อน

    After doing this everything is fine except it looks like my player is running at 2x speed also I'm getting shown FPS 60 two times at a time

  • @zaidanarif7674
    @zaidanarif7674 2 ปีที่แล้ว

    I got some problem, i create an object and whenever i move character down and right , the object is suddenly dissapered.. I don't know how to solve this problem

  • @nilojohnpaulpatacsil584
    @nilojohnpaulpatacsil584 ปีที่แล้ว

    I dont any error but the object dont appear on the screen, how can i fix it

  • @arian.a4181
    @arian.a4181 3 ปีที่แล้ว +1

    pls continue series:) tnx

  • @NikitaVolia
    @NikitaVolia ปีที่แล้ว

    Thank you very much for your video tutorials)))

  • @jeezfries2025
    @jeezfries2025 ปีที่แล้ว

    Hello mr. Ryisnow can you teach me how to make the character to spawn in random location?

  • @viviz4918
    @viviz4918 9 หลายเดือนก่อน +1

    How do you randomize object placement?

    • @NusrathCassim
      @NusrathCassim 7 หลายเดือนก่อน +1

      use Random Class to generate values, in my case, i wanted to generate objects and random positions but the player must be able to reach them(tiles which doesn't have collision property), after the player fetches them that object must be replaced with new one just like in the snake game.
      so instead of writing
      gp.obj[0] = new Object_blueRock(); //thats my class name
      gp.obj[0].obj_x = 11*gp.tileSize;
      gp.obj[0].obj_y = 4*gp.tileSize;
      i modify it like this
      -----------------------------------------------------------------------------------------------------
      boolean validPositionFound = false;
      do {
      int obj_x = (random.nextInt((int)(gp.screenWidth/gp.tileSize)))*gp.tileSize;
      int obj_y = (random.nextInt((int)(gp.screenHeight/gp.tileSize)))*gp.tileSize;
      // Check if the random position is on a tile with number 3
      int randomTileNumX = gp.tile.mapT_Num[obj_x / gp.tileSize][obj_y / gp.tileSize];
      int randomTileNumY = gp.tile.mapT_Num[obj_x / gp.tileSize][obj_y / gp.tileSize]; // Check the tile below as well
      if (randomTileNumX == 3 || randomTileNumY == 3) {

      gp.obj[0] = new Object_rock();
      gp.obj[0].obj_x = obj_x;
      gp.obj[0].obj_y = obj_y;
      validPositionFound = true;
      }

      } while (!validPositionFound);
      -----------------------------------------------------------------------------------------------------
      and to draw a new one again, inside the method that use to pickup object call the setObject method again :
      ------------------------------------------------------------------------------------------------------
      public void pickupObject(int i) {
      if(i != 999) {
      String Object_Name = gp.obj[i].name;
      switch(Object_Name) {
      case "rock_lv1":
      Numrocks++;
      gp.obj[i] = null;
      om.setObject(); //newObject

      break;
      }
      }
      }
      I hope it helps!

  • @cedricsahaghian1605
    @cedricsahaghian1605 ปีที่แล้ว

    Amazing, thanks!

  • @reborn4612
    @reborn4612 2 ปีที่แล้ว

    thank you very much, learning a lot :D

  • @ikninja1hd
    @ikninja1hd 2 ปีที่แล้ว +2

    My code is the exact same, but doesn't draw the objects. Anyone got the code for this part so I can check against mine?

    • @dcwavie
      @dcwavie ปีที่แล้ว

      bru same

    • @dcwavie
      @dcwavie ปีที่แล้ว +2

      check if u put public key instead of public void key

    • @HABIBMUHD92
      @HABIBMUHD92 ปีที่แล้ว +1

      Please try to run the game in debugger and see if the image path and draw method are okay. If not ensure your setObject() method has both world X and worldY. i accidentally used worldX only i faced the same issue as you. Hope this helps.
      public void setObject() {
      gp.obj[0] = new OBJ_Key();
      gp.obj[0].worldX = 23 * gp.tileSize;
      gp.obj[0].worldY = 7 * gp.tileSize;

      gp.obj[1] = new OBJ_Key();
      gp.obj[1].worldX = 23 * gp.tileSize;
      gp.obj[1].worldY = 40 * gp.tileSize;
      }

    • @ikninja1hd
      @ikninja1hd ปีที่แล้ว

      @@HABIBMUHD92 Thank you. I managed to figure it out.

  • @oskar6065
    @oskar6065 3 ปีที่แล้ว +3

    Amazing! :D

  • @ossalis9686
    @ossalis9686 2 ปีที่แล้ว

    What is the application u are using for drawing objects?

    • @RyiSnow
      @RyiSnow  2 ปีที่แล้ว

      Gimp and Piskel

  • @harryjesshop6890
    @harryjesshop6890 2 ปีที่แล้ว +1

    This is a great tutorial! I have 2 questions for trying to make my own code
    1.) I want to make objects that can be broken, such as trees or rocks. If there are going to be a lot of these, should I make them tiles or objects? If tiles, how do i create interactions between the player and the tile?
    2.) I want to randomize the placement of the trees, however im struggling with trying to get the mapTileNum variable from the TileManager class, so i can check for if it will spawn on water and stop it from happening. Can you help with importing the TileManager variables to the AssetSetter class?

    • @RyiSnow
      @RyiSnow  2 ปีที่แล้ว

      1.) I would do with tiles. You can do that by replacing numbers in mapTileNum. Actually cutting trees will be featured in later part of this series so please stay tuned!
      2.) You can access to mapTileNum from AssetSetter by typing gp.tileM.mapTileNum.

    • @harryjesshop6890
      @harryjesshop6890 2 ปีที่แล้ว

      @@RyiSnow thank you so much! I'll make sure to look out for future tutorials, then.

  • @ifeoluwaabimbola4864
    @ifeoluwaabimbola4864 2 ปีที่แล้ว +1

    Hey I'm currently experiencing some issues on this aspect..the last key isn't coming up and the first key has removed the grass tile and is standing on the earth tile ...any ideas on how I go around this?

    • @RyiSnow
      @RyiSnow  2 ปีที่แล้ว

      May I see your Player class and CollisionChecker class?

    • @ifeoluwaabimbola4864
      @ifeoluwaabimbola4864 2 ปีที่แล้ว

      @@RyiSnow any social media I can reach you on?

    • @RyiSnow
      @RyiSnow  2 ปีที่แล้ว

      You can paste the code here!

    • @ifeoluwaabimbola4864
      @ifeoluwaabimbola4864 2 ปีที่แล้ว

      @@RyiSnow package Main;
      import entity.Player;
      import java.awt.Color;
      import java.awt.Dimension;
      import java.awt.Graphics;
      import java.awt.Graphics2D;
      import javax.swing.JPanel;
      import object.SuperObject;
      import tile.TileManager;
      public class GamePanel extends JPanel implements Runnable{
      //SCREEN SETTNGS
      final int originalTileSize = 16; //16 x 16 tile
      final int scale =3;
      //remove final to make it flexible for ZOOMINOUT
      public final int tileSize = originalTileSize * scale ; // 48 x48 tile
      public final int maxScreenCol = 16;
      public final int maxScreenRow = 12;
      public final int screenWidth = tileSize * maxScreenCol; // 768 pixels
      public final int screenHeight = tileSize * maxScreenRow; //576 pixels

      //WORLD SETTINGS
      public final int maxWorldCol = 50;
      public final int maxWorldRow = 50;
      public final int worldWidth = tileSize * maxWorldCol;
      public final int worldHeight = tileSize * maxWorldRow;


      //FPS
      int FPS=60;
      TileManager tileM = new TileManager(this);

      KeyHandler keyH = new KeyHandler();

      Thread gameThread;
      public CollisionChecker cChecker = new CollisionChecker(this);
      public AssetSetter aSetter = new AssetSetter(this);
      public Player player= new Player(this,keyH);

      public SuperObject obj[]=new SuperObject[10];

      public GamePanel(){

      this.setPreferredSize(new Dimension(screenWidth, screenHeight));
      this.setBackground(Color.black);
      this.setDoubleBuffered(true);
      this.addKeyListener(keyH);
      this.setFocusable(true);
      }

      public void setupGame(){
      aSetter.setObject();

      }

      public void startGameThread(){
      gameThread = new Thread(this);
      gameThread.start();
      }
      public void run(){

      double drawInterval = 1000000000/FPS;
      double delta= 0;
      long lastTime =System.nanoTime();
      long currentTime;
      long timer = 0;
      int drawCount = 0;

      while (gameThread != null){
      currentTime = System.nanoTime();

      delta+= (currentTime - lastTime)/ drawInterval;
      timer +=(currentTime - lastTime);
      lastTime = currentTime;

      if(delta >=1){
      update();
      repaint();
      delta--;
      drawCount++;
      }
      if(timer >= 1000000000){
      System.out.println("FPS:" + drawCount);
      drawCount = 0;
      timer = 0;
      }
      }
      }
      public void update(){
      player.update();
      }

      public void paintComponent(Graphics g){

      super.paintComponent(g);

      Graphics2D g2 = (Graphics2D)g;
      //TILE
      tileM.draw(g2);

      //OBJECT
      for(int i =0; i < obj.length;i++){
      if(obj[i] != null){
      obj[i].draw(g2, this);
      }
      }

      //PLAYER
      player.draw(g2);
      g2.dispose();

      }
      }

    • @RyiSnow
      @RyiSnow  2 ปีที่แล้ว

      That's GamePanel class.

  • @niick6369
    @niick6369 11 หลายเดือนก่อน

    Can someone help me? So when we did the KeyHandler I took out the 'elses' and with this I could make my player have free movements, like, I could go diagonally with my player, but now after making collision work my player "lost" the free movements, how can I make it work again?

    • @apro8723
      @apro8723 10 หลายเดือนก่อน

      you have to make collisions with your diaganal movements... do it like you did with the up down left and right movements..

  • @realgungan5781
    @realgungan5781 2 ปีที่แล้ว

    Hi,
    do you know anyway of making the object to have an animation when not interacting with it? For example make the key spin. I've tried lots of things but none seem to work

    • @cftpafan
      @cftpafan ปีที่แล้ว +2

      Hi I know I'm very late but you could create multiple images for the key in different orientations and have them change every few frames in the game loop.

  • @gustavhenriksson867
    @gustavhenriksson867 2 ปีที่แล้ว

    I like coding with you RyiSnow! I learn a lot and i try to implement my own stuff here and there as i like. One thing i thought of, regarding this episode.
    Would it be possible to do the same thing as you did for the tiles but with objects? Read a text file to know where to place the objects. In that way i dont have to go to my code just to change things about my objects!
    thanks!

    • @gustavhenriksson867
      @gustavhenriksson867 2 ปีที่แล้ว

      Also one thing im trying to do is to change the game panel property "maxWorldCol" and "Row" by reading the file it is about to load and count the rows and colums and set the properties accordenly so i can draw more dynamic worlds in the text files without changin the value in the code

  • @MrLoser-ks2xn
    @MrLoser-ks2xn 2 ปีที่แล้ว

    Thanks!

  • @konstandinosdimitriou2301
    @konstandinosdimitriou2301 2 ปีที่แล้ว +1

    hey I mess something up and I have the following problem
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 16 out of bounds for length 16
    at tile.TileManager.loadMap(TileManager.java:119)
    at tile.TileManager.(TileManager.java:26)
    at main.GamePanel.(GamePanel.java:46)
    at main.Main.main(Main.java:16)
    can you help ; I am stack on this for some time :(

    • @RyiSnow
      @RyiSnow  2 ปีที่แล้ว

      Did you expand the size of mapTileNum to maxWorldCol and maxWorldRow so it can contain the world map?

    • @konstandinosdimitriou2301
      @konstandinosdimitriou2301 2 ปีที่แล้ว

      @@RyiSnow yes

    • @konstandinosdimitriou2301
      @konstandinosdimitriou2301 2 ปีที่แล้ว

      ​@@RyiSnowI found the problem catch (IOException e) it was supposed to be catch (Exception e)

  • @TheCeEJayyy
    @TheCeEJayyy ปีที่แล้ว

    Hey im having an issue. Everytime i add gamePanel.setupGame();. my player does not move

    • @wendelamorim9585
      @wendelamorim9585 7 หลายเดือนก่อน +1

      probably when you created the "objects" package, you put "object" or something different from what you typed when searching for the image.

  • @MrLoser-ks2xn
    @MrLoser-ks2xn 2 ปีที่แล้ว

    Thanks

  • @holmdev
    @holmdev 3 ปีที่แล้ว +2

    Nice
    Some ide from me
    Could you make a guide to implant NPCs that could make it harder for the gp in their quest

    • @RyiSnow
      @RyiSnow  3 ปีที่แล้ว +4

      We will implement NPCs in the second half of this series. You can talk to them and get some hints. Also you can buy/sell items with them. I'm not sure what you meant by "make it harder for the gp" though. What kind of stuff is on your mind?

    • @holmdev
      @holmdev 3 ปีที่แล้ว +1

      @@RyiSnow yes it Was that, thanks for a good tutorial

    • @akashmajji359
      @akashmajji359 7 หลายเดือนก่อน

      @@RyiSnow My screen is got black

  • @rianoliveira5378
    @rianoliveira5378 2 ปีที่แล้ว

    Why you multiplicate the position of object for "gp.tilseSize" ?

    • @RyiSnow
      @RyiSnow  2 ปีที่แล้ว

      Because we need to get its x and y.

    • @akashmajji359
      @akashmajji359 7 หลายเดือนก่อน

      @@RyiSnow My screen is got black

  • @realzguardian
    @realzguardian ปีที่แล้ว

    For some reason I cannot place more than one object of a type.

  • @nicovogel9924
    @nicovogel9924 2 ปีที่แล้ว

    can you also make a tutorial on how to make a 3d game

  • @andreas1903
    @andreas1903 2 ปีที่แล้ว

    hello again, i wanna say that i have a problem with my collision, so the problem is whenever i pressed down arrow keys and when the character touched the tree, suddenly it got stuck and cannot go up ended by stuck near those trees. Can you help me with that?? Also when i try to send my code in the comment section it always got auto deleted by youtube

    • @RyiSnow
      @RyiSnow  2 ปีที่แล้ว

      It happens only when you go down?

    • @andreas1903
      @andreas1903 2 ปีที่แล้ว

      @@RyiSnow yes sir

  • @keeplearning8979
    @keeplearning8979 ปีที่แล้ว

    Can I do this project on Intellij IDE?

  • @revue9457
    @revue9457 ปีที่แล้ว

    I'm getting this exception how do I deal with it?? Exception in thread "main" java.lang.IllegalArgumentException: input == null!

  • @angelmadrigal7552
    @angelmadrigal7552 ปีที่แล้ว

    Hello, I am experiencing some issues after placing the key in the world. If you could help I would really appreciate and these videos are amazing by the way. So much learned from watching your videos. Thanks!!

    • @slmo8997
      @slmo8997 9 หลายเดือนก่อน

      did you find out how to solve it?

  • @trungseven
    @trungseven 11 หลายเดือนก่อน

    Cool Bro. I subscribed.

  • @2MSTennis
    @2MSTennis 2 ปีที่แล้ว

    Hey Ry, thanks again for all you have done for me on my coding journey as a beginner. Having you as a coach as kept me motivated to stick with Java.
    I wanted to ask a question. I can get one item to appear but it seems like the code doesn't let me make multiple items because I am unable to see more than one item. I changed the item from key to door to chest and etc. so it isn't the file in IOStream!
    Please help!
    -Cal

  • @jokk-p1k
    @jokk-p1k 11 หลายเดือนก่อน

    How to make the game multiplayer
    online

    • @apro8723
      @apro8723 10 หลายเดือนก่อน

      no can do my guy....

    • @apro8723
      @apro8723 10 หลายเดือนก่อน

      bc idk how

  • @aarushbasak4941
    @aarushbasak4941 2 ปีที่แล้ว

    Can you make a 3D game(or you can't do that)

    • @haikamu7178
      @haikamu7178 2 ปีที่แล้ว

      You can checkout thinmatrix youtube channel for 3d game tutorial in Java

  • @reevandmello8960
    @reevandmello8960 ปีที่แล้ว

    im on 18:31

  • @EntificationALTWow
    @EntificationALTWow 2 ปีที่แล้ว

    I made setObject() far better.
    basically it takes in the name of the object to be set, whether or not it takes collisions, and it's tileX and tileY (i have a function to calculate position in pixel via tileX/Y), then, the function gets the correct image for that object, then places it in the right position. very cool, huh?

  • @oguzhantopaloglu9442
    @oguzhantopaloglu9442 3 ปีที่แล้ว

    you should call it ObjectKey or ObjKey instead of "OBJ_Key"

    • @RyiSnow
      @RyiSnow  3 ปีที่แล้ว +8

      Why?

  • @reddeadrp8554
    @reddeadrp8554 2 ปีที่แล้ว +1

    public void PlaceWorldObject() {
    //add objects

    gp.object[0] = new object_key();
    gp.object[0].worldX = 4 * gp.tileSize; //worldX cannot be resolved???
    gp.object[0].worldY = 25 * gp.tileSize; //worldY cannot be resolved??
    both ints are public in the object class though & object class is public, with no errors instantiating in the gp, any idea where I went wrong?

    • @reddeadrp8554
      @reddeadrp8554 2 ปีที่แล้ว +1

      UPDATE: was my bad, I should know better Object is already defined in Java.lang so i changed class to WorldObject and works!

  • @gigasetc1
    @gigasetc1 6 หลายเดือนก่อน

    I really enjoy your tutorial so far. I am wondering wouldn't it be better to make GameObject abstract, sicne we are repeating some code in Key and Door class.
    So we could for example have:
    package nl.xx1.horsebird.object;
    import lombok.Getter;
    import lombok.Setter;
    import nl.xx1.horsebird.GamePanel;
    import javax.imageio.ImageIO;
    import java.awt.*;
    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import java.util.Objects;
    import static nl.xx1.horsebird.GamePanel.TILE_SIZE;
    @Getter
    @Setter
    public abstract class GameObject {
    private BufferedImage image;
    private String name;
    private boolean collision;
    private int worldX;
    private int worldY;
    public abstract String getName();
    public GameObject() {
    try {
    BufferedImage image = ImageIO.read(Objects.requireNonNull(getClass().getResourceAsStream(String.format("/objects/%s.png", getName()))));
    setImage(image);
    } catch (IOException e) {
    throw new RuntimeException(e);
    }
    }
    public void draw(Graphics2D g2d) {
    int screenX = worldX - GamePanel.localPlayer.getWorldX() + GamePanel.localPlayer.getScreenX();
    int screenY = worldY - GamePanel.localPlayer.getWorldY() + GamePanel.localPlayer.getScreenY();
    g2d.drawImage(image, screenX, screenY, TILE_SIZE, TILE_SIZE, null);
    }
    }
    And then we could have a class:
    package nl.xx1.horsebird.object;
    import javax.imageio.ImageIO;
    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import java.util.Objects;
    public class Key extends GameObject{
    @Override
    public String getName() {
    return "key";
    }
    }

    • @gigasetc1
      @gigasetc1 6 หลายเดือนก่อน

      I think we could also improve the code a bit to make some things static in GamePanel so we don't have to pass GamePanel down the road all the time. Let me know what you think about it. Anyway great series!

  • @georgehaddad1810
    @georgehaddad1810 2 ปีที่แล้ว

    hello, these are great tutorials thank you so much.

    • @RyiSnow
      @RyiSnow  2 ปีที่แล้ว +2

      The error indicates that your code is failing to read the image at line 44 in the TileManager. That's where you want to check.

    • @georgehaddad1810
      @georgehaddad1810 2 ปีที่แล้ว +1

      @@RyiSnow thank you so much for answering, i found the error, it was an old version of a water tile which i wasn't using and it was saved as .gif and not .png.
      It's my first time coding in java and i started 4 days ago thanks to you