function SlotReel() { this.id = 0; this.position = {x: 0, y: 0}; this.width = 256; this.height = 512; this.isSpinning = false; this.scrollAmount = 2048; this.scrollSpeed = 15; this.reelRotationsOffset = 0; this.remainingRevolutions = 0; this.spinTarget = 0; this.resizeModifier = 1; this.init = function(newPos, offset) { this.position.x = newPos.x; this.position.y = newPos.y; this.reelRotationsOffset = offset; this.spinTarget = Math.floor(7 * Math.random()); this.scrollAmount = 256 * this.spinTarget - 128; this.scrollSpeed = Math.floor(10 * Math.random() - 5) + 25; } this.update = function(delta) { if(this.isSpinning) { this.scrollAmount -= this.scrollSpeed; if(this.remainingRevolutions <= 0) { if(this.scrollAmount <= 256 * this.spinTarget - 128) { this.scrollAmount = 256 * this.spinTarget - 128; this.isSpinning = false; } } if(this.scrollAmount <= -128) { this.scrollAmount += 2048; this.remainingRevolutions--; } } } this.draw = function(context) { context.save(); context.translate(this.position.x * this.resizeModifier, this.position.y * this.resizeModifier); context.drawImage(system.assets.getSprite("slotreel"), 0, this.scrollAmount + 2048, 256, 512, 0, 0, 256 * this.resizeModifier, 512 * this.resizeModifier); context.drawImage(system.assets.getSprite("slotreel"), 0, this.scrollAmount, 256, 512, 0, 0, 256 * this.resizeModifier, 512 * this.resizeModifier); context.drawImage(system.assets.getSprite("slotreel"), 0, this.scrollAmount - 2048, 256, 512, 0, 0, 256 * this.resizeModifier, 512 * this.resizeModifier); context.restore(); } this.handleResize = function(canvas) { this.resizeModifier = 1; if(canvas.width < 768) { this.resizeModifier = 0.5; } } this.startSpin = function() { this.isSpinning = true; this.remainingRevolutions = 1 + this.reelRotationsOffset; this.spinTarget = Math.floor(7 * Math.random()); } };