• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to create bullet in java

 
sudde gameeef
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i create a player and i want him to shoot bullet. i understand the logic but i need some help with it. my bullet will just be rect in paint method.

logic:
create bullet class
store in arraylist
print in paint method

in bullet class i set the variables:
Bullet.java









this is the code where i need help. how to print bullets from arraylist.
 
Tony Docherty
Bartender
Posts: 2953
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what exactly is your problem?
One thing I have noticed is you haven't shown any code to move the x,y position of the bullet every n milliseconds. BTW to do this your bullet class will need to know what direction the bullet is traveling in unless you can only fire in one direction. You may also want to record velocity and/or distance traveled unless your bullets go forever at the same speed.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never use == true and == false.
Why is the List inside the Bullet class? Do bullets hold information about other bullets in real life? I think that List belongs inside a different class, maybe Magazine or Bandolier.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic