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 Jon123

I am trying to create a way of respawning the player at a certain location when they die. I have a checkpoint entity, but I can't have the spawn coordinates in its code can I? As that would mean that every checkpoint entity in the game would spawn the player in the same place!

Jon

1 decade ago by stillen

The way I handle this is my player class has a respawn x and y coordinates. When the player touches the checkpoint, it records the checkpoints position to the respawn x and y coordinates.

Then when the player dies, he is respawned at the current respawn.x and respawn.y

The last checkpoint you player touches is then the respawn point. On player init if there is no checkpoint coordinates, then I save the original spawn point, basically the start of the level.

1 decade ago by Jon123

Thanks that makes sense. I was thinking of doing something like that but wasn't sure what happens when the kill() method of the player entity is called. I suppose I would just override that with a respawn.

1 decade ago by stillen

In my game, I override the default kill, and spawn the death animation(deadplayer entity). I pass the respawn coordinates to the death animation.

When the death animation finishes, the deadplayer entity spawns the player entity at the checkpoint, and then I kill that deadplayer entity.

It sounds much more complicated then it really is and looks pretty good.

1 decade ago by Jon123

SO your init method in the deadPlayer entity takes extra params? so something like this?
init: function( x, y, respawnX, respawnY, settings ) {
            this.parent( x, y, settings );
            // Add the animations
            this.addAnim( 'idle', 1, [0] );
            this.addAnim( 'fly', 0.07, [1,2] );
 }

and you kill the player entity like this?
var players = ig.game.getEntitiesByType('EntityPlayer');
var player  = players[0];
player.kill();

How do you know when the dead animation ends?

1 decade ago by stillen

Player Init:
startPosition:null,
init: function(x,y,settings){
	this.parent(x,y,settings);
	this.startPosition = {x:x,y:y};
},

Player Kill Function:
kill:function(){
			if( window.ejecta ){
				var vibrate = new Ejecta.Vibrate();
				vibrate.playVibrateEffect();
			}
			ig.game.screenShaker.applyImpulse(1000,1000);
			ig.game.spawnEntity(EntityPlayerdead,this.pos.x,this.pos.y,{
				startPosition:{
					x:this.startPosition.x,
					y:this.startPosition.y
				}
			});
			this.parent();
		},

Dead Player Update:
this.parent();
if(this.currentAnim == this.anims.dead && this.currentAnim.loopCount > 0){
    ig.game.spawnEntity(EntityBaseplayer,this.startPosition.x,this.startPosition.y);
    this.kill();
}


I used startPosition instead of respawn in my game, but its the same concept

1 decade ago by Jon123

Nice code! It looks good, I'll have a play with it tomorrow. Thanks again :-)
Page 1 of 1
« first « previous next › last »