1 decade ago by Jerczu
**SMALL FIX ADDED**
Let's say you want your level to be flooded by water - here's an example from the game I am currently developing.
This is a very dirty approach so if you find a better ,cleaner way of doing this let me know.
How it works - like any other "invisible, resizable" entity in weltmeister with one difference it does get rendered in the game. Position this entity at the bottom of your level and resize it to the width of the screen.
You may want to mess around with the positioning and sizing of the entity - you can see I am adding multiples of 16 to the position and sizing (16 is the size of my tile in the game).
Entity has a resize attribute which depending on true false value it will increase its size y creating the rising water effect.
At this moment it reacts when player entity gets in the water it forces it out by changing its y velocity so at some point the entity will float on top of the water.
if you want it to flood faster change this value
Edit: remeber to set resize in weltmeister to 0 for false or 1 for true.
Let's say you want your level to be flooded by water - here's an example from the game I am currently developing.
This is a very dirty approach so if you find a better ,cleaner way of doing this let me know.
How it works - like any other "invisible, resizable" entity in weltmeister with one difference it does get rendered in the game. Position this entity at the bottom of your level and resize it to the width of the screen.
You may want to mess around with the positioning and sizing of the entity - you can see I am adding multiples of 16 to the position and sizing (16 is the size of my tile in the game).
Entity has a resize attribute which depending on true false value it will increase its size y creating the rising water effect.
At this moment it reacts when player entity gets in the water it forces it out by changing its y velocity so at some point the entity will float on top of the water.
if you want it to flood faster change this value
this.size.y += 0.01;
ig.module( 'game.entities.waterzone' ) .requires( 'impact.entity' ) .defines(function(){ EntityWaterzone = ig.Entity.extend({ _wmDrawBox: true, _wmBoxColor: 'rgba(255,0,255,0.5)', _wmScalable: true, size:{x:40,y:40}, resize:false, checkAgainst: ig.Entity.TYPE.BOTH, name:null, check:function(other){ if(other instanceof EntityPlayer){ if((other.pos.y+other.size.y) > this.pos.y){ other.vel.y -= 8; } } }, draw:function(){ this.parent(); var x = (this.pos.x-16)*ig.system.scale; var y = this.pos.y*ig.system.scale; ig.system.context.fillStyle = "rgba(0,191,243,0.5)"; ig.system.context.fillRect(x,y,(this.size.x+32)*ig.system.scale,(this.size.y*2)*ig.system.scale); ig.system.context.fillStyle = "rgba(255,255,255,0.5)"; ig.system.context.fillRect(x,y,(this.size.x+32)*ig.system.scale,1*ig.system.scale); }, update: function() { this.parent(); if(this.resize){ this.size.y += 0.01; } } }); });
Edit: remeber to set resize in weltmeister to 0 for false or 1 for true.