User prompt
reduce in half the bounce of the ball
Code edit (1 edits merged)
Please save this source code
User prompt
wait 2 seconds before game over.
Code edit (3 edits merged)
Please save this source code
User prompt
stop rotating an moving the ball one second after it stopes moving on y direction.
Code edit (6 edits merged)
Please save this source code
User prompt
delete ball shadow 1 second after it is thrown.
Code edit (3 edits merged)
Please save this source code
User prompt
reduce bounce from rim speed
User prompt
move hooprim and hoopoutline 600 pixels up
Code edit (3 edits merged)
Please save this source code
User prompt
move hooprimseparate 200 pixels up
User prompt
move hooprim 100 pixels up
User prompt
increase ball speed
Code edit (1 edits merged)
Please save this source code
User prompt
movehoop rim 100 pixels up
Code edit (2 edits merged)
Please save this source code
User prompt
move hoop oultine 200 pixels down
User prompt
move rim 100 pixels up
User prompt
make ball dim faster
Code edit (3 edits merged)
Please save this source code
User prompt
more rim 100 pixels up
User prompt
move score 400 pixels down
Code edit (2 edits merged)
Please save this source code
User prompt
move score multiplier 500 pixels dow
var Particle = Container.expand(function () {
var self = Container.call(this);
self.interactive = false;
var particleGraphics = self.createAsset('fireParticle', 'Fire Particle', 0.5, 0.5);
particleGraphics.blendMode = 1;
self.lifeSpan = 60;
self.speed = {
x: (Math.random() - 0.5) * 2,
y: (Math.random() - 0.5) * 2
};
self.scale.set(Math.random() * 0.6 + 0.2);
self.rotation = Math.random() * Math.PI * 2;
self.move = function () {
self.x += self.speed.x;
self.y += self.speed.y;
self.alpha -= 0.03;
if (self.alpha <= 0) self.destroy();
};
});
var Ball = Container.expand(function () {
var self = Container.call(this);
self.hasScored = false;
self.hasBounced = false;
var ballGraphics = LK.getAsset('ball', 'Basketball', .5, .5);
self.addChild(ballGraphics);
self.speed = {
x: 0,
y: 0
};
self.hasThrown = false;
self.move = function () {
self.speed.y += 3.2;
self.x += self.speed.x;
self.y += self.speed.y;
self.rotation += self.speed.x * 0.01;
if (self.hasThrown) {
var targetScale = 0.8;
self.scale.x += (targetScale - self.scale.x) * 0.05;
self.scale.y += (targetScale - self.scale.y) * 0.05;
}
if (self.hasScored) {
self.alpha -= 0.35;
var targetScale = Math.max(0, self.scale.x - 0.05);
self.scale.set(targetScale);
} else {
self.alpha += 0.15;
if (self.alpha > 1) self.alpha = 1;
}
};
self.bounceOffPoint = function (x, y, elasticity) {
var dx = self.x - x;
var dy = self.y - y;
var angle = Math.atan2(dy, dx);
var speed = Math.sqrt(self.speed.x * self.speed.x + self.speed.y * self.speed.y);
self.speed.x = Math.cos(angle) * speed * elasticity;
self.speed.y = Math.sin(angle) * speed * elasticity;
};
self.angleTo = function (x, y) {
var dx = self.x - x;
var dy = self.y - y;
return Math.atan2(dy, dx);
};
self.distanceTo = function (x, y) {
var dx = self.x - x;
var dy = self.y - y;
return Math.sqrt(dx * dx + dy * dy);
};
self.moveToDistance = function (x, y, distance) {
var angle = self.angleTo(x, y);
self.x = x + Math.cos(angle) * (distance * 1.05);
self.y = y + Math.sin(angle) * (distance * 1.05);
};
});
var Hoop = Container.expand(function () {
var self = Container.call(this);
self.setScore = function (score) {
self.scoreLabel.setText(score.toString());
};
self.moveTo = function (newX, newY, hoopRim) {
var dx = (newX - self.x) / 60;
var dy = (newY - self.y) / 60;
var steps = 0;
var interval = LK.setInterval(function () {
self.x += dx;
self.y += dy;
steps++;
if (steps >= 60) {
LK.clearInterval(interval);
}
});
};
var backboardGraphics = LK.getAsset('backboard', 'Basketball Backboard', .5, .5);
backboardGraphics.y -= 250;
self.addChild(backboardGraphics);
self.hoopRimGraphics = LK.getAsset('hoopRim', 'Basketball Hoop Rim', .5, .5);
self.hoopRimGraphics.y = backboardGraphics.height / 2 - 550 + 20 + 120 + 150 - 300 - 100;
self.hoopRimGraphics.alpha = 0;
self.addChild(self.hoopRimGraphics);
self.leftElement = LK.getAsset('leftElement', 'Left Side Element', .5, .5);
self.leftElement.x = self.hoopRimGraphics.x - self.hoopRimGraphics.width / 2 + self.leftElement.width / 2 - 50;
self.leftElement.y = self.hoopRimGraphics.y - 600;
self.leftElement.alpha = 0;
self.addChild(self.leftElement);
self.rightElement = LK.getAsset('rightElement', 'Right Side Element', .5, .5);
self.rightElement.x = self.hoopRimGraphics.x + self.hoopRimGraphics.width / 2 - self.rightElement.width / 2 + 50;
self.rightElement.y = self.hoopRimGraphics.y - 600;
self.rightElement.alpha = 0;
self.addChild(self.rightElement);
self.hoopOutlineGraphics = LK.getAsset('hoopOutline', 'Basketball Hoop Outline', 1, .5);
self.hoopOutlineGraphics.y = self.hoopRimGraphics.y - 630;
self.hoopOutlineGraphics.alpha = 1;
self.hoopOutlineGraphics.rotation = Math.PI / 2;
self.hoopOutlineGraphics.dropShadow = false;
self.addChild(self.hoopOutlineGraphics);
self.multiplierLabel = new Text2('', {
size: 200,
fill: '#8d4529',
font: 'Impact',
dropShadow: true,
dropShadowColor: '#000000',
dropShadowBlur: 4,
dropShadowAngle: Math.PI / 4,
dropShadowDistance: 6
});
self.multiplierLabel.anchor.set(.5, 1);
self.multiplierLabel.x = self.hoopRimGraphics.x;
self.multiplierLabel.y = self.hoopRimGraphics.y - 250 - 50 + 30 - 50;
self.addChild(self.multiplierLabel);
self.scoreLabel = new Text2('0', {
size: 270,
fill: '#ffffff',
font: 'Impact',
dropShadow: true,
dropShadowColor: '#000000',
dropShadowBlur: 4,
dropShadowAngle: Math.PI / 4,
dropShadowDistance: 6
});
self.scoreLabel.anchor.set(.5, .5);
self.scoreLabel.x = self.hoopRimGraphics.x;
self.scoreLabel.y = self.hoopRimGraphics.y - 250 - 20 - 420 + 200 + 600;
self.addChild(self.scoreLabel);
});
var Game = Container.expand(function () {
var self = Container.call(this);
var bg = LK.getAsset('background', 'Background Image', 0.5, 0.5);
bg.x = 2048 / 2;
bg.y = 2732 / 2 + 150;
bg.alpha = 0.7;
self.addChild(bg);
var hoop = self.addChild(new Hoop());
var score = 0;
var scoreMultiplier = 1;
var ballShadow = LK.getAsset('ballShadow', 'Ball Shadow', .5, .5);
ballShadow.alpha = 0.5;
self.addChild(ballShadow);
var ball = self.addChild(new Ball());
ball.hitElement = '';
hoop.x = 2048 / 2;
hoop.y = 2732 / 2 - 100;
hoop.hoopRimGraphics.x = hoop.x;
hoop.hoopRimGraphics.y = hoop.y + hoop.children[1].y - 800;
console.log('Hoop Inicial position:', hoop.x, hoop.y);
ball.x = 2048 / 2;
ball.on('down', function (obj) {
if (!ball.hasThrown) {
var event = obj.event;
dragStart = event.getLocalPosition(self);
}
});
var dragStart = null;
stage.on('move', function (obj) {
var event = obj.event;
var pos = event.getLocalPosition(self);
if (dragStart !== null && ball.distanceTo(pos.x, pos.y) > 400) {
self.fireBall(obj);
}
});
self.fireBall = function (obj) {
if (dragStart !== null) {
var event = obj.event;
var pos = event.getLocalPosition(self);
var dx = pos.x - dragStart.x;
var dy = pos.y - dragStart.y;
var angle = Math.atan2(dy, dx);
ball.speed.x = Math.cos(angle) * 72 * 1.76 * 0.9 / 3;
ball.speed.y = Math.sin(angle) * 72 * 1.76 * 1;
ball.hasThrown = true;
ball.hitElement = '';
self.removeChild(ball);
self.addChild(ball);
dragStart = null;
}
};
stage.on('up', function (obj) {
if (dragStart !== null) {
var event = obj.event;
var pos = event.getLocalPosition(self);
var distance = Math.sqrt(Math.pow(pos.x - dragStart.x, 2) + Math.pow(pos.y - dragStart.y, 2));
if (distance > 150) {
self.fireBall(obj);
}
}
dragStart = null;
});
var floorY = 2732 - 40 + 900 * (ball.scale.y - 1);
ball.y = floorY - ball.height;
LK.on('tick', function () {
console.log('Hoop position:', hoop.x, hoop.y);
if (scoreMultiplier === 3) {
for (var i = 0; i < 2; i++) {
var particle = new Particle();
particle.alpha = ball.alpha;
var angle = Math.random() * Math.PI * 2;
var radius = ball.width * 0.5 * Math.sqrt(Math.random());
particle.x = ball.x + Math.cos(angle) * radius;
particle.y = ball.y + Math.sin(angle) * radius;
self.addChild(particle);
}
}
self.children.forEach(function (child) {
if (child instanceof Particle) {
child.move();
}
});
var floorY = 2732 - 140 + 900 * (ball.scale.y - 1);
ball.move();
if (ball.speed.y > 0) {
self.removeChild(hoop.hoopRimGraphics);
self.addChild(hoop.hoopRimGraphics);
}
ballShadow.x = ball.x;
ballShadow.y = 1800 + ball.height / 2 + 500 * ball.scale.x;
var scale = (1 - 2 * (ball.y - 2732 + ball.height) / 2732) * ball.scale.x;
ballShadow.scale.set(scale);
ballShadow.alpha = (1 - scale + 1) / 2 * ball.alpha;
if (ball.y + ball.height > floorY) {
ball.y = floorY - ball.height;
ball.speed.y *= -0.375;
ballShadow.x = ball.x;
ballShadow.visible = true;
if (ball.hasThrown && !ball.hasScored) {
if (!ball.hasBounced) {
ball.hasBounced = true;
} else {
LK.showGameOver();
}
} else if (ball.hasScored) {
ball.x = 2048 / 2;
ball.y = 2532 - ball.height;
ball.speed.x = 0;
ball.speed.y = 0;
ball.hasThrown = false;
ball.hasScored = false;
ball.hasBounced = false;
ball.scale.x = 1;
ball.scale.y = 1;
if (ball.hitElement === '') {
if (scoreMultiplier < 3) {
scoreMultiplier++;
}
} else {
scoreMultiplier = 1;
}
if (scoreMultiplier > 1) {
hoop.multiplierLabel.setText('x' + scoreMultiplier);
} else {
hoop.multiplierLabel.setText('');
}
ball.hitElement = '';
hoop.moveTo(Math.random() * (2048 - 1000) + 500, Math.random() * (2732 - 2000) + 1000);
}
}
if (ball.x + ball.width / 2 < 0 || ball.x - ball.width / 2 > 2048) {
LK.showGameOver();
} else if (ball.hasThrown && ball.intersects(hoop.hoopRimGraphics) && ball.speed.y > 0 && !ball.hasScored && !ball.hasBounced && ball.x > hoop.x + hoop.leftElement.x && ball.x < hoop.x + hoop.rightElement.x) {
ball.hasScored = true;
score += scoreMultiplier;
hoop.scoreLabel.setText(score.toString());
hoop.setScore(score);
}
});
});
Cartoon. Grass background. Backyard. Top view. In game asset Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Cartoon. Wood board. In game asset. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
stars particles. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.