/**** * Classes ****/ //<Assets used in the game will automatically appear here> // AnimatedBug class to represent the bug that flies to the top of the screen var AnimatedBug = Container.expand(function () { var self = Container.call(this); var bugGraphics = self.attachAsset('bug', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { // Determine the direction to fly to (left or right) var direction = Math.random() < 0.5 ? -1 : 1; // Update the x and y position self.x += self.speed * direction * 3; self.y -= self.speed * 3; // Destroy the bug when it flies off the screen if (self.y < 0 || self.x < 0 || self.x > 2048) { self.destroy(); } }; }); var Bug = Container.expand(function () { var self = Container.call(this); var bugGraphics = self.attachAsset('bug', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.y += self.speed; }; self.down = function (x, y, obj) { // Increment score LK.setScore(LK.getScore() + 1); // Update score text scoreTxt.setText('Score: ' + LK.getScore()); // Replace bug with AnimatedBug var animatedBug = game.addChild(new AnimatedBug()); animatedBug.x = self.x; animatedBug.y = self.y; self.destroy(); }; }); var ChristmasSlalom = Container.expand(function () { var self = Container.call(this); var slalomGraphics = self.attachAsset('tree', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.y += self.speed; }; }); // Dust class to represent the dust effect var Dust = Container.expand(function () { var self = Container.call(this); var dustGraphics = self.attachAsset('dust', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 1; self.update = function () { self.y += self.speed; self.alpha -= 0.01; // Fade out effect if (self.alpha <= 0) { self.destroy(); } }; }); // FastBug class to represent the fast bug that scrolls down the screen var FastBug = Container.expand(function () { var self = Container.call(this); var bugGraphics = self.attachAsset('fastBug', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { self.y += self.speed; // Add dust effect for (var i = 0; i < 3; i++) { var dust = new Dust(); dust.x = self.x + (Math.random() - 0.5) * 20; // Random x offset dust.y = self.y + (Math.random() - 0.5) * 20; // Random y offset game.addChild(dust); } }; self.down = function (x, y, obj) { // Increment score LK.setScore(LK.getScore() + 1); // Update score text scoreTxt.setText('Score: ' + LK.getScore()); // Replace bug with AnimatedBug var animatedBug = game.addChild(new AnimatedBug()); animatedBug.x = self.x; animatedBug.y = self.y; self.destroy(); }; }); var Gift = Container.expand(function () { var self = Container.call(this); var giftGraphics = self.attachAsset('gift', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.y += self.speed; }; self.down = function (x, y, obj) { LK.setScore(LK.getScore() + 5); scoreTxt.setText('Score: ' + LK.getScore()); self.destroy(); }; }); // Jeep class to represent the player's vehicle var Jeep = Container.expand(function () { var self = Container.call(this); var jeepGraphics = self.attachAsset('jeep', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 12; self.life = 100; // Add life property to the jeep object self.update = function () { // Jeep movement logic removed }; self.isInvulnerable = false; // Add invulnerability state self.collision = function () { if (self.isInvulnerable) { return; } // Skip collision if invulnerable self.isInvulnerable = true; // Set invulnerability LK.getSound('collisionSound').play(); // Play collision sound // Randomly push the jeep in a random direction by 250 pixels var randomAngle = Math.random() * 2 * Math.PI; // Random angle in radians self.x += 250 * Math.cos(randomAngle); self.y += 250 * Math.sin(randomAngle); // Add rotation animation var originalRotation = self.rotation; self.rotation += Math.PI; // Rotate 180 degrees LK.setTimeout(function () { self.rotation = originalRotation; // Reset rotation after 1 second }, 1000); // Disable control for 2 seconds isTouching = false; LK.setTimeout(function () { isTouching = true; }, 2000); LK.setTimeout(function () { self.isInvulnerable = false; // Remove invulnerability after 1 second }, 1000); // Add collision method to decrease life by 10% on collision self.life = Math.min(self.life - 5, 100); // Add collision animation effect LK.effects.flashObject(self, 0xff0000, 500); // Flash red for 500ms lifeTxt.setText('Life: ' + Math.round(self.life) + '%'); // Update the life counter if (self.life <= 0) { LK.clearTimeout(gameTimer); LK.showGameOver(); } var lifeCounterAsset = LK.getAsset('lifeCounter', {}); if (lifeCounterAsset.width <= 0) { LK.showGameOver(); } }; }); // LifeRestoration class to represent the object that restores life var LifeRestoration = Container.expand(function () { var self = Container.call(this); var lifeRestorationGraphics = self.attachAsset('lifeRestoration', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.y += self.speed; }; self.down = function (x, y, obj) { jeep.life = Math.min(jeep.life + jeep.life * 0.1, 100); // Increase life by 10% but cap at 100 lifeTxt.setText('Life: ' + Math.round(jeep.life) + '%'); // Update the life counter self.destroy(); }; }); // Sparkle class to represent the sparkle effect var Sparkle = Container.expand(function () { var self = Container.call(this); var sparkleGraphics = self.attachAsset('sparkle', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 4; self.update = function () { self.y += self.speed; self.alpha -= 0.08; // Fade out effect if (self.alpha <= 0) { self.destroy(); } }; }); var Tree = Container.expand(function () { var self = Container.call(this); var treeGraphics = self.attachAsset('tree', { anchorX: 0.5, anchorY: 0.5, scaleX: 0.8, scaleY: 0.8 }); self.speed = 5; self.update = function () { self.y += self.speed; }; }); var Tree2 = Container.expand(function () { var self = Container.call(this); var tree2Graphics = self.attachAsset('tree2', { anchorX: 0.5, anchorY: 0.5, scaleX: 0.8, scaleY: 0.8 }); self.speed = 5; self.update = function () { self.y += self.speed; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xADD8E6 //Init game with light blue background }); /**** * Game Code ****/ // Initialize game variables var jeep; var scoreTxt; var gameTimer; var timerTxt; // Text to display the timer var startScreen; // Start screen container var startButton; // Start button // Function to initialize game elements function initGame() { // Create start screen startScreen = new Container(); var startTextObject = LK.getAsset('christmasSlalom', { anchorX: 0.5, anchorY: 0.5 }); startTextObject.x = 2048 / 2 - 200; startTextObject.y = 2732 / 2 - 500; startScreen.addChild(startTextObject); startButton = new Container(); var startButtonText = LK.getAsset('startButton', { anchorX: 0.5, anchorY: 0.5 }); startButtonText.anchor.set(0.5, 0.5); startButtonText.x = 0; startButtonText.y = 0; startButton.addChild(startButtonText); startButton.x = 2048 / 2; startButton.y = 2732 / 2 + 100; startScreen.addChild(startButton); game.addChild(startScreen); // Add event listener for start button startButton.down = function () { game.removeChild(startScreen); startGame(); }; // Function to start the game function startGame() { // Play background music LK.playMusic('backgroundMusic'); jeep = game.addChild(new Jeep()); jeep.x = 2048 / 2; jeep.y = 2732 - 200; jeep.update = function () { // Jeep movement logic or other updates can be added here // Set a 2-minute timer to end the game gameTimer = LK.setTimeout(function () { LK.showGameOver(); }, 120000); // 120000 milliseconds = 2 minutes }; } // Initialize score display scoreTxt = new Text2('Score: 0', { size: 80, fill: "#ffffff" }); // Initialize life display lifeTxt = new Text2('Life: 100%', { size: 80, fill: "#ffffff" }); lifeTxt.anchor.set(0.5, 1); LK.gui.bottomLeft.addChild(lifeTxt); // Add life counter asset var lifeCounterAsset = LK.getAsset('lifeCounter', { anchorX: 1.5, anchorY: 0.5, x: lifeTxt.x, y: lifeTxt.y }); LK.gui.topLeft.addChild(lifeCounterAsset); // Initialize bugs, fastBugs and trees arrays bugs = []; fastBugs = []; trees = []; scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Initialize timer display timerTxt = new Text2('Time: 2:00', { size: 80, fill: "#ffffff" }); timerTxt.anchor.set(0.5, 0); timerTxt.x -= 250; // Move the timer 250 pixels to the left LK.gui.topRight.addChild(timerTxt); // Update the timer every second var timeRemaining = 120; // 2 minutes in seconds var timerInterval = LK.setInterval(function () { timeRemaining--; var minutes = Math.floor(timeRemaining / 60); var seconds = timeRemaining % 60; timerTxt.setText('Time: ' + minutes + ':' + (seconds < 10 ? '0' : '') + seconds); if (timeRemaining <= 0) { LK.clearInterval(timerInterval); } }, 1000); } // Event handler for moving the Jeep var isTouching = false; var touchPosition = { x: 0, y: 0 }; game.move = function (x, y, obj) { isTouching = true; touchPosition.x = x; touchPosition.y = y; }; game.up = function (x, y, obj) { isTouching = false; }; game.update = function () { if (isTouching && jeep) { var dx = touchPosition.x - jeep.x; var dy = touchPosition.y - jeep.y; var angle = Math.atan2(dy, dx); jeep.x += jeep.speed * Math.cos(angle); jeep.y += jeep.speed * Math.sin(angle); } if (jeep) { jeep.update(); } // Bug and tree spawning logic if (LK.ticks % 60 == 0) { var newBug = new Bug(); newBug.x = Math.random() * 2048; newBug.y = 0; bugs.push(newBug); game.addChild(newBug); } if (LK.ticks % 180 == 0) { var newFastBug = new FastBug(); newFastBug.x = Math.random() * 2048; newFastBug.y = 0; fastBugs.push(newFastBug); game.addChild(newFastBug); } if (LK.ticks % 180 == 0) { var newTree = new Tree(); newTree.x = Math.random() * 2048; newTree.y = 0; trees.push(newTree); game.addChild(newTree); var newTree2 = new Tree2(); newTree2.x = Math.random() * 2048; newTree2.y = 0; trees.push(newTree2); game.addChild(newTree2); } if (LK.ticks % 240 == 0) { var newSlalom = new ChristmasSlalom(); newSlalom.x = Math.random() * 2048; newSlalom.y = 0; game.addChild(newSlalom); } if (LK.ticks % 300 == 0) { var newGift = new Gift(); newGift.x = Math.random() * 2048; newGift.y = 0; game.addChild(newGift); var newLifeRestoration = new LifeRestoration(); newLifeRestoration.x = Math.random() * 2048; newLifeRestoration.y = 0; game.addChild(newLifeRestoration); } // Bug and tree movement and collision detection logic for (var i = bugs.length - 1; i >= 0; i--) { bugs[i].update(); if (bugs[i].intersects(jeep)) { jeep.collision(); var sparkle = new Sparkle(); var angle = Math.random() * 2 * Math.PI; // Random angle in radians var radius = Math.random() * 50 + 50; // Random radius between 50 and 100 sparkle.x = jeep.x + radius * Math.cos(angle); sparkle.y = jeep.y + radius * Math.sin(angle); game.addChild(sparkle); } if (bugs[i].y > 2732) { bugs[i].destroy(); bugs.splice(i, 1); } } for (var i = fastBugs.length - 1; i >= 0; i--) { fastBugs[i].update(); if (fastBugs[i].intersects(jeep)) { jeep.collision(); for (var j = 0; j < 3; j++) { var sparkle = new Sparkle(); var angle = Math.random() * 2 * Math.PI; // Random angle in radians var radius = Math.random() * 50 + 50; // Random radius between 50 and 100 sparkle.x = jeep.x + radius * Math.cos(angle); sparkle.y = jeep.y + radius * Math.sin(angle); game.addChild(sparkle); } } if (fastBugs[i].y > 2732) { fastBugs[i].destroy(); fastBugs.splice(i, 1); } } for (var i = trees.length - 1; i >= 0; i--) { trees[i].update(); if (trees[i].intersects(jeep)) { jeep.collision(); for (var j = 0; j < 10; j++) { var sparkle = new Sparkle(); sparkle.x = jeep.x + (Math.random() - 0.5) * 100; sparkle.y = jeep.y + (Math.random() - 0.5) * 100; game.addChild(sparkle); } } if (trees[i].y > 2732) { trees[i].destroy(); trees.splice(i, 1); } } // Check for collision between 'gift' and 'jeep' game.children.forEach(function (child) { if (child instanceof Gift && child.intersects(jeep, 0.8)) { LK.getSound('giftPickupSound').play(); LK.setScore(LK.getScore() + 5); scoreTxt.setText('Score: ' + LK.getScore()); child.destroy(); } // Check for collision between 'jeep' and 'lifeRestoration' if (child instanceof LifeRestoration && child.intersects(jeep, 0.8)) { LK.getSound('lifeRestorationSound').play(); // Play new sound effect for picking up lifeRestoration jeep.life = Math.min(jeep.life + 10, 100); // Increase life by 10 units but cap at 100 lifeTxt.setText('Life: ' + Math.round(jeep.life) + '%'); // Update the life counter child.destroy(); } }); }; // Initialize the game initGame(); ;
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// AnimatedBug class to represent the bug that flies to the top of the screen
var AnimatedBug = Container.expand(function () {
var self = Container.call(this);
var bugGraphics = self.attachAsset('bug', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
// Determine the direction to fly to (left or right)
var direction = Math.random() < 0.5 ? -1 : 1;
// Update the x and y position
self.x += self.speed * direction * 3;
self.y -= self.speed * 3;
// Destroy the bug when it flies off the screen
if (self.y < 0 || self.x < 0 || self.x > 2048) {
self.destroy();
}
};
});
var Bug = Container.expand(function () {
var self = Container.call(this);
var bugGraphics = self.attachAsset('bug', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
};
self.down = function (x, y, obj) {
// Increment score
LK.setScore(LK.getScore() + 1);
// Update score text
scoreTxt.setText('Score: ' + LK.getScore());
// Replace bug with AnimatedBug
var animatedBug = game.addChild(new AnimatedBug());
animatedBug.x = self.x;
animatedBug.y = self.y;
self.destroy();
};
});
var ChristmasSlalom = Container.expand(function () {
var self = Container.call(this);
var slalomGraphics = self.attachAsset('tree', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
};
});
// Dust class to represent the dust effect
var Dust = Container.expand(function () {
var self = Container.call(this);
var dustGraphics = self.attachAsset('dust', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 1;
self.update = function () {
self.y += self.speed;
self.alpha -= 0.01; // Fade out effect
if (self.alpha <= 0) {
self.destroy();
}
};
});
// FastBug class to represent the fast bug that scrolls down the screen
var FastBug = Container.expand(function () {
var self = Container.call(this);
var bugGraphics = self.attachAsset('fastBug', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
self.y += self.speed;
// Add dust effect
for (var i = 0; i < 3; i++) {
var dust = new Dust();
dust.x = self.x + (Math.random() - 0.5) * 20; // Random x offset
dust.y = self.y + (Math.random() - 0.5) * 20; // Random y offset
game.addChild(dust);
}
};
self.down = function (x, y, obj) {
// Increment score
LK.setScore(LK.getScore() + 1);
// Update score text
scoreTxt.setText('Score: ' + LK.getScore());
// Replace bug with AnimatedBug
var animatedBug = game.addChild(new AnimatedBug());
animatedBug.x = self.x;
animatedBug.y = self.y;
self.destroy();
};
});
var Gift = Container.expand(function () {
var self = Container.call(this);
var giftGraphics = self.attachAsset('gift', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
};
self.down = function (x, y, obj) {
LK.setScore(LK.getScore() + 5);
scoreTxt.setText('Score: ' + LK.getScore());
self.destroy();
};
});
// Jeep class to represent the player's vehicle
var Jeep = Container.expand(function () {
var self = Container.call(this);
var jeepGraphics = self.attachAsset('jeep', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 12;
self.life = 100; // Add life property to the jeep object
self.update = function () {
// Jeep movement logic removed
};
self.isInvulnerable = false; // Add invulnerability state
self.collision = function () {
if (self.isInvulnerable) {
return;
} // Skip collision if invulnerable
self.isInvulnerable = true; // Set invulnerability
LK.getSound('collisionSound').play(); // Play collision sound
// Randomly push the jeep in a random direction by 250 pixels
var randomAngle = Math.random() * 2 * Math.PI; // Random angle in radians
self.x += 250 * Math.cos(randomAngle);
self.y += 250 * Math.sin(randomAngle);
// Add rotation animation
var originalRotation = self.rotation;
self.rotation += Math.PI; // Rotate 180 degrees
LK.setTimeout(function () {
self.rotation = originalRotation; // Reset rotation after 1 second
}, 1000);
// Disable control for 2 seconds
isTouching = false;
LK.setTimeout(function () {
isTouching = true;
}, 2000);
LK.setTimeout(function () {
self.isInvulnerable = false; // Remove invulnerability after 1 second
}, 1000);
// Add collision method to decrease life by 10% on collision
self.life = Math.min(self.life - 5, 100);
// Add collision animation effect
LK.effects.flashObject(self, 0xff0000, 500); // Flash red for 500ms
lifeTxt.setText('Life: ' + Math.round(self.life) + '%'); // Update the life counter
if (self.life <= 0) {
LK.clearTimeout(gameTimer);
LK.showGameOver();
}
var lifeCounterAsset = LK.getAsset('lifeCounter', {});
if (lifeCounterAsset.width <= 0) {
LK.showGameOver();
}
};
});
// LifeRestoration class to represent the object that restores life
var LifeRestoration = Container.expand(function () {
var self = Container.call(this);
var lifeRestorationGraphics = self.attachAsset('lifeRestoration', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
};
self.down = function (x, y, obj) {
jeep.life = Math.min(jeep.life + jeep.life * 0.1, 100); // Increase life by 10% but cap at 100
lifeTxt.setText('Life: ' + Math.round(jeep.life) + '%'); // Update the life counter
self.destroy();
};
});
// Sparkle class to represent the sparkle effect
var Sparkle = Container.expand(function () {
var self = Container.call(this);
var sparkleGraphics = self.attachAsset('sparkle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 4;
self.update = function () {
self.y += self.speed;
self.alpha -= 0.08; // Fade out effect
if (self.alpha <= 0) {
self.destroy();
}
};
});
var Tree = Container.expand(function () {
var self = Container.call(this);
var treeGraphics = self.attachAsset('tree', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.8,
scaleY: 0.8
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
};
});
var Tree2 = Container.expand(function () {
var self = Container.call(this);
var tree2Graphics = self.attachAsset('tree2', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.8,
scaleY: 0.8
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xADD8E6 //Init game with light blue background
});
/****
* Game Code
****/
// Initialize game variables
var jeep;
var scoreTxt;
var gameTimer;
var timerTxt; // Text to display the timer
var startScreen; // Start screen container
var startButton; // Start button
// Function to initialize game elements
function initGame() {
// Create start screen
startScreen = new Container();
var startTextObject = LK.getAsset('christmasSlalom', {
anchorX: 0.5,
anchorY: 0.5
});
startTextObject.x = 2048 / 2 - 200;
startTextObject.y = 2732 / 2 - 500;
startScreen.addChild(startTextObject);
startButton = new Container();
var startButtonText = LK.getAsset('startButton', {
anchorX: 0.5,
anchorY: 0.5
});
startButtonText.anchor.set(0.5, 0.5);
startButtonText.x = 0;
startButtonText.y = 0;
startButton.addChild(startButtonText);
startButton.x = 2048 / 2;
startButton.y = 2732 / 2 + 100;
startScreen.addChild(startButton);
game.addChild(startScreen);
// Add event listener for start button
startButton.down = function () {
game.removeChild(startScreen);
startGame();
};
// Function to start the game
function startGame() {
// Play background music
LK.playMusic('backgroundMusic');
jeep = game.addChild(new Jeep());
jeep.x = 2048 / 2;
jeep.y = 2732 - 200;
jeep.update = function () {
// Jeep movement logic or other updates can be added here
// Set a 2-minute timer to end the game
gameTimer = LK.setTimeout(function () {
LK.showGameOver();
}, 120000); // 120000 milliseconds = 2 minutes
};
}
// Initialize score display
scoreTxt = new Text2('Score: 0', {
size: 80,
fill: "#ffffff"
});
// Initialize life display
lifeTxt = new Text2('Life: 100%', {
size: 80,
fill: "#ffffff"
});
lifeTxt.anchor.set(0.5, 1);
LK.gui.bottomLeft.addChild(lifeTxt);
// Add life counter asset
var lifeCounterAsset = LK.getAsset('lifeCounter', {
anchorX: 1.5,
anchorY: 0.5,
x: lifeTxt.x,
y: lifeTxt.y
});
LK.gui.topLeft.addChild(lifeCounterAsset);
// Initialize bugs, fastBugs and trees arrays
bugs = [];
fastBugs = [];
trees = [];
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Initialize timer display
timerTxt = new Text2('Time: 2:00', {
size: 80,
fill: "#ffffff"
});
timerTxt.anchor.set(0.5, 0);
timerTxt.x -= 250; // Move the timer 250 pixels to the left
LK.gui.topRight.addChild(timerTxt);
// Update the timer every second
var timeRemaining = 120; // 2 minutes in seconds
var timerInterval = LK.setInterval(function () {
timeRemaining--;
var minutes = Math.floor(timeRemaining / 60);
var seconds = timeRemaining % 60;
timerTxt.setText('Time: ' + minutes + ':' + (seconds < 10 ? '0' : '') + seconds);
if (timeRemaining <= 0) {
LK.clearInterval(timerInterval);
}
}, 1000);
}
// Event handler for moving the Jeep
var isTouching = false;
var touchPosition = {
x: 0,
y: 0
};
game.move = function (x, y, obj) {
isTouching = true;
touchPosition.x = x;
touchPosition.y = y;
};
game.up = function (x, y, obj) {
isTouching = false;
};
game.update = function () {
if (isTouching && jeep) {
var dx = touchPosition.x - jeep.x;
var dy = touchPosition.y - jeep.y;
var angle = Math.atan2(dy, dx);
jeep.x += jeep.speed * Math.cos(angle);
jeep.y += jeep.speed * Math.sin(angle);
}
if (jeep) {
jeep.update();
}
// Bug and tree spawning logic
if (LK.ticks % 60 == 0) {
var newBug = new Bug();
newBug.x = Math.random() * 2048;
newBug.y = 0;
bugs.push(newBug);
game.addChild(newBug);
}
if (LK.ticks % 180 == 0) {
var newFastBug = new FastBug();
newFastBug.x = Math.random() * 2048;
newFastBug.y = 0;
fastBugs.push(newFastBug);
game.addChild(newFastBug);
}
if (LK.ticks % 180 == 0) {
var newTree = new Tree();
newTree.x = Math.random() * 2048;
newTree.y = 0;
trees.push(newTree);
game.addChild(newTree);
var newTree2 = new Tree2();
newTree2.x = Math.random() * 2048;
newTree2.y = 0;
trees.push(newTree2);
game.addChild(newTree2);
}
if (LK.ticks % 240 == 0) {
var newSlalom = new ChristmasSlalom();
newSlalom.x = Math.random() * 2048;
newSlalom.y = 0;
game.addChild(newSlalom);
}
if (LK.ticks % 300 == 0) {
var newGift = new Gift();
newGift.x = Math.random() * 2048;
newGift.y = 0;
game.addChild(newGift);
var newLifeRestoration = new LifeRestoration();
newLifeRestoration.x = Math.random() * 2048;
newLifeRestoration.y = 0;
game.addChild(newLifeRestoration);
}
// Bug and tree movement and collision detection logic
for (var i = bugs.length - 1; i >= 0; i--) {
bugs[i].update();
if (bugs[i].intersects(jeep)) {
jeep.collision();
var sparkle = new Sparkle();
var angle = Math.random() * 2 * Math.PI; // Random angle in radians
var radius = Math.random() * 50 + 50; // Random radius between 50 and 100
sparkle.x = jeep.x + radius * Math.cos(angle);
sparkle.y = jeep.y + radius * Math.sin(angle);
game.addChild(sparkle);
}
if (bugs[i].y > 2732) {
bugs[i].destroy();
bugs.splice(i, 1);
}
}
for (var i = fastBugs.length - 1; i >= 0; i--) {
fastBugs[i].update();
if (fastBugs[i].intersects(jeep)) {
jeep.collision();
for (var j = 0; j < 3; j++) {
var sparkle = new Sparkle();
var angle = Math.random() * 2 * Math.PI; // Random angle in radians
var radius = Math.random() * 50 + 50; // Random radius between 50 and 100
sparkle.x = jeep.x + radius * Math.cos(angle);
sparkle.y = jeep.y + radius * Math.sin(angle);
game.addChild(sparkle);
}
}
if (fastBugs[i].y > 2732) {
fastBugs[i].destroy();
fastBugs.splice(i, 1);
}
}
for (var i = trees.length - 1; i >= 0; i--) {
trees[i].update();
if (trees[i].intersects(jeep)) {
jeep.collision();
for (var j = 0; j < 10; j++) {
var sparkle = new Sparkle();
sparkle.x = jeep.x + (Math.random() - 0.5) * 100;
sparkle.y = jeep.y + (Math.random() - 0.5) * 100;
game.addChild(sparkle);
}
}
if (trees[i].y > 2732) {
trees[i].destroy();
trees.splice(i, 1);
}
}
// Check for collision between 'gift' and 'jeep'
game.children.forEach(function (child) {
if (child instanceof Gift && child.intersects(jeep, 0.8)) {
LK.getSound('giftPickupSound').play();
LK.setScore(LK.getScore() + 5);
scoreTxt.setText('Score: ' + LK.getScore());
child.destroy();
}
// Check for collision between 'jeep' and 'lifeRestoration'
if (child instanceof LifeRestoration && child.intersects(jeep, 0.8)) {
LK.getSound('lifeRestorationSound').play(); // Play new sound effect for picking up lifeRestoration
jeep.life = Math.min(jeep.life + 10, 100); // Increase life by 10 units but cap at 100
lifeTxt.setText('Life: ' + Math.round(jeep.life) + '%'); // Update the life counter
child.destroy();
}
});
};
// Initialize the game
initGame();
;
Santa on a sleigh top view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
christmas tree. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
big snowball. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
snow tornado. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
christmas gift. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
кнопка "Старт" в різдвяному стилі. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
sparkle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
сніжинка. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.