View Single Post
Join Date: Feb 2008
Posts: 36
Reputation: CaffeineCoder is an unknown quantity at this point 
Solved Threads: 0
CaffeineCoder CaffeineCoder is offline Offline
Light Poster

Re: 2D Java Fireworks Explosion

 
0
  #7
Feb 15th, 2008
Forgive me if this is something obvious, but I'm still getting stuck on this. Right now the elements in the array don't seem to be initializing since I get NullPointerExceptions repeatedly in the loop. Does anyone see anything I'm missing? When I placed println statements within the code I could see that the initializations didn't work.

  1. int gravity, a, v, T, L, x, y;
  2. double valueA, valueB, dx, dy;
  3. int t;
  4. Random r = new Random();
  5. for(t = 0; t < Explosion.length; t ++)
  6. {
  7. gravity = 20;
  8. a = r.nextInt(50);
  9. v = r.nextInt(50);
  10. valueA = v*Math.sin(a)*t;
  11. valueB = (.5)*gravity*(t*t);
  12. dx = (int)v*Math.cos(a)*t;
  13. dy = (int)valueA - valueB;
  14. x = (int)dx;
  15. y = (int)dy;
  16. Explosion = new FireworksSprite[100];
  17. //for(t = 0; t < Explosion.length; t ++)
  18. //{
  19. System.out.print("Iterating through Array" + t);
  20. Explosion[t].setSpriteH(15);
  21. Explosion[t].setSpriteW(10);
  22. Explosion[t].setLocx(x);
  23. Explosion[t].setLocy(y);
  24. Explosion[t].setActive(true);
  25. Explosion[t].setVisible(true);
  26. Explosion[t].setVel(0, v);
  27.  
  28. }
Reply With Quote