(Extra) Answering Requests (Tile/Grid Based Movement etc.) - How to Make a 2D Game in Java

  Рет қаралды 11,867

RyiSnow

RyiSnow

Күн бұрын

Пікірлер: 71
@Nani-bk5op
@Nani-bk5op 3 жыл бұрын
RyiSnow, you created a perfect, easy to follow tutorial and THEN listened and replied to your viewers to help them. Truly an inspiration.
@RyiSnow
@RyiSnow 3 жыл бұрын
You guys inspire me too. Sometimes these requests/questions give me ideas that I'd never thought of!
@michaelk639
@michaelk639 3 жыл бұрын
RyiSnow you're my favorite programming KZbinr, keep up the great work!
@funkychicken3584
@funkychicken3584 3 жыл бұрын
YOOOOOOOOW this is fire I just watch you video yesterday and I finish it in one night! I havent sleept yet your video keeping me awake xD KEEEP IT UP!!!!
@RyiSnow
@RyiSnow 3 жыл бұрын
Wow I think that's like 5 hours watching. Good job! Glad you enjoyed it and thanks for the comment!
@mikemazanetz4183
@mikemazanetz4183 9 ай бұрын
I found a little bug and a way to fix it too. When you get the boots your speed becomes 5 hence the pixelcounter increases in units of 5, thus will never equal 48. So the if statement should read if (pixelcounter >= 48) problem solved. happy coding.
@badkinson5459
@badkinson5459 3 ай бұрын
I think i had the same bug. I found that when I pick up the boots the player would walk off the screen. Upon changing if(pixelcounter >= 48) it now lock up and I can't move. What is your speed set to and what is your speed += upon picking up the boots?
@vaughnscott511
@vaughnscott511 2 жыл бұрын
learned a lot. What I learned from you, is that we should create one class of assets that load images and sounds. We should also add a class that loads spritesheets. The sprite sheet class is a basic image loader class with a function called crop that takes x, y, width and height. that way, you can load all images with the spritesheet class, to your asset class. same as your sounds. great job. also, i added one overloaded draw function -it will post render objects on top on the map, so the player can walk behind objects.
@siebenzwei87
@siebenzwei87 2 жыл бұрын
Thank you so much, with the help of your videos, I learned very much and I was able to implement diagonal movement and collision detection. You are the best.
@sorcerian_bootleg7112
@sorcerian_bootleg7112 3 жыл бұрын
Hey! Thanks for answering one of my questions on your video! Much appreciated! n___n
@RyiSnow
@RyiSnow 3 жыл бұрын
My pleasure! Thanks for the great suggestion :)
@silverlock373
@silverlock373 Жыл бұрын
yo yo, RyiSnow, you are a lifesaver, loved your videos and so glad you covered this topic even after being done with the original series. I needed this video, thank you so much!!!!!1
@PaoloGSilva
@PaoloGSilva 3 жыл бұрын
You can make a platform game tutorial? Your channel is amazing.
@RyiSnow
@RyiSnow 3 жыл бұрын
I might do that in the future. What kind of game is on your mind?
@edrperez
@edrperez 3 жыл бұрын
Looks really complete!
@RyiSnow
@RyiSnow 3 жыл бұрын
This is just a beginning :P We'll add a lot more!
@forte2265
@forte2265 3 жыл бұрын
you do really helpful videos, really appreciate it!
@bluethemcguy4430
@bluethemcguy4430 3 жыл бұрын
Hi RyiSnow, thank you very much for making this series, I would like to know how to make a method to check which tile the entity is on
@RyiSnow
@RyiSnow 3 жыл бұрын
Dividing entity's current worldX and worldY by tileSize returns their current col and row. So if it's player, you can add something like this in the update(): int playerCol = worldX/gp.tileSize; int playerRow = worldY/gp.tileSize; System.out.println("Player Col: "+playerCol); System.out.println("Player Row: "+playerRow); If you want to find out its tile number, then you can add: int playerTileNum = gp.tileM.mapTileNum[playerCol][playerRow]; System.out.println("Player is on number " + playerTileNum + " tile");
@bluethemcguy4430
@bluethemcguy4430 3 жыл бұрын
@@RyiSnow Thank you so MUCH! It worked!
@Bagijoji_el_Bajoneado
@Bagijoji_el_Bajoneado Жыл бұрын
Hello man, I really like watching your videos, greetings🎉
@yauhyeah
@yauhyeah 2 жыл бұрын
Best series ever :D
@holmdev
@holmdev 3 жыл бұрын
Good work and thank you
@holmdev
@holmdev 3 жыл бұрын
I did so you could have three hearts, but do not get to a maximum of 3 live. Right now, manf smiles hearts about mom take health, Everything else works well. Maybe an idea to bring up .. how to get to the maximum number of lives. Thanks again
@RyiSnow
@RyiSnow 3 жыл бұрын
Player life also will be included in the second half! For the maximum life value, you can create a variable such as: int maxLife = 3;
@holmdev
@holmdev 3 жыл бұрын
@@RyiSnow yes that work fine for now
@holmdev
@holmdev 3 жыл бұрын
@@RyiSnow i make it work with three harts
@vampsz1592
@vampsz1592 2 жыл бұрын
What variables would I need to display hotbox of npc and monster?
@clovercandii
@clovercandii 2 жыл бұрын
hello! I was wondering if there would be a way to make water walking boots? like when you pick up the water walking boots, the collision on water tiles becomes false or something? thank you so much for this tutorial!
@clovercandii
@clovercandii 2 жыл бұрын
also, would there be an easy way to add toggling? like if they picked up the speed boots but dont want the speed anymore, would there be a way of toggling the effect off and on with a keyboard button or something like that?
@RyiSnow
@RyiSnow 2 жыл бұрын
For the water collision you just need to call the water tile class and change its collision false then you can walk on the water (water walking boots sounds interesting btw!). For toggling the speed up effect, here's an example: 1. Create a boolean dashOn = false; in the Player class 2. In the KeyHandler class, add the following lines: (KeyPressed method) if(code == KeyEvent.VK_SPACE) { gp.player.dashOn = true; } (KeyReleased method) if(code == KeyEvent.VK_SPACE) { gp.player.dashOn = false; } 3. In the update method of the Player class, add the following lines: if(dashOn == true) { speed = 8; // you can type any number } if(dashOn == false) { speed = 4; } Then the player character dashes while you are holding down space key.
@clovercandii
@clovercandii 2 жыл бұрын
@@RyiSnow Thank you! Your tutorials are amazing and you replying to comments is soo helpful.
@clovercandii
@clovercandii 2 жыл бұрын
hi, i have another question, sorry to bother ! if i have 2 moving sprites (left and right foot forward) and i would like to add a 3rd sprite, standing still, how would i do that? I tried changing spriteNum to 3 in else and adding another if in the switch cases to = spritenum 3 but it just made it so they were always in the 3rd spriteNum position.
@RyiSnow
@RyiSnow 2 жыл бұрын
Sounds like something is wrong in your if statement. >I tried changing spriteNum to 3 in else I can't really picture what you have done exactly. When you describe your issue, try describing in detail (writing your actual code etc.) so others can understand too.
@clovercandii
@clovercandii 2 жыл бұрын
@@RyiSnow sorry i shouldve explained better. this is what i tried: in the else statement, changing the 1 to spriteNum = 3 else { standCounter++; if (standCounter == 24) { spriteNum = 3; standCounter = 0; } } and adding a third if in the switch statement. switch (direction) { case "up" -> { if (spriteNum == 1) { image = up1; } if (spriteNum == 2) { image = up2; } image = up3; } case "down" -> { if (spriteNum == 1) { image = down1; } if (spriteNum == 2) { image = down2; } image = down3; } case "left" -> { if (spriteNum == 1) { image = left1; } if (spriteNum == 2) { image = left2; } image = left3; } case "right" -> { if (spriteNum == 1) { image = right1; } if (spriteNum == 2) { image = right2; } image = right3; } } sorry if its very incorrect, i am not very good at java so i just tried what i thought could work, but this ended up just making it so that the player was only showing spriteNum = 3 the entire time. after that i thought it might be because i didn't reset the spriteNum back to 1 in the else statement which u are doing in your code, but I couldn't figure out how to implement that without it not staying on the spriteNum = 3. else { standCounter++; if (standCounter == 24) { spriteNum = 3; standCounter = 0; } spriteNum = 1; // added this line } } that code just reset it back to how your code was working, with only the spriteNum = 1 and spriteNum = 2. do you have any ideas on what i could do? Thanks!
@clovercandii
@clovercandii 2 жыл бұрын
i tried doing something like this: spriteCounter++; if (spriteCounter > 24) { if (spriteNum == 1) { spriteNum = 2; }else if (spriteNum == 2) { spriteNum = 1; } spriteCounter = 0; } } else { standCounter++; spriteNum = 1; if (standCounter == 24) { spriteNum = 3; standCounter = 0; } } and its a bit better than the other one, it flickers between spriteNum = 1 and spriteNum = 3 when standing still. Just not really sure how to tell it to stay on spriteNum = 3 as well as go back to spriteNum = 1 when the player starts moving again. I tried putting a spriteNum = 1 into the keyh.(direction)Pressed if statements like this: if (keyH.upPressed == true) { direction = "up"; spriteNum = 1; } to see if it would reset it but that didn't work either, it just flickered between spriteNum = 1 and spriteNum = 3 extremely fast. I was thinking that maybe if you could tell when the player starts moving and tell spriteNum to = 1 when they start moving that would maybe work, but I am really unsure about how to do that.
@RyiSnow
@RyiSnow 2 жыл бұрын
Thank you so much for the detailed explanation! This helps greatly. One question though, do you want to use 3 sprites for walking animation (ex: left foot forwad > standstill > right foot forward)? Or you want to use 2 sprites for walking and 1 for standstill? How you code changes depending on which you want to adopt so I want to know.
@clovercandii
@clovercandii 2 жыл бұрын
@@RyiSnow i would like it to be left foot -> right foot for walking, then standstill for just standing. however, if it would be hard to do that, left foot-> standstill-> right foot is okay as well. thank you!
@LeighFlies
@LeighFlies 2 жыл бұрын
RyiSnow could you drop the link for the video that has the zooming in? You reference it in this video but the previous video in the playlist is #10 with the end of the game for part one... TIA. EDIT: I found it, but you might want to add it to the playlist for the Java 2D game (PLAYLIST tab) as it is not there currently. I found it in the general list of videos (VIDEOS tab) 😊
@RyiSnow
@RyiSnow 2 жыл бұрын
They all were in the playlist before but I removed them. Most of the edits in the extras are just alternative ideas and are not necessarily compatible with the main route program (the videos with a number). So as the main route progresses, incompatible issues are bound to happen because I'm not adding new content based on the edits in the extra videos. So if you go on an alternative route (such as adding zoom in/out or stopping the camera at the edge function), basically you are on your own. I warned that a couple of times but still I kept receiving "after adding the change in Part XX, my game is no longer working, something is wrong with your code" kind of messages. I checked their code and then found out that they had added those edits in extra videos... this repeated and eventually, I became a bit exhausted :( So I decided to remove several extra videos from the playlist. It was a tough choice but I just wanted to free them/myself from the confusion. Hope you understand!
@LeighFlies
@LeighFlies 2 жыл бұрын
@@RyiSnow Absolutely I do! I didn't know that because I had already reached the end of #10 when I learnt of the existence of it. But absolutely I understand. My heart sank for example when I had to delete my 80 objects to optimise the rendering experience, but I did it and it runs a lot better, so I totally get it. Luckily for me I have kept up ok with the coding side, no major issues, so I'm looking for ward to my next one - #15 NPC dialogue! Keep up the great work, excellent tutorials, thanks so much! Oh and the only other functionality I have implemented so far besides a completely different tile set etc, is to get the milliseconds of the clip when pausing game, and then stopping music, but unpausing to continue music where left off. That was a good little challenge for me!😄
@haikamu7178
@haikamu7178 2 жыл бұрын
I have a question, how do you rendering custom fonts?
@RyiSnow
@RyiSnow 2 жыл бұрын
Done that in Part 16!
@changge4305
@changge4305 2 жыл бұрын
Hi RyiSnow, when we zoom in/out, how can we deal with the solid area?
@vtba123
@vtba123 Ай бұрын
I want to use the space key to make the player jump, and I don't want to use the W, S keys to move up and down anymore, can you help me?
@deborahlawani5539
@deborahlawani5539 Ай бұрын
You can just change that in the keyHandler class @Override public void keyPressed(KeyEvent e) { int code = e.getKeyCode(); if (code == KeyEvent.VK_UP) { upPressed = true; } if (code == KeyEvent.VK_DOWN) { DownPressed = true; } if (code == KeyEvent.VK_LEFT) { leftPressed = true; } if (code == KeyEvent.VK_RIGHT) { rightPressed = true; } //DEBUG if (code == KeyEvent.VK_RIGHT) { if (checkDrawTime == false) { checkDrawTime = true; } else if (checkDrawTime == true){ checkDrawTime = false; } } } this is for when you want to change it from W,A,S,D
@OneLatteComingRightUp
@OneLatteComingRightUp 3 ай бұрын
Ryisnow, how can i make it able to move diagonal? That would be the most helpful tutorial ever!
@eddyxc1697
@eddyxc1697 3 ай бұрын
if you change the else if statements in player.update() to just if statements, you can get 8 direction movements
@eddyxc1697
@eddyxc1697 3 ай бұрын
forgot to add: the else if statements that look for KeyHandler inputs
@arian.a4181
@arian.a4181 3 жыл бұрын
nice
@funkychicken3584
@funkychicken3584 3 жыл бұрын
Bro how can you make an NPC and interact with it
@RyiSnow
@RyiSnow 3 жыл бұрын
We'll feature NPC interaction in the second half so stay tuned!
@yauhyeah
@yauhyeah 2 жыл бұрын
hmm my player sprite is 32x48 and the collisions are not working with the tile/grid based movement ._. any help to fix this is appreciated :d or advice EDIT: you should make discord server if this is still active so we can ask questions and help each other EDIT 2: Fixed it by adjusting the solidrectangle border to suit it
@Tercer2
@Tercer2 2 ай бұрын
What if i want to make swimming in the water?
@christianmingle3394
@christianmingle3394 2 жыл бұрын
If you pick up boots after making the game tile based movement, it breaks the game. it has to do with the speed changing i believe,
@RyiSnow
@RyiSnow 2 жыл бұрын
Yes, these are "extra" ideas so they are not necessarily compatible with the main course program and that's why I separated it as an extra video. If you go on a different direction such as grid based movement, naturally you'll need to adjust the code accordingly.
@robertfilip
@robertfilip 2 жыл бұрын
Hi! I got the same issue and fiddled around with it a bit. It seems that multiplying the speed (instead of adding to it) fixes the issue. This tile/grid movement feels way more natural to me, so I'm keeping it. May thanks, @RyiSnow!
@ExtremeCastGaming
@ExtremeCastGaming 3 жыл бұрын
How to make screen Endgame. pls, teach me.
@RyiSnow
@RyiSnow 3 жыл бұрын
That will be featured in the second half :) We will include a title screen, a game over screen and an ending screen so please stay tuned!
@LukasTalix
@LukasTalix 2 жыл бұрын
Thanks so much, really wanted to make a game that only moves tile to tile! I had to change some functions to make it work as intended with different speeds. if (moving) { if (!collisionOn) { // if collision is false, player can move for (int i = 0; i < speed; i++) { // because we want to be able to change speed but make sure we don't move more pixels then tileSize. switch (direction) { case "up" -> worldY -= 1; case "down" -> worldY += 1; case "left" -> worldX -= 1; case "right" -> worldX += 1; } pixelCounter++; if (pixelCounter == gp.tileSize) { moving = false; pixelCounter = 0; break; // breaks the loop so we don't move more pixels } } spriteCounter++; if (spriteCounter > 10 - speed) { // -speed to make legs move faster when the character does too. if (spriteNum == 1) { spriteNum = 2; } else if (spriteNum == 2) { spriteNum = 1; } spriteCounter = 0; } } else { moving = false; // if collision happens, moving have to be turned to false. } }
@RyiSnow
@RyiSnow 2 жыл бұрын
Glad you liked it. That said please keep in mind that the tile-based movement is just an alternative game design idea (that's why I made this video as extra) and not something we're using in the rest of the series. Naturally, some future functions will not be compatible as they are so if you're adopting the tile-based movement you'll need to do some adjustments from time to time.
@Gnarkson
@Gnarkson 3 жыл бұрын
Nippon?
@RyiSnow
@RyiSnow 3 жыл бұрын
Nippon.
@jamesconwell2767
@jamesconwell2767 3 жыл бұрын
Comment for the algorithm
@RyiSnow
@RyiSnow 3 жыл бұрын
Could you please stop posting these "algorithm" comment? You're probably doing it with good intension but these spam-like comments are not helping this channel. If you leave a comment, please write something meaningful.
@jamesconwell2767
@jamesconwell2767 3 жыл бұрын
@@RyiSnow sure
@michaelk639
@michaelk639 2 жыл бұрын
@@RyiSnow He's leaving the comment because if a youtube video has more comments on it then it will get recommended to more people. I think he has good intentions
@RyiSnow
@RyiSnow 2 жыл бұрын
@Michael K I know but that sort of comments are basically meaningless for other viewers if not annoying. Imagine if you visit someone's channel and the comment section is filled with "comment for the algorithm". I'm not interested in increasing views by using that sort of "trick". Also, if you are leaving the same comment again and again, you get regarded as a potential spammer by KZbin. In fact, many of his comments are starting to get flagged and becoming invisible. I had to salvage some of them from "Held for review" section (including his reply to this thread.) Long story short, it won't do anyone any good.
2D Top Down Movement UNITY Tutorial
7:21
BMo
Рет қаралды 227 М.
Муж внезапно вернулся домой @Oscar_elteacher
00:43
История одного вокалиста
Рет қаралды 4,5 МЛН
The Singing Challenge #joker #Harriet Quinn
00:35
佐助与鸣人
Рет қаралды 40 МЛН
1, 2, 3, 4, 5, 6, 7, 8, 9 🙈⚽️
00:46
Celine Dept
Рет қаралды 106 МЛН
When Cucumbers Meet PVC Pipe The Results Are Wild! 🤭
00:44
Crafty Buddy
Рет қаралды 53 МЛН
Optimizing my Game so it Runs on a Potato
19:02
Blargis
Рет қаралды 654 М.
I'm Making 2D Minecraft
9:04
CodeNoodles
Рет қаралды 50 М.
Drawing Tiles - How to Make a 2D Game in Java #4
27:26
RyiSnow
Рет қаралды 152 М.
NPC - How to Make a 2D Game in Java #14
31:52
RyiSnow
Рет қаралды 41 М.
Learning Unreal Engine in One Month to make a Game!
15:25
Will Hess
Рет қаралды 98 М.
How to Start Gamedev in 2024
10:28
Sasquatch B Studios
Рет қаралды 604 М.
5 Minute Top Down Shooter Unity Tutorial
5:01
BMo
Рет қаралды 75 М.
How to Make Pixel Art Tilesets
9:15
Apox Fox
Рет қаралды 37 М.
Муж внезапно вернулся домой @Oscar_elteacher
00:43
История одного вокалиста
Рет қаралды 4,5 МЛН