Jump to content

Game object within a game object


emshuttles
 Share

Recommended Posts

Two classmates and I are trying to build a Tetris RPG in which clearing a row gives you mana, which can be used to cast damaging spells at the enemy. Basically, your typical puzzle RPG mobile game, except you get to choose your attacks and when to do them.

We started out by building a vanilla Tetris game in the main game state file. Once that was finished, we tried creating a Tetris class to put all of that logic into. Then, we ran into a problem: we can't use the Phaser methods (e.g., creating sprites, detecting key presses) in the Tetris class, so we had to leave some functions behind in the game state file.

What is the most elegant solution to this? Could we have a Tetris game object running within a more general 'battle' game that would also handle the enemy and player logic? Or is there some other way to use Phaser methods in a JS class?

Link to comment
Share on other sites

You can extend the main Phaser object and create your own object from that, for example, using esnext class syntax:

class Tetris extends Phaser.Game {}

note: this is just sugar, if you're not writing using newer syntax then doing this is trivial also, just takes a few more lines of code.

You can also do this with Phaser states too if you like/need.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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