User prompt
Increase launch speed of ball
User prompt
Track if the ball has been thrown. If yes and the ball bounces on the floor without having scored a point. Make the game be game over
User prompt
If the ball bounces after successfully having scored a goal. Reset the ball
User prompt
Sometimes you get points even though the ball did not fall between the left and right element. Instead the ball bounces out of the rim. Please fix this
User prompt
Move the left circle to the right by the width of the circle and move the right circle left by the width of the circle
User prompt
Move the code that fires the ball to a separate method
User prompt
Auto throw the ball if drag distance is larger than the threshold. Rather than setting the ball position
User prompt
Set dragstart on down
User prompt
In move, calculate the current position of the mouse and use that to determine if we should auto fire
User prompt
Increase the drag threshold by 2x
User prompt
Move up rim by 400px
User prompt
Move up rim by 150px
User prompt
Move down the rim by 20px but keep the position of the left and right elements
User prompt
Add background image to the games class
User prompt
Center background image
User prompt
Move down background by 150px and make it have 70% opacity
User prompt
Move up backboard by 250px
User prompt
Move down hoop rim by 120px
User prompt
Move the left element down by 20px
User prompt
Move down the right element by 20px
User prompt
Add a function inside the hoop class, that moves the basketball backboard and hoop to a new position. This movement should be animated
User prompt
Rewrite the code to move self.moveTo inside the Hoop class
User prompt
Increase gravity by 2x
User prompt
Increase throw speed by 20%
User prompt
Increase gravity
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 += 1;
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.min(Math.sqrt(dx * dx + dy * dy) * elasticity, 10);
self.speed.x = Math.cos(angle) * speed;
self.speed.y = -Math.abs(Math.sin(angle) * speed);
};
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);
};
});
var Hoop = Container.expand(function () {
var self = Container.call(this);
var backboardGraphics = XS.getAsset('backboard', 'Basketball Backboard', .5, .5);
var hoopRimGraphics = XS.getAsset('hoopRim', 'Basketball Hoop Rim', .5, .5);
var leftElementGraphics = XS.getAsset('leftElement', 'Left Side Element', .5, .5);
var rightElementGraphics = XS.getAsset('rightElement', 'Right Side Element', .5, .5);
self.addChild(backboardGraphics);
hoopRimGraphics.y = backboardGraphics.height / 2;
self.addChild(hoopRimGraphics);
leftElementGraphics.x = hoopRimGraphics.x - hoopRimGraphics.width / 2 - leftElementGraphics.width / 2;
leftElementGraphics.y = hoopRimGraphics.y;
rightElementGraphics.x = hoopRimGraphics.x + hoopRimGraphics.width / 2 + rightElementGraphics.width / 2;
rightElementGraphics.y = hoopRimGraphics.y;
self.addChild(leftElementGraphics);
self.addChild(rightElementGraphics);
});
var Game = Container.expand(function () {
var self = Container.call(this);
XS.stageContainer.setBackgroundColor(0x008080);
var hoop = self.addChild(new Hoop());
var score = 0;
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());
ball.hasScored = false;
hoop.x = 2048 / 2;
hoop.y = 2732 / 2;
ball.x = 2048 / 2;
ball.y = 2732 - ball.height;
ball.on('down', function (obj) {
console.log('ball was pressed');
});
var dragStart = null;
stage.on('move', function (obj) {
var event = obj.event;
var pos = event.getLocalPosition(self);
if (dragStart === null) {
dragStart = pos;
} else if (ball.distanceTo(dragStart.x, dragStart.y) > 100) {
ball.x = pos.x;
ball.y = pos.y;
}
});
stage.on('up', 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) * 60;
ball.speed.y = Math.sin(angle) * 60;
dragStart = null;
}
});
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;
ball.hasScored = false;
}
if (ball.intersects(hoop.children[1]) && ball.speed.y > 0 && !ball.hasScored) {
ball.hasScored = true;
score++;
scoreTxt.setText(score.toString());
console.log('Score!');
}
if (ball.speed.y > 0) {
if (ball.distanceTo(hoop.x + hoop.children[2].x, hoop.y + hoop.children[2].y) < ball.width / 2 + hoop.children[2].width / 2) {
ball.bounceOffPoint(hoop.x + hoop.children[2].x, hoop.y + hoop.children[2].y, 0.75);
}
if (ball.distanceTo(hoop.x + hoop.children[3].x, hoop.y + hoop.children[3].y) < ball.width / 2 + hoop.children[3].width / 2) {
ball.bounceOffPoint(hoop.x + hoop.children[3].x, hoop.y + hoop.children[3].y, 0.75);
}
}
});
});
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