This week's book giveaway is in the Features new in Java 9 forum.
We're giving away four copies of Java 9 Revealed and have Kishori Sharan on-line!
See this thread for details.
Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to create bullet in java  RSS feed

 
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
Saloon Keeper
Posts: 3214
78
  • 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: 54030
130
  • 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
Boost this thread!