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

1 decade ago by silverspectro

Hello !

I'm pretty new on the Impact engine, so excuse my lack of knowledge in some part.
I'm trying to make a plateform game based on typography and i'd like to make a moveable plateform.
Not a normal one ( as there is already in the biolab entity pack ) but one that moves down if the player's on it and come back to it's original position when the player leaves it.
I know it's pretty easy, but i tried a lot and got stuck with the players presence on the plateform. I can't find a way to actually update the Boolean value after it has been change by the use of the check function...

I don't know if i'm completely wrong or not, but does someone have an hint ?

Thank you very much !

P.S : i don't post code as i've gone completely wrong... so it would be pointless, it's just like a blank new Entity.

1 decade ago by quidmonkey

collideWith: function( other, axis ){
	if( other instanceof PlayerEntity && axis === 'y' && other.pos.y < this.pos.y ){
		this.move = true;
	}
},

update: function(){
	if( this.move ){
		this.move = false;
		this.vel.y = move_down_vel;
	}
	else if( this.pos.y > this.start.y ){
		this.vel.y = move_up_vel;
	}
	else{
		this.pos.y = this.start.y;
		this.vel.y = 0;
	}
	this.parent();
}

1 decade ago by silverspectro

Hi,

thank tou for the fast reply !
I've made a new shit with it, but, it don't seem to work...
The game loads, but the platform does'nt move while the player's on it .
But I have some code this time ^^


ig.module(
	'game.entities.H'
)

.requires(
	'impact.entity'
)

.defines(function() { 
	
	EntityH = ig.Entity.extend ({ 
		
		_wmDrawBox: true,
		size: {x: 64, y: 64},
		offset: {x: 0, y: 1},
		maxVel: {x: 0, y: 100},
		gravityFactor: 0,
		
		type: ig.Entity.TYPE.NONE,
       checkAgainst: ig.Entity.TYPE.A,
       collides: ig.Entity.COLLIDES.FIXED,
       
       animSheet: new ig.AnimationSheet( 'media/H.png', 64, 64 ),
       
       init: function( x, y, settings) {
		   
		   this.addAnim ('change', .2, [0,1,2,3,4,5,6,7]);
		   this.parent(x, y, settings);
		   
		   
		},
		
		collideWith: function( other, axis ){
			var player = ig.game.getEntitiesByType( EntityPlayer )[0];
			
			if( player.y < this.pos.y) {
				
				this.move = true;
				
			}
			
		},
		
		update: function(){
			
			var start = this.pos.y;
			
			
			if(this.move){
				
				this.move = false;
				this.vel.y = this.vel.y + 2;
				
				} else if ( this.pos .y > start ){
					
					this.vel.y = this.vel.y - 2;
					
				} else { 
					
					this.pos.y = start;
					this.vel.y = 0;
					
				}
				
				this.parent()
				 	 
			
			}
		
	
	
	});
	
	
	
	
});

seems i can't get the code written right too ^^'

1 decade ago by quidmonkey

Try:
start: 0, //cache start pos.y

init: function( x, y, settings ){
    this.parent( x, y, settings );
    this.start = y;
},

collideWith: function( other, axis ){
    if( other instanceof PlayerEntity && axis === 'y' && other.pos.y < this.pos.y ){
        this.move = true;
    }
},

update: function(){
    if( this.move ){
        this.move = false;
        this.vel.y = -50;
    }
    else if( this.pos.y > this.start ){
        this.vel.y = 50;
    }
    else{
        this.pos.y = this.start;
        this.vel.y = 0;
    }
    this.parent();
}

1 decade ago by silverspectro

Thank you again !

This is almost it ! The platform is moving and returning to it's place !
But it's going up and it's strange because i can't jump on it, seems like the player is
contantly falling ?

Anyway if you have improvements, here's the code :

ig.module(
	'game.entities.Htest'
)

.requires(
	'impact.entity'
)

.defines(function() { 
	
	EntityHtest = ig.Entity.extend ({ 
		
		_wmDrawBox: true,
		size: {x: 64, y: 64},
		offset: {x: 0, y: 1},
		maxVel: {x: 0, y: 100},
		gravityFactor: 0,
		
		type: ig.Entity.TYPE.NONE,
       checkAgainst: ig.Entity.TYPE.A,
       collides: ig.Entity.COLLIDES.FIXED,
       
       animSheet: new ig.AnimationSheet( 'media/H.png', 64, 64 ),
       
       start: 0, //cache start pos.y

		init: function( x, y, settings ){
		    this.parent( x, y, settings );
		    this.addAnim ('change', .2, [0,1,2,3,4,5,6,7]);
		    this.start = y;
		    
		},
		
		collideWith: function( other, axis ){
			var PlayerEntity = ig.game.getEntitiesByType( EntityPlayer )[0];
		    if( PlayerEntity && axis === 'y' && other.pos.y < this.pos.y ){
		        this.move = true;
		    }
		},
		
		update: function(){
		    if( this.move ){
		        this.move = false;
		        this.vel.y = -50;
		    }
		    else if( this.pos.y > this.start ){
		        this.vel.y = 50;
		    }
		    else{
		        this.pos.y = this.start;
		        this.vel.y = 0;
		    }
		    this.parent();
		}
		
	
	
	});
	
	
	
	
});

1 decade ago by silverspectro

OK i've done it !

thank you very much !

here's the final code, it's perfect, maybe i'll set up a Timer if i can ^^

ig.module(
	'game.entities.Htest'
)

.requires(
	'impact.entity'
)

.defines(function() { 
	
	EntityHtest = ig.Entity.extend ({ 
		
		_wmDrawBox: true,
		size: {x: 64, y: 64},
		offset: {x: 0, y: 1},
		maxVel: {x: 0, y: 100},
		gravityFactor: 0,
		
		type: ig.Entity.TYPE.NONE,
       checkAgainst: ig.Entity.TYPE.A,
       collides: ig.Entity.COLLIDES.FIXED,
       
       animSheet: new ig.AnimationSheet( 'media/H.png', 64, 64 ),
       
       start: 0, //cache start pos.y

		init: function( x, y, settings ){
		    this.parent( x, y, settings );
		    this.addAnim ('change', .2, [0,1,2,3,4,5,6,7]);
		    this.start = y;
		    
		},
		
		collideWith: function( other, axis ){
			var PlayerEntity = ig.game.getEntitiesByType( EntityPlayer )[0];
		    if( PlayerEntity && axis === 'y' && other.pos.y < this.pos.y ){
		        this.move = true;
		    }
		},
		
		update: function(){
		    if( this.move ){
		        this.move = false;
		        this.vel.y++;
		    }
		    else if( this.pos.y > this.start ){
		        this.vel.y = -50;
		    }
		    else{
		        this.pos.y = this.start;
		        this.vel.y = 0;
		    }
		    this.parent();
		}
		
	
	
	});
	
	
	
	
});

1 decade ago by fulvio

I'd change the code slightly, otherwise any entity (whether it's particles, enemies, etc) are capable of moving the platform as well.

The following code ensures only the EntityPlayer can interact with the platform:

collideWith: function( other, axis ) {
	if (other instanceof EntityPlayer) {
		if (axis === 'y' && other.pos.y < this.pos.y ) {
			this.move = true;
		}
	}
}
Page 1 of 1
« first « previous next › last »