User prompt
The correct approach would be to place the event listener for the 'down' event outside of the tick event handler, ensuring it is added only once during the initialization of the game. This would allow the game to correctly listen for clicks or taps on Santa and trigger the present drop as expected.
User prompt
Fix Bug: 'TypeError: santa.containsPoint is not a function' in this line: 'if (santa.containsPoint(localPos)) {' Line Number: 202
User prompt
when user click on santa it should shot a present
User prompt
remove auto shot\
User prompt
improve collision so that there is not so much space when collision happens
User prompt
Fix Bug: 'TypeError: this.throwPresent is not a function' in this line: 'this.throwPresent();' Line Number: 199
User prompt
drop present when player click on top of santa
User prompt
remove automatic present drop
User prompt
move santa on swipe. it sshould move until where the finger stops contact
User prompt
throw gift on click
User prompt
stop automatic gift drop on tick
User prompt
swipe to move santa
User prompt
change automatic present drop to on click
User prompt
on click drop only 1 present
User prompt
swipe to move santa and click to drop presents
User prompt
moves score text 5 pixels down
User prompt
move score text 10 pixels down
Code edit (1 edits merged)
Please save this source code
User prompt
change score font to press start p2
User prompt
reduce score bg height by 100 px
User prompt
move scrorebg 30 pixels right
User prompt
moves score bg 400 pixels left
User prompt
move scrobg 500 pixels left
User prompt
show scorebg next to score
User prompt
show scorebg on tick
var ScoreBackground = Container.expand(function () {
var self = Container.call(this);
var scoreBgGraphics = self.createAsset('scoreBg', 'Score Background', 0.5, 0);
});
var PresentIcon = Container.expand(function () {
var self = Container.call(this);
var presentIconGraphics = self.createAsset('presentIcon', 'Present Icon', 0.5, 0.5);
});
var PresentTopper = Container.expand(function (speed) {
var self = Container.call(this);
var topperGraphics = self.createAsset('presentTopper', 'Present Topper', 0.5, 1);
self.speed = speed;
self.move = 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);
self.speedX = (Math.random() * 4 - 2) * 4;
self.speedY = (Math.random() * 4 - 2) * 4;
self.move = function () {
self.x += self.speedX;
self.y += self.speedY;
if (self.x < 0 || self.x > 2048) {
self.speedX *= -1;
}
if (self.y < 0 || self.y > 2732) {
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) {
icon.visible = index < this.presentCounter;
}).bind(this));
};
var santaGraphics = self.createAsset('santa', 'Santa character', .5, .5);
self.move = 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);
var speed = 10;
if (distance > speed) {
dx = dx / distance * speed;
dy = dy / distance * speed;
}
this.x += dx;
this.y += dy;
if (distance < speed) {
this.lastTouchPosition = null;
}
}
};
self.throwPresent = function () {
if (this.presentCounter > 0) {
var present = new Present();
present.x = this.x;
present.y = this.y;
this.parent.addChild(present);
this.parent.presents.push(present);
this.presentCounter--;
this.parent.presentIcons.forEach((function (icon, index) {
icon.visible = index < this.presentCounter;
}).bind(this));
}
if (this.presentCounter === 0) {
this.parent.hazardSpeed *= 1.5;
this.parent.hazardSpawnRate = Math.max(this.parent.hazardSpawnRate * 0.8, 20);
this.parent.rudolph.visible = true;
} else {
this.parent.rudolph.visible = false;
}
};
});
var Present = 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) {
if (this.intersects(hazard)) {
LK.effects.flashObject(this, 0xff0000, 300);
LK.setTimeout((function () {
this.destroy();
}).bind(this), 300);
}
}).bind(this));
};
});
var Chimney = 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 () {
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 + 50 + i * (lifeIconSize + lifeIconSpacing);
lifeIcon.y = lifeIconSpacing + 50;
self.lifeIcons.push(lifeIcon);
LK.gui.topLeft.addChild(lifeIcon);
}
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.y = 0;
self.addChild(scoreBackground);
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
self.presentIcons = [];
for (var i = 0; i < santa.presentCounter; i++) {
var presentIcon = new PresentIcon();
presentIcon.x = 60 + i * (presentIcon.width + 10);
presentIcon.y = self.lifeIcons[self.lifeIcons.length - 1].y + lifeIconSize + lifeIconSpacing;
self.presentIcons.push(presentIcon);
LK.gui.topLeft.addChild(presentIcon);
}
var maxChimneys = 5;
LK.on('tick', function () {
var currentTick = LK.ticks;
santa.move();
if (santa.presentDropTimer++ >= 120) {
santa.throwPresent();
santa.presentDropTimer = 0;
}
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();
self.presents.forEach(function (present, index) {
if (present.intersects(chimney) && !chimney.hasPresent) {
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) {
return chimney.x + chimney.width > 0;
});
});
scoreTxt.anchor.set(.5, 0);
LK.gui.topCenter.addChild(scoreBackground);
LK.gui.topCenter.addChild(scoreTxt);
LK.on('tick', function () {
for (var i = 0; i < self.presents.length; i++) {
self.presents[i].move(hazards);
}
for (var i = 0; i < chimneys.length; i++) {
chimneys[i].checkCollision();
}
if (hazardSpawnCounter++ >= hazardSpawnRate) {
var newHazard = new Hazard();
newHazard.x = 2048;
newHazard.y = Math.random() * (2732 * 0.6) + 2732 * 0.2;
newHazard.speed = hazardSpeed;
hazards.push(newHazard);
self.addChild(newHazard);
hazardSpawnCounter = 0;
}
hazards = hazards.filter(function (hazard) {
return !hazard.move();
});
var santaHit = false;
hazards.forEach(function (hazard, index) {
if (!santaHit && santa.intersects(hazard)) {
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();
}
}
});
hazards = hazards.filter(function (hazard) {
return !hazard.hitSanta;
});
self.stars = self.stars.filter(function (star) {
return !star.move();
});
self.rudolph.move();
if (santa.intersects(self.rudolph)) {
santa.resetPresents();
self.rudolph.visible = false;
}
});
});
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.