Jump to content

How to make a bossfight? (Phaser-question)


Jendrik
 Share

Recommended Posts

Hi!

I´m working on a sidescroller and I like to have a bossfight in the end.

But I don´t know how to realize it. I tried a lot with tweens, but the only thing I´ve got was a boss who flies away like a balloon...

In the end he has to fly around a bit, attacks the player with his body (collisionstuff) and throws any stuff to hurt the player.

 

What is the best way to get it into?

 

My bossFight function is actually something like this:

tween1.to({x:2800,y: 2600},1000).onComplete.add(function(){    console.log("onComplete");    tween1.to({x:2800,y:this.y +100},1000);    tween1.start();});    tween1.start();

I also tried

tween1.to({x:2800,y: 2500},1000).to({x:2900,y:2500},1000);

But nothing works.

The Boss has no gravity. I´m using arcade physics.

Link to comment
Share on other sites

Or use more detailed frames. Meaning if you have an animation for the boss doing somethingA then you just move the boss to a x/y while playing the animation. Then do somethingB and move him again. This way the animation does the part of the actual "movement" whilst the tweens just move him around to add notion to the animation playing.

Link to comment
Share on other sites

thanks for your hints!

Unfortunaly I can´t bring it to work. I get always "Cannot set property 'x' of undefined" 

This is what I have now:

bossFight: function(boss){	this.boss.animations.play('walk');	this.game.time.events.add(Phaser.Timer.SECOND * 2, this.bossUp(boss), this);},bossUp: function(boss){	boss.velocity.y = -10;},

How to call the boss-variable?

Link to comment
Share on other sites

I´ve got it!

Thank you for your help! game.time.events helped me a lot.

Next problem is, I don´t know how to get it on a loop. Also the fired cups (my bullets), don´t have any body or collision-stuff. That´s not cool...

 

Here my boss.js

Object is created only one time in update on a distanceBetween-if

	Boss = function (game, x,y){		Phaser.Sprite.call(this, game, x,y, 'boss');		game.add.existing(this);	}		Boss.prototype = Object.create(Phaser.Sprite.prototype);	Boss.prototype.constructor = Boss;	Boss.prototype.create = function(player, shootCup){		SBP.game.physics.enable(this, Phaser.Physics.ARCADE);		body=true;		this.animations.add('walk', [0,1,2,3], 5, true);		this.body.collideWorldBounds = true;		//create shootCup		this.shootCup = this.game.add.group();		this.shootCup.enableBody = true;		this.shootCup.createMultiple(100, 'Becher');		this.shootCup.setAll('outOfBoundsKill', true);		this.shootCup.setAll.collideWorldBounds = true;		this.shootCup.physicsBodyType = Phaser.Physics.ARCADE;				this.bosslife = true;		this.bossFight(player);		SBP.game.time.events.add(Phaser.Timer.SECOND * 13, this.bossFight(player),this);	}	Boss.prototype.bossFight = function(player){		this.animations.play('walk');						//nach links oben 		this.game.time.events.add(Phaser.Timer.SECOND * 1, function start(){			this.game.physics.arcade.moveToXY(this,2500,2600,200,700);			}			, this);				//kurve nach unten		this.game.time.events.add(Phaser.Timer.SECOND * 2, function part1(){			this.tween1 = this.game.add.tween(this).to({				x: [2500, 2600, 2700, 2800, 2900, 3000, 3050],				y: [2600, 2650, 2760, 2790, 2700, 2650, 2550],			}, 2000,Phaser.Easing.Quadratic.Out, true).interpolation(function(v, k){				return Phaser.Math.bezierInterpolation(v, k);				});		}, this);					//nach links oben		this.game.time.events.add(Phaser.Timer.SECOND * 4, function part2(){			this.game.physics.arcade.moveToXY(this,2500,2550,200,600);					}, this);					//body attack		this.game.time.events.add(Phaser.Timer.SECOND * 5, function part2(){			this.game.physics.arcade.moveToXY(this,player.x,player.y,600);			}, this);					//stoppen, danach nach links oben		this.game.time.events.add(Phaser.Timer.SECOND * 6, function part2(){			this.body.velocity.setTo(0,0);			this.game.physics.arcade.moveToXY(this,2500,2600,200,600);					}, this);		//kurve		this.game.time.events.add(Phaser.Timer.SECOND * 7, function part1(){			this.tween1 = this.game.add.tween(this).to({				x: [2500, 2600, 2700, 2800, 2900, 3000, 3050],				y: [2600, 2650, 2760, 2790, 2700, 2650, 2550],			}, 2000,Phaser.Easing.Quadratic.Out, true).interpolation(function(v, k){				return Phaser.Math.bezierInterpolation(v, k);				});		}, this);				//in die mitte		this.game.time.events.add(Phaser.Timer.SECOND * 9, function part2(){			this.game.physics.arcade.moveToXY(this,2700,2600,200,500);					}, this);					//stoppen, schießen		this.game.time.events.add(Phaser.Timer.SECOND * 9.5, function part2(){			this.body.velocity.setTo(0,0);			//hier schießfunktion einfügen			this.fireCup(player.x,player.y);			}, this);					//body attack		this.game.time.events.add(Phaser.Timer.SECOND * 11, function part2(){			this.game.physics.arcade.moveToXY(this,player.x,player.y,600);			}, this);					//stoppen, danach mitte		this.game.time.events.add(Phaser.Timer.SECOND * 12, function part2(){			this.body.velocity.setTo(0,0);			this.game.physics.arcade.moveToXY(this,2700,2500,200,500);				}, this);					//stoppen, schießen		this.game.time.events.add(Phaser.Timer.SECOND * 12.5, function part2(){			this.body.velocity.setTo(0,0);			var dirX = 2700;			var dirY = 2900;				this.fireCup(dirX,dirY);				this.fireCup(dirX-50,dirY-50);				this.fireCup(dirX-100,dirY-75);				this.fireCup(dirX-150,dirY-150);				this.fireCup(dirX,dirY-400);				this.fireCup(dirX+150,dirY-150);				this.fireCup(dirX+200,dirY-75);				this.fireCup(dirX+250,dirY-150);							}, this);		}		Boss.prototype.fireCup = function(x,y,shootCup){		this.fCup = this.shootCup.getFirstExists(false); 		this.fCup.physicsBodyType = Phaser.Physics.ARCADE;		this.fCup.enableBody = true;			if (this.fCup)				{				 this.fCup.reset(this.x+50, this.y+20);				 this.game.physics.arcade.moveToXY(this.fCup,x,y,600);								 this.shootCup.createMultiple(5, 'Becher');				}  	}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...