We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Code not working Properly
Pages: 1 2 
Code not working Properly (Read 1949 times)
Re: Code not working Properly
Reply #15 - Jul 5th, 2009, 12:47am
 
Well it 'works' but there are definitely still problems - I think the main one is the way you deal with the number of aliens and how you 'loop' them:

Code:
 if(timer.isFinished()) {
   alien[totalAlien]= new Alien();
   totalAlien++;
   if(totalAlien >= alien.length) {
totalAlien = 0;
   }
   timer.start();
 }


I think this approach is going to cause you lots of problems: for one thing when totalAlien is reset any aliens on screen when totalAlien >= alien.length are likely to just start disappearing.  You're handling a large number of aliens that are off screen which is really inefficient and will probably cause slowdown.  Also those aliens that have reachedBottom aren't removed so life reduces to 0 as soon as a single alien reaches the bottom.   I'm also getting an error when I 'start' the game - i.e. on mousePressed - which I suspect is a related problem.

A much better and more standard approach would be to reduce the number of aliens you create and take any alien that has reached the bottom and simply place it back above the top of the screen.  Since you have your reachedBottom method in place this would be very easy to do  - simply set the alien.y to something appropriate (and also shift x) -  and would resolve several issues.
Pages: 1 2