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 Bushstar

I have created an entity that when the player walks into it another game will load. I'm planning on using this to load in cut scenes. The code is below at the bottom. Currently it is hard coded to load a specific game. I want to make this dynamic but cannot get the game to load from an entity key I created for it in WM. In WM for the gameLoader entity I've set a "game: IntroScreen" key pair. I've tried to parse it using the following code.

var gameName = this.game.replace(/^(Level)?(\w)(\w*)/, function( m, l, a, b ) {return a.toUpperCase() + b;});

Then passed gameName to ig.system.setGame. It just generated an error in Firebug which says "gameClass is not a constructor" and "setGameNow(gameClass='IntroScreen'", the second part shows that it is picking up the key pair from WM.

How can I make this loading of a game from an entity dynamic?

ig.module(
	'game.entities.gameloader'
)
.requires(
	'impact.game',
	'impact.entity'
)
.defines(function(){
	EntityGameloader = ig.Entity.extend({
		_wmDrawBox: true,
		_wmBoxColor: 'rgba(0, 0, 255, 0.7)',
		size: {x: 10, y: 10},
		game: null,
		checkAgainst: ig.Entity.TYPE.A,
		
		update: function(){},
		
		check: function( other ) {
	    	if(other instanceof EntityPlayer){
        		if( this.game ) {
               		ig.system.setGame(IntroScreen);
          		}
    		}
		}
	});
});

1 decade ago by alexandre

You could have used EntityTrigger from dominic's biolab entity pack. It, when colliding with another entity of type t (as set in WM), calls the triggeredBy method of its targets.

You could then use the entity that follows--I wrote it for precisely that effect a while ago; should still be okay--, setting it as target.1 of the trigger, and setting its game property to the name of your other game class:

/*
This entity calls ig.system.setGame() when its triggeredBy() method is called.

Keys for Weltmeister:

game
	Name of the Game class to load. E.g. "GameIntro", "GamePlay", "GameOver", etc.
*/

ig.module(
	'game.entities.game-change'
)
.requires(
	'impact.entity'
)
.defines(function(){
	
EntityGameChange = ig.Entity.extend({

	_wmScalable: false,
	_wmDrawBox: true,
	_wmBoxColor: 'rgba(0, 128, 255, 0.4)',
	
	size: {x:16, y:16},
	
	triggeredBy: function(entity, trigger)
	{
		if (this.game)
			ig.system.setGame(ig.global[this.game]);
	},
});
});

1 decade ago by Bushstar

I've set the trigger with "game: IntroScreen". It still throws the error "gameClass is not a constructor" but I can see that it has picked up the name IntroScreen. It looks like it should work but doesn't.

I'll investigate BioLab when I can but if anyone knows what I'm doing wrong please let me know.

1 decade ago by alexandre

Try this (in WM):

Add these props to the EntityTrigger instance:
key:checks
value:A (or whatever type your player is set to)
key:target.1
value:gameChanger

Add these props to the EntityGameChanger instance:
key:name
value:gameChanger
key:game
value:IntroScreen

Then, when running the game, have your character collide with the trigger. What happens?

1 decade ago by Bushstar

I understand now. What I&039;ve been passing it is a String when it wants a Game class. So I can call the Game I want using #ig.global[this.game]. I guess I've reinvented the trigger. Anyway I'm going to use this to move to cut scenes running as separate games which will return to the main game. Thanks for your help alexandre.
Page 1 of 1
« first « previous next › last »