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 caranicas

Hi there, I'm from a C++ background and I think I am just having some difficulty understanding the module, requires, defines system. In my experience circular dependencies are a part of programming. two objects often need to know about one another. This is usually solved with #ifdef in the header file.

Ill explain my problem and hopefully that will make it clear. I made a win trigger and put it in my level. I am using check against to see when the player hits this trigger. (this part works) when he hits the trigger i wanted to go to the next level.

i am using a copy of Mike L.'s director plugin
http://impactjs.com/forums/impact-engine/new-director-level-manager-module

which i created inside my main game. I thought that if i made my game object a singleton that I would be able to require it in my win trigger create it and then go call
a wrapper function to go to the next level. but when i do this i get the following error

game.main (requires: game.states.main-game)
game.states.main-game (requires: game.levels.one)
game.levels.one (requires: game.entities.trigger-win)
game.entities.trigger-win (requires: game.states.main-game)

any help on this would be great. ill post all the relevant code in the following post

1 decade ago by caranicas

Main

ig.module( 
	'game.main' 
)
.requires(
	'game.states.main-game' 			
)
.defines(function(){

ig.main( '#canvas', mainGame, 60, 320, 240, 2 );

});

Main game

ig.module( 
	'game.states.main-game' 
)
.requires(
	'impact.game',
	'impact.font',
	'plugins.camera',
	'game.levels.one',
	'game.levels.two',
	'impact.debug.debug'	
)
.defines(function(){

mainGame = ig.Game.extend({
	
	// Load a font
	font: new ig.Font( 'media/04b03.font.png' ),

	init: function() {
	
		if(ig.ua.mobile)
		{
			// BIND BUTTONS
			ig.input.bindTouch('#buttonLeft','left');
			ig.input.bindTouch('#buttonRight','right');
			ig.input.bindTouch('#buttonJump','up');
		}
		
		else 
		{
			// BIND KEYS
			ig.input.bind( ig.KEY.UP_ARROW, 'up' );
			ig.input.bind( ig.KEY.LEFT_ARROW, 'left' );
			ig.input.bind( ig.KEY.RIGHT_ARROW, 'right' );
		}
	
		// CAMERA
		this.camera = new Camera( ig.system.width/4, ig.system.height/3, 5 );
	    this.camera.trap.size.x = ig.system.width/10;
	    this.camera.trap.size.y = ig.system.height/3;
	    this.camera.lookAhead.x = ig.ua.mobile ? ig.system.width/6 : 0;
		this.camera.debug = true;

		// LEVEL
		this.myDirector = new ig.Director(this, [LevelOne,  LevelTwo]);
	},
	
	staticInstantiate: function( ignoredFoo ) {
        if( mainGame.instance == null ) {
            return null;
        }
        else {
            return mainGame.instance;
        }
    },
	
	loadLevel: function( level ) {        
	    this.parent( level );

	    this.player = this.getEntitiesByType( EntityPlayer )[0];

	    // Set camera max and reposition trap
	    this.camera.max.x = this.collisionMap.width * this.collisionMap.tilesize - ig.system.width;
	    this.camera.max.y = this.collisionMap.height * this.collisionMap.tilesize - ig.system.height;
	    this.camera.set( this.player );
	},
	
	update: function() {
		// Update all entities and backgroundMaps
		this.parent();
		// Add your own, additional update code here
		this.camera.follow( this.player );
	},
	
	draw: function() {
		// Draw all entities and backgroundMaps
		this.parent();
		this.camera.draw();
	},
	
	nextLevel:function(){
		ig.log('NEXT LEVEL!');
		this.myDirector.nextLevel();
	}
	
});

});

Trigger

ig.module(
	'game.entities.trigger-win'
)
.requires(
	'game.entities.trigger',
	'game.states.main-game'
)
.defines(function(){
EntityTriggerWin = EntityTrigger.extend({
    size: {x: 16, y: 16},
    target: {},
    checkAgainst: ig.Entity.TYPE.A,
    
    _wmScalable: true,
    _wmDrawBox: true,
    _wmBoxColor: 'rgba(196, 255, 0, 0.7)',

 
    check: function( other ) {
		ig.log('checking for win');
		if (other instanceof EntityPlayer) {
				ig.log('check for win!');	
				var game = new mainGame();
				game.nextLevel()
		}
    }
});


});
Page 1 of 1
« first « previous next › last »