User prompt
ahora quita el rebote de las bolas
User prompt
mejora el rebote de las bolas
User prompt
haz que las bolas reboter un poquito
User prompt
haz que todas las bolas comiencen el medio y que tengan un poquito de mas gravedad
Code edit (1 edits merged)
Please save this source code
User prompt
Plinko Fortune
Initial prompt
crea un plinko que empiezes con 100$ y cada bola que tires sera de 10$ y que cuando caiga habla abajo 5 casillas la del centro sera un x0,2 de dinero de la bola que caiga luego un x1 y la casilla de los lados sera de un x5
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 0;
self.velocityY = 0;
self.gravity = 0.8;
self.bounce = 1.2;
self.friction = 0.995;
self.hasLanded = false;
self.update = function () {
if (self.hasLanded) return;
// Apply gravity
self.velocityY += self.gravity;
// Update position
self.x += self.velocityX;
self.y += self.velocityY;
// Apply friction
self.velocityX *= self.friction;
// Check for peg collisions
for (var i = 0; i < pegs.length; i++) {
var peg = pegs[i];
var dx = self.x - peg.x;
var dy = self.y - peg.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 30) {
// Ball radius + peg radius
// Bounce off peg with more bounce
var angle = Math.atan2(dy, dx);
self.velocityX = Math.cos(angle) * 6;
self.velocityY = Math.sin(angle) * 5;
// Add some randomness
self.velocityX += (Math.random() - 0.5) * 4;
// Apply bounce coefficient
self.velocityX *= self.bounce;
self.velocityY *= self.bounce;
LK.getSound('peg_hit').play();
break;
}
}
// Check if ball reached slots
if (self.y > 2400 && !self.hasLanded) {
self.hasLanded = true;
self.checkSlotLanding();
}
// Remove ball if it goes off screen
if (self.y > 2800) {
self.destroy();
var index = balls.indexOf(self);
if (index > -1) {
balls.splice(index, 1);
}
}
};
self.checkSlotLanding = function () {
var slotIndex = -1;
var ballX = self.x;
// Determine which slot the ball landed in
if (ballX >= 124 && ballX <= 474) {
slotIndex = 0; // x5 slot
} else if (ballX >= 474 && ballX <= 824) {
slotIndex = 1; // x1 slot
} else if (ballX >= 824 && ballX <= 1224) {
slotIndex = 2; // x0.2 slot (center)
} else if (ballX >= 1224 && ballX <= 1574) {
slotIndex = 3; // x1 slot
} else if (ballX >= 1574 && ballX <= 1924) {
slotIndex = 4; // x5 slot
}
if (slotIndex >= 0) {
var multiplier = slotMultipliers[slotIndex];
var winnings = Math.floor(10 * multiplier);
bankroll += winnings;
updateBankrollDisplay();
showWinnings(winnings, self.x, self.y);
LK.getSound('slot_land').play();
}
};
return self;
});
var Peg = Container.expand(function () {
var self = Container.call(this);
var pegGraphics = self.attachAsset('peg', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x0a0a0a
});
/****
* Game Code
****/
var bankroll = 100;
var ballCost = 10;
var balls = [];
var pegs = [];
var slotMultipliers = [5, 1, 0.2, 1, 5]; // Left to right multipliers
var canDropBall = true;
// Create board background
var board = game.addChild(LK.getAsset('board', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
// Create pegs in triangular pattern
function createPegs() {
var startY = 400;
var rows = 12;
var pegSpacing = 120;
for (var row = 0; row < rows; row++) {
var pegsInRow = row + 3;
var startX = 1024 - (pegsInRow - 1) * pegSpacing / 2;
for (var col = 0; col < pegsInRow; col++) {
var peg = new Peg();
peg.x = startX + col * pegSpacing;
peg.y = startY + row * 150;
pegs.push(peg);
game.addChild(peg);
}
}
}
createPegs();
// Create slots at bottom
var slots = [];
var slotLabels = [];
var slotColors = [0x00ff00, 0xffff00, 0xff0000, 0xffff00, 0x00ff00];
for (var i = 0; i < 5; i++) {
var slot = game.addChild(LK.getAsset('slot', {
anchorX: 0.5,
anchorY: 0.5,
x: 299 + i * 350,
y: 2450
}));
slot.tint = slotColors[i];
slots.push(slot);
// Create slot labels
var multiplierText = 'x' + slotMultipliers[i];
var label = new Text2(multiplierText, {
size: 60,
fill: 0xFFFFFF
});
label.anchor.set(0.5, 0.5);
label.x = 299 + i * 350;
label.y = 2450;
game.addChild(label);
slotLabels.push(label);
}
// Create bankroll display
var bankrollText = new Text2('$' + bankroll, {
size: 100,
fill: 0x00FF00
});
bankrollText.anchor.set(0.5, 0);
LK.gui.top.addChild(bankrollText);
// Create instructions
var instructionText = new Text2('Tap to drop $10 ball', {
size: 50,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 0);
instructionText.y = 120;
LK.gui.top.addChild(instructionText);
function updateBankrollDisplay() {
bankrollText.setText('$' + bankroll);
if (bankroll < ballCost) {
bankrollText.tint = 0xff0000;
instructionText.setText('Game Over - Not enough money!');
canDropBall = false;
// Show game over after a delay
LK.setTimeout(function () {
LK.showGameOver();
}, 2000);
}
}
function showWinnings(amount, x, y) {
var winText = new Text2((amount >= 10 ? '+$' : '') + (amount - 10), {
size: 80,
fill: amount >= 10 ? "#00ff00" : "#ff0000"
});
winText.anchor.set(0.5, 0.5);
winText.x = x;
winText.y = y;
game.addChild(winText);
// Animate winnings text
tween(winText, {
y: y - 100,
alpha: 0
}, {
duration: 2000,
onFinish: function onFinish() {
winText.destroy();
}
});
}
// Game input handling
game.down = function (x, y, obj) {
if (!canDropBall || bankroll < ballCost) return;
// Deduct cost immediately
bankroll -= ballCost;
updateBankrollDisplay();
// Create and drop ball
var ball = new Ball();
ball.x = 1024; // Start from center of screen
ball.y = 200;
ball.velocityX = (Math.random() - 0.5) * 2; // Small random horizontal velocity
ball.velocityY = 1;
balls.push(ball);
game.addChild(ball);
LK.getSound('drop').play();
// Prevent rapid dropping
canDropBall = false;
LK.setTimeout(function () {
canDropBall = true;
}, 500);
};
game.update = function () {
// Update all balls
for (var i = balls.length - 1; i >= 0; i--) {
var ball = balls[i];
if (ball.destroyed) {
balls.splice(i, 1);
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -14,10 +14,10 @@
});
self.velocityX = 0;
self.velocityY = 0;
self.gravity = 0.8;
- self.bounce = 0.85;
- self.friction = 0.98;
+ self.bounce = 1.2;
+ self.friction = 0.995;
self.hasLanded = false;
self.update = function () {
if (self.hasLanded) return;
// Apply gravity
@@ -36,12 +36,12 @@
if (distance < 30) {
// Ball radius + peg radius
// Bounce off peg with more bounce
var angle = Math.atan2(dy, dx);
- self.velocityX = Math.cos(angle) * 4;
- self.velocityY = Math.sin(angle) * 3;
+ self.velocityX = Math.cos(angle) * 6;
+ self.velocityY = Math.sin(angle) * 5;
// Add some randomness
- self.velocityX += (Math.random() - 0.5) * 3;
+ self.velocityX += (Math.random() - 0.5) * 4;
// Apply bounce coefficient
self.velocityX *= self.bounce;
self.velocityY *= self.bounce;
LK.getSound('peg_hit').play();