Skip to content

ktsalik/slot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

88 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

slot

Web Slot Machine game library based on PixiJS.

Example

Include library

<script src="../dist/slot.js"></script>

You game container element

<div id="game-container"></div>

Create the game

var resources = [
  ['symbol-1', 'assets/space adventure/symbol-1.png'],
  ['symbol-2', 'assets/space adventure/symbol-2.png'],
  ['symbol-3', 'assets/space adventure/symbol-3.png'],
];

function init(game) {
  // create a reel
  var reel = game.reels.add(3); // with 3 positions

  // position reel
  reel.x = 100;
  reel.y = 100;

  // initial values
  reel.values = [1, 1, 2, 3];

  game.on('start', function() {
    // populate reel with random spin values
    var symbolsCount = 3;
    for (var i = 0; i < 14; i++) {
      reel.spinValues.push(parseInt(Math.random() * symbolsCount) + 1);
    }
    // stop (result) values
    reel.stopValues = [3, 3, 2, 1];
  });

  // play using Spacebar
  window.addEventListener('keydown', function(e) {
    if (e.keyCode == 32) {
      game.play();
    }
  });
}

// initialize game
var game = new Slot({
  container: '#game-container',
  resources,
  init,
}, 1500, 640);

More examples

Basic Example

A simple 3x3 offline game.

Network Example

Uses hypothetical network.