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

2013/10/15

HELP WITH BULLETS!

Prish950 Prish950

2013/10/15

#
I want to make a zombie survival Game and i want an easy way to spawn bullets if Key is down "a" how can i do this ??
Prish950 Prish950

2013/10/15

#
and the bullets have to spawn on the coordinates where the Gamer was when i pressed a :D i write now: if(Greenfoot.KeyIsDown("a") { addObject(new Bullet()); } but i need teh coordinates :) Thanks for help :)
gdwd3 gdwd3

2013/10/15

#
Hi where you are adding the bullet you need to add getWord() Example below:
if(Greenfoot.isKeyDown("a"))
{
    getWorld().addObject(new Bullet(), LocationX, LocationY);
}
replace the Locations with the position you want your bullet to be at or if you want it to be random then use the: Greenfoot.getRandomNumber(Max);
danpost danpost

2013/10/15

#
@gdwd3, it appears that the code is being placed in a sub-class of World. What is needed is a reference to the Gamer object; whether it be in an instance field that is set when the Gamer object is created or obtained through method calls when needed.
danpost danpost

2013/10/15

#
The 'gamer' field below should set to your Gamer object with this code (provided one is in the world):
Actor gamer = (Actor)getObjects(Gamer.class).get(0);
You need to login to post a reply.