Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. class Main {
  2. constructor() {
  3. this.app = new PIXI.Application(800, 600);
  4. document.body.appendChild(this.app.view);
  5. this.currentSegment = 0;
  6. this.segmentArray = [4,2,6,3,7,5,3,5,2,15,3,2,5,7,3,2];
  7. this.wheel = PIXI.Sprite.fromImage('assets/images/wheel.png');
  8. this.wheel.anchor.set(0.5);
  9. this.arrow = PIXI.Sprite.fromImage('assets/images/arrow.png');
  10. this.spinSound = new Audio('assets/sounds/spin.mp3');
  11. this.winSound = new Audio('assets/sounds/win.mp3');
  12. this.app.ticker.add(
  13. (deltaTime) => this.enterFrame()
  14. );
  15. this.wheel.x = window.innerWidth / 2;
  16. this.wheel.y = window.innerHeight / 2;
  17. this.arrow.position.y = window.innerHeight / 2 - 79;
  18. this.arrow.position.x = window.innerWidth / 2 + 250;
  19. this.app.stage.addChild(this.wheel);
  20. this.app.stage.addChild(this.arrow);
  21. this.app.stage.interactive = true;
  22. this.app.stage.on('pointerdown', () => {
  23. this.spinWheel();
  24. });
  25. }
  26. /**
  27. * Main enterFrame loop.
  28. */
  29. getRandomInt(min, max) {
  30. return Math.floor(Math.random() * (max - min + 1)) + min;
  31. }
  32.  
  33. enterFrame() {
  34. this.app.renderer.resize(
  35. Math.min(window.innerWidth, document.documentElement.clientWidth),
  36. Math.min(window.innerHeight, document.documentElement.clientHeight)
  37. );
  38. }
  39.  
  40. spinWheel() {
  41. this.ourResult = this.getRandomInt(0, 15);
  42. this.spinResult = this.segmentArray[this.ourResult];
  43. this.spinTotal = 0;
  44. this.wheel.rotation = 0;
  45. console.log("click");
  46. this.spinSound.play();
  47. this.app.ticker.add(delta => this.spin(delta));
  48. }
  49.  
  50. spin(delta) {
  51. this.app.stage.off('pointerdown');
  52. console.log(this.spinResult);
  53. console.log(this.spinTotal);
  54. if (this.spinTotal < Math.PI * 2 * 0.0625 * this.ourResult + (Math.PI * 2 * 2)) {
  55. this.spinTotal = this.wheel.rotation += delta * Math.PI * 2 * 0.0125;
  56. console.log('spin');
  57. } else {
  58. console.log('stop');
  59. this.app.ticker.remove();
  60. this.app.stage.on('pointerdown', () => {
  61. this.spinWheel();
  62. });
  63. }
  64.  
  65. /* Application.prototype.stop = function stop() {
  66. this._ticker.stop();
  67. };
  68. */
  69. }
  70. }
  71.  
  72. new Main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement