Post Reply  Post Thread 
Some Weird Problem I found while coding this game in java
Author Message
Nate
Newbie
*


Posts: 3
Group: Registered
Joined: Jul 2010
Status: Offline
Reputation: 0
Last seen online:
06-09-2010, 06:53 AM
Post: #1
Some Weird Problem I found while coding this game in java

Well Recently I made this game in java and I wanted to make it if a bullet intersect with a asteroid, it adds to a double named damage. Once damage is equal to ten, the asteroid will go away. Here's how I tried to do it:

Code:
if(enemy.hitbox.intersects(bullet.hitbox3))
            {
                bullet.hit = true;
                enemy.damage +=1;
                System.out.println("("+enemy.damage+")");
            }


Well the asteroid disappearing works, But then I noticed it took only 1 shot instead of ten to get rid of it. So then I added the line at the end to check if there was something wrong. And Apparently instead of only adding 1 to damage once, it keeps adding 1 in a loop until it hits ten. The asteroids I added were just a test enemy, and I can't really make more challenging enemy's if all of the take one hit to kill. Any help will be great, I don't want a fix I just want to know why its happening.

31-07-2010 06:32 AM
Find all posts by this user Quote this message in a reply
MetroidFan2002
Senior Member
****


Posts: 611
Group: Registered
Joined: Jul 2007
Status: Offline
Reputation: 0
Last seen online:
06-09-2010, 11:25 AM
Post: #2
RE: Some Weird Problem I found while coding this game in java

Where did you place this? GTGE wants you to place this inside your update(long) method, by the way.

Could it be that you didn't move the enemy or the bullet at all? If that's the case, when update(long) fires, it keeps updating the enemy damage because it hasn't moved at all - because they still intersect (if both haven't moved, and they both intersect, then you'll get the hit)

31-07-2010 08:07 PM
Find all posts by this user Quote this message in a reply
Nate
Newbie
*


Posts: 3
Group: Registered
Joined: Jul 2010
Status: Offline
Reputation: 0
Last seen online:
06-09-2010, 06:53 AM
Post: #3
RE: Some Weird Problem I found while coding this game in java

Oh I see. I made it so that when when it hits the bullets are supposed to stop drawing themselves, but I think the hitbox remains there. Well I think I got a solution worked out but for now I'll just get rid of the code and make it so the bullet passes through.

04-08-2010 08:01 AM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Java Ebooks freggreen 5 951 05-09-2010 06:10 PM
Last Post: Deen
  What are implicit objects? List them? in Java carlcuper 1 408 12-08-2010 02:35 PM
Last Post: jsfmills
  Java problem Adydsauza 2 450 09-08-2010 04:55 PM
Last Post: franzharare
  TUTORIAL: Java Basic Fundamental cimot 3 4,871 27-07-2010 05:14 PM
Last Post: agienthea
  java addneybain 3 580 24-07-2010 01:10 AM
Last Post: princecheck13

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: