Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var numClouds;
- var clouds;
- var CloudRate;
- function manageClouds()
- {
- if (cloudRate == 0)
- {
- //do nothing
- }
- else if (numClouds == 0)
- {
- clouds[0] = new Cloud();
- }
- else if (Math.random() < cloudRate/numClouds)
- {
- clouds[numClouds] = new Cloud();
- }
- for (var i = 0; i < numClouds; i++)
- {
- clouds[i].execute();
- }
- }
- function Cloud()
- {
- this.x = context.canvas.width;
- this.y = Math.floor(Math.random() * (context.canvas.height/2 - 40) + 40);
- this.speed = -1.6 * Math.random() - .4;
- this.index = numClouds;
- numClouds++;
- this.execute = execute;
- this.move = move;
- this.drawSelf = drawSelf;
- this.removeSelf = removeSelf;
- }
- function execute()
- {
- this.move();
- if (this.x < -154)
- {
- this.removeSelf();
- }
- this.drawSelf();
- }
- function move()
- {
- this.x += this.speed;
- }
- function drawSelf()
- {
- context.drawImage(cloudImg,this.x,this.y);
- }
- <b>function removeSelf()
- {
- var tempCloud = this;
- var i = this.index;
- while (i < numClouds - 1)
- {
- clouds[i] = clouds[i+1];
- i++;
- }
- clouds[i] = null;
- numClouds--;
- tempCloud = null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement