Advertisement
Guest User

Untitled

a guest
Jul 6th, 2012
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. var numClouds;
  2. var clouds;
  3. var CloudRate;
  4.  
  5. function manageClouds()
  6. {
  7. if (cloudRate == 0)
  8. {
  9. //do nothing
  10. }
  11. else if (numClouds == 0)
  12. {
  13. clouds[0] = new Cloud();
  14. }
  15. else if (Math.random() < cloudRate/numClouds)
  16. {
  17. clouds[numClouds] = new Cloud();
  18. }
  19. for (var i = 0; i < numClouds; i++)
  20. {
  21. clouds[i].execute();
  22. }
  23. }
  24.  
  25. function Cloud()
  26. {
  27. this.x = context.canvas.width;
  28. this.y = Math.floor(Math.random() * (context.canvas.height/2 - 40) + 40);
  29. this.speed = -1.6 * Math.random() - .4;
  30. this.index = numClouds;
  31.  
  32. numClouds++;
  33.  
  34. this.execute = execute;
  35. this.move = move;
  36. this.drawSelf = drawSelf;
  37. this.removeSelf = removeSelf;
  38. }
  39.  
  40. function execute()
  41. {
  42. this.move();
  43. if (this.x < -154)
  44. {
  45. this.removeSelf();
  46. }
  47. this.drawSelf();
  48. }
  49.  
  50. function move()
  51. {
  52. this.x += this.speed;
  53. }
  54.  
  55. function drawSelf()
  56. {
  57. context.drawImage(cloudImg,this.x,this.y);
  58. }
  59.  
  60. <b>function removeSelf()
  61. {
  62. var tempCloud = this;
  63. var i = this.index;
  64. while (i < numClouds - 1)
  65. {
  66. clouds[i] = clouds[i+1];
  67. i++;
  68. }
  69. clouds[i] = null;
  70. numClouds--;
  71. tempCloud = null;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement