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 Pence

Hi there,

Im very new to coding and have a graphic design background, but have been enjoying playing with impactjs.

Im making a very basic mario/sonic style side scroller but have 2 problems relating to entites.

My first, and main problem is that i have absolutely no idea how to kill my player and have him restart the level. I want to make a transparent entity so when the player comes into contact with it he dies and restarts from a set point (dependant on where he dies - or the beginning of the level if this is too complicated).

My second, and this would just be a nice to have, is a spring type entity like in Sonic, so that when the player jumps on the entity he can jump 5X higher than he can usually.

Please can someone help me out with the code for these entities? As mentioned this is my first coding experience and although im finding my feet slowly i am really struggling with these two problems.

Many thanks

1 decade ago by end3r

To kill a player you can just execute player.kill() if you defined the player entity first. Then you can use spawnEntity to place him again in any place of the game you want.

The spring entity - never tried it, but maybe you can set the bounciness on a platform or give the player higher velocity if he collides with the platform?

1 decade ago by Joncom

/* Within your player entity's update function. */

// Get a list of springs in the level.
var springs = ig.game.getEntitiesByType(EntitySpring);

// Loop through all the springs.
for(var i=0; i<springs.length; i++) {

    // Is the player touching this spring?
    if(this.touches( spring[i] )) {

        // Launch the player into the air.
        this.vel.y = -300;

        // No need to consider any more springs during this update.
        break;

    }

}

1 decade ago by Pence

Thanks both so much for the replies. Im going to give it a go now and will update.

Really appreciate the help!

1 decade ago by zedd45

Hi,

for my spring platform I did a much simpler implementation based on what collided with the spring:

collideWith: function ( other, axis ) {
    		if ( other instanceof EntityPlayer )  {
				other.vel.y = -1 * Math.abs(this.springVelocity);
    		}
    	}

Hope this helps someone!
Page 1 of 1
« first « previous next › last »