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 KenD

How do you guys typically handle signaling the end of a level for a 2D side scroller? I'm planning on using a trigger with a Weltmeister property specifying which level to load when triggered, but was wondering what others were doing. I toyed with the idea of checking the player's position versus the level size, but that seems unnecessarily complicated.

1 decade ago by lazer

Trigger entity for the player to collide with seems like a good option to me and is what I've done in the past.

1 decade ago by Arantor

It's also what Biolab Disaster does.

1 decade ago by beardedbuddha

Here is a level exit entity from a sidescroller of mine. When using it in WM, you just give it a property with the key: "level" and value which is the name of the level you want to load..

 ig.module(
    'game.entities.levelexit'
)
.requires(
    'impact.entity'
)
.defines(function(){
	EntityLevelexit = ig.Entity.extend({
		checkAgainst: ig.Entity.TYPE.A,

		size: {x: 12, y: 16},
		offset: {x:0, y:0},
		animSheet: new ig.AnimationSheet('media/sign_arrow_right.png', 12, 16),
		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 EntityPlayer) {
				ig.game.toggleStats(this);
			}
		},

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

Edit: Note that this toggles an "end of level" screen first, which then sends the player to the next level. If you want the player to go directly to the next level, just move the code from the nextLevel method to the check method..
Page 1 of 1
« first « previous next › last »