Jump to content

Choosing a character from a roster for player 1 and 2


vernonr
 Share

Recommended Posts

Hi, good people! I encountered a new problem while coding my first game. First, let me explain what I have so far. It's a fighting game. I have my two characters on screen: player1 and player2. They move alright. They both have some movements in common (like moving around, jumping and ducking) and some movements of their own (a combination of keys will trigger a special move of some sort). 

 

Among other things, I have this in my code:

 

var player;

var player1;

 

In function create() :

 

player = game.add.sprite(18, 200, 'ciro');

player2 = game.add.sprite(618, 200, 'damian');
 
Finally, in function update() I have the movements of each of these characters.
 
So what's the problem? I also have other characters in mind, with individual sprites, animations and moves (and they will share the basic moves, as well). My idea is to have a roster of fighters from where player1 and player2 will choose one each and then, in a stage randomly picked, fight each other. You know how it goes. 
 
How can player1 and player2 "choose" a character? Should I set the characters, with the sprites, animations and special moves in some sort of class or separate file and then, add the chosen one to either player1 or player2? I'm guessing I need some sort of variable there but I know almost nothing about javascript :s
 
Help! I'm clueless!
 
 
 
 
 
 
Link to comment
Share on other sites

You need to extend Sprite and create custom character classes.

 




class FighterBase extends Phaser.Sprite
  // generic movement logic, generic animations, sound etc.

class RyuFighter extends FighterBase
  // Ryu specific movement logic, animations


Then you will have a FightMatch class that extends Phaser.Group, that will combine two players and match logic

 



class FightMatch extends Phaser.Group
  p1 = RyuFighter
  p2 = KenFighter


See I have hardcoded the players, but you can put the logic to select a specific fighter in this class
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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