User prompt
Migrate to the latest version of LK
User prompt
move lifes and gifts 1000 pixels to the right
User prompt
move lifes and gifts 400 pixels to the left
User prompt
move lifes and gift icons an counter to the top right of the screen
User prompt
hazards can appear on any y from the right of the screen
Code edit (1 edits merged)
Please save this source code
User prompt
santa can only collide with rudolph when rudolph is visible
User prompt
add chimney garbage collector
User prompt
add stars gardbage collector
User prompt
increase game performance
User prompt
Fix Bug: 'ReferenceError: chimneys is not defined' in this line: 'for (var i = 0; i < chimneys.length; i++) {' Line Number: 284
User prompt
Fix Bug: 'ReferenceError: chimneys is not defined' in this line: 'if (chimneys[i].x + chimneys[i].width <= 0) {' Line Number: 270
User prompt
Fix Bug: 'ReferenceError: chimneys is not defined' in this line: 'for (var i = chimneys.length - 1; i >= 0; i--) {' Line Number: 269
User prompt
Fix Bug: 'ReferenceError: chimneys is not defined' in this line: 'chimneys.forEach(function (chimney) {' Line Number: 246
User prompt
Fix Bug: 'ReferenceError: chimneys is not defined' in this line: 'chimneys.push(newChimney);' Line Number: 242
User prompt
Fix Bug: 'ReferenceError: chimneys is not defined' in this line: 'var lastChimney = chimneys[chimneys.length - 1];' Line Number: 236
User prompt
Fix Bug: 'ReferenceError: chimneys is not defined' in this line: 'if (chimneys.length < maxChimneys) {' Line Number: 235
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'some')' in this line: 'if (distance < speed || this.parent.chimneys.some(chimney => this.intersects(chimney))) {' Line Number: 72
User prompt
santa cant collide with chimeny. if santa touches a chimney he should stop moving
User prompt
make sure santa has 3 lifes and can collide with hazards 3 times before he dies
User prompt
add garbage collector
User prompt
improve perfomance by adding spatial partitioning
User prompt
Fix Bug: 'Uncaught TypeError: LK.showNotification is not a function' in this line: 'LK.showNotification('Auto shoot - ON');' Line Number: 143
User prompt
and message on start saying ''Auto shoot - ON''
User prompt
drop present on double click
===================================================================
--- original.js
+++ change.js
@@ -1,27 +1,93 @@
-var ScoreBackground = Container.expand(function () {
+/****
+* Classes
+****/
+var Chimney = Container.expand(function () {
var self = Container.call(this);
- var scoreBgGraphics = self.createAsset('scoreBg', 'Score Background', 0.5, 0);
- scoreBgGraphics.height -= 100;
+ var chimneyGraphics = self.attachAsset('chimney', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.originalTint = 0xFFFFFF;
+ self.presentDeliveredTint = 0x808080;
+ self.hasPresent = false;
+ self.speed = 2;
+ self._move_migrated = function () {
+ self.x -= self.speed;
+ if (self.x < -self.width) {
+ self.x = 2048;
+ }
+ };
+ self.checkCollision = function () {};
});
+var Hazard = Container.expand(function () {
+ var self = Container.call(this);
+ var hazardGraphics = self.attachAsset('hazard', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self._move_migrated = function () {
+ self.x -= self.speed;
+ if (self.x < -self.width) {
+ self.destroy();
+ return true;
+ }
+ return false;
+ };
+});
+var LifeIcon = Container.expand(function () {
+ var self = Container.call(this);
+ var lifeIconGraphics = self.attachAsset('lifeIcon', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+});
+var Present = Container.expand(function () {
+ var self = Container.call(this);
+ var presentGraphics = self.attachAsset('present', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self._move_migrated = function (hazards) {
+ this.y += 5;
+ hazards.forEach(function (hazard) {
+ var collisionBuffer = 10;
+ if (this.intersects(hazard) && Math.abs(this.x - hazard.x) < (this.width + hazard.width) / 2 - collisionBuffer && Math.abs(this.y - hazard.y) < (this.height + hazard.height) / 2 - collisionBuffer) {
+ LK.effects.flashObject(this, 0xff0000, 300);
+ LK.setTimeout(function () {
+ this.destroy();
+ }.bind(this), 300);
+ }
+ }.bind(this));
+ };
+});
var PresentIcon = Container.expand(function () {
var self = Container.call(this);
- var presentIconGraphics = self.createAsset('presentIcon', 'Present Icon', 0.5, 0.5);
+ var presentIconGraphics = self.attachAsset('presentIcon', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
});
var PresentTopper = Container.expand(function (speed) {
var self = Container.call(this);
- var topperGraphics = self.createAsset('presentTopper', 'Present Topper', 0.5, 1);
+ var topperGraphics = self.attachAsset('presentTopper', {
+ anchorX: 0.5,
+ anchorY: 1
+ });
self.speed = speed;
- self.move = function () {
+ self._move_migrated = function () {
self.x -= self.speed;
};
});
var RandomMover = Container.expand(function () {
var self = Container.call(this);
- var moverGraphics = self.createAsset('randomMover', 'Random Mover', 0.5, 0.5);
+ var moverGraphics = self.attachAsset('randomMover', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
self.speedX = (Math.random() * 4 - 2) * 4;
self.speedY = (Math.random() * 4 - 2) * 4;
- self.move = function () {
+ self._move_migrated = function () {
self.x += self.speedX;
self.y += self.speedY;
if (self.x < 0 || self.x > 2048) {
self.speedX *= -1;
@@ -30,35 +96,21 @@
self.speedY *= -1;
}
};
});
-var LifeIcon = Container.expand(function () {
- var self = Container.call(this);
- var lifeIconGraphics = self.createAsset('lifeIcon', 'Life Icon', 0.5, 0.5);
-});
-var Star = Container.expand(function () {
- var self = Container.call(this);
- var starGraphics = self.createAsset('star', 'Star', 0.5, 0.5);
- self.speed = 2 + Math.random() * 3;
- self.move = function () {
- self.x -= self.speed;
- if (self.x < -self.width) {
- self.destroy();
- return true;
- }
- return false;
- };
-});
var Santa = Container.expand(function () {
var self = Container.call(this);
self.resetPresents = function () {
this.presentCounter = 5;
- this.parent.presentIcons.forEach((function (icon, index) {
+ this.parent.presentIcons.forEach(function (icon, index) {
icon.visible = index < this.presentCounter;
- }).bind(this));
+ }.bind(this));
};
- var santaGraphics = self.createAsset('santa', 'Santa character', .5, .5);
- self.move = function () {
+ var santaGraphics = self.attachAsset('santa', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self._move_migrated = function () {
if (this.lastTouchPosition) {
var dx = this.lastTouchPosition.x - this.x;
var dy = this.lastTouchPosition.y - this.y;
var distance = Math.sqrt(dx * dx + dy * dy);
@@ -81,11 +133,11 @@
present.y = this.y;
this.parent.addChild(present);
this.parent.presents.push(present);
this.presentCounter--;
- this.parent.presentIcons.forEach((function (icon, index) {
+ this.parent.presentIcons.forEach(function (icon, index) {
icon.visible = index < this.presentCounter;
- }).bind(this));
+ }.bind(this));
}
if (this.presentCounter === 0) {
this.parent.hazardSpeed *= 1.5;
this.parent.hazardSpawnRate = Math.max(this.parent.hazardSpawnRate * 0.8, 20);
@@ -94,223 +146,211 @@
this.parent.rudolph.visible = false;
}
};
});
-var Present = Container.expand(function () {
+var ScoreBackground = Container.expand(function () {
var self = Container.call(this);
- var presentGraphics = self.createAsset('present', 'Present', .5, .5);
- self.move = function (hazards) {
- this.y += 5;
- hazards.forEach((function (hazard) {
- var collisionBuffer = 10;
- if (this.intersects(hazard) && Math.abs(this.x - hazard.x) < (this.width + hazard.width) / 2 - collisionBuffer && Math.abs(this.y - hazard.y) < (this.height + hazard.height) / 2 - collisionBuffer) {
- LK.effects.flashObject(this, 0xff0000, 300);
- LK.setTimeout((function () {
- this.destroy();
- }).bind(this), 300);
- }
- }).bind(this));
- };
+ var scoreBgGraphics = self.attachAsset('scoreBg', {
+ anchorX: 0.5
+ });
+ scoreBgGraphics.height -= 100;
});
-var Chimney = Container.expand(function () {
+var Star = Container.expand(function () {
var self = Container.call(this);
- var chimneyGraphics = self.createAsset('chimney', 'Chimney', .5, .5);
- self.originalTint = 0xFFFFFF;
- self.presentDeliveredTint = 0x808080;
- self.hasPresent = false;
- self.speed = 2;
- self.move = function () {
+ var starGraphics = self.attachAsset('star', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 2 + Math.random() * 3;
+ self._move_migrated = function () {
self.x -= self.speed;
if (self.x < -self.width) {
- self.x = 2048;
- }
- };
- self.checkCollision = function () {};
-});
-var Hazard = Container.expand(function () {
- var self = Container.call(this);
- var hazardGraphics = self.createAsset('hazard', 'Hazard', .5, .5);
- self.move = function () {
- self.x -= self.speed;
- if (self.x < -self.width) {
self.destroy();
return true;
}
return false;
};
});
-var Game = Container.expand(function () {
- var self = Container.call(this);
- self.toppers = [];
- self.stars = [];
- var starSpawnRate = 15;
- var starSpawnCounter = 0;
- var santa = self.addChild(new Santa());
- santa.x = 2048 / 2;
- santa.y = 2732 / 2;
- santa.presentDropTimer = 0;
- self.lastTapTime = 0;
- self.rudolph = self.addChild(new RandomMover());
- self.rudolph.x = Math.random() * 2048;
- self.rudolph.y = Math.random() * 2732;
- self.rudolph.visible = false;
- santa.lives = 3;
- self.lifeIcons = [];
- var lifeIconSpacing = 20;
- var lifeIconSize = 64;
- for (var i = 0; i < santa.lives; i++) {
- var lifeIcon = new LifeIcon();
- lifeIcon.x = lifeIconSpacing + 1050 + i * (lifeIconSize + lifeIconSpacing);
- lifeIcon.y = lifeIconSpacing + 50;
- self.lifeIcons.push(lifeIcon);
- LK.gui.topLeft.addChild(lifeIcon);
+
+/****
+* Initialize Game
+****/
+var game = new LK.Game({
+ backgroundColor: 0x000000
+});
+
+/****
+* Game Code
+****/
+game.toppers = [];
+game.stars = [];
+var starSpawnRate = 15;
+var starSpawnCounter = 0;
+var santa = game.addChild(new Santa());
+santa.x = 2048 / 2;
+santa.y = 2732 / 2;
+santa.presentDropTimer = 0;
+game.lastTapTime = 0;
+game.rudolph = game.addChild(new RandomMover());
+game.rudolph.x = Math.random() * 2048;
+game.rudolph.y = Math.random() * 2732;
+game.rudolph.visible = false;
+santa.lives = 3;
+game.lifeIcons = [];
+var lifeIconSpacing = 20;
+var lifeIconSize = 64;
+for (var i = 0; i < santa.lives; i++) {
+ var lifeIcon = new LifeIcon();
+ lifeIcon.x = lifeIconSpacing + 1050 + i * (lifeIconSize + lifeIconSpacing);
+ lifeIcon.y = lifeIconSpacing + 50;
+ game.lifeIcons.push(lifeIcon);
+ LK.gui.topLeft.addChild(lifeIcon);
+}
+santa.presentCounter = 5;
+game.presents = [];
+var chimneys = [];
+var hazards = [];
+var hazardSpeed = 8;
+var hazardSpawnRate = 80;
+var hazardSpawnCounter = 0;
+var rudolphSpawnCounter = 0;
+var scoreBackground = new ScoreBackground();
+scoreBackground.x = 2048 / 2 - scoreBackground.width / 2 - 880;
+scoreBackground.y = 0;
+game.addChild(scoreBackground);
+var scoreTxt = new Text2('0', {
+ size: 150,
+ fill: "#ffffff",
+ font: "'Press Start 2P', monospace",
+ dropShadow: true,
+ dropShadowColor: '#000000',
+ dropShadowBlur: 4
+});
+game.presentIcons = [];
+for (var i = 0; i < santa.presentCounter; i++) {
+ var presentIcon = new PresentIcon();
+ presentIcon.x = 1060 + i * (presentIcon.width + 10);
+ presentIcon.y = game.lifeIcons[game.lifeIcons.length - 1].y + lifeIconSize + lifeIconSpacing;
+ game.presentIcons.push(presentIcon);
+ LK.gui.topLeft.addChild(presentIcon);
+}
+var maxChimneys = 5;
+LK.on('tick', function () {
+ var currentTick = LK.ticks;
+ santa._move_migrated();
+ if (santa.presentDropTimer++ >= 120) {
+ santa.throwPresent();
+ santa.presentDropTimer = 0;
}
- santa.presentCounter = 5;
- self.presents = [];
- var chimneys = [];
- var hazards = [];
- var hazardSpeed = 8;
- var hazardSpawnRate = 80;
- var hazardSpawnCounter = 0;
- var rudolphSpawnCounter = 0;
- var scoreBackground = new ScoreBackground();
- scoreBackground.x = 2048 / 2 - scoreBackground.width / 2 - 880;
- scoreBackground.y = 0;
- self.addChild(scoreBackground);
- var scoreTxt = new Text2('0', {
- size: 150,
- fill: "#ffffff",
- font: "'Press Start 2P', monospace",
- dropShadow: true,
- dropShadowColor: '#000000',
- dropShadowBlur: 4
+ game.on('down', function (x, y, obj) {
+ var event = obj;
+ santa.lastTouchPosition = game.toLocal(event.global);
});
- self.presentIcons = [];
- for (var i = 0; i < santa.presentCounter; i++) {
- var presentIcon = new PresentIcon();
- presentIcon.x = 1060 + i * (presentIcon.width + 10);
- presentIcon.y = self.lifeIcons[self.lifeIcons.length - 1].y + lifeIconSize + lifeIconSpacing;
- self.presentIcons.push(presentIcon);
- LK.gui.topLeft.addChild(presentIcon);
+ game.toppers = game.toppers.filter(function (topper) {
+ return topper.x + topper.width > 0;
+ });
+ game.toppers.forEach(function (topper) {
+ topper._move_migrated();
+ });
+ if (starSpawnCounter++ >= starSpawnRate) {
+ var newStar = new Star();
+ newStar.x = 2048;
+ newStar.y = Math.random() * (2732 * 0.8);
+ game.stars.push(newStar);
+ game.addChild(newStar);
+ starSpawnCounter = 0;
}
- var maxChimneys = 5;
- LK.on('tick', function () {
- var currentTick = LK.ticks;
- santa.move();
- if (santa.presentDropTimer++ >= 120) {
- santa.throwPresent();
- santa.presentDropTimer = 0;
+ if (chimneys.length < maxChimneys) {
+ var lastChimney = chimneys[chimneys.length - 1];
+ var chimneySpacing = 500;
+ if (!lastChimney || lastChimney.x < 2048 - chimneySpacing) {
+ var newChimney = new Chimney();
+ newChimney.x = 2048;
+ newChimney.y = 2732 - newChimney.height - Math.random() * 500 + 750;
+ chimneys.push(newChimney);
+ game.addChild(newChimney);
}
- stage.on('down', function (obj) {
- var event = obj.event;
- santa.lastTouchPosition = event.getLocalPosition(self);
- });
- self.toppers = self.toppers.filter(function (topper) {
- return topper.x + topper.width > 0;
- });
- self.toppers.forEach(function (topper) {
- topper.move();
- });
- if (starSpawnCounter++ >= starSpawnRate) {
- var newStar = new Star();
- newStar.x = 2048;
- newStar.y = Math.random() * (2732 * 0.8);
- self.stars.push(newStar);
- self.addChild(newStar);
- starSpawnCounter = 0;
- }
- if (chimneys.length < maxChimneys) {
- var lastChimney = chimneys[chimneys.length - 1];
- var chimneySpacing = 500;
- if (!lastChimney || lastChimney.x < 2048 - chimneySpacing) {
- var newChimney = new Chimney();
- newChimney.x = 2048;
- newChimney.y = 2732 - newChimney.height - Math.random() * 500 + 750;
- chimneys.push(newChimney);
- self.addChild(newChimney);
+ }
+ chimneys.forEach(function (chimney) {
+ chimney._move_migrated();
+ game.presents.forEach(function (present, index) {
+ var chimneyCollisionBuffer = 15;
+ if (present.intersects(chimney) && !chimney.hasPresent && Math.abs(present.x - chimney.x) < (present.width + chimney.width) / 2 - chimneyCollisionBuffer && Math.abs(present.y - chimney.y) < (present.height + chimney.height) / 2 - chimneyCollisionBuffer) {
+ present.destroy();
+ game.presents.splice(index, 1);
+ chimney.hasPresent = true;
+ chimney.tint = chimney.presentDeliveredTint;
+ var newScore = LK.getScore() + 1;
+ LK.setScore(newScore);
+ scoreTxt.setText(newScore.toString());
+ var presentTopper = new PresentTopper(chimney.speed);
+ presentTopper.x = chimney.x;
+ presentTopper.y = chimney.y - chimney.height / 2;
+ game.addChild(presentTopper);
+ game.toppers.push(presentTopper);
}
- }
- chimneys.forEach(function (chimney) {
- chimney.move();
- self.presents.forEach(function (present, index) {
- var chimneyCollisionBuffer = 15;
- if (present.intersects(chimney) && !chimney.hasPresent && Math.abs(present.x - chimney.x) < (present.width + chimney.width) / 2 - chimneyCollisionBuffer && Math.abs(present.y - chimney.y) < (present.height + chimney.height) / 2 - chimneyCollisionBuffer) {
- present.destroy();
- self.presents.splice(index, 1);
- chimney.hasPresent = true;
- chimney.tint = chimney.presentDeliveredTint;
- var newScore = LK.getScore() + 1;
- LK.setScore(newScore);
- scoreTxt.setText(newScore.toString());
- var presentTopper = new PresentTopper(chimney.speed);
- presentTopper.x = chimney.x;
- presentTopper.y = chimney.y - chimney.height / 2;
- self.addChild(presentTopper);
- self.toppers.push(presentTopper);
- }
- });
});
- chimneys = chimneys.filter(function (chimney) {
- if (chimney.x + chimney.width <= 0) {
- chimney.destroy();
- return false;
- }
- return true;
- });
});
- scoreTxt.anchor.set(.5, 0);
- scoreTxt.y += 15;
- LK.gui.topCenter.addChild(scoreBackground);
- LK.gui.topCenter.addChild(scoreTxt);
- LK.on('tick', function () {
- for (var i = self.presents.length - 1; i >= 0; i--) {
- self.presents[i].move(hazards);
+ chimneys = chimneys.filter(function (chimney) {
+ if (chimney.x + chimney.width <= 0) {
+ chimney.destroy();
+ return false;
}
- for (var i = chimneys.length - 1; i >= 0; i--) {
- chimneys[i].checkCollision();
- }
- if (hazardSpawnCounter++ >= hazardSpawnRate) {
- var newHazard = new Hazard();
- newHazard.x = 2048;
- newHazard.y = Math.random() * 2732;
- newHazard.speed = hazardSpeed;
- hazards.unshift(newHazard);
- self.addChild(newHazard);
- hazardSpawnCounter = 0;
- }
- hazards = hazards.filter(function (hazard) {
- return !hazard.move();
- });
- var santaHit = false;
- hazards.forEach(function (hazard, index) {
- var santaCollisionBuffer = 15;
- if (!santaHit && santa.intersects(hazard) && Math.abs(santa.x - hazard.x) < (santa.width + hazard.width) / 2 - santaCollisionBuffer && Math.abs(santa.y - hazard.y) < (santa.height + hazard.height) / 2 - santaCollisionBuffer) {
- LK.effects.flashObject(santa, 0xffff00, 500);
- hazard.destroy();
- hazards.splice(index, 1);
- santaHit = true;
- santa.lives--;
- if (self.lifeIcons.length > santa.lives) {
- var removedLifeIcon = self.lifeIcons.pop();
- removedLifeIcon.destroy();
- }
- if (santa.lives <= 0) {
- LK.showGameOver();
- }
+ return true;
+ });
+});
+scoreTxt.anchor.set(.5, 0);
+scoreTxt.y += 15;
+LK.gui.top.addChild(scoreBackground);
+LK.gui.top.addChild(scoreTxt);
+LK.on('tick', function () {
+ for (var i = game.presents.length - 1; i >= 0; i--) {
+ game.presents[i]._move_migrated(hazards);
+ }
+ for (var i = chimneys.length - 1; i >= 0; i--) {
+ chimneys[i].checkCollision();
+ }
+ if (hazardSpawnCounter++ >= hazardSpawnRate) {
+ var newHazard = new Hazard();
+ newHazard.x = 2048;
+ newHazard.y = Math.random() * 2732;
+ newHazard.speed = hazardSpeed;
+ hazards.unshift(newHazard);
+ game.addChild(newHazard);
+ hazardSpawnCounter = 0;
+ }
+ hazards = hazards.filter(function (hazard) {
+ return !hazard._move_migrated();
+ });
+ var santaHit = false;
+ hazards.forEach(function (hazard, index) {
+ var santaCollisionBuffer = 15;
+ if (!santaHit && santa.intersects(hazard) && Math.abs(santa.x - hazard.x) < (santa.width + hazard.width) / 2 - santaCollisionBuffer && Math.abs(santa.y - hazard.y) < (santa.height + hazard.height) / 2 - santaCollisionBuffer) {
+ LK.effects.flashObject(santa, 0xffff00, 500);
+ hazard.destroy();
+ hazards.splice(index, 1);
+ santaHit = true;
+ santa.lives--;
+ if (game.lifeIcons.length > santa.lives) {
+ var removedLifeIcon = game.lifeIcons.pop();
+ removedLifeIcon.destroy();
}
- });
- hazards = hazards.filter(function (hazard) {
- return !hazard.hitSanta;
- });
- self.stars.forEach(function (star, index) {
- if (star.move()) {
- star.destroy();
- self.stars.splice(index, 1);
+ if (santa.lives <= 0) {
+ LK.showGameOver();
}
- });
- self.rudolph.move();
- if (self.rudolph.visible && santa.intersects(self.rudolph)) {
- santa.resetPresents();
- self.rudolph.visible = false;
}
});
-});
+ hazards = hazards.filter(function (hazard) {
+ return !hazard.hitSanta;
+ });
+ game.stars.forEach(function (star, index) {
+ if (star._move_migrated()) {
+ star.destroy();
+ game.stars.splice(index, 1);
+ }
+ });
+ game.rudolph._move_migrated();
+ if (game.rudolph.visible && santa.intersects(game.rudolph)) {
+ santa.resetPresents();
+ game.rudolph.visible = false;
+ }
+});
\ No newline at end of file
8-bit cloud with lightning. in game asset. white cloude. yellow lighning. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
8 bit x mas pressent. in game asset. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
8-bit. cartoon. santa on sledge. smiling. in game asset. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.