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 blobber

I am trying to create a simple jump-in-run game based of the jump-n-run demo where the user has to fight enemies as he passes through a level but every 3 grenades he shoots he needs to answer a simple question in order to be able to start shooting again I have tried trying to create this as an entity but its not really going that well and I could use a hand.

Heres the entity for the grenade (exact same as in the jump-n-run demo)

EntitySlimeGrenade = ig.Entity.extend({
	size: {x: 4, y: 4},
	offset: {x: 2, y: 2},
	maxVel: {x: 200, y: 200},
	
	
	// The fraction of force with which this entity bounces back in collisions
	bounciness: 0.6, 
	
	type: ig.Entity.TYPE.NONE,
	checkAgainst: ig.Entity.TYPE.B, // Check Against B - our evil enemy group
	collides: ig.Entity.COLLIDES.PASSIVE,
		
	animSheet: new ig.AnimationSheet( 'media/slime-grenade.png', 8, 8 ),
	
	bounceCounter: 0,
	
	
	init: function( x, y, settings ) {
		this.parent( x, y, settings );
		
		this.vel.x = (settings.flip ? -this.maxVel.x : this.maxVel.x);
		this.vel.y = -50;
		this.addAnim( 'idle', 0.2, [0,1] );
	},
		
	handleMovementTrace: function( res ) {
		this.parent( res );
		if( res.collision.x || res.collision.y ) {
			
			// only bounce 3 times
			this.bounceCounter++;
			if( this.bounceCounter > 3 ) {
				this.kill();
			}
		}
	},
	
	// This function is called when this entity overlaps anonther entity of the
	// checkAgainst group. I.e. for this entity, all entities in the B group.
	check: function( other ) {
		other.receiveDamage( 10, this );
		this.kill();
	}	
});

So basically I want to check if the user has shot 3 grenades and if this is true I want the game to show a question for example (how may pool balls on a table) and if the answer if true the user gets to keep on shooting.

Thanks

1 decade ago by vincentpiel

What you need here is to handle an overlay.
- So let's call the current game : game A. Have your player (not the grenade) handle / display a count of grenade nicely.
- Have a game (that extends ig.Game) that asks question, expects answers, and such : game B. test it on its own, have it running nicely.
- Now create another third game, game C, that will :
- in its init : create a new game A and a new game B, and create a boolean, like askQuestion, set to false.
- update *EITHER* A or B, depending on askQuestion.
- always draw A, and then draw B or not depending on askQuestion.

The game that you start in ig.main() will be game C. (After game B testing :-) )

So game A's player will set game C askQuestion = true when the grenade count reaches 0, and stop the game update.
Within game B, when the answer is given, update (or not) the player's grenade, then set game C's askQuestion to false again, ==> the game resumes without the question overlay.

You might have some variable scope issue. A dirty-but-who-cares solution is to declare before the call to ig.main something like :
ig.constant = {};
and then use it later to share data in between objects :
ig.constant.player = ...
ig.constant.myGameA = ...
You can then write/read those values at any place in game A, B, C or player.
Page 1 of 1
« first « previous next › last »