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 CruSher

Hi !

I'm programming something like a fighting game or a strategy or whatever (that means: i'm still learning)

What i want to do (really simple written, i hope you'll understand this):
- Character "a" that includes: animation, health, strenght, etc.
- 1 Player with movement keys and entity.type.a that can handle the character "a"
- 1 AI-Player (i'll programm it) that moves and attacks and is entity.type.b that can also handle the character "a"

I took the biolab player code to learn about this, but i really dont know how to "seperate" the character with the movement things from player or AI

1 decade ago by CruSher

Now:

ig.module(
	'game.entities.character001'
)
.requires(
	'impact.entity'
)
.defines(function(){
EntityCharacter001 = ig.Entity.extend({
	
	// Collision Area vom Character mit offset
	size: {x: 8, y:14},
	offset: {x: 4, y: 2},
	
	maxVel: {x: 100, y: 200},
	friction: {x: 600, y: 0},
	
	type: ig.Entity.TYPE.A, // "Spieler" Gruppe (.B Gruppe = CPU)
	checkAgainst: ig.Entity.TYPE.NONE,
	collides: ig.Entity.COLLIDES.PASSIVE,
	
	animSheet: new ig.AnimationSheet( 'media/character001.png', 16, 16 ),	
	
	
	// Eigenschaften
	flip: false,
	accelGround: 400,
	accelAir: 200,
	jump: 200,
	health: 10,
	flip: false,
	
	init: function( x, y, settings ) {
		this.parent( x, y, settings );
		
		// Animationen
		this.addAnim( 'idle', 1, [0] );
		this.addAnim( 'run', 0.07, [0,1,2,3,4,5] );
		this.addAnim( 'jump', 1, [9] );
		this.addAnim( 'fall', 0.4, [6,7] );
	},

	update: function() {
		
		// links, rechts bewegen
		var accel = this.standing ? this.accelGround : this.accelAir;
		if( ig.input.state('left') ) {
			this.accel.x = -accel;
			this.flip = true;
		}
		else if( ig.input.state('right') ) {
			this.accel.x = accel;
			this.flip = false;
		}
		else {
			this.accel.x = 0;
		}
		
		
		// jump
		if( this.standing && ig.input.pressed('jump') ) {
			this.vel.y = -this.jump;
		}
		
		
		// Animation nach Spielers Geschwindigkeit aufbauen
		if( this.vel.y < 0 ) {
			this.currentAnim = this.anims.jump;
		}
		else if( this.vel.y > 0 ) {
			this.currentAnim = this.anims.fall;
		}
		else if( this.vel.x != 0 ) {
			this.currentAnim = this.anims.run;
		}
		else {
			this.currentAnim = this.anims.idle;
		}
		
		this.currentAnim.flip.x = this.flip;
		
		
		// move!
		this.parent();
	}
});

});

But if i split it something like this:

Character:
	// Collision Area vom Character mit offset
	size: {x: 8, y:14},
	offset: {x: 4, y: 2},
	
	maxVel: {x: 100, y: 200},
	friction: {x: 600, y: 0},
	
	type: ig.Entity.TYPE.A, // "Spieler" Gruppe (.B Gruppe = CPU)
	checkAgainst: ig.Entity.TYPE.NONE,
	collides: ig.Entity.COLLIDES.PASSIVE,
	
	animSheet: new ig.AnimationSheet( 'media/character001.png', 16, 16 ),	
	
	
	// Eigenschaften
	flip: false,
	accelGround: 400,
	accelAir: 200,
	jump: 200,
	health: 10,
	flip: false,
	
	init: function( x, y, settings ) {
		this.parent( x, y, settings );
		
		// Animationen
		this.addAnim( 'idle', 1, [0] );
		this.addAnim( 'run', 0.07, [0,1,2,3,4,5] );
		this.addAnim( 'jump', 1, [9] );
		this.addAnim( 'fall', 0.4, [6,7] );
	}

Human Player:
update: function() {
		
		// links, rechts bewegen
		var accel = this.standing ? this.accelGround : this.accelAir;
		if( ig.input.state('left') ) {
			this.accel.x = -accel;
			this.flip = true;
		}
		else if( ig.input.state('right') ) {
			this.accel.x = accel;
			this.flip = false;
		}
		else {
			this.accel.x = 0;
		}
		
		
		// jump
		if( this.standing && ig.input.pressed('jump') ) {
			this.vel.y = -this.jump;
		}
		
		
		// Animation nach Spielers Geschwindigkeit aufbauen
		if( this.vel.y < 0 ) {
			this.currentAnim = this.anims.jump;
		}
		else if( this.vel.y > 0 ) {
			this.currentAnim = this.anims.fall;
		}
		else if( this.vel.x != 0 ) {
			this.currentAnim = this.anims.run;
		}
		else {
			this.currentAnim = this.anims.idle;
		}
		
		this.currentAnim.flip.x = this.flip;
		
		
		// move!
		this.parent();
	}

It wont work..

1 decade ago by Donzo

Your splitting one complete and functioning entity into two separate non-functioning entities.

The player entity only responds to keyboard events because he is programmed to in the Update function and main.js file.

The init function calls when the entity is initialized.
The update function is called every frame.

Both are required if you want an entity that does anything.

1 decade ago by CruSher

Thanks Donzo! That helped a lot and it works now! I knew it that it will be really simple to solve.. but if you stare at the code that long.. you know what i mean.
Tanks again!
Page 1 of 1
« first « previous next › last »