Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Main {
- constructor() {
- this.app = new PIXI.Application(800, 600);
- document.body.appendChild(this.app.view);
- this.currentSegment = 0;
- this.segmentArray = [4,2,6,3,7,5,3,5,2,15,3,2,5,7,3,2];
- this.wheel = PIXI.Sprite.fromImage('assets/images/wheel.png');
- this.wheel.anchor.set(0.5);
- this.arrow = PIXI.Sprite.fromImage('assets/images/arrow.png');
- this.spinSound = new Audio('assets/sounds/spin.mp3');
- this.winSound = new Audio('assets/sounds/win.mp3');
- this.app.ticker.add(
- (deltaTime) => this.enterFrame()
- );
- this.wheel.x = window.innerWidth / 2;
- this.wheel.y = window.innerHeight / 2;
- this.arrow.position.y = window.innerHeight / 2 - 79;
- this.arrow.position.x = window.innerWidth / 2 + 250;
- this.app.stage.addChild(this.wheel);
- this.app.stage.addChild(this.arrow);
- this.app.stage.interactive = true;
- this.app.stage.on('pointerdown', () => {
- this.spinWheel();
- });
- }
- /**
- * Main enterFrame loop.
- */
- getRandomInt(min, max) {
- return Math.floor(Math.random() * (max - min + 1)) + min;
- }
- enterFrame() {
- this.app.renderer.resize(
- Math.min(window.innerWidth, document.documentElement.clientWidth),
- Math.min(window.innerHeight, document.documentElement.clientHeight)
- );
- }
- spinWheel() {
- this.ourResult = this.getRandomInt(0, 15);
- this.spinResult = this.segmentArray[this.ourResult];
- this.spinTotal = 0;
- this.wheel.rotation = 0;
- console.log("click");
- this.spinSound.play();
- this.app.ticker.add(delta => this.spin(delta));
- }
- spin(delta) {
- this.app.stage.off('pointerdown');
- console.log(this.spinResult);
- console.log(this.spinTotal);
- if (this.spinTotal < Math.PI * 2 * 0.0625 * this.ourResult + (Math.PI * 2 * 2)) {
- this.spinTotal = this.wheel.rotation += delta * Math.PI * 2 * 0.0125;
- console.log('spin');
- } else {
- console.log('stop');
- this.app.ticker.remove();
- this.app.stage.on('pointerdown', () => {
- this.spinWheel();
- });
- }
- /* Application.prototype.stop = function stop() {
- this._ticker.stop();
- };
- */
- }
- }
- new Main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement