/**** * Classes ****/ // Background class var Background = Container.expand(function () { var self = Container.call(this); var backgroundGraphics = self.attachAsset('game_background', { anchorX: 0.5, anchorY: 0, width: game.width, height: game.height }); self.speedY = 14; self._move_migrated = function () { self.y += self.speedY; }; self.isOffScreen = function () { return self.y > game.height; }; }); // Hurdle class var Hurdle = Container.expand(function () { var self = Container.call(this); var hurdleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 // Anchor at the center for easier sky alignment }); var hurdleLegsGraphics = self.attachAsset('hurdle_legs', { anchorX: 0.5, anchorY: 0.0 // Anchor at the top to overlap with the obstacle }); hurdleLegsGraphics.y = hurdleGraphics.height / 2; // Position the legs at the bottom of the obstacle var obstacleEffectGraphics = self.attachAsset('obstacle_effect', { anchorX: 0.5, anchorY: 0.5 // Anchor at the center to overlap with the obstacle }); obstacleEffectGraphics.y = 0; // Position the effect at the center of the obstacle self.speedY = 15; self.scored = false; // Add a flag to track if this hurdle has already added a point to the score self._move_migrated = function () { self.y += self.speedY; var screenHeight = game.height; var midPoint = screenHeight * 0.75; var compressionRatio; if (self.y < midPoint) { compressionRatio = 1 - self.y / midPoint; } else { compressionRatio = (self.y - midPoint) / midPoint; } hurdleLegsGraphics.scale.y = compressionRatio; if (self.y >= midPoint) { hurdleLegsGraphics.scale.y *= -1; hurdleLegsGraphics.y = -hurdleGraphics.height / 2; } hurdleGraphics.alpha = 1 - self.y / screenHeight; // Add fading animation for the obstacle_effect obstacleEffectGraphics.alpha = self.y / screenHeight; }; self.isOffScreen = function () { return self.y > game.height + 100; }; }); // Assets are automatically created based on usage in the code. // Player class var Player = Container.expand(function () { var self = Container.call(this); self.frame = 0; // Add a new frame variable to the player self.frameTimer = 0; // Add a new timer to switch frames var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 // Anchor at the center for scaling animation during jumping }); self.state = 'running'; // Add a new state variable to the player self._update_migrated = function () { // Update method now only handles state changes if (self.state === 'running') { self.frameTimer += 1000 / 60; // Update frameTimer based on frame rate if (self.frameTimer >= 300) { self.frameTimer = 0; // Reset frameTimer self.frame = 1 - self.frame; // Switch frame playerGraphics.destroy(); // Remove the current frame // Add the new frame if (self.frame === 0) { playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); } else { playerGraphics = self.attachAsset('player_reverse', { anchorX: 0.5, anchorY: 0.5 }); } } } }; self.jump = function () { if (self.state === 'running') { self.state = 'jumping'; playerGraphics.destroy(); playerGraphics = self.attachAsset('player_jump', { anchorX: 0.5, anchorY: 0.5 }); LK.getSound('Jump').play(); var totalDuration = 1000; // Total duration of the jump state var halfDuration = totalDuration / 2; var currentTime = 0; var updateSize = function updateSize() { var progress = currentTime / halfDuration; if (currentTime <= halfDuration) { // Growing playerGraphics.scale.x = 1 + progress * 0.5; // Scale up to 1.5x original size playerGraphics.scale.y = 1 + progress * 0.5; } else { // Shrinking progress = 1 - (currentTime - halfDuration) / halfDuration; playerGraphics.scale.x = 1 + progress * 0.5; // Scale back to original size playerGraphics.scale.y = 1 + progress * 0.5; } currentTime += 1000 / 60; // Update currentTime based on frame rate if (currentTime >= totalDuration) { LK.clearInterval(sizeInterval); playerGraphics.destroy(); self.frame = 0; // Reset frame to 0 self.frameTimer = 0; // Reset frameTimer to 0 playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); playerGraphics.scale.x = 1; // Reset scale to original size playerGraphics.scale.y = 1; self.state = 'running'; // Reset state to running after jump LK.getSound('Land').play(); // Play the Land sound } }; var sizeInterval = LK.setInterval(updateSize, 1000 / 60); // Set interval based on frame rate } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Light blue background to simulate the sky }); /**** * Game Code ****/ var BackgroundContainer = new Container(); game.addChild(BackgroundContainer); var background1 = BackgroundContainer.addChild(new Background()); background1.x = game.width / 2; background1.y = 0; var background2 = BackgroundContainer.addChild(new Background()); background2.x = game.width / 2; background2.y = -background2.height; var MidgroundContainer = new Container(); game.addChild(MidgroundContainer); var ForegroundContainer = new Container(); game.addChild(ForegroundContainer); var player = ForegroundContainer.addChild(new Player()); player.x = game.width / 2; // Position at the middle of the screen player.y = game.height - 600; // Start position 500 pixels higher var obstacles = []; var spawnObstacleTimer = 0; var minSpawnInterval = 80; // Minimum frames until next obstacle spawns (700ms) var maxSpawnInterval = 150; // Maximum frames until next obstacle spawns (1000ms) var spawnObstacleInterval = 0; // Set to 0 to spawn the first hurdle immediately var narratives = ["Keep sprinting!", "Gold medal pace!", "Hurdle the obstacles!", "Relay on your skills!", "Vault over expectations!", "Catch that second wind!", "Pacing for gold!", "On track for victory!", "Lap the competition!", "Steeplechase superstar!", "Marathoner’s spirit!", "Sprint to success!", "Jump for joy!", "Record breaker!", "Faster, Higher, Stronger!", "You're the MVP!", "Go for the gold!", "Race to the finish!", "Outrun your shadow!", "Dash to the lead!", "Power through!", "It’s a relay, not a delay!", "Set a new record!", "Track star in the making!", "Zoom past the zoomers!", "Kicking it into high gear!", "Unleash your inner Olympian!", "Legs of lightning!", "Champion’s stride!", "Endurance of Hercules!", "Like a pro!", "You've got the moxie!", "Overtake the undertakers!", "Break the tape!", "The crowd goes wild!", "Phenomenal pace!", "Speed demon unleashed!", "You can’t be stopped!", "Stride and glide!", "Leaping legends!", "Breathe and believe!", "That’s Olympian strength!", "Sweat is just sparkle!", "Fuel your fire!", "Pump those legs!", "Olympic-worthy effort!", "Make tracks, superstar!", "History in the making!", "Torchbearer!", "Take the baton!", "No hurdles too high!", "Chase that horizon!", "Wind in your sails!", "Sprint it out!", "Medal moment!", "Don’t stop, won’t stop!", "Nothing but net!", "Keep the flame alive!", "Run down a dream!", "Winning in style!", "Celebrate every lap!", "Faster than the wind!", "This pace is ace!", "You’re miles ahead!", "Reach for the peak!", "Ready, set, go get 'em!", "This run’s a fun run!", "On your marks, jet set!", "Turning up the tempo!", "You’re a front runner!", "Outpace, outlast!", "Run the world!", "Kick up the dust!", "That's how you roll!", "Leap legends!", "Clear those hurdles!", "Hurdles? More like speed bumps!", "Jump to it!", "Leap and conquer!", "Hop, skip, win!", "Hurdle hero in action!", "Over in a flash!", "Leap past limits!", "Make it look easy!", "Sky-high ambition!", "Hops for the top!", "Bound for glory!", "Jumpstart your game!", "Over the top!", "Hopping to victory!", "Master the hurdles!", "Soar over challenges!", "Taking it in stride!", "Jump the queue!", "Flights of fancy!", "Clear the way!", "Soar above the rest!", "Jump for joy... and points!", "Elevate your game!", "Aim high, land soft!", "Smooth sailing over hurdles!", "Leapfrog the pack!", "Keep bouncing back!", "Stride through!", "Bound to win!", "Overcoming one leap at a time!", "Spring into action!", "Up and over!", "Take the leap!", "Hurdling to new heights!", "Jump into the lead!", "Leap over doubts!", "Breeze through barriers!", "Clearing with ease!", "Surpass each spike!", "Vault to victory!", "Conquer each leap!", "Stride over struggles!", "No hurdle too high!", "Leap ahead!", "Sky's the limit!", "Clear your path!", "Hurdles are just steps!", "Elevate and dominate!", "Skyrocket over those hurdles!", "Unleash the beast!", "Eclipse the competition!", "Defy gravity, defy limits!", "Hurdles quiver at your approach!", "Blast past barriers like a comet!", "Dominate the track!", "Supercharge your leap!", "Unstoppable force unleashed!", "Crush those hurdles underfoot!", "Thunder across the track!", "Command the course!", "Blaze a trail of glory!", "Heroic heights achieved!", "Turbocharged jumps!", "Ignite the track with every step!", "Power through with panache!", "Mighty leaps for mankind!", "Leap into legend!", "Full throttle over hurdles!", "Break barriers, shatter records!", "Sovereign of the track!", "Channel pure adrenaline!", "Go nuclear on those hurdles!", "Unleash havoc on the track!", "Pulverize the competition!", "Charge forward with fury!", "Conquer with colossal jumps!", "Rule the realm of air!", "Soar like an eagle!", "Hurdles bow before you!", "Make the ground tremble!", "Leap towards destiny!", "Obliterate every obstacle!", "Rise, rally, and reign!", "Harness the winds of victory!", "Summon strength, summon spirit!", "Become the hurricane, unstoppable!", "Jump as if your spirit’s on fire!", "Galactic greatness awaits!", "Summon the storm of success!", "Incite the crowd, ignite the track!", "Victory is yours to command!", "Leap out of this world!", "Power beyond belief!", "Bound beyond boundaries!", "Warrior of the wind!", "Epic every step of the way!"]; var availableNarratives = [].concat(narratives); var usedNarratives = []; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff", stroke: "#000000", strokeThickness: 15 }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); game.on('down', function (x, y, obj) { player.jump(); }); LK.on('tick', function () { background1._move_migrated(); background2._move_migrated(); if (background1.isOffScreen()) { background1.y = background2.y - background1.height; } if (background2.isOffScreen()) { background2.y = background1.y - background2.height; } player._update_migrated(); // Handle obstacle movement and cleanup for (var i = obstacles.length - 1; i >= 0; i--) { obstacles[i]._move_migrated(); if (obstacles[i].isOffScreen()) { obstacles[i].destroy(); obstacles.splice(i, 1); } else if (player.intersects(obstacles[i].children[0]) && player.state === 'running') { // Game over logic LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } else if (!player.intersects(obstacles[i]) && player.state === 'jumping' && obstacles[i].y > player.y && !obstacles[i].scored) { // Update score LK.setScore(LK.getScore() + 1); // Update score text scoreTxt.setText(LK.getScore()); // Update narrative text every 2 points if (LK.getScore() % 2 == 0) { if (availableNarratives.length === 0) { // If all narratives have been used, reset the arrays availableNarratives = [].concat(narratives); usedNarratives = []; } var randomIndex = Math.floor(Math.random() * availableNarratives.length); var narrative = availableNarratives[randomIndex]; // Move the used narrative from availableNarratives to usedNarratives availableNarratives.splice(randomIndex, 1); usedNarratives.push(narrative); // Destroy the old narrative text if it exists if (game.narrativeTxt) { game.narrativeTxt.destroy(); } // Display the narrative game.narrativeTxt = new Text2(narrative, { size: 70, fill: "#ffffff", stroke: "#000000", strokeThickness: 10 }); game.narrativeTxt.anchor.set(0.5, 0); game.narrativeTxt.y -= 780; LK.gui.center.addChild(game.narrativeTxt); } // Mark this hurdle as having added a point to the score obstacles[i].scored = true; // Decrease minSpawnInterval and maxSpawnInterval minSpawnInterval -= 0.5; maxSpawnInterval -= 0.25; } } // Spawn hurdles spawnObstacleTimer++; if (spawnObstacleTimer >= spawnObstacleInterval) { var hurdle = MidgroundContainer.addChild(new Hurdle()); hurdle.x = game.width / 2; // Position at the middle of the screen hurdle.y = -100; // Position 100 pixels above the top of the screen obstacles.push(hurdle); spawnObstacleTimer = 0; spawnObstacleInterval = Math.floor(Math.random() * (maxSpawnInterval - minSpawnInterval + 1)) + minSpawnInterval; } });
/****
* Classes
****/
// Background class
var Background = Container.expand(function () {
var self = Container.call(this);
var backgroundGraphics = self.attachAsset('game_background', {
anchorX: 0.5,
anchorY: 0,
width: game.width,
height: game.height
});
self.speedY = 14;
self._move_migrated = function () {
self.y += self.speedY;
};
self.isOffScreen = function () {
return self.y > game.height;
};
});
// Hurdle class
var Hurdle = Container.expand(function () {
var self = Container.call(this);
var hurdleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5 // Anchor at the center for easier sky alignment
});
var hurdleLegsGraphics = self.attachAsset('hurdle_legs', {
anchorX: 0.5,
anchorY: 0.0 // Anchor at the top to overlap with the obstacle
});
hurdleLegsGraphics.y = hurdleGraphics.height / 2; // Position the legs at the bottom of the obstacle
var obstacleEffectGraphics = self.attachAsset('obstacle_effect', {
anchorX: 0.5,
anchorY: 0.5 // Anchor at the center to overlap with the obstacle
});
obstacleEffectGraphics.y = 0; // Position the effect at the center of the obstacle
self.speedY = 15;
self.scored = false; // Add a flag to track if this hurdle has already added a point to the score
self._move_migrated = function () {
self.y += self.speedY;
var screenHeight = game.height;
var midPoint = screenHeight * 0.75;
var compressionRatio;
if (self.y < midPoint) {
compressionRatio = 1 - self.y / midPoint;
} else {
compressionRatio = (self.y - midPoint) / midPoint;
}
hurdleLegsGraphics.scale.y = compressionRatio;
if (self.y >= midPoint) {
hurdleLegsGraphics.scale.y *= -1;
hurdleLegsGraphics.y = -hurdleGraphics.height / 2;
}
hurdleGraphics.alpha = 1 - self.y / screenHeight;
// Add fading animation for the obstacle_effect
obstacleEffectGraphics.alpha = self.y / screenHeight;
};
self.isOffScreen = function () {
return self.y > game.height + 100;
};
});
// Assets are automatically created based on usage in the code.
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
self.frame = 0; // Add a new frame variable to the player
self.frameTimer = 0; // Add a new timer to switch frames
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5 // Anchor at the center for scaling animation during jumping
});
self.state = 'running'; // Add a new state variable to the player
self._update_migrated = function () {
// Update method now only handles state changes
if (self.state === 'running') {
self.frameTimer += 1000 / 60; // Update frameTimer based on frame rate
if (self.frameTimer >= 300) {
self.frameTimer = 0; // Reset frameTimer
self.frame = 1 - self.frame; // Switch frame
playerGraphics.destroy(); // Remove the current frame
// Add the new frame
if (self.frame === 0) {
playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
} else {
playerGraphics = self.attachAsset('player_reverse', {
anchorX: 0.5,
anchorY: 0.5
});
}
}
}
};
self.jump = function () {
if (self.state === 'running') {
self.state = 'jumping';
playerGraphics.destroy();
playerGraphics = self.attachAsset('player_jump', {
anchorX: 0.5,
anchorY: 0.5
});
LK.getSound('Jump').play();
var totalDuration = 1000; // Total duration of the jump state
var halfDuration = totalDuration / 2;
var currentTime = 0;
var updateSize = function updateSize() {
var progress = currentTime / halfDuration;
if (currentTime <= halfDuration) {
// Growing
playerGraphics.scale.x = 1 + progress * 0.5; // Scale up to 1.5x original size
playerGraphics.scale.y = 1 + progress * 0.5;
} else {
// Shrinking
progress = 1 - (currentTime - halfDuration) / halfDuration;
playerGraphics.scale.x = 1 + progress * 0.5; // Scale back to original size
playerGraphics.scale.y = 1 + progress * 0.5;
}
currentTime += 1000 / 60; // Update currentTime based on frame rate
if (currentTime >= totalDuration) {
LK.clearInterval(sizeInterval);
playerGraphics.destroy();
self.frame = 0; // Reset frame to 0
self.frameTimer = 0; // Reset frameTimer to 0
playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
playerGraphics.scale.x = 1; // Reset scale to original size
playerGraphics.scale.y = 1;
self.state = 'running'; // Reset state to running after jump
LK.getSound('Land').play(); // Play the Land sound
}
};
var sizeInterval = LK.setInterval(updateSize, 1000 / 60); // Set interval based on frame rate
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Light blue background to simulate the sky
});
/****
* Game Code
****/
var BackgroundContainer = new Container();
game.addChild(BackgroundContainer);
var background1 = BackgroundContainer.addChild(new Background());
background1.x = game.width / 2;
background1.y = 0;
var background2 = BackgroundContainer.addChild(new Background());
background2.x = game.width / 2;
background2.y = -background2.height;
var MidgroundContainer = new Container();
game.addChild(MidgroundContainer);
var ForegroundContainer = new Container();
game.addChild(ForegroundContainer);
var player = ForegroundContainer.addChild(new Player());
player.x = game.width / 2; // Position at the middle of the screen
player.y = game.height - 600; // Start position 500 pixels higher
var obstacles = [];
var spawnObstacleTimer = 0;
var minSpawnInterval = 80; // Minimum frames until next obstacle spawns (700ms)
var maxSpawnInterval = 150; // Maximum frames until next obstacle spawns (1000ms)
var spawnObstacleInterval = 0; // Set to 0 to spawn the first hurdle immediately
var narratives = ["Keep sprinting!", "Gold medal pace!", "Hurdle the obstacles!", "Relay on your skills!", "Vault over expectations!", "Catch that second wind!", "Pacing for gold!", "On track for victory!", "Lap the competition!", "Steeplechase superstar!", "Marathoner’s spirit!", "Sprint to success!", "Jump for joy!", "Record breaker!", "Faster, Higher, Stronger!", "You're the MVP!", "Go for the gold!", "Race to the finish!", "Outrun your shadow!", "Dash to the lead!", "Power through!", "It’s a relay, not a delay!", "Set a new record!", "Track star in the making!", "Zoom past the zoomers!", "Kicking it into high gear!", "Unleash your inner Olympian!", "Legs of lightning!", "Champion’s stride!", "Endurance of Hercules!", "Like a pro!", "You've got the moxie!", "Overtake the undertakers!", "Break the tape!", "The crowd goes wild!", "Phenomenal pace!", "Speed demon unleashed!", "You can’t be stopped!", "Stride and glide!", "Leaping legends!", "Breathe and believe!", "That’s Olympian strength!", "Sweat is just sparkle!", "Fuel your fire!", "Pump those legs!", "Olympic-worthy effort!", "Make tracks, superstar!", "History in the making!", "Torchbearer!", "Take the baton!", "No hurdles too high!", "Chase that horizon!", "Wind in your sails!", "Sprint it out!", "Medal moment!", "Don’t stop, won’t stop!", "Nothing but net!", "Keep the flame alive!", "Run down a dream!", "Winning in style!", "Celebrate every lap!", "Faster than the wind!", "This pace is ace!", "You’re miles ahead!", "Reach for the peak!", "Ready, set, go get 'em!", "This run’s a fun run!", "On your marks, jet set!", "Turning up the tempo!", "You’re a front runner!", "Outpace, outlast!", "Run the world!", "Kick up the dust!", "That's how you roll!", "Leap legends!", "Clear those hurdles!", "Hurdles? More like speed bumps!", "Jump to it!", "Leap and conquer!", "Hop, skip, win!", "Hurdle hero in action!", "Over in a flash!", "Leap past limits!", "Make it look easy!", "Sky-high ambition!", "Hops for the top!", "Bound for glory!", "Jumpstart your game!", "Over the top!", "Hopping to victory!", "Master the hurdles!", "Soar over challenges!", "Taking it in stride!", "Jump the queue!", "Flights of fancy!", "Clear the way!", "Soar above the rest!", "Jump for joy... and points!", "Elevate your game!", "Aim high, land soft!", "Smooth sailing over hurdles!", "Leapfrog the pack!", "Keep bouncing back!", "Stride through!", "Bound to win!", "Overcoming one leap at a time!", "Spring into action!", "Up and over!", "Take the leap!", "Hurdling to new heights!", "Jump into the lead!", "Leap over doubts!", "Breeze through barriers!", "Clearing with ease!", "Surpass each spike!", "Vault to victory!", "Conquer each leap!", "Stride over struggles!", "No hurdle too high!", "Leap ahead!", "Sky's the limit!", "Clear your path!", "Hurdles are just steps!", "Elevate and dominate!", "Skyrocket over those hurdles!", "Unleash the beast!", "Eclipse the competition!", "Defy gravity, defy limits!", "Hurdles quiver at your approach!", "Blast past barriers like a comet!", "Dominate the track!", "Supercharge your leap!", "Unstoppable force unleashed!", "Crush those hurdles underfoot!", "Thunder across the track!", "Command the course!", "Blaze a trail of glory!", "Heroic heights achieved!", "Turbocharged jumps!", "Ignite the track with every step!", "Power through with panache!", "Mighty leaps for mankind!", "Leap into legend!", "Full throttle over hurdles!", "Break barriers, shatter records!", "Sovereign of the track!", "Channel pure adrenaline!", "Go nuclear on those hurdles!", "Unleash havoc on the track!", "Pulverize the competition!", "Charge forward with fury!", "Conquer with colossal jumps!", "Rule the realm of air!", "Soar like an eagle!", "Hurdles bow before you!", "Make the ground tremble!", "Leap towards destiny!", "Obliterate every obstacle!", "Rise, rally, and reign!", "Harness the winds of victory!", "Summon strength, summon spirit!", "Become the hurricane, unstoppable!", "Jump as if your spirit’s on fire!", "Galactic greatness awaits!", "Summon the storm of success!", "Incite the crowd, ignite the track!", "Victory is yours to command!", "Leap out of this world!", "Power beyond belief!", "Bound beyond boundaries!", "Warrior of the wind!", "Epic every step of the way!"];
var availableNarratives = [].concat(narratives);
var usedNarratives = [];
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff",
stroke: "#000000",
strokeThickness: 15
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
game.on('down', function (x, y, obj) {
player.jump();
});
LK.on('tick', function () {
background1._move_migrated();
background2._move_migrated();
if (background1.isOffScreen()) {
background1.y = background2.y - background1.height;
}
if (background2.isOffScreen()) {
background2.y = background1.y - background2.height;
}
player._update_migrated();
// Handle obstacle movement and cleanup
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i]._move_migrated();
if (obstacles[i].isOffScreen()) {
obstacles[i].destroy();
obstacles.splice(i, 1);
} else if (player.intersects(obstacles[i].children[0]) && player.state === 'running') {
// Game over logic
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
} else if (!player.intersects(obstacles[i]) && player.state === 'jumping' && obstacles[i].y > player.y && !obstacles[i].scored) {
// Update score
LK.setScore(LK.getScore() + 1);
// Update score text
scoreTxt.setText(LK.getScore());
// Update narrative text every 2 points
if (LK.getScore() % 2 == 0) {
if (availableNarratives.length === 0) {
// If all narratives have been used, reset the arrays
availableNarratives = [].concat(narratives);
usedNarratives = [];
}
var randomIndex = Math.floor(Math.random() * availableNarratives.length);
var narrative = availableNarratives[randomIndex];
// Move the used narrative from availableNarratives to usedNarratives
availableNarratives.splice(randomIndex, 1);
usedNarratives.push(narrative);
// Destroy the old narrative text if it exists
if (game.narrativeTxt) {
game.narrativeTxt.destroy();
}
// Display the narrative
game.narrativeTxt = new Text2(narrative, {
size: 70,
fill: "#ffffff",
stroke: "#000000",
strokeThickness: 10
});
game.narrativeTxt.anchor.set(0.5, 0);
game.narrativeTxt.y -= 780;
LK.gui.center.addChild(game.narrativeTxt);
}
// Mark this hurdle as having added a point to the score
obstacles[i].scored = true;
// Decrease minSpawnInterval and maxSpawnInterval
minSpawnInterval -= 0.5;
maxSpawnInterval -= 0.25;
}
}
// Spawn hurdles
spawnObstacleTimer++;
if (spawnObstacleTimer >= spawnObstacleInterval) {
var hurdle = MidgroundContainer.addChild(new Hurdle());
hurdle.x = game.width / 2; // Position at the middle of the screen
hurdle.y = -100; // Position 100 pixels above the top of the screen
obstacles.push(hurdle);
spawnObstacleTimer = 0;
spawnObstacleInterval = Math.floor(Math.random() * (maxSpawnInterval - minSpawnInterval + 1)) + minSpawnInterval;
}
});