Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

8 years 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

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.

8 years ago by stahlmanDesign

Sounds cool. I'll try to check it out.

8 years ago by Jerczu

its really dirty approach i will be rewriting my code this weekend

8 years ago by pm99

Hi Jerczu,
I just tried your waterzone entity and got it to 'fill up' my level. Nice work.

Now either I fiddle around with this to get other entities like crates to float on the surface and even have the player (using biolab template) float upon getting into the water, then change to a horizontal position to swim under water! Haha.. ya.. hmm.

I think it will be over my head. I'm a newbie to JS. I may have to just stick to the basics for now and play with weltmeister. : )

I'm wondering there must be a library of entities out there? I've looked in the 'tools' section and found yours, but am surprised to not find a greater plythora of goodies? ; )

anyone know where there are more.. or better, mods for impact that extend functionality? i.e. for example so i don't have to continue to create new entities and update the requires in the main js.
PM99

8 years ago by Jerczu

Search the forum - thats the best option there is loads of good stuff here - As regards the water entity... Well all you need to do is to edit this section...

 check:function(other){
      if(other instanceof EntityPlayer){
        if((other.pos.y+other.size.y) > this.pos.y){
            other.vel.y -= 8;
        }
        
     }
   },

and instead of if use switch statement and set up what entities should be checked against then give them negative y velocities or just set them to 0 - Once again this entity is very badly written and for the last 4-5 months I simply was pre-occupied with other stuff to actually spend any time on it. I'm currently working on my first HTML5 iPhone game and the 1.19 couldnt come at better time.

8 years ago by pm99

Thanks Jerczu.
PM99
Page 1 of 1
« first « previous next › last »