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

2020/10/11

How can i spawn more and faster?

ShortScream ShortScream

2020/10/11

#
Can someone tell me how i can spawn more "SpaceInvadersGestein" in less time? I'm new to programming and a friend of mine gave me his code but i don't really understand it: private int timer = 100; private int TimerSpaceInvadersGestein = 100; public boolean StartSpaceInvadersGestein = false; public int cache = 100; public int red = 100; public void act() { int randSpawn = Greenfoot.getRandomNumber(cache); if(randSpawn >= 1 && randSpawn < 20) { cache = 350; addObject(new SpaceInvadersGestein(), getWidth(),Greenfoot.getRandomNumber(getHeight() - 100) + 50); if(red < 200) { red += 100; } } else { cache = cache - red; if(cache <= 0) { cache = 3500; addObject(new SpaceInvadersGestein(), getWidth(), getHeight()); if(red < 200) { red += 200; } } } } }
RcCookie RcCookie

2020/10/11

#
You can adjust the propability of objects spawning in line 10 by increasing 20, and you can decrease the maximum time between spawns in line 37 (what cache is set to)
You need to login to post a reply.