Me. Again. Surprise. Like I haven't had to ask for help three other times for the same stupid game. If there was ever a doubt that technology hates me, I'll show them every single problem I've had on this scenario that has forced me to "phone a friend." This time, though, it's even more infuriating, because I don't even know which problem to start with. I've got a Shooter class that utilizes the following code:
}
}
}
The problem is that addObject, apparently, can't be referenced from a static context, because it's a non-static method. Furthermore, when I try to make a Bullet actor go away after it hits an opponent, Greenfoot says that it can't find the Bullet variable, even though Bullet is a class (or Actor). Here's the code I'm using:
Final question in this discussion: I've got three spawning locations for both mobs and weapon pickups (makes programming a first-person flash shooter much easier), but the actors LOVE to spawn on each other. How do I ensure that nothing spawns on top of something else?
public void act(){
if(Greenfoot.isKeyDown("space"))
{
timer = System.currentTimeMillis();//Time in ms
hasShot = true;
if(usingPistol)
{
if(bulletsShot == 1)
{
this.setImage(shootPistol);
Background.addObject(new Bullet(), this.getX(), this.getY());
//rest of code follows/*all previous code does NOT relate to the current problem*/
public void act()
if(this.isTouching(Bullet))
{
this.removeTouching(Bullet);
health--;
}
//rest of code followsboolean spriteOnLeft = false;
boolean spriteInMid = false;
boolean spriteOnRight = false; //All false because nothing spawns immediately
if(count >= 100)
{
int spriteSpawned = Greenfoot.getRandomNumber(6); //Decides what to spawn: some type of enemy or a weapon pickup
int spawnLocation = Greenfoot.getRandomNumber(3); //chooses one of the three locations to place said actor
if(spriteSpawned == 0) {
if(spawnLocation == 0 && spriteOnLeft == false)
{
this.addObject(new Grunt(), 125, 175);
spriteOnLeft = true;
}
else if(spawnLocation == 1 && spriteInMid == false)
{
this.addObject(new Grunt(), 300, 175);
spriteInMid = true;
}
else if(spawnLocation == 2 && spriteOnRight == false)
{
this.addObject(new Grunt(), 475, 175);
spriteOnRight = true;
}
}
else if(spriteSpawned == 1){
if(spawnLocation == 0 && spriteOnLeft == false)
{
this.addObject(new Grunt(), 125, 175);
spriteOnLeft = true;
}
else if(spawnLocation == 1 && spriteInMid == false)
{
this.addObject(new Grunt(), 300, 175);
spriteInMid = true;
}
else if(spawnLocation == 2 && spriteOnRight == false)
{
this.addObject(new Grunt(), 475, 175);
spriteOnRight = true;
}
}
else if (spriteSpawned == 2){
if(spawnLocation == 0 && spriteOnLeft == false)
{
this.addObject(new Grunt(), 125, 175);
spriteOnLeft = true;
}
else if(spawnLocation == 1 && spriteInMid == false)
{
this.addObject(new Grunt(), 300, 175);
spriteInMid = true;
}
else if(spawnLocation == 2 && spriteOnRight == false)
{
this.addObject(new Grunt(), 475, 175);
spriteOnRight = true;
}
}
else if (spriteSpawned == 3){
if(spawnLocation == 0 && spriteOnLeft == false)
{
this.addObject(new Grunt(), 125, 175);
spriteOnLeft = true;
}
else if(spawnLocation == 1 && spriteInMid == false)
{
this.addObject(new Grunt(), 300, 175);
spriteInMid = true;
}
else if(spawnLocation == 2 && spriteOnRight == false)
{
this.addObject(new Grunt(), 475, 175);
spriteOnRight = true;
}
}
else if(spriteSpawned == 4){
if(spawnLocation == 0 && spriteOnLeft == false)
{
this.addObject(new Grunt(), 125, 175);
spriteOnLeft = true;
}
else if(spawnLocation == 1 && spriteInMid == false)
{
this.addObject(new Grunt(), 300, 175);
spriteInMid = true;
}
else if(spawnLocation == 2 && spriteOnRight == false)
{
this.addObject(new Grunt(), 475, 175);
spriteOnRight = true;
}
}
else
{
if(spawnLocation == 0 && spriteOnLeft == false)
{
this.addObject(new Grunt(), 125, 175);
spriteOnLeft = true;
}
else if(spawnLocation == 1 && spriteInMid == false)
{
this.addObject(new Grunt(), 300, 175);
spriteInMid = true;
}
else if(spawnLocation == 2 && spriteOnRight == false)
{
this.addObject(new Grunt(), 475, 175);
spriteOnRight = true;
}
}
count = 0;
}

