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

2012/8/4

Enemie code?

1
2
3
4
MatheMagician MatheMagician

2012/8/4

#
enemie class
CrazyGamer1122 CrazyGamer1122

2012/8/4

#
it still says "Method getObjectInRange in class greenfoot.Actor cannot be applied to given types;"
CrazyGamer1122 CrazyGamer1122

2012/8/4

#
im going to upload the game so far and you guys can download it to see what is wrong
SPower SPower

2012/8/4

#
Which exact line?
CrazyGamer1122 CrazyGamer1122

2012/8/4

#
public void act()
    {
        if(getObjectsInRange(100,false,Rocket.class).size() > 0)  
        {  
            List<Rocket> ships = getObjectsInRange(100,false,Rocket.class);  
            Actor thing = ships.get(0);  
            turnTowards(thing.getX(),thing.getY());  
        }  
        else   
        {  
            moveRandom();  
        } 

    }
    public void shoot()
    {
        enemieShot enemieshot = new enemieShot();
        getWorld(). addObject(enemieshot, getX(), getY());
        enemieShot.setRotation(-90);
    }
}

        
        
    
CrazyGamer1122 CrazyGamer1122

2012/8/4

#
the error is in line 3
SPower SPower

2012/8/4

#
change line 3 to:
if(getObjectsInRange(100, Rocket.class).size() > 0)
CrazyGamer1122 CrazyGamer1122

2012/8/4

#
now its the same error but on line 5.
SPower SPower

2012/8/4

#
change line 5:
List<Rocket> ships = getObjectsInRange(100,Rocket.class);
And a little optimisation, I would change line 3,4 and 5 to:
List<Rocket> ships = getObjectsInRange(100,Rocket.class);
if (!ships.isEmpty())
{
// ...
CrazyGamer1122 CrazyGamer1122

2012/8/4

#
one more thing.... can you post the getRandomNumber code for moving around? im really sorry i just dont remember it.
SPower SPower

2012/8/4

#
Moving around of the enemies? My Crabs on the beach scenario has some code, look at the Lobster class: http://www.greenfoot.org/scenarios/4742
CrazyGamer1122 CrazyGamer1122

2012/8/4

#
thanks.... ill post back if i need any more help.
CrazyGamer1122 CrazyGamer1122

2012/8/4

#
oh, by the way.... can i use the saver class from the game? ill give cred.
SPower SPower

2012/8/4

#
Yeah, sure (if you give credit, you can use all my open source things, except for when you can read from the doc you musn't).
CrazyGamer1122 CrazyGamer1122

2012/8/4

#
also, the atWorldEdge() method, can you give me the code to put into it.
There are more replies on the next page.
1
2
3
4