aspose file tools*
The moose likes Beginning Java and the fly likes how to create bullet in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to create bullet in java" Watch "how to create bullet in java" New topic
Author

how to create bullet in java

sudde gameeef
Greenhorn

Joined: Mar 21, 2013
Posts: 19
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

Joined: Aug 07, 2007
Posts: 2316
    
  49
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

Joined: Oct 13, 2005
Posts: 39409
    
  28
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.
 
Consider Paul's rocket mass heater.
 
subject: how to create bullet in java