Code edit (3 edits merged)
Please save this source code
User prompt
Add a coin counter in top right
Code edit (4 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'intersects')' in this line: 'if (snowballs[a].intersects(allCoins[k])) {' Line Number: 353
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'intersects')' in this line: 'if (zombieKids[b] && snowballs[a].intersects(zombieKids[b]) && snowballs[a].mayHit) {' Line Number: 324
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'destroy')' in this line: 'self.children[c].destroy();' Line Number: 356
Code edit (3 edits merged)
Please save this source code
User prompt
store all coins in a global array
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
if a showball hits a coin the coin should be removed
User prompt
If a snowball hits a coin user is rewarded with a coin
Code edit (3 edits merged)
Please save this source code
User prompt
add a pulsate animation to coins
User prompt
add a nice animation to coins
Code edit (3 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: self.jellyAnimation is not a function' in this line: 'self.jellyAnimation();' Line Number: 27
User prompt
replace the coin jelly animation with a better suiting animation
Code edit (1 edits merged)
Please save this source code
User prompt
make the coin animation much slower
User prompt
add a jelly animation to coins
User prompt
Sometimes spawn a coin on screen
Code edit (2 edits merged)
Please save this source code
User prompt
change max snowballs to 3
Code edit (1 edits merged)
Please save this source code
var Coin = Container.expand(function () { var self = Container.call(this); self.pulsate = function () { var maxScale = 1.2; var minScale = 0.8; var scaleStep = 0.005; var growing = true; self.scale.x = minScale; self.scale.y = minScale; LK.on('tick', function () { if (growing) { self.scale.x += scaleStep; self.scale.y += scaleStep; if (self.scale.x >= maxScale) growing = false; } else { self.scale.x -= scaleStep; self.scale.y -= scaleStep; if (self.scale.x <= minScale) growing = true; } }); }; var coinGraphics = self.createAsset('coin', 'Coin Graphics', .5, .5); self.init = function () { self.x = Math.random() * (2048 - self.width) + self.width / 2; self.y = Math.random() * (2732 - self.height) + self.height / 2; LK.stage.addChild(self); self.pulsate(); }; }); var Shadow = Container.expand(function () { var self = Container.call(this); var shadowGraphics = self.createAsset('shadow', 'Shadow Graphics', .5, .5); self.follow = function (target) { self.x = target.x; self.y = target.y + 50; var scale = target.scale.x * target.scale.x * 0.7; self.scale.x = self.scale.y = scale; self.scale.x = self.scale.y = scale; self.alpha = .5 / scale; }; }); var Aim = Container.expand(function () { var self = Container.call(this); var aimGraphics = self.createAsset('aim', 'Aim Graphics', .5, .5); }); var ParticleSplash = Container.expand(function () { var self = Container.call(this); var particleSplashGraphics = self.createAsset('particleSplash', 'Particle Splash Graphics', .5, .5); var randomScale = 0.5 + Math.random() * 0.5; self.scale.x = randomScale; self.scale.y = randomScale; self.directionX = Math.random() * 2 - 1; self.directionY = Math.random() * 2 - 1; self.animate = function () { self.alpha -= 0.01; self.x += self.directionX; self.y += self.directionY; if (self.alpha <= 0) { self.destroy(); } }; }); var ProgressBar = Container.expand(function () { var self = Container.call(this); var progressBarGraphics = self.createAsset('progressBar', 'Progress Bar Graphics', 0, .5); self.updateProgress = function (progress) { progressBarGraphics.scale.x = progress; }; }); var Snowball = Container.expand(function () { var self = Container.call(this); self.aim = arguments[0]; var snowballGraphics = self.createAsset('snowball', 'Snowball Graphics', .5, .5); self.speed = -5; self.targetX = self.aim.x; self.targetY = self.aim.y; self.speedX = 0; self.speedY = 0; self.totalDistance = 0; self.rotationAjd = (Math.random() - 1) * 0.05; self.move = function () { self.totalDistance = Math.sqrt(Math.pow(self.startX - self.x, 2) + Math.pow(self.y - self.startY, 2)); var halfDistance = self.targetTotalDistance / 2; var distanceFromHalf = 0; if (self.totalDistance < halfDistance) distanceFromHalf = halfDistance - self.totalDistance; else distanceFromHalf = self.totalDistance - halfDistance; var percentFromHalf = distanceFromHalf / halfDistance; if (percentFromHalf > 1.1) { self.shouldBeDestroyed = true; } else { var scaleAdj = 2 - percentFromHalf * 2; self.scale.x = 1 + scaleAdj; self.scale.y = 1 + scaleAdj; self.rotation += self.rotationAjd; self.mayHit = scaleAdj < 0.8; self.x += self.speedX; self.y += self.speedY; if (self.shadow) self.shadow.follow(self); } }; self.init = function () { self.targetTotalDistance = Math.sqrt(Math.pow(self.targetX - self.x, 2) + Math.pow(self.y - self.targetY, 2)); self.shadow = new Shadow(); self.shadow.follow(self); LK.stage.addChild(self.shadow); LK.stage.addChild(self); }; }); var ZombieKid = Container.expand(function (targetGift) { var self = Container.call(this); var zombieKidGraphics = self.createAsset('zombieKid', 'Zombie Kid Graphics', .5, .5); self.speed = Math.random() * 2 + 1; self.targetGift = targetGift; self.hasGift = false; self.pickedUpGift = null; self.findNewTarget = function () { var availableGifts = this.parent.children.filter(function (child) { return child instanceof ChristmasGift && !child.isDestroyed && !child.hasBeenPickedUp; }); if (availableGifts.length > 0) { var randomIndex = Math.floor(Math.random() * availableGifts.length); this.targetGift = availableGifts[randomIndex]; } }; self.move = function () { if (!self.hasGift) { var dx = self.targetGift.x - self.x; var dy = self.targetGift.y - self.y; var angle = Math.atan2(dy, dx); self.x += Math.cos(angle) * self.speed; self.y += Math.sin(angle) * self.speed; if (Math.abs(self.x - self.targetGift.x) < 10 && Math.abs(self.y - self.targetGift.y) < 10) { self.hasGift = true; self.targetGift.hasBeenPickedUp = true; self.pickedUpGift = self.targetGift; if (self.pickedUpGift.parent) { self.pickedUpGift.parent.setChildIndex(self.pickedUpGift, self.pickedUpGift.parent.children.length - 1); } self.pickedUpGift.x = self.x; self.pickedUpGift.y = self.y; } else if (!self.targetGift || self.targetGift.isDestroyed || self.targetGift.hasBeenPickedUp) { self.findNewTarget(); } } else { if (self.hasGift && !self.speedIncreased) { self.speed *= 1.5; self.speedIncreased = true; } self.y -= self.speed; if (self.pickedUpGift) { self.pickedUpGift.x = self.x; self.pickedUpGift.y = self.y; self.pickedUpGift.hasBeenPickedUp = true; } if (self.y < -self.height) { self.destroy(); var gameInstance = self.getGameInstance(); if (gameInstance && gameInstance.giftCounterTxt) { gameInstance.giftCounterTxt.setText('Gifts: ' + gameInstance.christmasGifts.filter(function (gift) { return !gift.isDestroyed; }).length); } } } }; }); var Santa = Container.expand(function () { var self = Container.call(this); var santaGraphics = self.createAsset('santa', 'Santa Graphics', .5, .5); }); var ChristmasGift = Container.expand(function () { var self = Container.call(this); self.offScreenHandler = function () { if (self.y > 2732 || self.x < 0 || self.x > 2048 || self.y < 0) { self.flaggedForRemoval = true; } }; var giftTypes = ['christmasGift1', 'christmasGift2', 'christmasGift3']; var randomType = giftTypes[Math.floor(Math.random() * giftTypes.length)]; var christmasGiftGraphics = self.createAsset(randomType, 'Christmas Gifts Graphics', 0.5, 1); self.x = Math.random() * 1536 + 256; self.y = Math.random() * 2032 + 100; }); Container.prototype.getGameInstance = function () { var currentParent = this.parent; while (currentParent) { if (currentParent instanceof Game) { return currentParent; } currentParent = currentParent.parent; } return null; }; var Game = Container.expand(function () { var self = Container.call(this); var background = self.createAsset('background', 'Full Screen Background', 0, 0); background.width = 2048; background.height = 2732; self.isThrowing = false; self.addChildAt(background, 0); var santa = self.addChild(new Santa()); santa.x = 2048 / 2; santa.y = 2732 - santa.height - 2732 / 20; var progressBar = self.addChild(new ProgressBar()); progressBar.x = 2048 - progressBar.width; progressBar.y = 2732 - progressBar.height; var christmasGifts = []; var placedGifts = 0; var tries = 0; self.giftCounterTxt = new Text2('Gifts: 10', { size: 100, fill: "#000000" }); while (placedGifts < 10) { tries++; if (tries > 1000) break; var gift = new ChristmasGift(); var intersects = false; for (var j = 0; j < christmasGifts.length; j++) { if (gift === christmasGifts[j]) continue; if (Math.abs(gift.x - christmasGifts[j].x) < 150 && Math.abs(gift.y - christmasGifts[j].y) < 150) intersects = true; } if (!intersects) { christmasGifts.push(gift); self.addChild(gift); placedGifts++; this.giftCounterTxt.setText('Gifts: ' + christmasGifts.length); } } var scoreTxt = new Text2('0', { size: 150, fill: "#000000" }); self.giftCounterTxt.anchor.set(.5, 0); self.giftCounterTxt.y = 1710; LK.gui.topCenter.addChild(self.giftCounterTxt); self.giftCounterTxt.setText('Gifts left: ' + christmasGifts.length); scoreTxt.anchor.set(.5, 0); LK.gui.topCenter.addChild(scoreTxt); self.updateScoreDisplay = function () { scoreTxt.setText(LK.getScore().toString()); }; self.updateScoreDisplay(); var snowballs = []; var zombieKids = []; var touchStartTime = 0; stage.on('down', function (obj) { touchStartTime = LK.ticks; progressBar.updateProgress(0); isThrowing = true; var event = obj.event; var pos = event.getLocalPosition(self); santa.baseRotation = Math.atan2(pos.y - santa.y, pos.x - santa.x) + Math.PI * 0.6; self.aimPosition = pos; var aim = new Aim(); self.currentAim = aim; aim.x = pos.x; aim.y = pos.y; var progress = 0; aim.scale.x = aim.scale.y = 0.5 + progress * 0.5; self.addChild(aim); aim.tweenToAlpha = function (targetAlpha, duration) { var step = (1 - targetAlpha) / (duration * 60); var fadeInterval = LK.setInterval(function () { aim.alpha -= step; if (aim.alpha <= targetAlpha) { LK.clearInterval(fadeInterval); aim.destroy(); } }, 1000 / 60); }; aim.tweenToAlpha(0, 3); }); stage.on('up', function (obj) { if (self.aim) { self.aim.destroy(); self.aim = null; } progressBar.updateProgress(0); santa.rotation = santa.baseRotation; isThrowing = false; if (snowballs.length < 3 && self.aimPosition) { var newSnowball = new Snowball(self.currentAim); newSnowball.x = santa.x + 120; ; newSnowball.y = santa.y; newSnowball.startX = santa.x + 120; newSnowball.startY = santa.y; newSnowball.targetX = self.aimPosition.x; newSnowball.targetY = self.aimPosition.y; newSnowball.init(); var dx = newSnowball.targetX - newSnowball.x; var dy = newSnowball.targetY - newSnowball.y; var distance = Math.sqrt(dx * dx + dy * dy); var throwSpeed = 10; var touchDuration = LK.ticks - touchStartTime; var speedMultiplier = Math.min(touchDuration / 30, 10) * throwSpeed; newSnowball.speedMultiplier = speedMultiplier; newSnowball.speedX = -dx / distance * newSnowball.speed * speedMultiplier; newSnowball.speedY = -Math.abs(dy / distance * newSnowball.speed) * speedMultiplier; snowballs.push(newSnowball); self.aimPosition = null; } self.currentAim = null; }); LK.on('tick', function () { if (touchStartTime > 0 && isThrowing) { var progress = Math.min((LK.ticks - touchStartTime) / 30, 1); progressBar.updateProgress(progress); santa.rotation = santa.baseRotation + progress * Math.PI * 2 / 10; if (self.aim) { self.aim.scale.x = self.aim.scale.y = 0.5 + progressBarGraphics.scale.x * 0.5; } if (self.currentAim) { self.currentAim.scale.x = 0.2 + progress; self.currentAim.scale.y = 0.2 + progress; } } for (var a = snowballs.length - 1; a >= 0; a--) { if (snowballs[a]) { snowballs[a].move(); for (var b = zombieKids.length - 1; b >= 0; b--) { if (zombieKids[b] && snowballs[a].intersects(zombieKids[b]) && snowballs[a].mayHit) { LK.setScore(LK.getScore() + 1); self.updateScoreDisplay(); for (var i = 0; i < 10; i++) { var particleSplash = new ParticleSplash(); particleSplash.x = snowballs[a].x; particleSplash.y = snowballs[a].y; particleSplash.directionX *= snowballs[a].speedY; particleSplash.directionY *= snowballs[a].speedY; self.addChild(particleSplash); } if (zombieKids[b].hasGift) { var droppedGift = zombieKids[b].pickedUpGift; droppedGift.x = zombieKids[b].x; droppedGift.y = zombieKids[b].y; droppedGift.hasBeenDropped = true; droppedGift.hasBeenPickedUp = false; } zombieKids[b].destroy(); zombieKids.splice(b, 1); if (snowballs[a].aim) snowballs[a].aim.destroy(); if (snowballs[a].shadow) snowballs[a].shadow.destroy(); snowballs[a].destroy(); snowballs[a].shadow.destroy(); snowballs.splice(a, 1); break; } } if (snowballs[a] && (snowballs[a].y < -50 || snowballs[a].shouldBeDestroyed)) { snowballs[a].destroy(); snowballs[a].shadow.destroy(); snowballs.splice(a, 1); } } } for (var b = zombieKids.length - 1; b >= 0; b--) { if (zombieKids[b]) { zombieKids[b].move(); } } for (var c = self.children.length - 1; c >= 0; c--) { if (self.children[c] instanceof ParticleSplash) { self.children[c].animate(); } } for (var j = 0; j < christmasGifts.length; j++) { christmasGifts[j].offScreenHandler(); if (christmasGifts[j].flaggedForRemoval) { christmasGifts[j].destroy(); christmasGifts.splice(j, 1); self.giftCounterTxt.setText('Gifts left: ' + christmasGifts.length); } } if (LK.ticks % 60 == 0) { if (Math.random() < 0.1) { var newCoin = new Coin(); newCoin.init(); } if (christmasGifts.length > 0) { var targetGiftIndex = Math.floor(Math.random() * christmasGifts.length); var targetGift = christmasGifts[targetGiftIndex]; var newZombieKid = new ZombieKid(targetGift); newZombieKid.x = Math.random() * (2048 - newZombieKid.width); newZombieKid.y = -newZombieKid.height; zombieKids.push(newZombieKid); self.addChild(newZombieKid); } else { LK.showGameOver(); } } }); });
===================================================================
--- original.js
+++ change.js
@@ -1,16 +1,31 @@
var Coin = Container.expand(function () {
var self = Container.call(this);
+ self.pulsate = function () {
+ var maxScale = 1.2;
+ var minScale = 0.8;
+ var scaleStep = 0.005;
+ var growing = true;
+ self.scale.x = minScale;
+ self.scale.y = minScale;
+ LK.on('tick', function () {
+ if (growing) {
+ self.scale.x += scaleStep;
+ self.scale.y += scaleStep;
+ if (self.scale.x >= maxScale) growing = false;
+ } else {
+ self.scale.x -= scaleStep;
+ self.scale.y -= scaleStep;
+ if (self.scale.x <= minScale) growing = true;
+ }
+ });
+ };
var coinGraphics = self.createAsset('coin', 'Coin Graphics', .5, .5);
self.init = function () {
self.x = Math.random() * (2048 - self.width) + self.width / 2;
self.y = Math.random() * (2732 - self.height) + self.height / 2;
LK.stage.addChild(self);
- self.rotationSpeed = 0.1;
- self.animate = function () {
- self.rotation += self.rotationSpeed;
- };
- LK.on('tick', self.animate);
+ self.pulsate();
};
});
var Shadow = Container.expand(function () {
var self = Container.call(this);
@@ -87,15 +102,8 @@
self.shadow = new Shadow();
self.shadow.follow(self);
LK.stage.addChild(self.shadow);
LK.stage.addChild(self);
- self.floatSpeed = 0.5;
- self.floatOffset = 0;
- self.animateFloat = function () {
- self.floatOffset += self.floatSpeed;
- self.y += Math.sin(self.floatOffset * Math.PI / 180) * 2;
- };
- LK.on('tick', self.animateFloat);
};
});
var ZombieKid = Container.expand(function (targetGift) {
var self = Container.call(this);
a christmas gift Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
red crosshair Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
snowball of soft snow Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Christmas gift with glowing green wrapping paper Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas gift in beautiful glowing wrapping paper Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Christmas gift beautifully wrapped in green glowing wrapping paper Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Snowy flat surface viewed from above at nighttime Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
an empty painting with a winter styled frame Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a kid thief in wearing a black hoodie. Also looking like a zombie Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A button with the text "play". Winter theme Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A winter themed button, with no text Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A buy upgrade button, winter theme, no text Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a wide white sheet of paper Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a snowball Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a snowball
A game over screen for the game "Snowball Santa". Santa is very sad because all the presents has been stolen from ninja kids. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A wooden sign with text "UPGRADES" in a winter theme. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A ninja kid thief, full body, with a dark purple hoodie. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A ninja kid thief, full body, with a dark colored hoodie. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A ninja kid thief, full body, with a dark colored hoodie. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a precious colorful glowing gem with snow and ice on it. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a logo for the game "Snowball santa" with the text "Snowball Santa". Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A beautiful winter snowy christmas landscape with ninja thieves kids lurking. Christmas gifts are hidden in the snow. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.