Will you show how to add events to objects too? Also, when the player keeps walking through the pit they constantly take damage and get message, can we make it so event only happens if they leave and go back through the pit?
We will add object reactions eventually (we've already done it in the first half but it will be handled in more object oriented way in this second half). For the event keeps happening when you are going to the same direction, there are two ways to fix. The one is creating some margin so the event won't happen again until player moves certain amount of pixels from where the event happened. This will be implemented when we add stairs in the future. The second one is making the event one time only so each event has boolean value and check if the event has already happened in the past or not. For the second method, you'll probably want to handle it by creating an event tile class. Maybe I will make a video for this.
I created a method to take in a direction and move the player backwards if they step on a pit. You could also create some sort of timer where the player is invincible for a second or so after taking damage
hello Mr. Ryisnow i follow your lesson. in part 19 I found an error. where the application runs but when it will "healing" in water. "enter" doesn't work. Please help
Hi, can you help me with this moment at 11:35, when I try to walk, a window immediately appears that I fell into a hole - a dialog box, and each press of the w button opens a window, but in fact it should have worked on a certain place, but immediately after pressing w a window appears, how can I fix this, I didn’t write the code after 11:35
hi, is it normal if after falling into the pit (min 11:45 of the video), I can't move away like you did? Even if I press enter the message "You fall into a pit" doesn't disappear :/
my code somehow messed up so now every UI element goes super fast. Like for example, when I walk over the event trigger that takes away half a heart... mine takes away all three. It also skims every sentence with the NPC if I walk while interacting with it. Edit: I figured out what was wrong. In "GamePanel", the "gameState == dialogueState" was set to "player.update()" for some reason
Love this im totaly hooked creating this game! Really fun and a lot of learning! now i have not watched all the episodes but i wonder, all these entity, player and object collition where you check the intersect isnt these possible to turn in to a method instead? or is it to many different values being handle to achieve this?
I am having this key issue. Whenever I try to drink water, I have to press the W+Enter otherwise it doest work. Same problem with the npc, when i try to talk to the oldman, i have to press any direction key+enter to talk to him
I think i must be missing something, but why doesnt the pit event trigger continously? Its being check every frame, and as long as youre in the event collision, it should still trigger.
I’ve added another public void to not heal the player by checking if the player’s life is lower than its max life. If not then display a different dialogue saying that the player’s health is fine and don’t heal the player.
I need your help @RyiSnow , when i comment out the EventHandler class the game works as soon as i load the Eventhandler class from the GamePanel. The game never starts, ive tried debugging it. Seems like its stuck in a loop when loading the EventHandler.
my healing function is not working. i think the reason is water is a collision = true tile. when the character tries to reach to a healing water tile the collision is not letting character to touch the healing rectangle. so the hit function returns false. if i put the healing tile in a collision = false tile, then it works fine. how can i fix that ?
okay i fixed that, im not sure if this solution brings more problem in the future :) i guess it is a problem if the hit function is called for an object but not for a tile. My solution is : when the hit function is working on a collision = true tile , i expanded the rectangle's area. So the collision is still happening but now the character can reach the healing area. here is the code : if anyone can see a bug here pls inform me.. int tileNum = gp.tileM.mapTileNum[eventCol][eventRow]; if(gp.tileM.tile[tileNum].collision == false) { gp.player.solidArea.x += gp.player.worldX; gp.player.solidArea.y += gp.player.worldY; eventRect.x += eventCol*gp.tileSize; eventRect.y += eventRow*gp.tileSize; }else { gp.player.solidArea.x += gp.player.worldX; gp.player.solidArea.y += gp.player.worldY; eventRect.x = -8 ; eventRect.x += eventCol*gp.tileSize; eventRect.y = -8; eventRect.y += eventRow*gp.tileSize; eventRect.width = 64; eventRect.height = 64;
Hi, when I try to make the event happen, my hit is always true because I don't have time to move my character away from the event emplacement so the event is constantly happening. Do you have a solution ? I also think I have the same problem for dialogues.
@@RyiSnow I mean if I try to dialogue with the NPC just by hitting him (without using keyPressed) it works. But then I use the enter key to quit dialogue and the game instantly gets back to dialogueState because I'm still hitting the NPC and I don't have time to move away from him before the next loop. And it seems that I have the same kind of problem with events
Can you make a multi-level system? Example: The Player collides with a specific Tile and hes taken into a different level and if he collides with another Tile he returns to the previous level
Hi RyiSnow! Not sure if you are still replying to comments on these videos, but I want to thank you for creating a series that is in depth, very helpful and a great learning material. You claim to be a mediocre programmer but I think everyone here including myself would definitely beg to differ. Anyways, I was hoping to have some help with an issue or two i am having. I am having some issues with my event handler, specifically, the healing pool event isn't working at all (doesn't read e(i used e instead of enter) being pressed) and won't show any dialogue. My damage pit, however works TOO well. It will work as I walk into it, showing the dialogue, but then I will have to press e and move left multiple times to get out , as if i am stuck. This causes my player to lose 1 & a half hearts. I saw yours allows you to just press enter and walk out and then walk right back in, but mine won't do that. please help! I will send my code if need be. Although my EventHandler class I THINK is exactly the same😅
If he doesnt respond, try asking chat gpt. its a cheap way to see if it can sniff out basic coding errors, if not there are tons of subs on reddit that can help. I coded a dodgeroll just for fun and learned how to do it with Chatgpt. its not the most reliable, but it can help tanslate some of the things and catch a missing { or capitalized letter where it neednt be. Hope you figured it out!
I am having trouble with the events and can't seem to get them to work. The event rectangle does not seem to stay in the same place, rather it has a fixed location on the screen and moves whenever the character moves. Anyone know how to fix this?
@@BrimstoneMwG ok broski. i did almost the whole series last december then i lost motivation so i stopped then i started again a few months later then i stopped again then last week i accidentally cleared my entire drive so i kinda lost everything. i know you wont believe this but its true.
@@RyiSnow oh neat. Question: I’m getting black lines when I move up or left in proportion to the speed and can’t figure out why. Any thoughts? It’s fine when I don’t move or move down or to the right
Does anyone know why is this Event thing necessary? Wouldn't it be easier to just make an object with no collision that makes the same thing? Or even using tiles instead of objects? Couldnt you make a pit tile and check if the player is on it with the checkTile method we already did in the CollisionChecker class?
We're basically handling it by making objects with no collision (EventRect) here. If what you mean is creating a class for each event, you'll need to create many classes as your game becomes larger (if the game has 100 events, you'll have 100 classes). It works but I thought handling it in a single class is more convenient so you don't need to search & open the class every time you adjust its coordinates or other parameters. As for handling it with the CollisionChecker, the tile basically becomes a collision tile so you cannot step on or walk through it (like hitting an invisible NPC). That said the method shown in this video is not the only way so feel free to try your own idea and improve it. Maybe you can come up with something better :)
This is good series but it would be better if you tried using more proper java. For example, not making every value public and having methods to either get or set some values. Or for GameStates and Directions instead of having Strings and Integers use Enums.
This is not a Java tutorial. Its a game dev tutorial which happens to be done in Java. But if you think you can do better, by all means, show us your free tutorial videos. I'd love to learn some more proper Java as it were.
@@AlexanderHL1919 As someone teaching in java code, no matter what that is, you MUST follow the SOLID principle, you MUST very well know design patterns and OOP very extensively. You saying "please provide us with your own tutorials" doesn't justify the fact that the tutorial is badly written. There shouldn't be any bad tutorials as there are loads nowadays and they are the reason new developers struggle to get better. Me making a bad tutorial wouldn't justify my first claim that this tutorial is badly written. Let people that ACTUALLY know how to write OOP do the tutorials. Let's not teach others bad practices just because you feel excited about making tutorials.
@ΚΥΡΙΑΚΟΣΓΕΩΡΓΑΝΤΗΣ-υ4δ his Java is fine. Also, It's for a game; I'm a SWE and work with Java every day, his practices are perfectly fine for his purpose. When you get better, you'll realize it's not about rigorous adherence to policies, and more about doing what you can to make things work 🙂
I am facing a problem where the code is not even entering if(gp.player.solidArea.intersects(eventRect)) part [I figured the the if statement was not being accessed by debugging] so do you have any idea why this could be happening? Update: So for some reason the event appears a tile diagonally bottom right to the mentioned coordinates, Why does this happen?
This is the best series. Doesn’t matter whether you want to have a career in gamedev or not. It’s perfect for learning how to program in general.
THE BEST Java Game-Dev on youtube, thanks for the videos man!
Had little time to do anything today. Life has been hard but this series is the best thing to come home to
Thank you! Please continue with lessons!
Thank you for the amazing video.
Will you show how to add events to objects too? Also, when the player keeps walking through the pit they constantly take damage and get message, can we make it so event only happens if they leave and go back through the pit?
We will add object reactions eventually (we've already done it in the first half but it will be handled in more object oriented way in this second half). For the event keeps happening when you are going to the same direction, there are two ways to fix. The one is creating some margin so the event won't happen again until player moves certain amount of pixels from where the event happened. This will be implemented when we add stairs in the future. The second one is making the event one time only so each event has boolean value and check if the event has already happened in the past or not. For the second method, you'll probably want to handle it by creating an event tile class. Maybe I will make a video for this.
I created a method to take in a direction and move the player backwards if they step on a pit.
You could also create some sort of timer where the player is invincible for a second or so after taking damage
hello Mr. Ryisnow
i follow your lesson.
in part 19 I found an error. where the application runs but when it will "healing" in water. "enter" doesn't work.
Please help
Hi, can you help me with this moment at 11:35, when I try to walk, a window immediately appears that I fell into a hole - a dialog box, and each press of the w button opens a window, but in fact it should have worked on a certain place, but immediately after pressing w a window appears, how can I fix this, I didn’t write the code after 11:35
hi, is it normal if after falling into the pit (min 11:45 of the video), I can't move away like you did? Even if I press enter the message "You fall into a pit" doesn't disappear :/
Can you close the window when you talk to an NPC?
@@RyiSnow Yes
May I see your KeyHandler class?
@@RyiSnow Here: package main;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class KeyHandler implements KeyListener{
public boolean enterPressed, upPressed, downPressed, leftPressed, rightPressed;
GamePanel gp;
public KeyHandler(GamePanel gp) {
this.gp = gp;
}
@Override
public void keyPressed(KeyEvent evt) {
int code = evt.getKeyCode();
//game state
if (gp.gameState == gp.Play) {
if(code == KeyEvent.VK_Z) {
upPressed = true;
}
if(code == KeyEvent.VK_S) {
downPressed = true;
}
if(code == KeyEvent.VK_Q) {
leftPressed = true;
}
if(code == KeyEvent.VK_D) {
rightPressed = true;
}
if(code == KeyEvent.VK_P) {
gp.gameState = gp.pauseState;
}
}
if(code == KeyEvent.VK_ENTER) {
enterPressed = true;
}
else if (gp.ecranEtat == gp.pauseState) {
if(code == KeyEvent.VK_P) {
gp.gameState = gp.Play;
}
}
else if (gp.gameState == gp.Dialogue) {
if(code == KeyEvent.VK_ENTER) {
gp.gameState = gp.Play;
}
}
}
@Override
public void keyReleased(KeyEvent evt) {
int code = evt.getKeyCode();
if(code == KeyEvent.VK_Z) {
upPressed = false;
}
if(code == KeyEvent.VK_S) {
downPressed = false;
}
if(code == KeyEvent.VK_Q) {
leftPressed = false;
}
if(code == KeyEvent.VK_D) {
rightPressed = false;
}
}
}
Are you sure you can quit NPC dialogues by pressing Enter? I tested your code but NPC dialogue window doesn't close even if I press enter.
my code somehow messed up so now every UI element goes super fast. Like for example, when I walk over the event trigger that takes away half a heart... mine takes away all three. It also skims every sentence with the NPC if I walk while interacting with it.
Edit: I figured out what was wrong. In "GamePanel", the "gameState == dialogueState" was set to "player.update()" for some reason
not sure if it would cause issues down the line in this tutorial but i put a release key check for enter in the keyhandler to avoid errors like that.
Love this im totaly hooked creating this game! Really fun and a lot of learning!
now i have not watched all the episodes but i wonder, all these entity, player and object collition where you check the intersect isnt these possible to turn in to a method instead? or is it to many different values being handle to achieve this?
I am having this key issue. Whenever I try to drink water, I have to press the W+Enter otherwise it doest work. Same problem with the npc, when i try to talk to the oldman, i have to press any direction key+enter to talk to him
Yes, that was a bug and has been addressed at the start of Part 23.
@@RyiSnow oh thank you very much☺️ Your tutorials are very helpful. I prefer this more than using game engines 👌
My question might be trivial, but could you tell me which part of this script ensures that the tile event isn't triggered continuously?
I think i must be missing something, but why doesnt the pit event trigger continously? Its being check every frame, and as long as youre in the event collision, it should still trigger.
I’ve added another public void to not heal the player by checking if the player’s life is lower than its max life. If not then display a different dialogue saying that the player’s health is fine and don’t heal the player.
I need your help @RyiSnow , when i comment out the EventHandler class the game works as soon as i load the Eventhandler class from the GamePanel. The game never starts, ive tried debugging it. Seems like its stuck in a loop when loading the EventHandler.
my healing function is not working. i think the reason is water is a collision = true tile. when the character tries to reach to a healing water tile the collision is not letting character to touch the healing rectangle. so the hit function returns false. if i put the healing tile in a collision = false tile, then it works fine. how can i fix that ?
okay i fixed that, im not sure if this solution brings more problem in the future :) i guess it is a problem if the hit function is called for an object but not for a tile.
My solution is : when the hit function is working on a collision = true tile , i expanded the rectangle's area. So the collision is still happening but now the character can reach the healing area. here is the code : if anyone can see a bug here pls inform me..
int tileNum = gp.tileM.mapTileNum[eventCol][eventRow];
if(gp.tileM.tile[tileNum].collision == false) {
gp.player.solidArea.x += gp.player.worldX;
gp.player.solidArea.y += gp.player.worldY;
eventRect.x += eventCol*gp.tileSize;
eventRect.y += eventRow*gp.tileSize;
}else {
gp.player.solidArea.x += gp.player.worldX;
gp.player.solidArea.y += gp.player.worldY;
eventRect.x = -8 ;
eventRect.x += eventCol*gp.tileSize;
eventRect.y = -8;
eventRect.y += eventRow*gp.tileSize;
eventRect.width = 64;
eventRect.height = 64;
}
Great videos!
Hi, when I try to make the event happen, my hit is always true because I don't have time to move my character away from the event emplacement so the event is constantly happening. Do you have a solution ? I also think I have the same problem for dialogues.
Maybe you forgot to change the enterPressed to false?
@@RyiSnow I mean if I try to dialogue with the NPC just by hitting him (without using keyPressed) it works. But then I use the enter key to quit dialogue and the game instantly gets back to dialogueState because I'm still hitting the NPC and I don't have time to move away from him before the next loop. And it seems that I have the same kind of problem with events
Yeah, so did you add the line: enterPressed = false after checking everything like we did in the video?
Okay I'm sorry I'm going to check my code and the video again I probably made a mistake somewhere
@@cedrichuynh9752 No worries!
i have done al the things i eventHandler, nothing happend (what can i have done wrong)
same issue here idk
@@Rebigex My fix was to set the rectangle to 96, imo 2 is way way too small
Thank you!
Can you make a multi-level system? Example: The Player collides with a specific Tile and hes taken into a different level and if he collides with another Tile he returns to the previous level
It will be featured when we implement a dungeon level in the later part of the series :)
Also, where are the "right" and "up" being called from?
Sorry this may be a silly q!
Hi RyiSnow! Not sure if you are still replying to comments on these videos, but I want to thank you for creating a series that is in depth, very helpful and a great learning material. You claim to be a mediocre programmer but I think everyone here including myself would definitely beg to differ. Anyways, I was hoping to have some help with an issue or two i am having. I am having some issues with my event handler, specifically, the healing pool event isn't working at all (doesn't read e(i used e instead of enter) being pressed) and won't show any dialogue. My damage pit, however works TOO well. It will work as I walk into it, showing the dialogue, but then I will have to press e and move left multiple times to get out , as if i am stuck. This causes my player to lose 1 & a half hearts. I saw yours allows you to just press enter and walk out and then walk right back in, but mine won't do that. please help! I will send my code if need be. Although my EventHandler class I THINK is exactly the same😅
If he doesnt respond, try asking chat gpt. its a cheap way to see if it can sniff out basic coding errors, if not there are tons of subs on reddit that can help. I coded a dodgeroll just for fun and learned how to do it with Chatgpt. its not the most reliable, but it can help tanslate some of the things and catch a missing { or capitalized letter where it neednt be. Hope you figured it out!
I am having trouble with the events and can't seem to get them to work. The event rectangle does not seem to stay in the same place, rather it has a fixed location on the screen and moves whenever the character moves. Anyone know how to fix this?
Do you fix it , if you can please tell me how ?
when i press key for closing dialoguebubble, when i step on fallingPit, i cannot close it
can anyone help?
Amazing series.
Could you please upload the entire and updated code on a drive pls?
That could be awesome. Thank you so much for the series.
blud what 💀💀💀💀💀 just type it out 😂😂😂😂😂😂
@@BrimstoneMwG ok broski. i did almost the whole series last december then i lost motivation so i stopped then i started again a few months later then i stopped again then last week i accidentally cleared my entire drive so i kinda lost everything. i know you wont believe this but its true.
Loving it so far. Do you think this would scale OK for something as big as a Dragon Quest NES game?
Actually this has a higher resolution than the NES Dragon Quest which is 256x240 :P
@@RyiSnow oh neat. Question: I’m getting black lines when I move up or left in proportion to the speed and can’t figure out why. Any thoughts?
It’s fine when I don’t move or move down or to the right
amazing amazing amazing amazing
How can we do it for multiple directions not only right?
Thanks in advance!
just type "any"
Thanks!
LOL I were teleported IN the npc so i couldn't escape from him XD
Haha you can check the current NPC position and adjust the position to avoid that.
Please help I can not get events to work.
package main;
import java.awt.Event;
import java.awt.Rectangle;
public class EventHandler {
GamePanel gp;
Rectangle eventRect;
int eventRectDefaultX, eventRectDefaultY;
public EventHandler(GamePanel gp) {
this.gp = gp;
eventRect = new Rectangle();
eventRect.x = 8;
eventRect.y = 8;
eventRect.width = 8;
eventRect.height = 8;
eventRectDefaultX = eventRect.x;
eventRectDefaultY = eventRect.y;
}
public void checkEvent() {
if(hit(24,16,"right") == true) {
damagePit(gp.dialougeState);
}
if(hit(24,16,"up") == true) {
damagePit(gp.dialougeState);
}
}
public boolean hit(int eventCol, int eventRow, String reqDirection) {
boolean hit = false;
gp.player.soildArea.x = gp.player.worldX + gp.player.soildArea.x;
gp.player.soildArea.y = gp.player.worldY + gp.player.soildArea.y;
eventRect.x = eventCol*gp.tileSize + eventRect.x;
eventRect.y = eventRow*gp.tileSize + eventRect.y;
if(gp.player.soildArea.intersects(eventRect)) {
if(gp.player.direction.contentEquals(reqDirection) || reqDirection.contentEquals("any")) {
hit = true;
}
}
gp.player.soildArea.x = gp.player.soildAreaDefaultX;
gp.player.soildArea.y = gp.player.soildAreaDefaultY;
eventRect.x = eventRectDefaultX;
eventRect.y = eventRectDefaultY;
return hit;
}
public void damagePit(int gameState) {
gp.gameState = gameState;
gp.ui.currentDialouge = "You Fell Into A Pit, Damn It!!";
gp.player.life -= 1;
}
}
redo
package main;
import java.awt.Event;
import java.awt.Rectangle;
public class EventHandler {
GamePanel gp;
Rectangle eventRect;
int eventRectDefaultX, eventRectDefaultY;
public EventHandler(GamePanel gp) {
this.gp = gp;
eventRect = new Rectangle();
eventRect.x = 23;
eventRect.y = 23;
eventRect.width = 4;
eventRect.height = 4;
eventRectDefaultX = eventRect.x;
eventRectDefaultY = eventRect.y;
}
public void checkEvent() {
if(hit(27,16,"right") == true) {damagePit(gp.dialougeState);}
}
public boolean hit(int eventCol, int eventRow, String reqDirection) {
boolean hit = false;
gp.player.soildArea.x = gp.player.worldX + gp.player.soildArea.x;
gp.player.soildArea.x = gp.player.worldY + gp.player.soildArea.y;
eventRect.x = eventCol*gp.tileSize + eventRect.x;
eventRect.y = eventRow*gp.tileSize + eventRect.y;
if(gp.player.soildArea.intersects(eventRect)) {
if(gp.player.direction.contentEquals(reqDirection) || reqDirection.contentEquals("any")) {
hit = true;
}
}
gp.player.soildArea.x = gp.player.soildAreaDefaultX;
gp.player.soildArea.y = gp.player.soildAreaDefaultY;
eventRect.x = eventRectDefaultX;
eventRect.y = eventRectDefaultY;
return hit;
}
public void damagePit(int gameState) {
gp.gameState = gameState;
gp.ui.currentDialouge = "You fall into a pit!";
gp.player.life -= 1;
}
}
@@nicholasbrooks7349 holy it works now thanks man, you're a savior
🥰🥰🥰
Does anyone know why is this Event thing necessary? Wouldn't it be easier to just make an object with no collision that makes the same thing? Or even using tiles instead of objects? Couldnt you make a pit tile and check if the player is on it with the checkTile method we already did in the CollisionChecker class?
We're basically handling it by making objects with no collision (EventRect) here. If what you mean is creating a class for each event, you'll need to create many classes as your game becomes larger (if the game has 100 events, you'll have 100 classes). It works but I thought handling it in a single class is more convenient so you don't need to search & open the class every time you adjust its coordinates or other parameters.
As for handling it with the CollisionChecker, the tile basically becomes a collision tile so you cannot step on or walk through it (like hitting an invisible NPC).
That said the method shown in this video is not the only way so feel free to try your own idea and improve it. Maybe you can come up with something better :)
hello sir, please i need your help in little thing in my college project
This is good series but it would be better if you tried using more proper java. For example, not making every value public and having methods to either get or set some values. Or for GameStates and Directions instead of having Strings and Integers use Enums.
This is not a Java tutorial. Its a game dev tutorial which happens to be done in Java. But if you think you can do better, by all means, show us your free tutorial videos. I'd love to learn some more proper Java as it were.
@@AlexanderHL1919 As someone teaching in java code, no matter what that is, you MUST follow the SOLID principle, you MUST very well know design patterns and OOP very extensively. You saying "please provide us with your own tutorials" doesn't justify the fact that the tutorial is badly written. There shouldn't be any bad tutorials as there are loads nowadays and they are the reason new developers struggle to get better. Me making a bad tutorial wouldn't justify my first claim that this tutorial is badly written. Let people that ACTUALLY know how to write OOP do the tutorials. Let's not teach others bad practices just because you feel excited about making tutorials.
@@ΚΥΡΙΑΚΟΣΓΕΩΡΓΑΝΤΗΣ-υ4δ Such cringe. Imagine being so entitled that you'd complain about a free service. You're seriously deranged.
@ΚΥΡΙΑΚΟΣΓΕΩΡΓΑΝΤΗΣ-υ4δ his Java is fine. Also, It's for a game; I'm a SWE and work with Java every day, his practices are perfectly fine for his purpose. When you get better, you'll realize it's not about rigorous adherence to policies, and more about doing what you can to make things work 🙂
I am facing a problem where the code is not even entering if(gp.player.solidArea.intersects(eventRect)) part [I figured the the if statement was not being accessed by debugging] so do you have any idea why this could be happening?
Update: So for some reason the event appears a tile diagonally bottom right to the mentioned coordinates, Why does this happen?
Thanks!