Jump to content

Phaser game - Few questions/problems


Mizukage
 Share

Recommended Posts

Hi,

 

My idea is make a game based on Phaser.js engine in 72h (Not in a row of course) 
At this moment I'm after 24h of work on my first game and I have a lot ideas how to upgrade my game. But not enought skill for that ;)

 

u9um7z.jpg

 

 

It will be some PvP fight game, two players will share one keyboard.

 

My main problem at the moment is how can I put simply animation in to shurikens collision, animation like show one picture for maybe 400ms is place where this collision was.

Its my shurikens collision function (shuriken I mean throwing star like a Shinobi)

  function shurikenCollision(sprite, jutsu) {    if (sprite == player_sprite) {      attack(player);    } else if (sprite == enemy_sprite) {      attack(enemy);    } else if (sprite == enemy_shurikens || shurikens && jutsu == enemy_shurikens || shurikens) {      sprite.kill();      jutsu.kill();      clashSound();    }         jutsu.kill();    refresh_bar();  }
  function clashSound() {    //25% na dziwiek clash1 i 75% na clash2    x = Math.floor(Math.random() * 4) +1;        if (x === 1) {      clash1_fx.play();    } else {      clash2_fx.play();    }   }

And my second problem atm is how can I change my shuriken throwing function for make it better.

  function throw_shuriken(sprite) {    if (sprite === enemy_sprite) {      if (player.sh_cap > 0 && player.stamina >= 5 && player.life) {        shuriken = shurikens.getFirstExists(false);        if (shuriken) {          shuriken.reset(player_sprite.x + player.way, player_sprite.y + 18);          shuriken.body.velocity.x = player.trace;          player.stamina -= 5;          player.sh_cap -= 1;          throw_fx.play();          refresh_bar();        }      }    } else if (sprite === player_sprite) {        if (enemy.sh_cap > 0 && enemy.stamina >= 5 && enemy.life) {          enemy_shuriken = enemy_shurikens.getFirstExists(false);          if (enemy_shuriken) {          enemy_shuriken.reset(enemy_sprite.x + enemy.way, enemy_sprite.y + 18);          enemy_shuriken.body.velocity.x = enemy.trace;          enemy.stamina -= 5;          enemy.sh_cap -= 1;          throw_fx.play();          refresh_bar();        }      }    }  }

Its working pretty fine, but only when players have some distance from each other, when they too close then shurikens can be throwed extremly fast like from AK74 :D 



Sorry for my english, and thanks for help !! 
:ph34r:  :ph34r:

Link to comment
Share on other sites

To show an effect where your shuriken collided, you can create another sprite object at that location and just make it run until it's animation is finished then remove it.  Particle systems are good for this type of effect and for that you create a new particle system at the collision point, remove the shuriken, then run the particle system for a short while before removing it.

 

For your second problem, I'm not familiar with the .trace variable you are using but would suggest that the speed problem is there.  You need to set the speed as a constant value regardless of how near the players are to each other, and modified only by the direction:

 

// example only, 5 is probably not a good velocity!

if (player.sprite.x > enemy.sprite.x) shuriken.body.velocity = 5;

else shuriken.body.velocity = -5;

Link to comment
Share on other sites

Hmm ok I made this effect after shurikens collision, by include this part od code to my former collide function

 

      shu_animation = shu_animations.getFirstExists(false);      shu_animation.reset()      shu_animation.reset(jutsu.body.x + jutsu.body.halfWidth, jutsu.body.y + jutsu.body.halfHeight);      shu_animation.play('shu_animation');

And @InsaneHero I dont get your solution, I have problem becaouse my shuricens can be throwed when last shuriken was destroyed, so if player come closer to oponent then shurikiens are that fast. 

Link to comment
Share on other sites

Which out player.trace or enemy.trace  shurikens can't move 

 

Its like this movement function 

enemy_sprite.body.velocity.x = 0;    if (cursors.left.isDown) {    //Idzie w lewo    enemy_sprite.body.velocity.x = -enemy.speed;    //odegraj animacje    enemy_sprite.animations.play('left');    //    enemy.way = -49;    enemy.trace = -800;      } else if (cursors.right.isDown) {    enemy_sprite.body.velocity.x = enemy.speed;    enemy_sprite.animations.play('right');    enemy.way = 49;    enemy.trace = 800;      } else {    enemy_sprite.animations.stop();  }    if (player_fire.isDown && player.life) {    throw_shuriken(player_sprite);  }
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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