/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Football = Container.expand(function () {
var self = Container.call(this);
self.graphics = self.attachAsset('football', {
anchorX: 0.5,
anchorY: 0.5
});
self.rotationSpeed = (Math.random() - 0.5) * 0.1;
self.floatSpeed = Math.random() * 2 + 1;
self.floatOffset = Math.random() * Math.PI * 2;
self.initialY = 0;
self.update = function () {
self.rotation += self.rotationSpeed;
self.y = self.initialY + Math.sin(LK.ticks * 0.05 + self.floatOffset) * self.floatSpeed * 10;
};
return self;
});
var SlotReel = Container.expand(function () {
var self = Container.call(this);
self.reelBg = self.attachAsset('reel', {
anchorX: 0.5,
anchorY: 0.5
});
self.symbols = [];
self.symbolTypes = ['cherry', 'orange', 'plum', 'bell', 'bar', 'seven'];
self.spinning = false;
self.spinSpeed = 0;
self.targetSymbol = 'cherry';
self.spinDuration = 0;
self.maxSpinDuration = 180; // 3 seconds at 60fps
self.isSpinning = false;
self.lastSpinning = false;
// Create visible symbols (3 visible at once)
for (var i = 0; i < 3; i++) {
var symbol = new SlotSymbol();
symbol.setSymbol(self.symbolTypes[Math.floor(Math.random() * self.symbolTypes.length)]);
symbol.y = (i - 1) * 350; // Space symbols 350px apart to prevent overlapping
self.symbols.push(symbol);
self.addChild(symbol);
}
self.startSpin = function () {
self.isSpinning = true;
self.spinSpeed = 20 + Math.random() * 20; // Random initial speed
self.spinDuration = 0;
self.targetSymbol = self.symbolTypes[Math.floor(Math.random() * self.symbolTypes.length)];
LK.getSound('spin').play();
};
self.update = function () {
if (self.isSpinning) {
self.spinDuration++;
// Move symbols down
for (var i = 0; i < self.symbols.length; i++) {
self.symbols[i].y += self.spinSpeed;
// Reset symbol to top when it goes too far down
if (self.symbols[i].y > 525) {
self.symbols[i].y -= 1050; // 3 symbols * 350px spacing
self.symbols[i].setSymbol(self.symbolTypes[Math.floor(Math.random() * self.symbolTypes.length)]);
}
}
// Gradually slow down
if (self.spinDuration > self.maxSpinDuration * 0.7) {
self.spinSpeed *= 0.95;
}
// Stop spinning
if (self.spinDuration >= self.maxSpinDuration || self.spinSpeed < 1) {
self.stopSpin();
}
}
// Track state change for sound effects
if (self.lastSpinning && !self.isSpinning) {
LK.getSound('reel_stop').play();
}
self.lastSpinning = self.isSpinning;
};
self.stopSpin = function () {
self.isSpinning = false;
self.spinSpeed = 0;
// Snap to exact positions
for (var i = 0; i < self.symbols.length; i++) {
var targetY = (i - 1) * 350;
self.symbols[i].y = targetY;
}
// Set the center symbol to target
self.symbols[1].setSymbol(self.targetSymbol);
};
self.getCenterSymbol = function () {
return self.symbols[1].symbolType;
};
return self;
});
var SlotSymbol = Container.expand(function () {
var self = Container.call(this);
self.symbolType = 'cherry';
self.graphics = self.attachAsset('cherry', {
anchorX: 0.5,
anchorY: 0.5
});
self.setSymbol = function (symbolType) {
self.symbolType = symbolType;
self.removeChild(self.graphics);
self.graphics = self.attachAsset(symbolType, {
anchorX: 0.5,
anchorY: 0.5
});
};
return self;
});
var SpinButton = Container.expand(function () {
var self = Container.call(this);
self.graphics = self.attachAsset('spinButton', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonText = new Text2('SPIN', {
size: 40,
fill: 0x000000
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.enabled = true;
self.down = function () {
if (self.enabled && credits >= betAmount) {
startSpin();
}
};
self.setEnabled = function (enabled) {
self.enabled = enabled;
self.graphics.alpha = enabled ? 1.0 : 0.5;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a2e
});
/****
* Game Code
****/
// Game state
var gameStarted = false;
var spinning = false;
var credits = 1000;
var betAmount = 10;
// Game objects
var slotMachine;
var reels = [];
var spinButton;
var creditsText;
var betText;
var winText;
var titleText;
var footballs = [];
// Winning combinations
var payouts = {
'seven': {
three: 1000,
two: 100
},
'bar': {
three: 500,
two: 50
},
'bell': {
three: 200,
two: 20
},
'plum': {
three: 100,
two: 10
},
'orange': {
three: 80,
two: 8
},
'cherry': {
three: 40,
two: 4
}
};
function createSlotMachine() {
// Create slot machine box container
var slotBox = game.addChild(LK.getAsset('slotBox', {
anchorX: 0.5,
anchorY: 0.5
}));
slotBox.x = 1024;
slotBox.y = 1366;
slotBox.scaleX = 0.85;
slotBox.scaleY = 0.85;
// Create slot machine frame inside the box
slotMachine = slotBox.addChild(LK.getAsset('slotMachine', {
anchorX: 0.5,
anchorY: 0.5
}));
slotMachine.x = 0;
slotMachine.y = -50; // Align with reel positioning
slotMachine.scaleX = 0.6; // Slightly smaller to ensure reels are visible
slotMachine.scaleY = 0.6;
// Create 3 reels inside the box
for (var i = 0; i < 3; i++) {
var reel = new SlotReel();
reel.x = (i - 1) * 500; // Even larger spacing between slot columns to separate symbols
reel.y = -50; // Move slightly up for better positioning
reel.scaleX = 0.5; // Smaller scale to fit better in the slot machine frame
reel.scaleY = 0.5;
reels.push(reel);
slotBox.addChild(reel);
}
// Create spin button inside the box
spinButton = new SpinButton();
spinButton.x = 0;
spinButton.y = 280;
spinButton.scaleX = 0.7;
spinButton.scaleY = 0.7;
slotBox.addChild(spinButton);
// Create football balls around slot machine
createFootballs();
}
function createFootballs() {
// Create footballs in a circle around the slot machine
var centerX = 1024;
var centerY = 1366;
var radius = 800;
var numFootballs = 12;
for (var i = 0; i < numFootballs; i++) {
var angle = i / numFootballs * Math.PI * 2;
var football = new Football();
football.x = centerX + Math.cos(angle) * radius;
football.y = centerY + Math.sin(angle) * radius;
football.initialY = football.y;
footballs.push(football);
game.addChild(football);
}
}
function createUI() {
// Title
titleText = new Text2('SEXDAT MAKİNASI', {
size: 80,
fill: 0xFFD700
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 400;
game.addChild(titleText);
// Credits display
creditsText = new Text2('Credits: ' + credits, {
size: 60,
fill: 0xFFFFFF
});
creditsText.anchor.set(0.5, 0);
LK.gui.top.addChild(creditsText);
// Bet display
betText = new Text2('Bet: ' + betAmount, {
size: 50,
fill: 0xFFFFFF
});
betText.anchor.set(0, 0);
betText.x = 50;
betText.y = 50;
LK.gui.topLeft.addChild(betText);
// Win display
winText = new Text2('', {
size: 80,
fill: 0x00FF00
});
winText.anchor.set(0.5, 0.5);
winText.x = 1024;
winText.y = 2200;
winText.alpha = 0;
game.addChild(winText);
}
function startSpin() {
if (spinning || credits < betAmount) return;
spinning = true;
credits -= betAmount;
updateUI();
// Clear any previous win text
winText.alpha = 0;
// Start all reels spinning with slight delays
for (var i = 0; i < reels.length; i++) {
LK.setTimeout(function (reelIndex) {
return function () {
reels[reelIndex].startSpin();
};
}(i), i * 200); // 200ms delay between each reel
}
spinButton.setEnabled(false);
// Set timeout to check results after all reels stop
LK.setTimeout(function () {
checkWin();
spinning = false;
spinButton.setEnabled(true);
}, 4000); // 4 seconds total spin time
}
function checkWin() {
var symbols = [];
for (var i = 0; i < reels.length; i++) {
symbols.push(reels[i].getCenterSymbol());
}
var winAmount = 0;
var winMessage = '';
// Check for three of a kind
if (symbols[0] === symbols[1] && symbols[1] === symbols[2]) {
winAmount = payouts[symbols[0]].three;
winMessage = 'THREE ' + symbols[0].toUpperCase() + 'S! Win: ' + winAmount;
}
// Check for two of a kind
else if (symbols[0] === symbols[1] || symbols[1] === symbols[2] || symbols[0] === symbols[2]) {
var symbol = symbols[0] === symbols[1] ? symbols[0] : symbols[1] === symbols[2] ? symbols[1] : symbols[0];
winAmount = payouts[symbol].two;
winMessage = 'TWO ' + symbol.toUpperCase() + 'S! Win: ' + winAmount;
}
if (winAmount > 0) {
credits += winAmount;
LK.setScore(LK.getScore() + winAmount);
showWinMessage(winMessage);
LK.getSound('win').play();
LK.effects.flashScreen(0x00ff00, 500);
// Make winning symbols sparkle
sparkleWinningSymbols(symbols);
}
updateUI();
// Check for jackpot (1000+ credits)
if (credits >= 5000) {
LK.setTimeout(function () {
LK.showYouWin();
}, 2000);
}
// Check for game over
if (credits < betAmount) {
LK.setTimeout(function () {
LK.showGameOver();
}, 2000);
}
}
function showWinMessage(message) {
winText.setText(message);
winText.alpha = 1;
// Fade out after 3 seconds
tween(winText, {
alpha: 0
}, {
duration: 3000
});
}
function sparkleWinningSymbols(symbols) {
// Check for three of a kind
if (symbols[0] === symbols[1] && symbols[1] === symbols[2]) {
// All three symbols match - sparkle all reels
for (var i = 0; i < reels.length; i++) {
sparkleReel(reels[i]);
}
}
// Check for two of a kind
else if (symbols[0] === symbols[1] || symbols[1] === symbols[2] || symbols[0] === symbols[2]) {
// Two symbols match - sparkle matching reels
if (symbols[0] === symbols[1]) {
sparkleReel(reels[0]);
sparkleReel(reels[1]);
} else if (symbols[1] === symbols[2]) {
sparkleReel(reels[1]);
sparkleReel(reels[2]);
} else if (symbols[0] === symbols[2]) {
sparkleReel(reels[0]);
sparkleReel(reels[2]);
}
}
}
function sparkleReel(reel) {
var centerSymbol = reel.symbols[1]; // Center symbol
var originalAlpha = centerSymbol.alpha;
var originalScale = centerSymbol.scaleX;
// Create pulsing sparkle effect
for (var i = 0; i < 5; i++) {
LK.setTimeout(function (iteration) {
return function () {
// Fade out and scale up
tween(centerSymbol, {
alpha: 0.3,
scaleX: originalScale * 1.3,
scaleY: originalScale * 1.3
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
// Fade back in and scale down
tween(centerSymbol, {
alpha: originalAlpha,
scaleX: originalScale,
scaleY: originalScale
}, {
duration: 200,
easing: tween.easeIn
});
}
});
};
}(i), i * 400);
}
}
function updateUI() {
creditsText.setText('Credits: ' + credits);
betText.setText('Bet: ' + betAmount);
}
// Create game elements
createSlotMachine();
createUI();
game.update = function () {
// Update reels
for (var i = 0; i < reels.length; i++) {
if (reels[i].update) {
reels[i].update();
}
}
// Update footballs
for (var i = 0; i < footballs.length; i++) {
if (footballs[i].update) {
footballs[i].update();
}
}
};
game.down = function (x, y, obj) {
// Start game if not started
if (!gameStarted) {
gameStarted = true;
return;
}
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Football = Container.expand(function () {
var self = Container.call(this);
self.graphics = self.attachAsset('football', {
anchorX: 0.5,
anchorY: 0.5
});
self.rotationSpeed = (Math.random() - 0.5) * 0.1;
self.floatSpeed = Math.random() * 2 + 1;
self.floatOffset = Math.random() * Math.PI * 2;
self.initialY = 0;
self.update = function () {
self.rotation += self.rotationSpeed;
self.y = self.initialY + Math.sin(LK.ticks * 0.05 + self.floatOffset) * self.floatSpeed * 10;
};
return self;
});
var SlotReel = Container.expand(function () {
var self = Container.call(this);
self.reelBg = self.attachAsset('reel', {
anchorX: 0.5,
anchorY: 0.5
});
self.symbols = [];
self.symbolTypes = ['cherry', 'orange', 'plum', 'bell', 'bar', 'seven'];
self.spinning = false;
self.spinSpeed = 0;
self.targetSymbol = 'cherry';
self.spinDuration = 0;
self.maxSpinDuration = 180; // 3 seconds at 60fps
self.isSpinning = false;
self.lastSpinning = false;
// Create visible symbols (3 visible at once)
for (var i = 0; i < 3; i++) {
var symbol = new SlotSymbol();
symbol.setSymbol(self.symbolTypes[Math.floor(Math.random() * self.symbolTypes.length)]);
symbol.y = (i - 1) * 350; // Space symbols 350px apart to prevent overlapping
self.symbols.push(symbol);
self.addChild(symbol);
}
self.startSpin = function () {
self.isSpinning = true;
self.spinSpeed = 20 + Math.random() * 20; // Random initial speed
self.spinDuration = 0;
self.targetSymbol = self.symbolTypes[Math.floor(Math.random() * self.symbolTypes.length)];
LK.getSound('spin').play();
};
self.update = function () {
if (self.isSpinning) {
self.spinDuration++;
// Move symbols down
for (var i = 0; i < self.symbols.length; i++) {
self.symbols[i].y += self.spinSpeed;
// Reset symbol to top when it goes too far down
if (self.symbols[i].y > 525) {
self.symbols[i].y -= 1050; // 3 symbols * 350px spacing
self.symbols[i].setSymbol(self.symbolTypes[Math.floor(Math.random() * self.symbolTypes.length)]);
}
}
// Gradually slow down
if (self.spinDuration > self.maxSpinDuration * 0.7) {
self.spinSpeed *= 0.95;
}
// Stop spinning
if (self.spinDuration >= self.maxSpinDuration || self.spinSpeed < 1) {
self.stopSpin();
}
}
// Track state change for sound effects
if (self.lastSpinning && !self.isSpinning) {
LK.getSound('reel_stop').play();
}
self.lastSpinning = self.isSpinning;
};
self.stopSpin = function () {
self.isSpinning = false;
self.spinSpeed = 0;
// Snap to exact positions
for (var i = 0; i < self.symbols.length; i++) {
var targetY = (i - 1) * 350;
self.symbols[i].y = targetY;
}
// Set the center symbol to target
self.symbols[1].setSymbol(self.targetSymbol);
};
self.getCenterSymbol = function () {
return self.symbols[1].symbolType;
};
return self;
});
var SlotSymbol = Container.expand(function () {
var self = Container.call(this);
self.symbolType = 'cherry';
self.graphics = self.attachAsset('cherry', {
anchorX: 0.5,
anchorY: 0.5
});
self.setSymbol = function (symbolType) {
self.symbolType = symbolType;
self.removeChild(self.graphics);
self.graphics = self.attachAsset(symbolType, {
anchorX: 0.5,
anchorY: 0.5
});
};
return self;
});
var SpinButton = Container.expand(function () {
var self = Container.call(this);
self.graphics = self.attachAsset('spinButton', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonText = new Text2('SPIN', {
size: 40,
fill: 0x000000
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.enabled = true;
self.down = function () {
if (self.enabled && credits >= betAmount) {
startSpin();
}
};
self.setEnabled = function (enabled) {
self.enabled = enabled;
self.graphics.alpha = enabled ? 1.0 : 0.5;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a2e
});
/****
* Game Code
****/
// Game state
var gameStarted = false;
var spinning = false;
var credits = 1000;
var betAmount = 10;
// Game objects
var slotMachine;
var reels = [];
var spinButton;
var creditsText;
var betText;
var winText;
var titleText;
var footballs = [];
// Winning combinations
var payouts = {
'seven': {
three: 1000,
two: 100
},
'bar': {
three: 500,
two: 50
},
'bell': {
three: 200,
two: 20
},
'plum': {
three: 100,
two: 10
},
'orange': {
three: 80,
two: 8
},
'cherry': {
three: 40,
two: 4
}
};
function createSlotMachine() {
// Create slot machine box container
var slotBox = game.addChild(LK.getAsset('slotBox', {
anchorX: 0.5,
anchorY: 0.5
}));
slotBox.x = 1024;
slotBox.y = 1366;
slotBox.scaleX = 0.85;
slotBox.scaleY = 0.85;
// Create slot machine frame inside the box
slotMachine = slotBox.addChild(LK.getAsset('slotMachine', {
anchorX: 0.5,
anchorY: 0.5
}));
slotMachine.x = 0;
slotMachine.y = -50; // Align with reel positioning
slotMachine.scaleX = 0.6; // Slightly smaller to ensure reels are visible
slotMachine.scaleY = 0.6;
// Create 3 reels inside the box
for (var i = 0; i < 3; i++) {
var reel = new SlotReel();
reel.x = (i - 1) * 500; // Even larger spacing between slot columns to separate symbols
reel.y = -50; // Move slightly up for better positioning
reel.scaleX = 0.5; // Smaller scale to fit better in the slot machine frame
reel.scaleY = 0.5;
reels.push(reel);
slotBox.addChild(reel);
}
// Create spin button inside the box
spinButton = new SpinButton();
spinButton.x = 0;
spinButton.y = 280;
spinButton.scaleX = 0.7;
spinButton.scaleY = 0.7;
slotBox.addChild(spinButton);
// Create football balls around slot machine
createFootballs();
}
function createFootballs() {
// Create footballs in a circle around the slot machine
var centerX = 1024;
var centerY = 1366;
var radius = 800;
var numFootballs = 12;
for (var i = 0; i < numFootballs; i++) {
var angle = i / numFootballs * Math.PI * 2;
var football = new Football();
football.x = centerX + Math.cos(angle) * radius;
football.y = centerY + Math.sin(angle) * radius;
football.initialY = football.y;
footballs.push(football);
game.addChild(football);
}
}
function createUI() {
// Title
titleText = new Text2('SEXDAT MAKİNASI', {
size: 80,
fill: 0xFFD700
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 400;
game.addChild(titleText);
// Credits display
creditsText = new Text2('Credits: ' + credits, {
size: 60,
fill: 0xFFFFFF
});
creditsText.anchor.set(0.5, 0);
LK.gui.top.addChild(creditsText);
// Bet display
betText = new Text2('Bet: ' + betAmount, {
size: 50,
fill: 0xFFFFFF
});
betText.anchor.set(0, 0);
betText.x = 50;
betText.y = 50;
LK.gui.topLeft.addChild(betText);
// Win display
winText = new Text2('', {
size: 80,
fill: 0x00FF00
});
winText.anchor.set(0.5, 0.5);
winText.x = 1024;
winText.y = 2200;
winText.alpha = 0;
game.addChild(winText);
}
function startSpin() {
if (spinning || credits < betAmount) return;
spinning = true;
credits -= betAmount;
updateUI();
// Clear any previous win text
winText.alpha = 0;
// Start all reels spinning with slight delays
for (var i = 0; i < reels.length; i++) {
LK.setTimeout(function (reelIndex) {
return function () {
reels[reelIndex].startSpin();
};
}(i), i * 200); // 200ms delay between each reel
}
spinButton.setEnabled(false);
// Set timeout to check results after all reels stop
LK.setTimeout(function () {
checkWin();
spinning = false;
spinButton.setEnabled(true);
}, 4000); // 4 seconds total spin time
}
function checkWin() {
var symbols = [];
for (var i = 0; i < reels.length; i++) {
symbols.push(reels[i].getCenterSymbol());
}
var winAmount = 0;
var winMessage = '';
// Check for three of a kind
if (symbols[0] === symbols[1] && symbols[1] === symbols[2]) {
winAmount = payouts[symbols[0]].three;
winMessage = 'THREE ' + symbols[0].toUpperCase() + 'S! Win: ' + winAmount;
}
// Check for two of a kind
else if (symbols[0] === symbols[1] || symbols[1] === symbols[2] || symbols[0] === symbols[2]) {
var symbol = symbols[0] === symbols[1] ? symbols[0] : symbols[1] === symbols[2] ? symbols[1] : symbols[0];
winAmount = payouts[symbol].two;
winMessage = 'TWO ' + symbol.toUpperCase() + 'S! Win: ' + winAmount;
}
if (winAmount > 0) {
credits += winAmount;
LK.setScore(LK.getScore() + winAmount);
showWinMessage(winMessage);
LK.getSound('win').play();
LK.effects.flashScreen(0x00ff00, 500);
// Make winning symbols sparkle
sparkleWinningSymbols(symbols);
}
updateUI();
// Check for jackpot (1000+ credits)
if (credits >= 5000) {
LK.setTimeout(function () {
LK.showYouWin();
}, 2000);
}
// Check for game over
if (credits < betAmount) {
LK.setTimeout(function () {
LK.showGameOver();
}, 2000);
}
}
function showWinMessage(message) {
winText.setText(message);
winText.alpha = 1;
// Fade out after 3 seconds
tween(winText, {
alpha: 0
}, {
duration: 3000
});
}
function sparkleWinningSymbols(symbols) {
// Check for three of a kind
if (symbols[0] === symbols[1] && symbols[1] === symbols[2]) {
// All three symbols match - sparkle all reels
for (var i = 0; i < reels.length; i++) {
sparkleReel(reels[i]);
}
}
// Check for two of a kind
else if (symbols[0] === symbols[1] || symbols[1] === symbols[2] || symbols[0] === symbols[2]) {
// Two symbols match - sparkle matching reels
if (symbols[0] === symbols[1]) {
sparkleReel(reels[0]);
sparkleReel(reels[1]);
} else if (symbols[1] === symbols[2]) {
sparkleReel(reels[1]);
sparkleReel(reels[2]);
} else if (symbols[0] === symbols[2]) {
sparkleReel(reels[0]);
sparkleReel(reels[2]);
}
}
}
function sparkleReel(reel) {
var centerSymbol = reel.symbols[1]; // Center symbol
var originalAlpha = centerSymbol.alpha;
var originalScale = centerSymbol.scaleX;
// Create pulsing sparkle effect
for (var i = 0; i < 5; i++) {
LK.setTimeout(function (iteration) {
return function () {
// Fade out and scale up
tween(centerSymbol, {
alpha: 0.3,
scaleX: originalScale * 1.3,
scaleY: originalScale * 1.3
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
// Fade back in and scale down
tween(centerSymbol, {
alpha: originalAlpha,
scaleX: originalScale,
scaleY: originalScale
}, {
duration: 200,
easing: tween.easeIn
});
}
});
};
}(i), i * 400);
}
}
function updateUI() {
creditsText.setText('Credits: ' + credits);
betText.setText('Bet: ' + betAmount);
}
// Create game elements
createSlotMachine();
createUI();
game.update = function () {
// Update reels
for (var i = 0; i < reels.length; i++) {
if (reels[i].update) {
reels[i].update();
}
}
// Update footballs
for (var i = 0; i < footballs.length; i++) {
if (footballs[i].update) {
footballs[i].update();
}
}
};
game.down = function (x, y, obj) {
// Start game if not started
if (!gameStarted) {
gameStarted = true;
return;
}
};