Jendrik

Members
  • Content count

    20
  • Joined

  • Last visited

About Jendrik

  • Rank
    Member
  • Birthday 04/05/1983

Profile Information

  • Gender
    Male
  • Location
    Bremen, Germany
  1. Change the controlled sprite

    Hey, how could I change the controlled sprite? In my game, I want that the player first controls the wolf and when schaaf reaches the end, the player will control the hund and not anymore the wolf. wolf will flee away to the left side. in my actually code, the "reverse"-switch (boolean) doesn´t work. Means, when schaaf touches end, the boolean doesn´t switch to "true". But the console.log function is called. My first idea was to switch the state. But that wasn´t working, too. "Unable to call undefined "state"..."blabla. this.game.state.start("reverse");This is my actually code without hindernis-stuff: "use strict";window.wolf.state.play = { preload: function(){ console.log("loading play state"); }, create: function(){ console.log("starting play state"); this.bg = mt.create("bg"); this.unten = mt.create("unten"); this.wolf = mt.create("wolf"); this.schaaf = mt.create("schaaf"); this.end = mt.create("end"); this.hund = mt.create("hund"); this._hindernis = this.add.group(); this.pos = [10]; var i = 0; while(i != 10){ this.spawnHindernis(i); i++; } this.reverse = false; this.cursors = this.game.input.keyboard.createCursorKeys(); this.game.camera.follow(this.wolf); }, update: function(){ this.game.physics.arcade.collide(this.hund, this.unten); this.game.physics.arcade.collide(this.hund, this.end); this.game.physics.arcade.collide(this.hund, this._hindernis); this.game.physics.arcade.collide(this.schaaf, this.end, function(){ this.reverse = true; console.log("jetzt"); }); if(this.reverse === false) this.playerWolf(); else this.playerHund(); console.log(this.reverse); }, //ENDE UPDATE ---[some hindernis-stuff]--- }, playerWolf: function(){ this.game.physics.arcade.collide(this.wolf, this.unten); this.game.physics.arcade.collide(this.wolf, this.end); this.game.physics.arcade.collide(this.wolf, this._hindernis); this.game.physics.arcade.collide(this.schaaf, this.unten); this.game.physics.arcade.collide(this.schaaf, this._hindernis, function(schaaf){ schaaf.body.velocity.x = 0; schaaf.body.velocity.y = -300; }); this.game.physics.arcade.collide(this.wolf, this.schaaf, function(wolf,schaaf){ console.log("Schaf bekommt aufs Maul"); schaaf.body.velocity.y = -500; }); if (this.cursors.left.isDown) { this.wolf.body.velocity.x = -200; } else if (this.cursors.right.isDown) { this.wolf.body.velocity.x = 200; } else { this.wolf.body.velocity.x = 0; } if (this.cursors.up.isDown && this.wolf.body.wasTouching.down) { this.wolf.body.velocity.y = -300; } this.schaaf.body.velocity.x = 180; }, playerHund: function(){ this.game.physics.arcade.collide(this.wolf, this.unten); this.game.physics.arcade.collide(this.wolf, this._hindernis, function(wolf){ wolf.body.velocity.x = 0; wolf.body.velocity.y = -300; }); this.game.physics.arcade.collide(this.hund, this.wolf, function(hund,wolf){ console.log("wolf bekommt aufs Maul"); wolf.body.velocity.y = -500; }); this.game.physics.arcade.collide(this.wolf, this.end, function(){ console.log("spiel zuende"); }); if (this.cursors.left.isDown) { this.hund.body.velocity.x = -220; } else if (this.cursors.right.isDown) { this.hund.body.velocity.x = 220; } else { this.hund.body.velocity.x = 0; } if (this.cursors.up.isDown && this.hund.body.wasTouching.down) { this.hund.body.velocity.y = -300; } this.wolf.body.velocity.x = -200; } };
  2. Yeah, topic says all... ;-) I´m trying to get a random png out of a group like this: var block = this.game.add.sprite(spawnPos, 416,GROUPNAME);of course it´s not working. Anybody knows how to do it right?
  3. Creating an "intelligent" enemy

    indeed, it works. Thank you! It looks a little bit silly but for now it´s enough
  4. Creating an "intelligent" enemy

    Hi all! I´m trying to get an enemy who flees from the player. But I have no idea how to get him jump. The following code makes that he ran and stop on an hindernis. But he don´t want to jump... Any ideas? window.wolf.state.play = { preload: function(){ console.log("loading play state"); }, create: function(){ console.log("starting play state"); this.bg = mt.create("bg"); this.unten = mt.create("unten"); this.wolf = mt.create("wolf"); this.schaaf = mt.create("schaaf"); this.hindernis = mt.create("hindernis"); //this.points = mt.create("points"); this.cursors = this.game.input.keyboard.createCursorKeys(); this.game.camera.follow(this.wolf); }, update: function(){ this.game.physics.arcade.collide(this.wolf, this.unten); this.game.physics.arcade.collide(this.wolf, this.hindernis); this.game.physics.arcade.collide(this.schaaf, this.unten); this.game.physics.arcade.collide(this.schaaf, this.hindernis); if (this.cursors.left.isDown) { this.wolf.body.velocity.x = -200; } else if (this.cursors.right.isDown) { this.wolf.body.velocity.x = 200; } else { this.wolf.body.velocity.x = 0; } if (this.cursors.up.isDown) { this.wolf.body.velocity.y = -300; } if(this.game.physics.arcade.distanceBetween(this.schaaf, this.hindernis) < 50){ console.log("hüpf!"); this.schaafJump(); this.schaaf.body.velocity.x = 180; }else{ this.schaaf.body.velocity.x = 180; } }, schaafJump: function(){ this.schaaf.body.velocity.x = 0; this.schaaf.body.velocity.y = -100; }};
  5. Physic Collision problem

    Hm, maybe when you put nach pipe in a group. Give the group a body and physics. Then putthe group to the collide Funktion.
  6. How to make a bossfight? (Phaser-question)

    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'); } }
  7. How to make a bossfight? (Phaser-question)

    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?
  8. How to make a bossfight? (Phaser-question)

    wrong forum I guess... may be an admin could delete it? I copied it in the phaser one...
  9. 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.
  10. 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.
  11. problems with Virtual Joystick plugin

    Ok, got it! I replaced my phaser.min.js with that from the zip file. Now everything works fine. Thank you so much!!
  12. problems with Virtual Joystick plugin

    I bet I've done something wrong with the positions oft the JS files...
  13. problems with Virtual Joystick plugin

    unfortunaly yes, there are errors phaser.min.js:7 Uncaught TypeError: Cannot set property 'game' of undefinedGameTOUCH.js:250 Uncaught TypeError: Cannot read property 'isDown' of undefined 250 is if (this.stick.isDown){ ...
  14. problems with Virtual Joystick plugin

    oh dear, that was amazing stupid from me... yeah, I had to put the .\ as main directory in my webserver... now the example works ^^ here is my code. I replaced the phaser.js with the new one out of the zip-file. var SBP = SBP || {}; SBP.GameTOUCH = function(){}; SBP.GameTOUCH.prototype = { preload: function() { ... this.pad = this.game.plugins.add(Phaser.VirtualJoystick); this.stick = this.pad.addDPad(0, 0, 200, 'dpad');this.buttonA = this.pad.addButton(500, 520, 'dpad', 'button1-up', 'button1-down'); this.buttonA.onDown.add(this.pressButtonA, this); this.buttonB = this.pad.addButton(615, 450, 'dpad', 'button2-up', 'button2-down'); this.buttonB.onDown.add(this.pressButtonB, this);}, pressButtonA: function () { this.player.body.velocity.y = -400;this.jump.play(); }, pressButtonB: function () { this.fireBean(); },... }, update: function(){ ...var maxSpeed = 250;if (this.stick.isDown){ this.player.body.velocity.set = 0;if (this.stick.direction === Phaser.LEFT){// Move to the left this.player.body.velocity.x = -this.maxSpeed; this.player.animations.play('left'); if(!this.walk.isPlaying && this.player.body.onFloor()) this.walk.play(); }else if (this.stick.direction === Phaser.RIGHT){// Move to the right this.player.body.velocity.x = +this.maxSpeed; this.player.animations.play('right'); if(!this.walk.isPlaying && this.player.body.onFloor()) this.walk.play();}//Sprungelse if (this.stick.direction === Phaser.UP && this.player.body.onFloor()){ this.player.body.velocity.y = -400; this.jump.play();}...}
  15. problems with Virtual Joystick plugin

    Thats from the example of the zip file: var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example');var PhaserGame = function () { this.sprite; this.pad; this.stick; this.buttonA; this.buttonB; this.buttonC;};PhaserGame.prototype = { init: function () { this.game.renderer.renderSession.roundPixels = true; this.physics.startSystem(Phaser.Physics.ARCADE); }, preload: function () { this.load.atlas('arcade', 'assets/virtualjoystick/skins/arcade-joystick.png', 'assets/virtualjoystick/skins/arcade-joystick.json'); this.load.image('ball', 'assets/virtualjoystick/beball1.png'); this.load.image('bg', 'assets/virtualjoystick/space1.png'); }, create: function () { this.add.image(0, 0, 'bg'); this.sprite = this.add.sprite(400, 200, 'ball'); this.physics.arcade.enable(this.sprite); this.pad = this.game.plugins.add(Phaser.VirtualJoystick); this.stick = this.pad.addStick(0, 0, 200, 'arcade'); this.stick.alignBottomLeft(); this.buttonA = this.pad.addButton(500, 520, 'arcade', 'button1-up', 'button1-down'); this.buttonA.onDown.add(this.pressButtonA, this); this.buttonB = this.pad.addButton(615, 450, 'arcade', 'button2-up', 'button2-down'); this.buttonB.onDown.add(this.pressButtonB, this); this.buttonC = this.pad.addButton(730, 520, 'arcade', 'button3-up', 'button3-down'); this.buttonC.onDown.add(this.pressButtonC, this); }, pressButtonA: function () { this.sprite.tint = Math.random() * 0xFFFFFF; }, pressButtonB: function () { this.sprite.scale.set(Math.random() * 4); }, pressButtonC: function () { this.sprite.scale.set(1); this.sprite.tint = 0xFFFFFF; }, update: function () { var maxSpeed = 400; if (this.stick.isDown) { this.physics.arcade.velocityFromRotation(this.stick.rotation, this.stick.force * maxSpeed, this.sprite.body.velocity); } else { this.sprite.body.velocity.set(0); } }};game.state.add('Game', PhaserGame, true);On my own game I replaced the phaser.js with the new plugin-included js file. I could post that code also, but it is really much. Do you need that too?