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

2012/7/11

AirForce

1
2
3
4
SPower SPower

2012/7/14

#
To talk about erdelfs post about a more precise location setter, you're not really using exactX or exactY. You actually must add their getters:
public double getExactX()
{ return exactX; }

public double getExactY()
{ return exactY; }
or just remove them: they're not used anywhere except for in setLocation
KommandoFaust KommandoFaust

2012/7/15

#
Is there any other method than this,
if(Greenfoot.getRandomNumber(4) == 0) {  
        //call addObject method  
    }  
to let objects randomly appear? Won't give me an error, but the objects won't appear either. Or should I add a location to it, maybe this would do the trick?
erdelf erdelf

2012/7/15

#
well, try this for the random appearing
if(Greenfoot.getRandomNumber(10) == 5)
{
     int x = Greenfoot.getRandomNumber(getWidth());
     int y = Greenfoot.getRandomNumber(getHeight());
     addObject(new Dummy(), x, y); // change Dummy to your class
} 
if you have questions for this airforce game, check out my Scenario , it is the same kind of game so I think it should help you
KommandoFaust KommandoFaust

2012/7/15

#
Danke für diene Hilfe, bist echt ein Elf´!
KommandoFaust KommandoFaust

2012/7/15

#
One problem solved, more to add :) . Got huge amount of the objects appearing everywhere on the screen... but I need them to appear on the top edge, and can you set a limit to the objects, so that there isn't 100++ units at the same time on the screen?
MatheMagician MatheMagician

2012/7/15

#
if(getObjects(null).size() < 100)
        addObject(new Enemy(),Greenfoot.getRandomNumber(300)+100, 0);
danpost danpost

2012/7/15

#
To have them appear at the top edge of the screen, change erdelf's line 4 to
int y = 0;
or a moderately low number (so the objects are not half cut by the top edge of the screen).
SPower SPower

2012/7/15

#
To explain: the getObjects(null) returns a list of all the actors in the world. If it's size (the number of actors in it) is less than 100, a new Enemy objects is added.
danpost danpost

2012/7/15

#
There is also a World method 'numberOfObjects()' which returns the number of objects in the world.
KommandoFaust KommandoFaust

2012/7/15

#
Thank you all, it will do the trick.
You need to login to post a reply.
1
2
3
4