User prompt
Reset the variable that tracks if we hit left or right element when we throw the ball
User prompt
Just after we move the hoop, increment the score multiplier by 1 if the variable that tracks if we hit left or right indicates that we did not hit either of those elements
User prompt
If hitElement is not empty reset the score multiplier to 1
User prompt
Factor in score multiplier when awarding points
User prompt
Cap score multiplier to 3x
User prompt
Hide the score multiplayer label if score multiplier is equal to 1
User prompt
Move down the score multiplier label by 50pox
User prompt
Move down the score multiplier label by 20px
User prompt
Hide score multiplier label on startup
User prompt
make score multiplayer label have the color #9f4a2d
User prompt
Increase the score multiplayer label size by 30%
User prompt
Add a shadow element below the ball when it's on the ground
User prompt
Hide the ball shadow as soon as the ball starts flying
User prompt
Move up ball shadow by 260px
User prompt
Make sure ball has a higher z-index than the ball shadow
User prompt
Move down ball shadow by 50px
User prompt
Always show ball shadow
User prompt
Make sure ball shadow is always moved along with the ball
User prompt
Never change ball shadow y on tick
User prompt
Initialize the ball shadow below the ball
User prompt
Don't move the ball shadow y inside tick
User prompt
Set ball shadow y to 2000 after initializing it
User prompt
after creating ball shadow, set y to 2000
User prompt
Move down the y position of ball shadow position by 500px
User prompt
remove the ball shadow y setting inside tick
var HoopRim = Container.expand(function () {
var self = Container.call(this);
var hoopRimGraphics = XS.getAsset('hoopRimSeparate', 'Basketball Hoop Rim Separate', .5, .5);
self.addChild(hoopRimGraphics);
});
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = XS.getAsset('ball', 'Basketball', .5, .5);
self.addChild(ballGraphics);
self.speed = {
x: 0,
y: 0
};
self.move = function () {
self.speed.y += 3.2;
self.x += self.speed.x;
self.y += self.speed.y;
};
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;
self.y = y + Math.sin(angle) * distance;
};
});
var Hoop = Container.expand(function () {
var self = Container.call(this);
self.moveTo = function (newX, newY, hoopRim) {
var dx = (newX - self.x) / 60;
var dy = (newY - self.y) / 60;
var steps = 0;
var interval = XS.setInterval(function () {
self.x += dx;
self.y += dy;
hoopRim.x = self.x;
hoopRim.y = self.y + self.children[1].y - 100;
steps++;
if (steps >= 60) {
XS.clearInterval(interval);
}
});
};
var backboardGraphics = XS.getAsset('backboard', 'Basketball Backboard', .5, .5);
backboardGraphics.y -= 250;
self.addChild(backboardGraphics);
self.hoopRimGraphics = XS.getAsset('hoopRim', 'Basketball Hoop Rim', .5, .5);
self.hoopRimGraphics.y = backboardGraphics.height / 2 - 550 + 20 + 120 + 100;
self.hoopRimGraphics.alpha = 0;
self.addChild(self.hoopRimGraphics);
self.leftElement = XS.getAsset('leftElement', 'Left Side Element', .5, .5);
self.leftElement.x = self.hoopRimGraphics.x - self.hoopRimGraphics.width / 2 + self.leftElement.width / 2;
self.leftElement.y = self.hoopRimGraphics.y - 100;
self.leftElement.alpha = 0;
self.addChild(self.leftElement);
self.rightElement = XS.getAsset('rightElement', 'Right Side Element', .5, .5);
self.rightElement.x = self.hoopRimGraphics.x + self.hoopRimGraphics.width / 2 - self.rightElement.width / 2;
self.rightElement.y = self.hoopRimGraphics.y - 100;
self.rightElement.alpha = 0;
self.addChild(self.rightElement);
self.multiplierLabel = new Text2('x1', {
size: 150,
fill: '#000000',
font: 'Impact'
});
self.multiplierLabel.anchor.set(.5, .5);
self.multiplierLabel.x = self.hoopRimGraphics.x;
self.multiplierLabel.y = self.hoopRimGraphics.y - 300;
self.addChild(self.multiplierLabel);
});
var Game = Container.expand(function () {
var self = Container.call(this);
var bg = XS.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 scoreTxt = new Text2(score.toString(), {
size: 150,
fill: '#ffffff'
});
scoreTxt.anchor.set(.5, 0);
XS.gui.topCenter.addChild(scoreTxt);
var ball = self.addChild(new Ball());
var hoopRim = self.addChild(new HoopRim());
ball.hasScored = false;
ball.hasThrown = false;
ball.hitElement = '';
hoop.x = 2048 / 2;
hoop.y = 2732 / 2;
hoopRim.x = hoop.x;
hoopRim.y = hoop.y + hoop.children[1].y - 100;
ball.x = 2048 / 2;
ball.y = 2732 - ball.height;
ball.on('down', function (obj) {
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) > 200) {
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 / 2;
ball.speed.y = Math.sin(angle) * 72 * 1.76 * 0.9;
ball.hasThrown = true;
ball.hitElement = '';
self.removeChild(ball);
self.addChild(ball);
dragStart = null;
}
};
stage.on('up', function (obj) {
self.fireBall(obj);
});
var floorY = 2732 - 100;
XS.on('tick', function () {
ball.move();
if (ball.y + ball.height > floorY) {
ball.y = floorY - ball.height;
ball.speed.y *= -0.75;
if (ball.hasThrown && !ball.hasScored) {
XS.showGameOver();
} else if (ball.hasScored) {
ball.x = 2048 / 2;
ball.y = 2732 - ball.height;
ball.speed.x = 0;
ball.speed.y = 0;
ball.hasThrown = false;
ball.hasScored = false;
hoop.moveTo(Math.random() * (2048 - 1000) + 500, Math.random() * (2732 - 2000) + 1000, hoopRim);
}
}
if (ball.intersects(hoop.hoopRimGraphics) && ball.speed.y > 0 && !ball.hasScored && ball.x > hoop.x + hoop.leftElement.x && ball.x < hoop.x + hoop.rightElement.x) {
ball.hasScored = true;
score++;
scoreTxt.setText(score.toString());
}
if (ball.speed.y > 0) {
self.removeChild(hoopRim);
self.addChild(hoopRim);
if (ball.distanceTo(hoop.x + hoop.leftElement.x, hoop.y + hoop.leftElement.y) < ball.width / 2 + hoop.leftElement.width / 2) {
ball.moveToDistance(hoop.x + hoop.leftElement.x, hoop.y + hoop.leftElement.y, ball.width / 2 + hoop.leftElement.width / 2 + 1);
ball.bounceOffPoint(hoop.x + hoop.leftElement.x, hoop.y + hoop.leftElement.y, 0.5);
ball.hitElement = 'left';
}
if (ball.distanceTo(hoop.x + hoop.rightElement.x, hoop.y + hoop.rightElement.y) < ball.width / 2 + hoop.rightElement.width / 2) {
ball.moveToDistance(hoop.x + hoop.rightElement.x, hoop.y + hoop.rightElement.y, ball.width / 2 + hoop.rightElement.width / 2 + 1);
ball.bounceOffPoint(hoop.x + hoop.rightElement.x, hoop.y + hoop.rightElement.y, 0.5);
ball.hitElement = 'right';
}
}
});
});
Basketball, cartoon style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
4:3 Simple rectangle white outline. Black background
Skull explosion
Wide Single Orange metal bar lying down Single Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast. —ar 2:1
https://kagi.com/proxy/basketball_backboard.png?c=iNrrnnUOe99nVfDGJsYBLujiaX2Hu-zxBFRkvLEyXdRnJ8cU3RjcAYbR-o12E923qVNGy1CEGrQG87ogCD3yUarJdZYt5R03mmEMb7Jrh-8%3D blank backboard Single Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
Indoor stadium seen from court Single Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast. --no goal