SuperIntendant Posted September 22, 2012 Report Share Posted September 22, 2012 Okay, so background, I'm making a Tron game in Java and ever since I added in the second bike the instant the game starts both bikes receive a signal that they have intersected the opposing players track and disappear. This is the getHit method from the square class (the things that change colors when people drive over them and stuff). It should be all the code you need to see: public boolean getHit(Rectangle d, int player){ if (!touch && rect.intersects(d) && owner != 3){ return true; } else if (rect.intersects(d)) { touch = true; if (player == 0){ c = Color.BLUE; owner = player; } else { c = Color.RED; owner = player; } return false; } else { touch = false; return false; } } I'll break down what it should do in the spawning situation if it was working properly. First it would go through the first if statement, since at this point touch is set to false that would trigger, then since the rectangles are intersecting that would trigger as well, but when it gets to the last one since the square is currently neutral (owner = 3) it wouldn't trigger. So now it goes to the else if which would declare the current player the owner, change the color, say that the square is being touched, and return false (false means that the bike is okay, true triggers a losing condition). All would be okay. The next time it would go through it would do the same thing since even though the squares are no longer neutral and the bike is in contact with them, touch is now true since it touched the squares the first time it went through. So, any ideas why the above doesn't happen and it returns true? I can post the Eclipse project file if necessary. EDIT: It ruined my perfect indention 2 Quote Link to comment Share on other sites More sharing options...
MCPO Mayh3m Posted September 22, 2012 Report Share Posted September 22, 2012 hmmm... give me some time to look it over.. however I am sure by the time I break it down Twinreaper will have already formed a response. Quote Link to comment Share on other sites More sharing options...
Twinreaper Posted September 22, 2012 Report Share Posted September 22, 2012 I am concerned about your player code. Player should never be defined by just "player" for both. You should be breaking it down to player1 and player 2 style naming. Otherwise the game will think both players are the same player. If your just making a player vs pc style game, then you should name the second player AI or something like that. As for the returning true part, I can't see why it would. You seem to have clearly defined the return flag to be false for touch towards the end. There must be something else that is overriding it somewhere. Do you have another set of variables inside another code block that may have a renegade section of "if" variables? Edit real quick here, I just noticed something odd. It looks like the section of code listed as player=0...it looks like the equal sign is a bit stretched compared to a standard one. Almost as if you have 2 equal symbols before the 0. this may cause an exception with any player references since the game cannot localize the specific code that is not right. As far as I can recall.....the game will nullify all code past the point of where the code cannot be read correctly...which means this particular instance is completely missing any false declarations and only reading the true one. 1 Quote Link to comment Share on other sites More sharing options...
The Director Posted September 22, 2012 Report Share Posted September 22, 2012 public boolean getHit(Rectangle d, int player){ if (!touch && rect.intersects(d) && owner != 3){ return true; } else if (rect.intersects(d)) { touch = true; if (player = 0){ c = Color.BLUE; owner = player; } else { c = Color.RED; owner = player; } return false; } else { touch = false; return false; } } This is what Twin just said to use. lol And yes, there was an extra =. Quote Link to comment Share on other sites More sharing options...
SuperIntendant Posted September 22, 2012 Author Report Share Posted September 22, 2012 I am concerned about your player code. Player should never be defined by just "player" for both. You should be breaking it down to player1 and player 2 style naming. Otherwise the game will think both players are the same player. If your just making a player vs pc style game, then you should name the second player AI or something like that. As for the returning true part, I can't see why it would. You seem to have clearly defined the return flag to be false for touch towards the end. There must be something else that is overriding it somewhere. Do you have another set of variables inside another code block that may have a renegade section of "if" variables? Edit real quick here, I just noticed something odd. It looks like the section of code listed as player=0...it looks like the equal sign is a bit stretched compared to a standard one. Almost as if you have 2 equal symbols before the 0. this may cause an exception with any player references since the game cannot localize the specific code that is not right. As far as I can recall.....the game will nullify all code past the point of where the code cannot be read correctly...which means this particular instance is completely missing any false declarations and only reading the true one. The double "=" is Java's way of differing between declaring something equal to something else or checking to see if it's equal to the other thing. player == 0 is asking if player is equal to 0, player = 0 would be setting the value of player to 0. In regards to what you originally said, all this class does is manage small sections of the screen so there would be no real reason to define which player is which beyond an integer value. Both players are clearly defined in the main driver class as two separate instances of the player class. Quote Link to comment Share on other sites More sharing options...
Twinreaper Posted September 22, 2012 Report Share Posted September 22, 2012 While the players may be defined in a seperate class, when it comes to this class, it doesn't know which player is which...from what i can tell. When I look at the code, I see the color being defined as "player"...no matter which color it is, it gets defined as player..no seperation between player instances. Then again, it's been about 5 years since I touched anything Java.....now if it was a C# or Lua question...... Quote Link to comment Share on other sites More sharing options...
SuperIntendant Posted September 22, 2012 Author Report Share Posted September 22, 2012 Here's the complete project folder if anyone wants it: http://www.mediafire...6d0o3295po6fk8o It shouldn't matter if it knows who the player is, the only reason I send it any form of identification is so that it can figure out what color to change itself to. It's entire job is to see if the player that is sent to it is inside of it, and if so, to figure out if it is already owned by someone. EDIT: More detail, in the color part of the originally posted code, what it is doing is figuring out if it is player 1 (the integer that the method is receiving would be 0) or player 2 (the int would be either 1 or 2 depending on if it is controlled by a player or AI respectively). Quote Link to comment Share on other sites More sharing options...
Twinreaper Posted September 23, 2012 Report Share Posted September 23, 2012 Biggest question I have is.... Is this for fun or school? If it's for fun, then Java can be a fun side project to create stuff with. if it's for school, go more mainstream and use something that isn't complete crap..lol 3 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.