I need help with how to code a gun in GreenFoot. Currently, here is my code:
For the bullets class:
for the pistolBullet class, which extends the bullets class (the super(15) sets the speed to 15):
and, for how I fire it (sigma is my main character):
the problem is I want to be able to have multiple bullets on the screen at once, but it doesn't work. please help!!!!!
public boolean check() { return (isAtEdge() || isTouching(armory.class)); } public void turn() { MouseInfo info = Greenfoot.getMouseInfo(); if (info != null) turnTowards(info.getX(), info.getY()); } public void fire() { if(!turned) { turn(); turned = true; } if(fired) { move(speed); if(check()) { getWorld().removeObject(this); fired = false; } } }
public pistolBullet() { super(15); } public void act() { if((pistol.has || AK.has) && sigma.noPbullets > 0) { fire(); } }
else if(pistol.has) { if (Greenfoot.mousePressed(null) && sigma.noPbullets > 0 && guns.cooldown > 50) { pistolBullet p = new pistolBullet(); addObject(p, sigma.X, sigma.Y); p.setFired(true); sigma.noPbullets--; guns.cooldown = 0; } }