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 hschillig

I have a trigger (exit into new level and then they can exit back out). So it's similar to Pokemon where you can enter a building and then leave it. However, when it goes back to the previous map, I want the entity to spawn right by the trigger (in this case, below it).

How would I go about doing that with an entity?

EntityGirl = ig.Entity.extend({

	animSheet: new ig.AnimationSheet( 'media/game2/player.png', 16, 16 ),
	size: {x: 16, y: 16},
	flip: false,
	friction: {x: 800, y: 800},
	accelGround: 300,
	accelAir: 150,
	health: 100,
	lastAction: 0,
	type: ig.Entity.TYPE.A,

	init: function( x, y, settings ) {
		this.parent( x, y, settings );
		this.addAnim( 'idle', 1, [0] );
		this.addAnim( 'run', 0.05, [0,1,2] );
		this.addAnim( 'runUp', 0.05, [6,7,8] );
		this.addAnim( 'runDown', 0.05, [3,4,5] );
		this.addAnim( 'upIdle', 1, [6]);
		this.addAnim( 'downIdle', 1, [3]);
	},

	update: function() {

		if( ig.input.state('left') ) {
			this.accel = {x: -this.accelGround, y: 0};
			this.flip = true;
			this.lastAction = 0;
		}
		else if( ig.input.state('right') ) {
			this.accel = {x: this.accelGround, y: 0};
			this.flip = false;
			this.lastAction = 0;
		}
		else if( ig.input.state('up') ) {
			this.accel = {x: 0, y: -this.accelAir};
			this.flip = false;
			this.lastAction = 'up';
		}
		else if( ig.input.state('down') ) {
			this.accel = {x: 0, y: this.accelAir};
			this.flip = false;
			this.lastAction = 'down';
		}
		else {
			this.accel = {x: 0, y: 0};
		}

		// set the current animation, based on the player's speed
		if( this.accel.x != 0 ) {
			this.currentAnim = this.anims.run;
		}
		else if( this.accel.y > 0 ) {
			this.currentAnim = this.anims.runDown;
		}
		else if( this.accel.y < 0 ) {
			this.currentAnim = this.anims.runUp;
		}
		else {
			if( this.lastAction == 'up' )
			{
				this.currentAnim = this.anims.upIdle;
			}
			else if( this.lastAction == 'down' )
			{
				this.currentAnim = this.anims.downIdle;
			}
			else
			{
				this.currentAnim = this.anims.idle;
			}
		}

		this.currentAnim.flip.x = this.flip;

		// move!
		this.parent();
	}
		
});

1 decade ago by hschillig

Oh woops and then here is my trigger entity:

EntityHouse = ig.Entity.extend({

	animSheet: new ig.AnimationSheet( 'media/game2/house-enter.png', 16, 16 ),
	size: {x: 16, y: 16},
	flip: false,
	checkAgainst: ig.Entity.TYPE.A,
	level: null,

	// overwrite the update method and remove the this.parent() call, to stop it from rendering
    update: function(){},

    init: function(x, y, settings) {
        this.addAnim('idle', 1, [0]);
        this.parent(x, y, settings);
    },

    check: function(other) {
        if(other instanceof EntityGirl) {
            var levelName = this.level.replace(/^(Level)?(\w)(\w*)/, function(m, l, a, b) {
                return a.toUpperCase() + b;
            });
            ig.game.loadLevelDeferred(ig.global['Level'+levelName]);
        }
    }
		
});

1 decade ago by Joncom

Maybe something like:
check: function(other) {
    if(other instanceof EntityGirl) {
        var levelName = this.level.replace(/^(Level)?(\w)(\w*)/, function(m, l, a, b) {
            return a.toUpperCase() + b;
        });
        ig.game.loadLevelDeferred(ig.global['Level'+levelName]);
        ig.game.pos_to_spawn_player = { x: 0, y: 0 }; // <-- calculate these numbers
    }
}

Then when you&039;re spawning the player, check if #pos_to_spawn_player has a value. If so, spawn there.
Page 1 of 1
« first « previous next › last »