Advertisement
Guest User

Untitled

a guest
Jul 16th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Initiate the Phaser framework.
  2. const game = new Phaser.Game(750, 450, Phaser.AUTO, '', { preload: preload, create: create, update, update });
  3.  
  4. // Load the game assets before the game starts.
  5. function preload() {
  6.     game.load.image('Background', 'assets/bg.jpg');
  7.     game.load.image('Background_Coins', 'assets/bg-coins.png');
  8.     game.load.image('Background_Overlay', 'assets/dark-bg-overlay.png');
  9.     game.load.image('Big_Win', 'assets/big-win.png');
  10.     game.load.image('Coin_Animation', 'assets/coin-animation.png');
  11.     game.load.image('Mouse_Hand', 'assets/mousehand.png');
  12.     game.load.image('Huge_Win', 'assets/huge-win.png');
  13.     game.load.image('Install_Button', 'assets/install-btn.png');
  14.     game.load.image('Lines_Number', 'assets/lines-number.png');
  15.     game.load.image('Numbers_Top', 'assets/number-button.png');
  16.     game.load.image('Reel_Background', 'assets/reel-bg.png');
  17.     game.load.image('Reel_Overlay', 'assets/reel-overlay.png');
  18.     game.load.image('Slotmachine', 'assets/slotmachine-transparant.png');
  19.     game.load.image('Slots_Bar', 'assets/slots-bar.png');
  20.     game.load.image('Slots_Bar_Lighter', 'assets/slots-bar-lighter.png');
  21.     game.load.image('Slots_Crown', 'assets/slots-crown.png');
  22.     game.load.image('Slots_Diamond', 'assets/slots-diamond.png');
  23.     game.load.image('Slots_Diamond_Lighter', 'assets/slots-diamond-lighter.png');
  24.     game.load.image('Slots_Lemon', 'assets/slots-lemon.png');
  25.     game.load.image('Slots_Watermelon', 'assets/slots-watermelon.png');
  26.     game.load.image('Slots_Seven', 'assets/slots-7.png');
  27.     game.load.image('Slots_Ten', 'assets/slots-10.png');
  28.     game.load.image('Spin_Button', 'assets/spin-btn.png');
  29.     game.load.image('Spin_Button_Lighter', 'assets/spin-btn-glow.png');
  30.     game.load.image('Start_Spinning', 'assets/start-spinning.png');
  31.     game.load.image('Top_Bars_Glow', 'assets/top-bars-glow.png');
  32.     game.load.image('Top_Diamond_Glow', 'assets/top-diamond-glow.png');
  33.     game.load.image('Total_Bet_Number', 'assets/total-bet-number.png');
  34.  
  35.     game.load.spritesheet('Numbers_Spritesheet', 'assets/red-numbers-sprite.png', 11, 22, 11);
  36. }
  37.  
  38. var sprite;
  39. var slotmachine;
  40. var slotValues, counter;
  41. var slotsSeven, slotsTen, slotsBar, slotsDiamond, slotsLemon, slotsWatermelon, slotsCrown;
  42. var speed, maxUp, maxDown, upDownTimer;
  43. var spinButton, spinButtonGlow, spinStart, mouseHand;
  44. var reelBackground1, reelBackground2, reelBackground3, reelBackground4;
  45. var reelOverlay1, reelOverlay2, reelOverlay3, reelOverlay4;
  46. var linesNumber, totalBetNumber;
  47.  
  48. // Executed after everything is loaded.
  49. function create() {
  50.  
  51.     speed = 15;
  52.     maxUp = 320;
  53.     maxDown = 325;
  54.  
  55.     // Physics System.
  56.     game.physics.startSystem(Phaser.Physics.ARCADE);
  57.  
  58.     game.add.image(0, 0, 'Background');
  59.  
  60.     slotmachine = game.add.image(155, 12, 'Slotmachine');
  61.  
  62.     // Adds the reel background.
  63.     reelBackground1 = game.add.image(200, 167, 'Reel_Background');
  64.     reelBackground2 = game.add.image(0, 0, 'Reel_Background').alignTo(reelBackground1, Phaser.RIGHT_CENTER, -18);
  65.     reelBackground3 = game.add.image(0, 0, 'Reel_Background').alignTo(reelBackground2, Phaser.RIGHT_CENTER, -17);
  66.     reelBackground4 = game.add.image(0, 0, 'Reel_Background').alignTo(reelBackground3, Phaser.RIGHT_CENTER, -13);
  67.  
  68.     // Adds images of the slots.
  69.     slotsCrown = game.add.image(207, -6, 'Slots_Crown')
  70.     slotsSeven = game.add.image(0, 0, 'Slots_Seven').alignTo(slotsCrown, Phaser.BOTTOM_CENTER, 0, -27);
  71.     slotsTen = game.add.image(0, 0, 'Slots_Ten').alignTo(slotsSeven, Phaser.BOTTOM_CENTER, 0, -27);
  72.     slotsBar = game.add.image(0, 0, 'Slots_Bar').alignTo(slotsTen, Phaser.BOTTOM_CENTER, 0, -27);
  73.     slotsWatermelon = game.add.image(0, 0, 'Slots_Watermelon').alignTo(slotsBar, Phaser.BOTTOM_CENTER, 0, -27);
  74.     slotsLemon = game.add.image(0, 0, 'Slots_Lemon').alignTo(slotsWatermelon, Phaser.BOTTOM_CENTER, 0, -27);
  75.     slotsDiamond = game.add.image(0, 0, 'Slots_Diamond').alignTo(slotsLemon, Phaser.BOTTOM_CENTER, 0, -27);
  76.  
  77.     // Adds the greyish reel overlay.
  78.     reelOverlay1 = game.add.image(205.3, 172, 'Reel_Overlay');
  79.     reelOverlay2 = game.add.image(0, 0, 'Reel_Overlay').alignTo(reelOverlay1, Phaser.RIGHT_CENTER, 0);
  80.     reelOverlay3 = game.add.image(0, 0, 'Reel_Overlay').alignTo(reelOverlay2, Phaser.RIGHT_CENTER, 1);
  81.     reelOverlay4 = game.add.image(0, 0, 'Reel_Overlay').alignTo(reelOverlay3, Phaser.RIGHT_CENTER, 5);
  82.  
  83.     linesNumber = game.add.image(198, 388, 'Lines_Number');
  84.     totalBetNumber = game.add.image(241.5, 388, 'Total_Bet_Number');
  85.  
  86.     spinButton = game.add.button(481, 366, 'Spin_Button', actionOnUp, this, 2, 1, 0);
  87.     spinButton.onInputOver.add(actionOnOver, this);
  88.     spinButton.onInputOut.add(actionOnOut, this);
  89.  
  90.     spinButtonGlow = game.add.image(481, 366, 'Spin_Button_Lighter');
  91.     spinButtonGlow.visible = false;
  92.  
  93.     spinStart = game.add.sprite(460, 320, 'Start_Spinning');
  94.     spinStart.visible = true;
  95.  
  96.     // Enables the Physics System for spinStart.
  97.     game.physics.enable(spinStart, Phaser.Physics.ARCARDE);
  98.  
  99.     // Takes the first sprite from the spritesheet.
  100.     sprite = game.add.sprite(376.5, 388, 'Numbers_Spritesheet');
  101.     sprite.frame = 0;
  102.  
  103.     mouseHand = game.add.image(545, 390, 'Mouse_Hand');
  104.     mouseHand.visible = true;
  105.  
  106.     // Scales images down.
  107.     slotmachine.scale.setTo(0.62, 0.62);
  108.  
  109.     // Reel backgrounds.
  110.     reelBackground1.scale.setTo(0.59, 0.59);
  111.     reelBackground2.scale.setTo(0.59, 0.59);
  112.     reelBackground3.scale.setTo(0.59, 0.59);
  113.     reelBackground4.scale.setTo(0.59, 0.59);
  114.  
  115.     // Slots images.
  116.     slotsBar.scale.setTo(0.6, 0.6);
  117.     slotsCrown.scale.setTo(0.6, 0.6);
  118.     slotsDiamond.scale.setTo(0.6, 0.6);
  119.     slotsLemon.scale.setTo(0.6, 0.6);
  120.     slotsSeven.scale.setTo(0.6, 0.6);
  121.     slotsTen.scale.setTo(0.6, 0.6);
  122.     slotsWatermelon.scale.setTo(0.6, 0.6);
  123.  
  124.     // Reel overlays.
  125.     reelOverlay1.scale.setTo(0.5898, 0.5898);
  126.     reelOverlay2.scale.setTo(0.5898, 0.5898);
  127.     reelOverlay3.scale.setTo(0.5898, 0.5898);
  128.     reelOverlay4.scale.setTo(0.5898, 0.5898);
  129.  
  130.     linesNumber.scale.setTo(0.7, 0.7);
  131.     totalBetNumber.scale.setTo(0.7, 0.7);
  132.     sprite.scale.setTo(0.7, 0.7);
  133.  
  134.     spinButton.scale.setTo(0.611, 0.611);
  135.     spinButtonGlow.scale.setTo(0.611, 0.611);
  136.     spinStart.scale.setTo(0.6, 0.6);
  137.  
  138.     mouseHand.scale.setTo(0.6, 0.6);
  139. }
  140. // Executed per frame.
  141. function update() {
  142.     if (spinStart.body.position.y <= maxUp) {
  143.         spinStart.body.velocity.y = speed;
  144.     }
  145.     else if (spinStart.body.position.y >= maxDown) {
  146.         spinStart.body.velocity.y = -speed;
  147.     }
  148. }
  149.  
  150. function actionOnUp(button, pointer, onClick) {
  151.     // If the button is re-pressed, the action will be canceled so the spinButtonGlow disappears and spinStart won't pop up.
  152.     if (onClick) {
  153.         spinStart.visible = !spinStart.visible;
  154.         spinButtonGlow.visible = !spinButtonGlow.visible;
  155.         mouseHand.visible = !mouseHand.visible;
  156.     }
  157. }
  158.  
  159. function actionOnOver() {
  160.     spinStart.visible = false;
  161.     if (!spinButtonGlow.visible) {
  162.         spinStart.visible = true;
  163.     }
  164. }
  165.  
  166. function actionOnOut() {
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement