User prompt
set score label color to 0x83371c
User prompt
set hoop outline graphics tint to e75b22
User prompt
set multiplayer label color to 0xe75b22
User prompt
set hoopOutlineGraphics tint to e75b22
User prompt
increase multiplierLabel size to 200
User prompt
set multiplier label fill to b05026
User prompt
set hoop outline tint to bb502e
User prompt
move down self.multiplierLabel by 30px
User prompt
set multiplier label tint to 8d4529
User prompt
don't allow scoring to happen unless hasThrown is true
User prompt
make ball twice as fast
Code edit (2 edits merged)
Please save this source code
User prompt
Set ball target scale to .6
User prompt
Move down ball floor by 100px
User prompt
Move down ball floor by 200px
User prompt
Move up ball shadow y by 200px
User prompt
Move up ball shadow y by 100px
User prompt
Move down ball floor by 70px
User prompt
Move down floory by 200px
User prompt
when updating score text also call LK.setScore
User prompt
set bg color to 355673
User prompt
set bg color to 477096
===================================================================
--- original.js
+++ change.js
@@ -1,4 +1,7 @@
+/****
+* Classes
+****/
var Particle = Container.expand(function () {
var self = Container.call(this);
self.interactive = false;
var particleGraphics = self.createAsset('fireParticle', 'Fire Particle', 0.5, 0.5);
@@ -13,9 +16,11 @@
self.move = function () {
self.x += self.speed.x;
self.y += self.speed.y;
self.alpha -= 0.03;
- if (self.alpha <= 0) self.destroy();
+ if (self.alpha <= 0) {
+ self.destroy();
+ }
};
});
var HoopRim = Container.expand(function () {
var self = Container.call(this);
@@ -46,9 +51,11 @@
if (self.hasScored) {
self.alpha -= 0.15;
} else {
self.alpha += 0.15;
- if (self.alpha > 1) self.alpha = 1;
+ if (self.alpha > 1) {
+ self.alpha = 1;
+ }
}
};
self.bounceOffPoint = function (x, y, elasticity) {
var dx = self.x - x;
@@ -135,153 +142,161 @@
self.scoreLabel.x = self.hoopRimGraphics.x;
self.scoreLabel.y = self.hoopRimGraphics.y - 250 - 20 - 420;
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());
- var hoopRim = self.addChild(new HoopRim());
- ball.hitElement = '';
- hoop.x = 2048 / 2;
- hoop.y = 2732 / 2;
- hoopRim.x = hoop.x;
- hoopRim.y = hoop.y + hoop.children[1].y - 250;
- 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) {
+
+/****
+* Initialize Game
+****/
+var game = new LK.Game({
+ backgroundColor: 0x000000
+});
+
+/****
+* Game Code
+****/
+var bg = LK.getAsset('background', 'Background Image', 0.5, 0.5);
+bg.x = 2048 / 2;
+bg.y = 2732 / 2 + 150;
+bg.alpha = 0.7;
+game.addChild(bg);
+var hoop = game.addChild(new Hoop());
+var score = 0;
+var scoreMultiplier = 1;
+var ballShadow = LK.getAsset('ballShadow', 'Ball Shadow', .5, .5);
+ballShadow.alpha = 0.5;
+game.addChild(ballShadow);
+var ball = game.addChild(new Ball());
+var hoopRim = game.addChild(new HoopRim());
+ball.hitElement = '';
+hoop.x = 2048 / 2;
+hoop.y = 2732 / 2;
+hoopRim.x = hoop.x;
+hoopRim.y = hoop.y + hoop.children[1].y - 250;
+ball.x = 2048 / 2;
+ball.on('down', function (obj) {
+ if (!ball.hasThrown) {
var event = obj.event;
- var pos = event.getLocalPosition(self);
- if (dragStart !== null && ball.distanceTo(pos.x, pos.y) > 400) {
- self.fireBall(obj);
+ dragStart = event.getLocalPosition(game);
+ }
+});
+var dragStart = null;
+game.on('move', function (obj) {
+ var event = obj.event;
+ var pos = event.getLocalPosition(game);
+ if (dragStart !== null && ball.distanceTo(pos.x, pos.y) > 400) {
+ game.fireBall(obj);
+ }
+});
+game.fireBall = function (obj) {
+ if (dragStart !== null) {
+ var event = obj.event;
+ var pos = event.getLocalPosition(game);
+ 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 * 2;
+ ball.speed.y = Math.sin(angle) * 72 * 1.76 * 0.9 * 2;
+ ball.hasThrown = true;
+ ball.hitElement = '';
+ game.removeChild(ball);
+ game.addChild(ball);
+ dragStart = null;
+ }
+};
+game.on('up', function (obj) {
+ if (dragStart !== null) {
+ var event = obj.event;
+ var pos = event.getLocalPosition(game);
+ var distance = Math.sqrt(Math.pow(pos.x - dragStart.x, 2) + Math.pow(pos.y - dragStart.y, 2));
+ if (distance > 150) {
+ game.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 * 0.9;
- ball.hasThrown = true;
- ball.hitElement = '';
- self.removeChild(ball);
- self.addChild(ball);
- dragStart = null;
+ }
+ dragStart = null;
+});
+var floorY = 2732 - 40 + 900 * (ball.scale.y - 1);
+ball.y = floorY - ball.height;
+LK.on('tick', function () {
+ 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;
+ game.addChild(particle);
}
- };
- 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);
- }
+ }
+ game.children.forEach(function (child) {
+ if (child instanceof Particle) {
+ child.move();
}
- dragStart = null;
});
var floorY = 2732 - 40 + 900 * (ball.scale.y - 1);
- ball.y = floorY - ball.height;
- LK.on('tick', function () {
- 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);
- }
+ ball.move();
+ if (ball.speed.y > 0) {
+ game.removeChild(hoopRim);
+ game.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';
}
- self.children.forEach(function (child) {
- if (child instanceof Particle) {
- child.move();
- }
- });
- var floorY = 2732 - 40 + 900 * (ball.scale.y - 1);
- ball.move();
- 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';
- }
+ 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';
}
+ }
+ 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.75;
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.75;
- ballShadow.x = ball.x;
- ballShadow.visible = true;
- if (ball.hasThrown && !ball.hasScored) {
- if (!ball.hasBounced) {
- ball.hasBounced = true;
- } else {
- LK.showGameOver();
+ 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 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, hoopRim);
+ } 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.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);
- }
- });
-});
+ }
+ 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);
+ }
+});
\ No newline at end of file
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