User prompt
Make the scale of ball shadow be related to the y position of the ball
User prompt
Increase the y impact of ball shadow scale by 2
User prompt
Make the ball shadow alpha be more transparent the larger the ball shadow is
User prompt
Add 1 to the ball shadow alpha math
User prompt
Divide the ball shadow alpha math by 2
User prompt
Move up ball shadow by 20px
User prompt
Make the ball rotate based on the x movement of the ball
User prompt
Make score font Impact and add drop shadows
User prompt
Add 5% additional margin when calling moveToDistance
User prompt
Decrease the impact of the y offset when throwing balls
User prompt
Decrease the impact of the x offset when throwing balls
User prompt
Set the initial y of the basketball to the same as it is after it resets
User prompt
Make sure floorY is defined before it's used
User prompt
Set hoop rim graphics alpha to 1
User prompt
Set alpha on left and right elements to 1
User prompt
Move down hoop rim graphics by 50 px
User prompt
Move up left and right elements by 50 px
User prompt
In hoop move move hoopRim up by 50px
User prompt
In hoop move move up hoop rim by 100 px
User prompt
In hoop move to method move up hoopRim by 50px
User prompt
In game move hoopRim y up by 50px
User prompt
Move up multiplier label by 50px
User prompt
Set hoop rim graphics alpha in hoop class to 0
User prompt
Set left and right elements alpha in hoop to 0
User prompt
Let the ball bounce once
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('', {
size: 150 * 1.3,
fill: '#9f4a2d',
font: 'Impact'
});
self.multiplierLabel.anchor.set(.5, .5);
self.multiplierLabel.x = self.hoopRimGraphics.x;
self.multiplierLabel.y = self.hoopRimGraphics.y - 250 + 20;
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 ballShadow = XS.getAsset('ballShadow', 'Ball Shadow', .5, .5);
ballShadow.alpha = 0.5;
ballShadow.y = 2500;
self.addChild(ballShadow);
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();
ballShadow.x = ball.x;
ballShadow.scale.set(1 - (ball.y - 2732 + ball.height) / 2732);
if (ball.y + ball.height > floorY) {
ball.y = floorY - ball.height;
ball.speed.y *= -0.75;
ballShadow.x = ball.x;
ballShadow.visible = true;
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;
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, 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 += scoreMultiplier;
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