Remix started
Copy Basketball Forge
User prompt
don't allow scoring to happen unless hasThrown is true
Code edit (4 edits merged)
Please save this source code
User prompt
subtract 70 from hoop rim y rather than 250
Code edit (2 edits merged)
Please save this source code
User prompt
subtract 60 from hoop rim y rather than 70
User prompt
in hoop move, when subtracting 70 from hoop rim y, subtract 60 instead
User prompt
set hoop outline tint to 424e95
User prompt
set multiplier text color to 363b74
User prompt
set score label color to 161a30
User prompt
set game bg alpha to 1
User prompt
do not add 150 to bg y
User prompt
set bg alpha to .8
User prompt
After defining and adding bg to game, add a bg overlay graphics element. With anchor point .5,1 and position at game width / 2, game height
User prompt
when updating score text also call LK.setScore
User prompt
set bg color to 19314b
===================================================================
--- original.js
+++ change.js
@@ -1,8 +1,14 @@
+/****
+* 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);
+ var particleGraphics = self.attachAsset('fireParticle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
particleGraphics.blendMode = 1;
self.lifeSpan = 60;
self.speed = {
x: (Math.random() - 0.5) * 2,
@@ -13,21 +19,29 @@
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);
- var hoopRimGraphics = LK.getAsset('hoopRimSeparate', 'Basketball Hoop Rim Separate', .5, .5);
+ var hoopRimGraphics = LK.getAsset('hoopRimSeparate', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
self.addChild(hoopRimGraphics);
});
var Ball = Container.expand(function () {
var self = Container.call(this);
self.hasScored = false;
self.hasBounced = false;
- var ballGraphics = LK.getAsset('ball', 'Basketball', .5, .5);
+ var ballGraphics = LK.getAsset('ball', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
self.addChild(ballGraphics);
self.speed = {
x: 0,
y: 0
@@ -46,9 +60,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;
@@ -93,26 +109,41 @@
LK.clearInterval(interval);
}
});
};
- var backboardGraphics = LK.getAsset('backboard', 'Basketball Backboard', .5, .5);
+ var backboardGraphics = LK.getAsset('backboard', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
backboardGraphics.y -= 250;
self.addChild(backboardGraphics);
- self.hoopRimGraphics = LK.getAsset('hoopRim', 'Basketball Hoop Rim', .5, .5);
+ self.hoopRimGraphics = LK.getAsset('hoopRim', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
self.hoopRimGraphics.y = backboardGraphics.height / 2 - 550 + 20 + 120 + 150 + 100;
self.hoopRimGraphics.alpha = 0;
self.addChild(self.hoopRimGraphics);
- self.leftElement = LK.getAsset('leftElement', 'Left Side Element', .5, .5);
+ self.leftElement = LK.getAsset('leftElement', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
self.leftElement.x = self.hoopRimGraphics.x - self.hoopRimGraphics.width / 2 + self.leftElement.width / 2 - 50;
self.leftElement.y = self.hoopRimGraphics.y - 250;
self.leftElement.alpha = 0;
self.addChild(self.leftElement);
- self.rightElement = LK.getAsset('rightElement', 'Right Side Element', .5, .5);
+ self.rightElement = LK.getAsset('rightElement', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
self.rightElement.x = self.hoopRimGraphics.x + self.hoopRimGraphics.width / 2 - self.rightElement.width / 2 + 50;
self.rightElement.y = self.hoopRimGraphics.y - 250;
self.rightElement.alpha = 0;
self.addChild(self.rightElement);
- self.hoopOutlineGraphics = LK.getAsset('hoopOutline', 'Basketball Hoop Outline', 1, .5);
+ self.hoopOutlineGraphics = LK.getAsset('hoopOutline', {
+ anchorX: 1,
+ anchorY: 0.5
+ });
self.hoopOutlineGraphics.y = self.hoopRimGraphics.y - 230;
self.hoopOutlineGraphics.alpha = 1;
self.hoopOutlineGraphics.tint = 0x424e95;
self.hoopOutlineGraphics.rotation = Math.PI / 2;
@@ -135,157 +166,175 @@
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;
- bg.alpha = 0.8;
- self.addChild(bg);
- var bgOverlay = LK.getAsset('bgOverlay', 'Background Overlay', 0.5, 1);
- bgOverlay.x = 2048 / 2;
- bgOverlay.y = 2732;
- self.addChild(bgOverlay);
- 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 - 60;
- 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', {
+ anchorX: 0.5,
+ anchorY: 0.5
+});
+bg.x = 2048 / 2;
+bg.y = 2732 / 2;
+bg.alpha = 0.8;
+game.addChild(bg);
+var bgOverlay = LK.getAsset('bgOverlay', {
+ anchorX: 0.5,
+ anchorY: 1
+});
+bgOverlay.x = 2048 / 2;
+bgOverlay.y = 2732;
+game.addChild(bgOverlay);
+var hoop = game.addChild(new Hoop());
+var score = 0;
+var scoreMultiplier = 1;
+var ballShadow = LK.getAsset('ballShadow', {
+ anchorX: 0.5,
+ anchorY: 0.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 - 60;
+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;
+ ball.speed.y = Math.sin(angle) * 72 * 1.76 * 0.9;
+ 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;
+ LK.setScore(score);
+ hoop.scoreLabel.setText(score.toString());
+ hoop.setScore(score);
+ }
+});
\ No newline at end of file
4:3 Simple rectangle white outline. Black background
Ball with Christmas skin. Cartoon. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Sparse Ice particle. Single Game Texture. In-Game asset. 2d. black background. High contrast. No shadows.
Simple Row of iceales hanging from snowy bar, cartoon. Flat, seen from side. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Frozen blank backboard rectangle. Cartoon. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. No outlines.
Simple Outdoor empty frozen icy lake, Christmas decorated. Camera standing at the middle of the lake looking towards shore. Cartoon. Middle of rink view. Snowmen and threes on the edge of area Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Outdoor empty frozen icy lake, Christmas decorated. View from standing at the middle of the lake looking towards shore. Cartoon. Middle of rink view.