Code edit (1 edits merged)
Please save this source code
User prompt
Add a add a trail when he's dropped and get rid of it when he lands ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'TypeError: Cannot read properties of null (reading 'growthFactor')' in or related to this line: 'tween(blueberryGraphics, {' Line Number: 293 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
add a throwing effect ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Fix it where blueberry is wide
User prompt
Make it look like it's actually getting thrown with effects ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make it make it so you can throw the blueberry too this is
User prompt
Increase the velocity when the blueberry is falling
User prompt
Make the goldenBerry spawn more often
User prompt
make the player have to collect 100 to win
Code edit (1 edits merged)
Please save this source code
User prompt
Make make it so the the food doesn't go in the red
User prompt
Fix the bug where blueberry would teleport through stuff when you click there
User prompt
Make the game a little easier
User prompt
Stop the bug where blueberry would fall when you're still holding him
User prompt
Make the blueberry roll when he's dropped ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Add gravity and ground
Code edit (1 edits merged)
Please save this source code
User prompt
Berry Bounce Adventure
Initial prompt
make a about a living blueberry
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Blueberry = Container.expand(function () { var self = Container.call(this); var graphics = self.attachAsset('blueberry', { anchorX: 0.5, anchorY: 0.5 }); self.baseSize = 80; self.growthFactor = 1.0; self.velocityX = 0; self.velocityY = 0; self.friction = 0.95; self.bounceForce = 0.7; self.grow = function () { self.growthFactor += 0.05; graphics.scaleX = self.growthFactor; graphics.scaleY = self.growthFactor; }; self.getBounds = function () { var radius = self.baseSize * self.growthFactor / 2; return { left: self.x - radius, right: self.x + radius, top: self.y - radius, bottom: self.y + radius, radius: radius }; }; self.update = function () { self.x += self.velocityX; self.y += self.velocityY; self.velocityX *= self.friction; self.velocityY *= self.friction; var bounds = self.getBounds(); var bounced = false; if (bounds.left <= 0) { self.x = bounds.radius; self.velocityX = Math.abs(self.velocityX) * self.bounceForce; bounced = true; } if (bounds.right >= 2048) { self.x = 2048 - bounds.radius; self.velocityX = -Math.abs(self.velocityX) * self.bounceForce; bounced = true; } if (bounds.top <= 0) { self.y = bounds.radius; self.velocityY = Math.abs(self.velocityY) * self.bounceForce; bounced = true; } if (bounds.bottom >= 2732) { self.y = 2732 - bounds.radius; self.velocityY = -Math.abs(self.velocityY) * self.bounceForce; bounced = true; } if (bounced) { LK.getSound('bounce').play(); } }; return self; }); var GoldenBerry = Container.expand(function () { var self = Container.call(this); var graphics = self.attachAsset('goldenBerry', { anchorX: 0.5, anchorY: 0.5 }); self.floatOffset = Math.random() * Math.PI * 2; self.floatSpeed = 0.05; self.startY = 0; self.update = function () { self.y = self.startY + Math.sin(LK.ticks * self.floatSpeed + self.floatOffset) * 10; }; return self; }); var RedThorn = Container.expand(function () { var self = Container.call(this); var graphics = self.attachAsset('redThorn', { anchorX: 0.5, anchorY: 0.5 }); graphics.rotation = Math.PI / 4; self.pulseOffset = Math.random() * Math.PI * 2; self.pulseSpeed = 0.08; self.update = function () { var pulse = 1 + Math.sin(LK.ticks * self.pulseSpeed + self.pulseOffset) * 0.1; graphics.scaleX = pulse; graphics.scaleY = pulse; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ var blueberry = game.addChild(new Blueberry()); blueberry.x = 1024; blueberry.y = 1366; var goldenBerries = []; var redThorns = []; var dragNode = null; var lastMouseX = 0; var lastMouseY = 0; var thornSpawnTimer = 0; var berrySpawnTimer = 0; var scoreTxt = new Text2('0', { size: 120, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); function spawnGoldenBerry() { var berry = new GoldenBerry(); var margin = 50; berry.x = margin + Math.random() * (2048 - margin * 2); berry.y = margin + Math.random() * (2732 - margin * 2); berry.startY = berry.y; var tooClose = true; var attempts = 0; while (tooClose && attempts < 10) { tooClose = false; var berryBounds = { x: berry.x, y: berry.y, radius: 20 }; var blueberryBounds = blueberry.getBounds(); var dist = Math.sqrt(Math.pow(berry.x - blueberry.x, 2) + Math.pow(berry.y - blueberry.y, 2)); if (dist < blueberryBounds.radius + 100) { berry.x = margin + Math.random() * (2048 - margin * 2); berry.y = margin + Math.random() * (2732 - margin * 2); berry.startY = berry.y; tooClose = true; } attempts++; } goldenBerries.push(berry); game.addChild(berry); } function spawnRedThorn() { var thorn = new RedThorn(); var margin = 50; thorn.x = margin + Math.random() * (2048 - margin * 2); thorn.y = margin + Math.random() * (2732 - margin * 2); var tooClose = true; var attempts = 0; while (tooClose && attempts < 15) { tooClose = false; var blueberryBounds = blueberry.getBounds(); var dist = Math.sqrt(Math.pow(thorn.x - blueberry.x, 2) + Math.pow(thorn.y - blueberry.y, 2)); if (dist < blueberryBounds.radius + 150) { thorn.x = margin + Math.random() * (2048 - margin * 2); thorn.y = margin + Math.random() * (2732 - margin * 2); tooClose = true; } attempts++; } redThorns.push(thorn); game.addChild(thorn); } function handleMove(x, y, obj) { if (dragNode) { var deltaX = x - lastMouseX; var deltaY = y - lastMouseY; dragNode.x = x; dragNode.y = y; dragNode.velocityX = deltaX * 0.3; dragNode.velocityY = deltaY * 0.3; } lastMouseX = x; lastMouseY = y; } game.move = handleMove; game.down = function (x, y, obj) { dragNode = blueberry; lastMouseX = x; lastMouseY = y; handleMove(x, y, obj); }; game.up = function (x, y, obj) { dragNode = null; }; spawnGoldenBerry(); spawnGoldenBerry(); spawnGoldenBerry(); game.update = function () { berrySpawnTimer++; thornSpawnTimer++; if (berrySpawnTimer > 300 && goldenBerries.length < 5) { spawnGoldenBerry(); berrySpawnTimer = 0; } var thornSpawnRate = Math.max(180 - Math.floor(LK.getScore() * 5), 60); if (thornSpawnTimer > thornSpawnRate) { spawnRedThorn(); thornSpawnTimer = 0; } var blueberryBounds = blueberry.getBounds(); for (var i = goldenBerries.length - 1; i >= 0; i--) { var berry = goldenBerries[i]; var dist = Math.sqrt(Math.pow(berry.x - blueberry.x, 2) + Math.pow(berry.y - blueberry.y, 2)); if (dist < blueberryBounds.radius + 20) { LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); blueberry.grow(); LK.getSound('collect').play(); LK.effects.flashObject(berry, 0xFFFFFF, 200); berry.destroy(); goldenBerries.splice(i, 1); if (LK.getScore() >= 50) { LK.showYouWin(); } } } for (var j = 0; j < redThorns.length; j++) { var thorn = redThorns[j]; var dist = Math.sqrt(Math.pow(thorn.x - blueberry.x, 2) + Math.pow(thorn.y - blueberry.y, 2)); if (dist < blueberryBounds.radius + 30) { LK.effects.flashScreen(0xFF0000, 1000); LK.showGameOver(); } } };
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,237 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Blueberry = Container.expand(function () {
+ var self = Container.call(this);
+ var graphics = self.attachAsset('blueberry', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.baseSize = 80;
+ self.growthFactor = 1.0;
+ self.velocityX = 0;
+ self.velocityY = 0;
+ self.friction = 0.95;
+ self.bounceForce = 0.7;
+ self.grow = function () {
+ self.growthFactor += 0.05;
+ graphics.scaleX = self.growthFactor;
+ graphics.scaleY = self.growthFactor;
+ };
+ self.getBounds = function () {
+ var radius = self.baseSize * self.growthFactor / 2;
+ return {
+ left: self.x - radius,
+ right: self.x + radius,
+ top: self.y - radius,
+ bottom: self.y + radius,
+ radius: radius
+ };
+ };
+ self.update = function () {
+ self.x += self.velocityX;
+ self.y += self.velocityY;
+ self.velocityX *= self.friction;
+ self.velocityY *= self.friction;
+ var bounds = self.getBounds();
+ var bounced = false;
+ if (bounds.left <= 0) {
+ self.x = bounds.radius;
+ self.velocityX = Math.abs(self.velocityX) * self.bounceForce;
+ bounced = true;
+ }
+ if (bounds.right >= 2048) {
+ self.x = 2048 - bounds.radius;
+ self.velocityX = -Math.abs(self.velocityX) * self.bounceForce;
+ bounced = true;
+ }
+ if (bounds.top <= 0) {
+ self.y = bounds.radius;
+ self.velocityY = Math.abs(self.velocityY) * self.bounceForce;
+ bounced = true;
+ }
+ if (bounds.bottom >= 2732) {
+ self.y = 2732 - bounds.radius;
+ self.velocityY = -Math.abs(self.velocityY) * self.bounceForce;
+ bounced = true;
+ }
+ if (bounced) {
+ LK.getSound('bounce').play();
+ }
+ };
+ return self;
+});
+var GoldenBerry = Container.expand(function () {
+ var self = Container.call(this);
+ var graphics = self.attachAsset('goldenBerry', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.floatOffset = Math.random() * Math.PI * 2;
+ self.floatSpeed = 0.05;
+ self.startY = 0;
+ self.update = function () {
+ self.y = self.startY + Math.sin(LK.ticks * self.floatSpeed + self.floatOffset) * 10;
+ };
+ return self;
+});
+var RedThorn = Container.expand(function () {
+ var self = Container.call(this);
+ var graphics = self.attachAsset('redThorn', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ graphics.rotation = Math.PI / 4;
+ self.pulseOffset = Math.random() * Math.PI * 2;
+ self.pulseSpeed = 0.08;
+ self.update = function () {
+ var pulse = 1 + Math.sin(LK.ticks * self.pulseSpeed + self.pulseOffset) * 0.1;
+ graphics.scaleX = pulse;
+ graphics.scaleY = pulse;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB
+});
+
+/****
+* Game Code
+****/
+var blueberry = game.addChild(new Blueberry());
+blueberry.x = 1024;
+blueberry.y = 1366;
+var goldenBerries = [];
+var redThorns = [];
+var dragNode = null;
+var lastMouseX = 0;
+var lastMouseY = 0;
+var thornSpawnTimer = 0;
+var berrySpawnTimer = 0;
+var scoreTxt = new Text2('0', {
+ size: 120,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+function spawnGoldenBerry() {
+ var berry = new GoldenBerry();
+ var margin = 50;
+ berry.x = margin + Math.random() * (2048 - margin * 2);
+ berry.y = margin + Math.random() * (2732 - margin * 2);
+ berry.startY = berry.y;
+ var tooClose = true;
+ var attempts = 0;
+ while (tooClose && attempts < 10) {
+ tooClose = false;
+ var berryBounds = {
+ x: berry.x,
+ y: berry.y,
+ radius: 20
+ };
+ var blueberryBounds = blueberry.getBounds();
+ var dist = Math.sqrt(Math.pow(berry.x - blueberry.x, 2) + Math.pow(berry.y - blueberry.y, 2));
+ if (dist < blueberryBounds.radius + 100) {
+ berry.x = margin + Math.random() * (2048 - margin * 2);
+ berry.y = margin + Math.random() * (2732 - margin * 2);
+ berry.startY = berry.y;
+ tooClose = true;
+ }
+ attempts++;
+ }
+ goldenBerries.push(berry);
+ game.addChild(berry);
+}
+function spawnRedThorn() {
+ var thorn = new RedThorn();
+ var margin = 50;
+ thorn.x = margin + Math.random() * (2048 - margin * 2);
+ thorn.y = margin + Math.random() * (2732 - margin * 2);
+ var tooClose = true;
+ var attempts = 0;
+ while (tooClose && attempts < 15) {
+ tooClose = false;
+ var blueberryBounds = blueberry.getBounds();
+ var dist = Math.sqrt(Math.pow(thorn.x - blueberry.x, 2) + Math.pow(thorn.y - blueberry.y, 2));
+ if (dist < blueberryBounds.radius + 150) {
+ thorn.x = margin + Math.random() * (2048 - margin * 2);
+ thorn.y = margin + Math.random() * (2732 - margin * 2);
+ tooClose = true;
+ }
+ attempts++;
+ }
+ redThorns.push(thorn);
+ game.addChild(thorn);
+}
+function handleMove(x, y, obj) {
+ if (dragNode) {
+ var deltaX = x - lastMouseX;
+ var deltaY = y - lastMouseY;
+ dragNode.x = x;
+ dragNode.y = y;
+ dragNode.velocityX = deltaX * 0.3;
+ dragNode.velocityY = deltaY * 0.3;
+ }
+ lastMouseX = x;
+ lastMouseY = y;
+}
+game.move = handleMove;
+game.down = function (x, y, obj) {
+ dragNode = blueberry;
+ lastMouseX = x;
+ lastMouseY = y;
+ handleMove(x, y, obj);
+};
+game.up = function (x, y, obj) {
+ dragNode = null;
+};
+spawnGoldenBerry();
+spawnGoldenBerry();
+spawnGoldenBerry();
+game.update = function () {
+ berrySpawnTimer++;
+ thornSpawnTimer++;
+ if (berrySpawnTimer > 300 && goldenBerries.length < 5) {
+ spawnGoldenBerry();
+ berrySpawnTimer = 0;
+ }
+ var thornSpawnRate = Math.max(180 - Math.floor(LK.getScore() * 5), 60);
+ if (thornSpawnTimer > thornSpawnRate) {
+ spawnRedThorn();
+ thornSpawnTimer = 0;
+ }
+ var blueberryBounds = blueberry.getBounds();
+ for (var i = goldenBerries.length - 1; i >= 0; i--) {
+ var berry = goldenBerries[i];
+ var dist = Math.sqrt(Math.pow(berry.x - blueberry.x, 2) + Math.pow(berry.y - blueberry.y, 2));
+ if (dist < blueberryBounds.radius + 20) {
+ LK.setScore(LK.getScore() + 1);
+ scoreTxt.setText(LK.getScore());
+ blueberry.grow();
+ LK.getSound('collect').play();
+ LK.effects.flashObject(berry, 0xFFFFFF, 200);
+ berry.destroy();
+ goldenBerries.splice(i, 1);
+ if (LK.getScore() >= 50) {
+ LK.showYouWin();
+ }
+ }
+ }
+ for (var j = 0; j < redThorns.length; j++) {
+ var thorn = redThorns[j];
+ var dist = Math.sqrt(Math.pow(thorn.x - blueberry.x, 2) + Math.pow(thorn.y - blueberry.y, 2));
+ if (dist < blueberryBounds.radius + 30) {
+ LK.effects.flashScreen(0xFF0000, 1000);
+ LK.showGameOver();
+ }
+ }
+};
\ No newline at end of file