Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ig.module('game.entities.non-weltmeister.weather-controller')
- .requires('impact.entity')
- .defines(function() {
- EntityWeatherController = ig.Entity.extend({
- // How many raindrops to spawn per second.
- rainRate: 64,
- // Timer for spawning entities.
- timer: null,
- // Used to prevent spawning too quickly.
- lastFrame: -1,
- // Type of weather effect.
- weather: null,
- init: function(x, y, settings) {
- this.parent(x, y, settings);
- // Start spawn timer.
- this.timer = new ig.Timer();
- },
- update: function() {
- if(this.weather=='rain') rate = this.rainRate;
- var frame = Math.floor(this.timer.delta() * rate);
- // Rain
- if (this.weather=='rain') {
- if( frame != this.lastFrame ) {
- // Make up for missed spawns if too many frames passed.
- for(var i=0; i< frame - this.lastFrame; i++) {
- // Random distance from left of screen.
- var x = ig.game.screen.x + Math.floor(Math.random() * (ig.system.width + ((1 / 3) * ig.system.height) - 30)) + 30;
- // Random distance above top of screen.
- var y = ig.game.screen.y - Math.floor(Math.random() * 16) - 32;
- // Spawn a raindrop.
- ig.game.spawnEntity(EntityRaindrop, x, y, {});
- }
- this.lastFrame = frame;
- }
- }
- // Call parent.
- this.parent();
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment