Guest User

Untitled

a guest
May 26th, 2018
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>MushroomSlalom</title>
  6. <script src="//cdn.jsdelivr.net/npm/phaser@3.1.1/dist/phaser.min.js"></script>
  7. <script lang="js">
  8.  
  9. window.onload = function() {
  10.  
  11.  
  12. class MazeToGoal extends Phaser.Scene {
  13.  
  14. constructor (config)
  15. {
  16. super(config);
  17. Phaser.Scene.call(this, { key: "MazeToGoal", active: true });
  18. this.gameOn=true;
  19. this.score=0;
  20. this.scoreMsg="Score: ";
  21. this.scoreText;
  22. this.my_buttons = [];
  23. this.step=4;
  24. this.counter;
  25. this.gates=[];
  26. }
  27.  
  28. preload() {
  29. this.load.spritesheet('mushrooms', '/assets/icons/mushrooms-diffrent-color-128x128-7x3.png', { frameWidth: 128, frameHeight: 128});
  30. }
  31.  
  32. create ()
  33. {
  34. this.pen = this.make.graphics({x: 0, y: 0, add: false});
  35. this.pen.fillStyle(0x00FF00, 1.0);
  36. this.pen.fillRect(0, 0, 30, 30);
  37. this.pen.generateTexture('goal', 30, 30);
  38. this.player = this.add.image(100, 270, 'goal');
  39. this.scoreText = this.add.text(10, 10,this.scoreMsg+this.score, { fontSize: '32px', fill: '#FFF' });
  40. this.counter=0;
  41.  
  42. this.gates[0]=this.createGate(100);
  43.  
  44. this.cursors = this.input.keyboard.createCursorKeys();
  45. }
  46.  
  47. update()
  48. {
  49. if(this.gameOn) {
  50. this.counter++;
  51. if(this.counter % 200 === 0) {
  52. this.gates.push(this.createGate(100));
  53. }
  54. if (this.cursors.up.isDown)
  55. {
  56. this.player.y-=this.step;
  57. }
  58. else if (this.cursors.down.isDown)
  59. {
  60. this.player.y+=this.step;
  61. }
  62.  
  63. if(this.player.x-5 < this.gates[0].left.x && this.gates[0].left.x < this.player.x+5) {
  64. if(this.gates[0].left.y < this.player.y && this.player.y < this.gates[0].right.y) {
  65. console.log("Hit");
  66. this.gates.shift();
  67.  
  68. }
  69. else {
  70. this.gameOn=false;
  71. this.add.text(25, 200,"Game Over", { fontSize: '128px', fill: '#F00' });
  72. console.log("Boom");
  73. }
  74. }
  75.  
  76. }
  77. }
  78.  
  79. createGate(StartY) {
  80. let gate={};
  81. gate.left = this.add.image(700,StartY, 'mushrooms', 1).setScale(0.25);
  82. gate.right = this.add.image(700, StartY+100, 'mushrooms', 1).setScale(0.25);
  83.  
  84. gate.tween = this.tweens.add({
  85. targets: [gate.left, gate.right] ,
  86. x: -50,
  87. //ease: 'Power1',
  88. duration: 5000
  89. });
  90. return gate;
  91. }
  92.  
  93. }
  94.  
  95. const config = {
  96. type: Phaser.WEBGL,
  97. width: 800,
  98. height: 600,
  99. backgroundColor: "#FFFFFF",
  100. parent: "phaser-example",
  101. scene: [MazeToGoal]
  102. };
  103.  
  104.  
  105. const game = new Phaser.Game(config);
  106. };
  107. </script>
  108. </head>
  109. <body>
  110. <div id="phaser-example"></div>
  111. </body>
  112. </html>
Add Comment
Please, Sign In to add comment