Jump to content
  • Advertisement
Sign in to follow this  
gema9923

Shooting Bullet in JAVA

This topic is 4055 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am writing a shmup type game in java Here is the function to shoot 5 bullets from the player public Shot Shoot5Bullet() { for(int direction=0;direction<5;direction++){ Shot shot = new Shot(start_x, start_y,direction); } return shot; } However it output error with .\Player.java:39: cannot find symbol symbol : variable shot location: class Player return shot; Can anyone help me to fix the problem? thx :D

Share this post


Link to post
Share on other sites
Advertisement
Your 5 Shot instances are lost inside the scope of the foor loop.

You have to declare the shot variable outside of the loop.

Another but: You can't return 5 instances of the variable in a simple Shot type, you need to return an array.

Share this post


Link to post
Share on other sites
I like your code. Is
direction
some kind of angle modifier so that the shots emanate from the player in a fan shape? That's pretty nifty.

As Endurion said, the reason for the error is that when you try to return
shot
, the compiler can't find that variable because that variable no longer exists when you exit the for loop. Try this:


public Shot[] Shoot5Bullet()
{
Shot[] shots = new Shot[5];
for(int direction = 0; direction < 5; direction++)
shots[direction] = new Shot(start_x, start_y, direction);
return shots;
}


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!