This site requires JavaScript, please enable it in your browser!
Greenfoot back
alexanderwrobinson
alexanderwrobinson wrote ...

2016/4/20

Shooting; setting rotation of bullet?

alexanderwrobinson alexanderwrobinson

2016/4/20

#
Hey, I'm making a game where you walk around and shoot the zombies, I've made a game similar to this however did not need to shoot the zombies so I already have the base code. The part where I'm stuck on is getting the bullets to go in the right direction based off of the "Man's" rotation but this doesn't seem to be working. If anyone could help, that would be appreciated :)
danpost danpost

2016/4/20

#
Since it is the Man object who will be "pointing" the gun, code it in the class of the man when creating the bullet:
Bullet bullet = new Bullet();
bullet.setRotation(getRotation());
alexanderwrobinson alexanderwrobinson

2016/4/20

#
Thanks! this was exactly what I need, how would I now put a delay on each bullet shot, such as shoot a bullet wait a second shoot another etc. ?
danpost danpost

2016/4/20

#
alexanderwrobinson wrote...
Thanks! this was exactly what I need, how would I now put a delay on each bullet shot, such as shoot a bullet wait a second shoot another etc. ?
Add an instance int field to be used as a timer (count act cycles to track the sense of time passage). If its value is zero, the actor can fire a bullet. When a bullet is fired, set the value of the timer to, say -- '50'. Add a line in the act method that decreases the value of the timer if its value is greater than zero.
You need to login to post a reply.