By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,653 Members | 1,419 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,653 IT Pros & Developers. It's quick & easy.

change bullets!

P: 59
i need some help with java. i am creating a game where i have a player and he shoot bullets. u can also change u types of bullet.
bullets are just fillOval. and change types of bullets is different colo.

i have created a class bullet. which just create one bullet.
than if player hit space bar. than create a bullet and store in arraylist.

Expand|Select|Wrap|Line Numbers
  1. if(space)
  2. {
  3.     bulletObject = new Bullet();    //create bullet
  4.     bulletStore.add(bulletObject);  //store in arraylist
  5. }
now to change bullets. i have create a variable call bulletName. if it has a value of 1 than its bullet type is 1. If it has value of 2 than its bullet type is 2.

if user hit 'f' key than change bullet type.
Expand|Select|Wrap|Line Numbers
  1. if(f)
  2. {
  3.     bulletName ++;  //go to next bullet type
  4. }
now to draw the bullets.
Expand|Select|Wrap|Line Numbers
  1. pubic void paint(Graphics g)
  2. {
  3.     if(bulletName == 1)
  4.         g.setColor(; 
  5.    if(bulletName == 2)
  6.         g.setColor(;
  7.     if(bulletName == 3)
  8.         g.setColor(;
  10.      g.fillOval(x,y,width,height);    
  11. }
The problem is that if user hit space bar than it will shoot one bullet. than if user hit 'f' key than it will change color of all bullets on screen.

i want it so that it doesnt change color of bullets on screen. it only change color of bullet that are about to get shoot.change
Apr 9 '13 #1
Share this Question
Share on Google+
1 Reply

P: 13,264
Difficult to say without seeing the structure of your code and the order of your events.
Apr 9 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.