PhaserGame.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import Phaser from "phaser";
  2. import logoImg from "../assets/twelveHeroes_cover.png";
  3. function addCard(x, y, game,heroName,heroCost,heroPower,heroDesc) {
  4. let textStyle = {
  5. font: "normal 12px Arial",
  6. fill: '#000000',
  7. align: 'center',
  8. boundsAlignH: "center", // bounds center align horizontally
  9. boundsAlignV: "middle" // bounds center align vertically
  10. };
  11. let graphics = game.add.graphics(0, 0);
  12. let color = 0xffff00;
  13. let thickness = 2;
  14. let alpha = 1;
  15. graphics.lineStyle(thickness, color, alpha);
  16. graphics.strokeRect(0, 0, 100, 160);
  17. let text = `${heroName}
  18. cost : ${heroCost}
  19. power : ${heroPower}
  20. ${heroDesc}`;
  21. let label = game.add.text(3, 3, text, textStyle);
  22. label.setOrigin(0, 0);
  23. let container = game.add.container(x,y, [graphics, label]).setSize(5, 5);
  24. // container.setOrigin(0, 0);
  25. }
  26. export default class PhaserGameScene {
  27. constructor(heroesSet) {
  28. this.heroesSet = heroesSet;
  29. // create a new scene named "Game"
  30. this.gameScene = new Phaser.Scene('Game');
  31. this.gameScene.preload = function () {
  32. this.load.image("logo", logoImg);
  33. };
  34. this.gameScene.create = function () {
  35. let i = 0;
  36. heroesSet.forEach(hero => {
  37. addCard(10+(i*100),10,this,hero.name,hero.cost,hero.power,hero.ability.description);
  38. i++;
  39. });
  40. };
  41. // our game's configuration
  42. let config = {
  43. type: Phaser.AUTO, //Phaser will decide how to render our game (WebGL or Canvas)
  44. width: 1200, // game width
  45. height: 550, // game height
  46. scene: this.gameScene, // our newly created scene
  47. backgroundColor: 'rgba(173,216,230 ,1 )'
  48. };
  49. // create the game, and pass it the configuration
  50. this.game = new Phaser.Game(config);
  51. }
  52. }