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

2013/5/17

Help for Rudi

Kartoffelbrot Kartoffelbrot

2013/5/17

#
If you want to be able to shoot, you need two classes. The class, who is the player, and who should be shoot. The other one should be the bullet or laser or whatever you want to shoot. Then you can use this method:
public void shoot()
{
Projectile bullet = new Projectile();
//Projectile has to be the class, which you shoot.
//bullet is only the name for it. You can name it "Peter" too.
getWorld().addObject(bullet, getX(), getY());
//here the bullet is set into the world
bullet.setRotation(getRotation);
//here the bullet is turned into the direction you are facing to
bullet.move(getImage().getWidth()/2+bullet.getImage().getWidth()/2);
//this is optional. It makes the bullet coming out at the front of the shooter
}
The act method of the shooter/player shoul be like this:
public void act()
{
if(Greenfoot.isKeyDown("space")) //or how the controls to shoot be like
{
shoot();
}
}
In the act method of the bullet, you have to write only: move(10) or how fast the bullet should be.
Kartoffelbrot Kartoffelbrot

2013/5/18

#
Any questions, Rudi?
GreenGoo GreenGoo

2013/5/18

#
Kartoffelbrot, thank you for the "bullet.move(getImage().getWidth()/2+bullet.getImage().getWidth()/2);" - I couldn't figure out what you meant when you told me what to do earlier.
Kartoffelbrot Kartoffelbrot

2013/5/18

#
No problem :) Is your Image from Men in Black 3?
GreenGoo GreenGoo

2013/5/18

#
My blobfish? It might be, I don't know.
You need to login to post a reply.