I need a little help with my little shooter. Whenever I press the space key in the Defender Class, a new weapon (should look like a ball) starts in Y-direction.
The Weapons (the ball) behave like this
The problem:
the weapon (ball) is not a single round ball, it is a row of several balls that are connected to each others. It does not look like a weapon.
I know it is difficult to explain, but I hope you understand the problem.
Thanks a lot
public class Defender extends Actor
{
public void act()
{
this.navigating();
}
public void navigating()
{
if(Greenfoot.isKeyDown("right"))
{
this.setLocation(this.getX() +5, this.getY());
}
if(Greenfoot.isKeyDown("left"))
{
this.setLocation(this.getX() - 5, this.getY());
}
if(Greenfoot.isKeyDown("space"))
{
this.getWorld().addObject(new Weapons(), this.getX(), this.getY() - 50);
}
}
}public Weapons()
{
GreenfootImage image = new GreenfootImage(20,20);
Color color = new Color(255, 0,0);
this.setImage(image);
this.getImage().setColor(color);
this.getImage().drawOval(0, 0, 20, 20);
this.getImage().fillOval(0, 0, 20, 20);
}
public void act()
{
this.setRotation(270);
this.move(10);
this.shooting();
this.vanishing();
}
public void shooting()
{
if(this.isTouching(Enemies.class))
{
Greenfoot.playSound("Explosion.wav");
this.removeTouching(Enemies.class);
this.getWorldOfType(MyWorld.class).getCounter().addScore();
}
}
public void vanishing()
{
if(this.isAtEdge())
{
this.getWorldOfType(MyWorld.class).removeObject(this);
}
}
}
