/**** * Classes ****/ // Explosion class var Explosion = Container.expand(function () { var self = Container.call(this); var explosionGraphics = self.createAsset('explosion', 'Explosion Graphics', 0.5, 0.5); self.animate = function () { explosionGraphics.alpha = 1; var scale = 0.1; var animationStep = function animationStep() { scale += 0.1; if (scale >= 2) { self.destroy(); return; } explosionGraphics.scale.set(scale, scale); explosionGraphics.alpha -= 0.05; LK.setTimeout(animationStep, 50); }; LK.setTimeout(animationStep, 50); }; }); // Roulette Wheel class var RouletteWheel = Container.expand(function () { var self = Container.call(this); var wheelGraphics = self.createAsset('rouletteWheel', 'Roulette Wheel', 0.5, 0.5); wheelGraphics.scale.set(2.5); // Increase the wheel size by 150% self.angle = 0; // Current angle of the wheel self.rotationSpeed = 0; // Current rotation speed of the wheel // Update the wheel's rotation self.update = function () { self.angle += self.rotationSpeed; self.angle %= 360; // Keep the angle within 0-359 degrees wheelGraphics.rotation = self.angle * (Math.PI / 180); // Convert to radians for PIXI rotation // Gradually slow down the wheel if (self.rotationSpeed > 0) { self.rotationSpeed -= 0.1; if (self.rotationSpeed < 0.1) { self.rotationSpeed = 0; } } }; // Start spinning the wheel self.spin = function () { self.rotationSpeed = 10 + Math.random() * 10; // Random rotation speed between 10 and 20 }; }); // Arrow class var Arrow = Container.expand(function () { var self = Container.call(this); var arrowGraphics = self.createAsset('arrow', 'Arrow at the top of the wheel', 0.5, 0.5); // Position the arrow above the wheel self.updatePosition = function (wheel) { self.x = wheel.x; self.y = wheel.y - wheel.height / 2 - arrowGraphics.height / 2; }; }); // Ball class var Ball = Container.expand(function () { var self = Container.call(this); var ballGraphics = self.createAsset('ball', 'Ball', 0.5, 0.5); self.positionOnWheel = 0; // Position on the wheel // Update the ball's position self.update = function (wheel) { // Ball's position is relative to the wheel's current angle self.positionOnWheel = (wheel.angle + 5) % 360; // Offset by 5 degrees for visual effect var radians = self.positionOnWheel * (Math.PI / 180); // Calculate the ball's position around the wheel self.x = wheel.x + Math.cos(radians) * wheel.width * 0.45; self.y = wheel.y + Math.sin(radians) * wheel.height * 0.45; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // Initialize the roulette wheel var rouletteWheel = game.addChild(new RouletteWheel()); rouletteWheel.x = game.width / 2; rouletteWheel.y = game.height / 2; // Initialize the arrow var arrow = game.addChild(new Arrow()); // Initialize the ball var ball = game.addChild(new Ball()); // Update the arrow's position arrow.updatePosition(rouletteWheel); // Spin button var spinButton = game.addChild(LK.getAsset('spinButton', 'Spin Button', 0.5, 0.5)); spinButton.x = game.width / 2; spinButton.y = game.height - spinButton.height / 2; spinButton.interactive = true; spinButton.buttonMode = true; // Event listener for the spin button var spinClickCount = 0; // Counter for the number of spin button clicks spinButton.on('down', function () { rouletteWheel.spin(); spinClickCount++; if (spinClickCount >= 10) { var explosion = game.addChild(new Explosion()); explosion.x = game.width / 2; explosion.y = game.height / 2; explosion.animate(); LK.showGameOver('game over, you clicked too fast'); } }); // Main game update loop LK.on('tick', function () { rouletteWheel.update(); ball.update(rouletteWheel); // Check if the wheel has stopped spinning if (rouletteWheel.rotationSpeed <= 0) { // Determine the winning number based on the ball's position var winningNumber = Math.floor(ball.positionOnWheel / (360 / 37)); // Assuming a 37-slot wheel (0-36) // Display the winning number (this is a placeholder, actual display code would be needed) console.log("Winning Number: " + winningNumber); } });
/****
* Classes
****/
// Explosion class
var Explosion = Container.expand(function () {
var self = Container.call(this);
var explosionGraphics = self.createAsset('explosion', 'Explosion Graphics', 0.5, 0.5);
self.animate = function () {
explosionGraphics.alpha = 1;
var scale = 0.1;
var animationStep = function animationStep() {
scale += 0.1;
if (scale >= 2) {
self.destroy();
return;
}
explosionGraphics.scale.set(scale, scale);
explosionGraphics.alpha -= 0.05;
LK.setTimeout(animationStep, 50);
};
LK.setTimeout(animationStep, 50);
};
});
// Roulette Wheel class
var RouletteWheel = Container.expand(function () {
var self = Container.call(this);
var wheelGraphics = self.createAsset('rouletteWheel', 'Roulette Wheel', 0.5, 0.5);
wheelGraphics.scale.set(2.5); // Increase the wheel size by 150%
self.angle = 0; // Current angle of the wheel
self.rotationSpeed = 0; // Current rotation speed of the wheel
// Update the wheel's rotation
self.update = function () {
self.angle += self.rotationSpeed;
self.angle %= 360; // Keep the angle within 0-359 degrees
wheelGraphics.rotation = self.angle * (Math.PI / 180); // Convert to radians for PIXI rotation
// Gradually slow down the wheel
if (self.rotationSpeed > 0) {
self.rotationSpeed -= 0.1;
if (self.rotationSpeed < 0.1) {
self.rotationSpeed = 0;
}
}
};
// Start spinning the wheel
self.spin = function () {
self.rotationSpeed = 10 + Math.random() * 10; // Random rotation speed between 10 and 20
};
});
// Arrow class
var Arrow = Container.expand(function () {
var self = Container.call(this);
var arrowGraphics = self.createAsset('arrow', 'Arrow at the top of the wheel', 0.5, 0.5);
// Position the arrow above the wheel
self.updatePosition = function (wheel) {
self.x = wheel.x;
self.y = wheel.y - wheel.height / 2 - arrowGraphics.height / 2;
};
});
// Ball class
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.createAsset('ball', 'Ball', 0.5, 0.5);
self.positionOnWheel = 0; // Position on the wheel
// Update the ball's position
self.update = function (wheel) {
// Ball's position is relative to the wheel's current angle
self.positionOnWheel = (wheel.angle + 5) % 360; // Offset by 5 degrees for visual effect
var radians = self.positionOnWheel * (Math.PI / 180);
// Calculate the ball's position around the wheel
self.x = wheel.x + Math.cos(radians) * wheel.width * 0.45;
self.y = wheel.y + Math.sin(radians) * wheel.height * 0.45;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize the roulette wheel
var rouletteWheel = game.addChild(new RouletteWheel());
rouletteWheel.x = game.width / 2;
rouletteWheel.y = game.height / 2;
// Initialize the arrow
var arrow = game.addChild(new Arrow());
// Initialize the ball
var ball = game.addChild(new Ball());
// Update the arrow's position
arrow.updatePosition(rouletteWheel);
// Spin button
var spinButton = game.addChild(LK.getAsset('spinButton', 'Spin Button', 0.5, 0.5));
spinButton.x = game.width / 2;
spinButton.y = game.height - spinButton.height / 2;
spinButton.interactive = true;
spinButton.buttonMode = true;
// Event listener for the spin button
var spinClickCount = 0; // Counter for the number of spin button clicks
spinButton.on('down', function () {
rouletteWheel.spin();
spinClickCount++;
if (spinClickCount >= 10) {
var explosion = game.addChild(new Explosion());
explosion.x = game.width / 2;
explosion.y = game.height / 2;
explosion.animate();
LK.showGameOver('game over, you clicked too fast');
}
});
// Main game update loop
LK.on('tick', function () {
rouletteWheel.update();
ball.update(rouletteWheel);
// Check if the wheel has stopped spinning
if (rouletteWheel.rotationSpeed <= 0) {
// Determine the winning number based on the ball's position
var winningNumber = Math.floor(ball.positionOnWheel / (360 / 37)); // Assuming a 37-slot wheel (0-36)
// Display the winning number (this is a placeholder, actual display code would be needed)
console.log("Winning Number: " + winningNumber);
}
});
spin button. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
roulette wheel with only numbers. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
arrow pointing down. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
realistic explosion. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.