Guest User

Untitled

a guest
Jun 14th, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ig.module('game.entities.non-weltmeister.weather-controller')
  2.  
  3. .requires('impact.entity')
  4.  
  5. .defines(function() {
  6.  
  7.     EntityWeatherController = ig.Entity.extend({
  8.  
  9.  
  10.         // How many sand clouds to spawn per second.
  11.         sandRate: 2,
  12.  
  13.         // How many raindrops to spawn per second.
  14.         rainRate: 64,
  15.  
  16.         // Timer for spawning entities.
  17.         timer: null,
  18.  
  19.         // Used to prevent spawning too quickly.
  20.         lastFrame: -1,
  21.  
  22.         // Type of weather effect.
  23.         weather: null,
  24.  
  25.         init: function(x, y, settings) {
  26.             this.parent(x, y, settings);
  27.  
  28.             // Start spawn timer.
  29.             this.timer = new ig.Timer();
  30.  
  31.             // Start sandstorm.
  32.             if (this.weather=='sandstorm') {
  33.  
  34.                 // Start sand-screen.
  35.                 this.sandscreen = ig.game.spawnEntity(EntitySandScreen, 0, 0, {});
  36.             }
  37.         },
  38.  
  39.         update: function() {
  40.  
  41.             if(this.weather=='sandstorm') rate = this.sandRate;
  42.             else if(this.weather=='rain') rate = this.rainRate;
  43.  
  44.             var frame = Math.floor(this.timer.delta() * rate);
  45.  
  46.             // Rain
  47.             if (this.weather=='rain') {
  48.  
  49.                 if( frame != this.lastFrame ) {
  50.  
  51.                     // Make up for missed spawns if too many frames passed.
  52.                     for(var i=0; i< frame - this.lastFrame; i++) {
  53.  
  54.                         // Random distance from left of screen.
  55.                         var x = ig.game.screen.x + Math.floor(Math.random() * (ig.system.width + ((1 / 3) * ig.system.height) - 30)) + 30;
  56.  
  57.                         // Random distance above top of screen.
  58.                         var y = ig.game.screen.y - Math.floor(Math.random() * 16) - 32;
  59.  
  60.                         // Spawn a raindrop.
  61.                         ig.game.spawnEntity(EntityRaindrop, x, y, {});
  62.  
  63.                     }
  64.  
  65.                     this.lastFrame = frame;
  66.                 }
  67.             }
  68.  
  69.             /*
  70.             // Sandstorm
  71.             else if (this.weather=='sandstorm') {
  72.  
  73.                 // Random distance from left of screen.
  74.                 var x = ig.game.screen.x + Math.floor(Math.random() * (ig.system.width - 32));
  75.  
  76.                 // Start below screen.
  77.                 var y = ig.game.screen.y + ig.system.height;
  78.  
  79.                 if( frame != this.lastFrame ) {
  80.  
  81.                     // Spawn a raindrop.
  82.                     ig.game.spawnEntity(EntitySandCloud, x, y, {});
  83.  
  84.                     this.lastFrame = frame;
  85.                 }
  86.             }
  87.             */
  88.  
  89.             // Call parent.
  90.             this.parent();
  91.         }
  92.  
  93.     });
  94. });
Advertisement
Add Comment
Please, Sign In to add comment