Initial prompt
Copy endless runner v3
User prompt
Add lines to separate the lanes
User prompt
Make sure lane lines fill top to bottom of the acreen
User prompt
Lane lines only cober the top half of the screen. Fix it maybe fixing the anchor
User prompt
Add outline lines to the left and right lane. Should have the size of the center lane width
User prompt
Please fix the bug: 'TypeError: Cannot set properties of null (setting 'update')' in or related to this line: 'leftPlayer.update = function () {' Line Number: 1173
User prompt
Please fix the bug: 'TypeError: Cannot set properties of null (setting 'update')' in or related to this line: 'leftPlayer.update = function () {' Line Number: 1173
User prompt
Make sure taht if two obstcles spwan at the same tkme and are in different lanes, taht their speed is the same
User prompt
Once spawned obstavles should keep constant speed
User prompt
When two small obstacles are spawn together but different lanes, make sure they move at the same speed
User prompt
When two small obstacles are paralle have them share the same speed
Code edit (1 edits merged)
Please save this source code
User prompt
To ensure that small obstacles are perfectly aligned, it is crucial to: - Set their initial `y` positions to be exactly the same. - Create them within the same function call to avoid timing discrepancies. - Ensure that their update logic is synchronized and that they move at the exact same speed.
User prompt
Please fix the bug: 'TypeError: Cannot set properties of undefined (setting 'y')' in or related to this line: 'smallObstacleLeft.y = smallObstacleRight.y = -smallObstacleLeft.height * 2;' Line Number: 1360
User prompt
Please fix the bug: 'TypeError: Cannot set properties of null (setting 'update')' in or related to this line: 'leftPlayer.update = function () {' Line Number: 1174
User prompt
Make obstavles move amoother
User prompt
Use linear interpolation for obstacles but keep their current speed
User prompt
Remove starfield
User prompt
Please fix the bug: 'TypeError: Cannot set properties of null (setting 'update')' in or related to this line: 'leftPlayer.update = function () {' Line Number: 1129
User prompt
Particles should use the color of the asset they are sxploding to
User prompt
Make text font thicker and add border
User prompt
Add border to textobject
User prompt
Add border to textobstacle
User prompt
Make textobstacle a little bigger
User prompt
Not so big a little smaller
/****
* Classes
****/
// Define the SmallObstacle class
var BigObstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('bigobstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = gameSpeed;
self.update = function () {
self.y += self.speed;
if (self.y > 2732 + self.height / 2) {
self.destroy();
}
};
});
// Define the Coin class
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = gameSpeed;
self.update = function () {
self.y += self.speed;
if (self.y > 2732 + self.height / 2) {
self.destroy();
}
};
});
// Define the LeftPlayer class
var LeftPlayer = Container.expand(function () {
var self = Container.call(this);
var leftPlayerGraphics = self.attachAsset('leftplayer', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 15;
self.update = function () {
// Add any specific update logic for LeftPlayer here
if (LK.ticks % 4 == 0) {
var trail = new Trail();
trail.scale.x = 0.5;
trail.scale.y = 0.5;
if (leftPlayer && leftPlayer.x !== undefined) {
trail.x = leftPlayer.x;
} else {
trail.x = self.x;
}
trail.y = self.y + leftPlayerGraphics.height / 2;
game.addChildAt(trail, game.getChildIndex(self));
}
};
});
var LineObstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('lineobstacle', {
anchorX: 0.5,
anchorY: 0.5,
width: 2048 // Set the width to the full screen width
});
self.speed = gameSpeed;
self.update = function () {
self.y += self.speed;
if (self.y > 2732 + self.height / 2) {
self.destroy();
}
};
});
// Define the Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = gameSpeed;
self.update = function () {
self.y += self.speed;
if (self.y > 2732 + self.height / 2) {
self.destroy();
}
};
});
// Define the Particle class
var Particle = Container.expand(function () {
var self = Container.call(this);
var particleGraphics = self.attachAsset('particle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 5 + 2; // Random speed for each particle
self.direction = Math.random() * Math.PI * 2; // Random direction for each particle
self.update = function () {
self.x += Math.cos(self.direction) * self.speed; // Move the particle in the direction
self.y += Math.sin(self.direction) * self.speed;
self.alpha -= 0.01; // Fade out the particle
if (self.alpha <= 0) {
self.destroy();
}
};
});
// Define the Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 15;
self.shield = null;
self.transitionToLane = function (targetX) {
self.isMoving = true;
self.targetX = targetX;
if (self.x < self.targetX) {
playerGraphics.rotation = Math.PI / 4; // Rotate player 45 degrees to the direction of movement
} else {
playerGraphics.rotation = -Math.PI / 4; // Rotate player -45 degrees to the direction of movement
}
};
self.update = function () {
if (self.isInvulnerable) {
self.invulnerableTimer--;
if (!self.shield) {
self.shield = self.addChild(LK.getAsset('shield', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.5 // Set shield transparency
}));
}
if (self.invulnerableTimer <= 0) {
self.isInvulnerable = false;
if (self.shield) {
self.shield.destroy();
self.shield = null;
}
}
}
if (self.isMoving) {
if (Math.abs(self.x - self.targetX) < self.speed) {
self.x = self.targetX;
self.isMoving = false;
} else {
self.x += (self.targetX - self.x) * 0.1; // Smooth movement using linear interpolation
playerGraphics.rotation = self.x < self.targetX ? Math.PI / 4 : -Math.PI / 4; // Rotate player 45 degrees to the direction of movement
}
} else {
// Smoothly transition player rotation back to its original position
if (playerGraphics.rotation > 0) {
playerGraphics.rotation -= 0.1;
} else if (playerGraphics.rotation < 0) {
playerGraphics.rotation += 0.1;
}
if (Math.abs(playerGraphics.rotation) < 0.1) {
playerGraphics.rotation = 0; // Reset rotation when player is not moving
}
}
if (!self.isJumping && self.visible) {
if (self.isMoving && LK.ticks % 1 == 0) {
var trail = new Trail();
trail.x = self.x;
trail.y = self.y + playerGraphics.height / 2;
game.addChild(trail);
} else if (LK.ticks % 4 == 0) {
var trail = new Trail();
trail.x = self.x;
trail.y = self.y + playerGraphics.height / 2;
game.addChild(trail);
}
}
if (self.isJumping) {
if (self.y > self.jumpPeakY && !self.isFalling) {
self.y -= self.jumpSpeed;
playerGraphics.scale.x += 0.01; // Increase player size when moving up
playerGraphics.scale.y += 0.01;
if (self.shield) {
self.shield.scale.x += 0.01; // Increase shield size when moving up
self.shield.scale.y += 0.01;
}
} else {
self.isFalling = true;
self.y += self.jumpSpeed;
playerGraphics.scale.x -= 0.01; // Decrease player size when falling down
playerGraphics.scale.y -= 0.01;
if (self.shield) {
self.shield.scale.x -= 0.01; // Decrease shield size when falling down
self.shield.scale.y -= 0.01;
}
if (self.y >= self.jumpStartY) {
self.y = self.jumpStartY;
self.isJumping = false;
self.isFalling = false;
playerGraphics.scale.x = 1; // Reset player size when not jumping
playerGraphics.scale.y = 1;
if (self.shield) {
self.shield.scale.x = 1; // Reset shield size when not jumping
self.shield.scale.y = 1;
}
// Destroy the player's shadow
shadow.destroy();
}
}
}
// Update shadow rotation to match player rotation
if (shadow) {
shadow.rotation = playerGraphics.rotation;
}
// Ensure player is always on top if it is a child of the game
if (game.children.includes(self)) {
game.setChildIndex(self, game.children.length - 1);
}
};
self.moveLeft = function () {
if (!gameStarted) {
return;
} // Prevent player movement when the home screen is up
if (self.lane > 0 && !self.isMoving && !leftPlayer && !rightPlayer) {
self.lane--;
self.transitionToLane(lanes[self.lane]);
}
};
self.moveRight = function () {
if (!gameStarted) {
return;
} // Prevent player movement when the home screen is up
if (self.lane < 2 && !self.isMoving && !leftPlayer && !rightPlayer) {
self.lane++;
self.transitionToLane(lanes[self.lane]);
}
};
self.jump = function () {
if (!self.isMoving && !self.isJumping && !leftPlayer && !rightPlayer) {
self.isJumping = true;
self.jumpStartY = self.y;
self.jumpPeakY = self.y - 250; // Increase jump height
self.jumpSpeed = 4;
// Create the player's shadow
shadow = new Shadow();
shadow.x = self.x;
shadow.y = self.y;
game.addChild(shadow);
}
};
});
// Define the PowerUp class
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var powerUpGraphics = self.attachAsset('powerup', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = gameSpeed;
self.update = function () {
self.y += self.speed;
if (self.y > 2732 + self.height / 2) {
self.destroy();
}
};
});
// Define the PowerUpCenterLane class
var PowerUpCenterLane = Container.expand(function () {
var self = Container.call(this);
var powerUpGraphics = self.attachAsset('powerup', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = gameSpeed;
self.update = function () {
self.y += self.speed;
if (self.y > 2732 + self.height / 2) {
self.destroy();
}
};
});
// Define the RightPlayer class
var RightPlayer = Container.expand(function () {
var self = Container.call(this);
var rightPlayerGraphics = self.attachAsset('rightplayer', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 15;
self.update = function () {
// Add any specific update logic for RightPlayer here
if (LK.ticks % 4 == 0) {
var trail = new Trail();
trail.scale.x = 0.5;
trail.scale.y = 0.5;
if (rightPlayer) {
trail.x = rightPlayer.x;
} else {
trail.x = self.x;
}
trail.y = self.y + rightPlayerGraphics.height / 2;
game.addChildAt(trail, game.getChildIndex(self));
}
};
});
//<Assets used in the game will automatically appear here>
// Define the Shadow class
var Shadow = Container.expand(function () {
var self = Container.call(this);
var shadowGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5,
tint: 0x000000 // Set the color to black
});
shadowGraphics.alpha = 0.5; // Dim the shadow
self.update = function () {
// The shadow's size changes based on the player's y position
var scale = 1 - (player.y - self.y) / 1000;
self.scale.x = scale;
self.scale.y = scale;
// Update the shadow's position to match the player's position
self.x = player.x;
// Rotate the shadow to match the player's rotation
if (player.playerGraphics) {
shadowGraphics.rotation = player.playerGraphics.rotation;
}
};
});
// Define the LineObstacle class
var SmallObstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = gameSpeed;
self.update = function () {
self.y += self.speed;
if (self.y > 2732 + self.height / 2) {
self.destroy();
}
};
});
// Define the SmallObstacleCenterCoinSides class
var SmallObstacleCenterCoinSides = Container.expand(function () {
var self = Container.call(this);
var smallObstacle = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = gameSpeed;
self.update = function () {
self.y += self.speed;
if (self.y > 2732 + self.height / 2) {
self.destroy();
}
};
});
// Function to spawn SmallObstacle in the center and Coins on the sides
// Define the Starfield class
var Starfield = Container.expand(function () {
var self = Container.call(this);
var starGraphics = self.attachAsset('particle', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.5,
scaleX: 0.5,
scaleY: 0.5
});
self.speed = gameSpeed * 0.8; // Starfield moves at 80% of the game speed
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -self.height;
}
};
});
// Define the TextObstacle class
var TextObstacle = Container.expand(function (customText) {
var self = Container.call(this);
var textGraphics = new Text2(customText || 'Sample Text', {
size: 100,
fill: "#ffffff",
align: "center"
});
textGraphics.anchor.set(0.5, 0.5);
self.addChild(textGraphics);
self.speed = gameSpeed;
self.update = function () {
self.y += self.speed;
self.hitbox = null; // Ensure TextObstacle does not collide with player
if (self.y > 2732 + self.height / 2) {
self.destroy();
}
};
});
// Function to spawn SmallObstacle
// Define the Trail class
var Trail = Container.expand(function () {
var self = Container.call(this);
var trailGraphics = self.attachAsset('trail', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
self.alpha -= 0.01; // Fade out the trail
self.scale.x -= 0.01; // Shrink the trail
self.scale.y -= 0.01; // Shrink the trail
if (self.y > 2732 || self.alpha <= 0 || self.scale.x <= 0 || self.scale.y <= 0) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x303030 //Init game with darker grey background
});
/****
* Game Code
****/
// Function to spawn PowerUp in the center lane
function spawnPowerUpCenterLane() {
var powerUpCenterLane = new PowerUpCenterLane();
powerUpCenterLane.x = lanes[1]; // Center lane
powerUpCenterLane.y = -powerUpCenterLane.height * 2;
if (!powerups) {
powerups = [];
}
powerups.push(powerUpCenterLane);
game.addChild(powerUpCenterLane);
}
// Create main menu container
var mainMenu = new Container();
game.addChild(mainMenu);
// Create title text
var titleText = new Text2('Endless Runner', {
size: 200,
fill: "#ffffff",
stroke: "#000000",
strokeThickness: 5,
border: true
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 2048 / 2;
titleText.y = 2732 / 4;
mainMenu.addChild(titleText);
// Create mode 1 button
var mode1Button = new Container();
var mode1ButtonText = new Text2('->Training!', {
size: 150,
fill: "#ffffff",
stroke: "#000000",
strokeThickness: 5,
border: true
});
mode1ButtonText.anchor.set(0.5, 0.5);
mode1Button.addChild(mode1ButtonText);
mode1Button.x = 2048 / 2;
mode1Button.y = 2732 / 2;
mainMenu.addChild(mode1Button);
// Create mode 2 button
var mode2Button = new Container();
var mode2ButtonText = new Text2('->I am Ready!', {
size: 150,
fill: "#ffffff",
stroke: "#000000",
strokeThickness: 5,
border: true
});
mode2ButtonText.anchor.set(0.5, 0.5);
mode2Button.addChild(mode2ButtonText);
mode2Button.x = 2048 / 2;
mode2Button.y = 2732 / 2 + 300;
mainMenu.addChild(mode2Button);
// Add event listeners for buttons
mode1Button.down = function () {
startGame('mode1');
};
mode2Button.down = function () {
startGame('mode2');
};
// Function to start the game
function startGame(mode) {
mainMenu.visible = false;
scoreTxt.visible = true; // Show score when game starts
// Initialize game elements based on selected mode
if (mode === 'mode1') {
// Initialize mode 1 specific elements
obstacleSpawnOrder = [{
type: 'TextObstacle',
interval: 100,
text: 'Swipe LEFT or RIGHT!'
}, {
type: 'SmallObstacle',
interval: 100
}, {
type: 'SmallObstacleLeftMiddleCoinRight',
interval: 100
}, {
type: 'SmallObstacleRightCenterCoinLeft',
interval: 100
}, {
type: 'TextObstacle',
interval: 100,
text: 'Swipe UP to JUMP!'
}, {
type: 'LineObstacle',
interval: 100
}, {
type: 'SmallObstaclesSidesCoinMiddle',
interval: 100
}, {
type: 'TextObstacle',
interval: 100,
text: 'Swipe DOWN to SPLIT!'
}, {
type: 'BigObstacle',
interval: 100
}, {
type: 'SmallObstaclesSidesCoinMiddle',
interval: 100
}, {
type: 'TextObstacle',
interval: 100,
text: 'Collect SHIELD to become INVINCIBLE!'
}, {
type: 'PowerUpCenterLane',
interval: 100
}, {
type: 'ObstacleLine',
interval: 50
}, {
type: 'ObstacleLine',
interval: 50
}, {
type: 'ObstacleLine',
interval: 50
}, {
type: 'TextObstacle',
interval: 100,
text: 'You are READY!'
}];
} else if (mode === 'mode2') {
// Initialize mode 2 specific elements
obstacleSpawnOrder = [{
type: 'SmallObstacle',
interval: 100
}, {
type: 'SmallObstacleLeftMiddleCoinRight',
interval: 100
}, {
type: 'SmallObstacleRightCenterCoinLeft',
interval: 100
}, {
type: 'LineObstacle',
interval: 100
}, {
type: 'SmallObstacleCenterCoinLeftPowerUpRight',
interval: 100
}, {
type: 'SmallObstaclesSidesCoinMiddle',
interval: 100
}, {
type: 'SmallObstacleCenterCoinSides',
interval: 100
}, {
type: 'BigObstacle',
interval: 100
}, {
type: 'ObstacleLine',
interval: 100
}];
obstacleSpawnOrder = obstacleSpawnOrder.sort(function () {
return Math.random() - 0.5;
});
}
// Start the game
var timeout = LK.setTimeout(function () {
gameStarted = true;
}, 500);
}
// Function to spawn TextObstacle
function spawnTextObstacle(customText) {
var textObstacle = new TextObstacle(customText);
textObstacle.x = 2048 / 2; // Center the TextObstacle
textObstacle.y = -textObstacle.height * 2;
if (!obstacles) {
obstacles = [];
}
obstacles.push(textObstacle);
game.addChild(textObstacle);
}
// Function to spawn powerups
function spawnPowerUp(lane) {
var powerup = new PowerUp();
powerup.lane = lane;
powerup.x = lanes[powerup.lane];
powerup.y = -powerup.height * 2;
powerups.push(powerup);
game.addChild(powerup);
}
// Initialize gameStarted flag
var gameStarted = false;
// Initialize array for powerups
var powerups = [];
// Initialize shadow
var shadow;
// Initialize lanes
var lanes = [2048 / 4, 2048 / 2, 2048 / 4 * 3];
// Initialize starfield
var starfield = [];
for (var i = 0; i < 30; i++) {
var star = new Starfield();
star.scale.x = 1.0;
star.scale.y = 1.0;
star.x = Math.random() * 2048;
star.y = Math.random() * 2732;
star.speed = gameSpeed * 0.8; // Initialize starfield with dynamic speed
starfield.push(star);
game.addChild(star);
}
// Initialize player
var player = game.addChild(new Player());
player.hitbox = [player];
player.lane = 1; // Start in the middle lane
player.x = lanes[player.lane];
player.y = 2732 - 200 - 350;
// Initialize left and right players
var leftPlayer = null;
var rightPlayer = null;
// Initialize arrays for obstacles and coins
var obstacles = [];
var coins = [];
// Initialize split duration timer
var splitDuration = 120; // Duration in frames (2 seconds at 60 FPS)
var splitTimer = 0;
// Initialize score
var score = 0;
// Initialize game speed
var gameSpeed = 5;
// Initialize global spawn interval
var globalSpawnInterval = 120; // Default interval in frames (2 seconds at 60 FPS)
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff",
stroke: "#000000",
strokeThickness: 5,
border: true
});
scoreTxt.anchor.set(0.5, 0);
scoreTxt.visible = false; // Hide score on main menu
LK.gui.top.addChild(scoreTxt);
// Configuration for defining the order in which obstacles will spawn
var obstacleSpawnOrder = [{
type: 'TextObstacle',
// New TextObstacle type
interval: 100,
text: 'Swipe LEFT or RIGHT!' // Custom text for TextObstacle
}, {
type: 'SmallObstacle',
interval: 100
}, {
type: 'SmallObstacleLeftMiddleCoinRight',
interval: 100
}, {
type: 'SmallObstacleRightCenterCoinLeft',
interval: 100
}, {
type: 'TextObstacle',
// New TextObstacle type
interval: 100,
text: 'Swipe UP to JUMP!' // Custom text for TextObstacle
}, {
type: 'LineObstacle',
interval: 100
}, {
type: 'SmallObstacleCenterCoinLeftPowerUpRight',
interval: 100
}, {
type: 'SmallObstaclesSidesCoinMiddle',
interval: 100
}, {
type: 'TextObstacle',
// New TextObstacle type
interval: 100,
text: 'Swipe DOWN to SPLIT!' // Custom text for TextObstacle
}, {
type: 'BigObstacle',
interval: 100
}, {
type: 'SmallObstaclesSidesCoinMiddle',
interval: 100
}, {
type: 'LineObstacle',
interval: 100
}, {
type: 'SmallObstacleRightCenterCoinLeft',
interval: 100
}, {
type: 'TextObstacle',
// New TextObstacle type
interval: 100,
text: 'Avoid the Obstacles!' // Custom text for TextObstacle
}];
var currentObstacleIndex = 0;
var obstacleSpawnTimer = 0;
var obstacleSpawnOrderRandom = [{
type: 'SmallObstacle',
interval: 100
}, {
type: 'SmallObstacleLeftMiddleCoinRight',
interval: 100
}, {
type: 'SmallObstacleRightCenterCoinLeft',
interval: 100
}, {
type: 'LineObstacle',
interval: 100
}, {
type: 'SmallObstacleCenterCoinLeftPowerUpRight',
interval: 100
}, {
type: 'SmallObstaclesSidesCoinMiddle',
interval: 100
}, {
type: 'SmallObstacleCenterCoinSides',
interval: 100
}, {
type: 'BigObstacle',
interval: 100
}, {
type: 'ObstacleLine',
interval: 100
}];
// Initialize queue for predicting next obstacle
var obstacleQueue = [];
// Function to spawn obstacles
function spawnObstacle(lane) {
var obstacle;
if (lane === undefined) {
obstacle = new LineObstacle();
obstacle.x = 2048 / 2; // Center the LineObstacle
} else {
obstacle = new Obstacle();
obstacle.lane = lane;
obstacle.x = lanes[obstacle.lane];
}
obstacle.y = -obstacle.height * 2;
if (!obstacles) {
obstacles = [];
}
obstacles.push(obstacle);
game.addChild(obstacle);
}
// Function to spawn BigObstacle with specific rules
function spawnBigObstacle() {
var bigObstacle = new BigObstacle();
bigObstacle.x = 2048 / 2; // Center the BigObstacle
bigObstacle.y = -bigObstacle.height / 4;
if (!obstacles) {
obstacles = [];
}
obstacles.push(bigObstacle);
game.addChild(bigObstacle);
}
// Function to spawn coins
function spawnCoin(lane) {
var coin = new Coin();
coin.lane = lane;
coin.x = lanes[coin.lane];
coin.y = -coin.height * 2;
coins.push(coin);
game.addChild(coin);
}
// Function to spawn powerups
// Handle swipe events for player movement
var touchStartX = 0;
var touchStartY = 0;
game.down = function (x, y, obj) {
if (!gameStarted) {
return;
} // Prevent player movement when the home screen is up
touchStartX = x;
touchStartY = y;
};
game.up = function (x, y, obj) {
if (!gameStarted) {
return;
} // Prevent player movement when the home screen is up
if (Math.abs(y - touchStartY) > Math.abs(x - touchStartX)) {
if (y < touchStartY && !leftPlayer && !rightPlayer) {
player.jump();
} else if (y > touchStartY && !leftPlayer && !rightPlayer && !player.isJumping && player.lane === 1) {
// Split player into left and right players
// Animate leftPlayer and rightPlayer to move to the sides
var leftTargetX = player.x - 650;
var rightTargetX = player.x + 550;
var animationDuration = 20; // Duration in frames (0.33 seconds at 60 FPS)
leftPlayer = new LeftPlayer();
rightPlayer = new RightPlayer();
leftPlayer.x = player.x;
leftPlayer.y = player.y;
rightPlayer.x = player.x;
rightPlayer.y = player.y;
game.addChild(leftPlayer);
game.addChild(rightPlayer);
player.visible = false; // Hide the original player
player.hitbox = [leftPlayer, rightPlayer]; // Move player hitbox to left and right players
// Initialize update functions after adding to game
if (leftPlayer) {
leftPlayer.update = function () {
if (animationDuration > 0) {
leftPlayer.x += (leftTargetX - leftPlayer.x) / animationDuration;
animationDuration--;
}
// Add any specific update logic for LeftPlayer here
if (LK.ticks % 4 == 0) {
var trail = new Trail();
trail.scale.x = 0.5;
trail.scale.y = 0.5;
if (leftPlayer && leftPlayer.x !== undefined) {
trail.x = leftPlayer.x;
} else {
trail.x = this.x; // Ensure trail uses self's x-coordinate
}
trail.y = this.y + (leftPlayerGraphics ? leftPlayerGraphics.height / 2 : 0);
game.addChildAt(trail, game.getChildIndex(this));
}
};
}
if (rightPlayer) {
rightPlayer.update = function () {
if (animationDuration > 0) {
rightPlayer.x += (rightTargetX - rightPlayer.x) / animationDuration;
animationDuration--;
}
// Add any specific update logic for RightPlayer here
if (LK.ticks % 4 == 0) {
var trail = new Trail();
trail.scale.x = 0.5;
trail.scale.y = 0.5;
if (rightPlayer && rightPlayer.x !== undefined) {
trail.x = rightPlayer.x;
} else {
trail.x = this.x; // Ensure trail uses self's x-coordinate
}
trail.y = this.y + (rightPlayerGraphics ? rightPlayerGraphics.height / 2 : 0);
game.addChildAt(trail, game.getChildIndex(this));
}
};
}
// Initialize update functions after adding to game
leftPlayer.update = function () {
if (animationDuration > 0) {
leftPlayer.x += (leftTargetX - leftPlayer.x) * 0.1; // Smooth movement using linear interpolation
animationDuration--;
}
// Add any specific update logic for LeftPlayer here
if (LK.ticks % 4 == 0) {
var trail = new Trail();
trail.scale.x = 0.5;
trail.scale.y = 0.5;
trail.x = leftPlayer.x;
trail.y = leftPlayer.y + leftPlayer.height / 2;
game.addChildAt(trail, game.getChildIndex(leftPlayer));
}
};
rightPlayer.update = function () {
if (animationDuration > 0) {
rightPlayer.x += (rightTargetX - rightPlayer.x) * 0.1; // Smooth movement using linear interpolation
animationDuration--;
}
// Add any specific update logic for RightPlayer here
if (LK.ticks % 4 == 0) {
var trail = new Trail();
trail.scale.x = 0.5;
trail.scale.y = 0.5;
trail.x = rightPlayer.x;
trail.y = rightPlayer.y + rightPlayer.height / 2;
game.addChildAt(trail, game.getChildIndex(rightPlayer));
}
};
// Initialize update functions after adding to game
leftPlayer.update = function () {
if (animationDuration > 0) {
leftPlayer.x += (leftTargetX - leftPlayer.x) / animationDuration;
animationDuration--;
}
// Add any specific update logic for LeftPlayer here
if (LK.ticks % 4 == 0) {
var trail = new Trail();
trail.scale.x = 0.5;
trail.scale.y = 0.5;
trail.x = leftPlayer.x;
trail.y = leftPlayer.y + leftPlayer.height / 2;
game.addChildAt(trail, game.getChildIndex(leftPlayer));
}
};
rightPlayer.update = function () {
if (animationDuration > 0) {
rightPlayer.x += (rightTargetX - rightPlayer.x) / animationDuration;
animationDuration--;
}
// Add any specific update logic for RightPlayer here
if (LK.ticks % 4 == 0) {
var trail = new Trail();
trail.scale.x = 0.5;
trail.scale.y = 0.5;
trail.x = rightPlayer.x;
trail.y = rightPlayer.y + rightPlayer.height / 2;
game.addChildAt(trail, game.getChildIndex(rightPlayer));
}
};
// Initialize update functions after adding to game
leftPlayer.update = function () {
if (animationDuration > 0) {
leftPlayer.x += (leftTargetX - leftPlayer.x) / animationDuration;
animationDuration--;
}
// Add any specific update logic for LeftPlayer here
if (LK.ticks % 4 == 0) {
var trail = new Trail();
trail.scale.x = 0.5;
trail.scale.y = 0.5;
trail.x = leftPlayer.x;
trail.y = leftPlayer.y + leftPlayer.height / 2;
game.addChildAt(trail, game.getChildIndex(leftPlayer));
}
};
rightPlayer.update = function () {
if (animationDuration > 0) {
rightPlayer.x += (rightTargetX - rightPlayer.x) / animationDuration;
animationDuration--;
}
// Add any specific update logic for RightPlayer here
if (LK.ticks % 4 == 0) {
var trail = new Trail();
trail.scale.x = 0.5;
trail.scale.y = 0.5;
trail.x = rightPlayer.x;
trail.y = rightPlayer.y + rightPlayer.height / 2;
game.addChildAt(trail, game.getChildIndex(rightPlayer));
}
};
}
// Start split timer
splitTimer = splitDuration;
} else {
if (x < touchStartX) {
player.moveLeft();
} else {
player.moveRight();
}
}
};
// Update game logic
game.update = function () {
if (!gameStarted) {
// Update starfield
for (var i = 0; i < starfield.length; i++) {
starfield[i].y += gameSpeed * 0.8; // Starfield moves at 80% of the game speed
starfield[i].speed = gameSpeed * 0.8; // Update starfield speed dynamically
starfield[i].update();
}
return;
}
// Update starfield
for (var i = 0; i < starfield.length; i++) {
starfield[i].y += gameSpeed * 0.8; // Starfield moves at 80% of the game speed
starfield[i].speed = gameSpeed * 0.8; // Update starfield speed dynamically
starfield[i].update();
}
// Update player
player.update();
// Increase game speed and decrease global spawn interval over time
if (LK.ticks % 600 == 0) {
// Increase speed every 10 seconds
gameSpeed *= 1.03; // Increase speed by 3%
for (var i = 0; i < starfield.length; i++) {
starfield[i].speed = gameSpeed * 0.8; // Update starfield speed dynamically
}
// Decrease global spawn interval to make spawns more frequent
globalSpawnInterval = Math.max(30, globalSpawnInterval - 10); // Ensure interval doesn't go below 30 frames (0.5 seconds)
}
// Update obstacles, coins, and powerups
for (var i = powerups.length - 1; i >= 0; i--) {
powerups[i].y += gameSpeed;
powerups[i].update();
if (player && !player.isJumping && player.hitbox.some(function (hitbox) {
return hitbox.intersects(powerups[i]);
})) {
player.isInvulnerable = true;
player.invulnerableTimer = 600; // 10 seconds at 60 FPS
powerups[i].destroy();
powerups.splice(i, 1);
}
}
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].y += gameSpeed;
obstacles[i].update();
if (!player.isJumping && player.hitbox && player.hitbox.some(function (hitbox) {
return hitbox.intersects(obstacles[i]) && obstacles[i].hitbox !== null;
})) {
if (player.isInvulnerable) {
// Spawn particles
for (var j = 0; j < 10; j++) {
var particle = new Particle();
particle.x = obstacles[i].x;
particle.y = obstacles[i].y;
particle.tint = obstacles[i].children[0].tint; // Inherit tint from the obstacle
game.addChild(particle);
}
obstacles[i].destroy();
obstacles.splice(i, 1);
} else {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
}
// Handle obstacle spawning based on configuration
obstacleSpawnTimer++;
if (obstacleSpawnTimer >= obstacleSpawnOrder[currentObstacleIndex].interval) {
var obstacleType = obstacleSpawnOrder[currentObstacleIndex].type;
if (obstacleType === 'BigObstacle') {
spawnBigObstacle();
} else if (obstacleType === 'LineObstacle') {
spawnObstacle();
} else if (obstacleType === 'Obstacle') {
spawnObstacle();
} else if (obstacleType === 'SmallObstacle') {
spawnSmallObstacle();
} else if (obstacleType === 'SmallObstacleLeftMiddleCoinRight') {
spawnSmallObstacleLeftMiddleCoinRight();
} else if (obstacleType === 'SmallObstacleRightCenterCoinLeft') {
spawnSmallObstacleRightCenterCoinLeft();
} else if (obstacleType === 'SmallObstacleCenterCoinLeftPowerUpRight') {
spawnSmallObstacleCenterCoinLeftPowerUpRight();
} else if (obstacleType === 'TextObstacle') {
var customText = obstacleSpawnOrder[currentObstacleIndex].text || 'Default Text';
spawnTextObstacle(customText);
} else if (obstacleType === 'ObstacleLine') {
spawnObstacleLine();
} else if (obstacleType === 'SmallObstaclesSidesCoinMiddle') {
spawnSmallObstaclesSidesCoinMiddle();
} else if (obstacleType === 'SmallObstacleCenterCoinSides') {
spawnSmallObstacleCenterCoinSides();
} else if (obstacleType === 'PowerUpCenterLane') {
spawnPowerUpCenterLane();
}
currentObstacleIndex++;
if (currentObstacleIndex >= obstacleSpawnOrder.length) {
currentObstacleIndex = 0;
if (obstacleSpawnOrder === obstacleSpawnOrderRandom) {
obstacleSpawnOrder = obstacleSpawnOrderRandom.sort(function () {
return Math.random() - 0.5;
});
} else {
obstacleSpawnOrder = obstacleSpawnOrderRandom;
}
}
obstacleSpawnTimer = 0;
}
// Handle split duration and animate back to center
if (splitTimer > 0) {
splitTimer--;
if (splitTimer === 0) {
// Animate leftPlayer and rightPlayer back to the center
var centerX = player.x;
var animationDuration = 20; // Duration in frames (0.33 seconds at 60 FPS)
// Initialize update functions after adding to game
leftPlayer.update = function () {
if (animationDuration > 0) {
leftPlayer.x += (centerX - leftPlayer.x) * 0.1; // Smooth movement using linear interpolation
animationDuration--;
} else {
leftPlayer.destroy();
leftPlayer = null;
player.visible = true;
player.hitbox = [player]; // Reset player hitbox to original player
}
// Add any specific update logic for LeftPlayer here
if (LK.ticks % 4 == 0) {
var trail = new Trail();
trail.scale.x = 0.5;
trail.scale.y = 0.5;
trail.x = leftPlayer.x;
trail.y = leftPlayer.y + leftPlayer.height / 2;
game.addChildAt(trail, game.getChildIndex(leftPlayer));
}
};
rightPlayer.update = function () {
if (animationDuration > 0) {
rightPlayer.x += (centerX - rightPlayer.x) * 0.1; // Smooth movement using linear interpolation
animationDuration--;
} else {
rightPlayer.destroy();
rightPlayer = null;
player.visible = true;
player.hitbox = [player]; // Reset player hitbox to original player
}
// Add any specific update logic for RightPlayer here
if (LK.ticks % 4 == 0) {
var trail = new Trail();
trail.scale.x = 0.5;
trail.scale.y = 0.5;
trail.x = rightPlayer.x;
trail.y = rightPlayer.y + rightPlayer.height / 2;
game.addChildAt(trail, game.getChildIndex(rightPlayer));
}
};
}
}
for (var i = coins.length - 1; i >= 0; i--) {
coins[i].y += gameSpeed;
coins[i].update();
if (player && !player.isJumping && player.hitbox.some(function (hitbox) {
return hitbox.intersects(coins[i]);
})) {
score += 1;
scoreTxt.setText(score);
// Spawn particles
for (var j = 0; j < 10; j++) {
var particle = new Particle();
particle.x = coins[i].x;
particle.y = coins[i].y;
particle.tint = coins[i].children[0].tint; // Inherit tint from the coin
game.addChild(particle);
}
coins[i].destroy();
coins.splice(i, 1);
}
}
for (var i = powerups.length - 1; i >= 0; i--) {
powerups[i].y += gameSpeed;
powerups[i].update();
if (player && !player.isJumping && player.hitbox.some(function (hitbox) {
return hitbox.intersects(powerups[i]);
})) {
player.isInvulnerable = true;
player.invulnerableTimer = 600; // 10 seconds at 60 FPS
powerups[i].destroy();
powerups.splice(i, 1);
}
}
// Automatic spawning of obstacles, coins, and powerups has been removed
};
// Function to spawn SmallObstacle
function spawnSmallObstacle() {
var smallObstacle = new SmallObstacle();
smallObstacle.x = 2048 / 2; // Center the SmallObstacle
smallObstacle.y = -smallObstacle.height * 2;
if (!obstacles) {
obstacles = [];
}
obstacles.push(smallObstacle);
game.addChild(smallObstacle);
}
// Function to spawn SmallObstacle on left and middle lanes, and Coin on right lane
function spawnSmallObstacleLeftMiddleCoinRight() {
var smallObstacleLeft = new SmallObstacle();
smallObstacleLeft.x = lanes[0]; // Left lane
smallObstacleLeft.y = -smallObstacleLeft.height * 2;
if (!obstacles) {
obstacles = [];
}
obstacles.push(smallObstacleLeft);
game.addChild(smallObstacleLeft);
var smallObstacleMiddle = new SmallObstacle();
smallObstacleMiddle.x = lanes[1]; // Middle lane
smallObstacleMiddle.y = -smallObstacleMiddle.height * 2;
obstacles.push(smallObstacleMiddle);
game.addChild(smallObstacleMiddle);
var coinRight = new Coin();
coinRight.x = lanes[2]; // Right lane
coinRight.y = -coinRight.height * 2;
if (!coins) {
coins = [];
}
coins.push(coinRight);
game.addChild(coinRight);
}
// Function to spawn SmallObstacle on right and center lanes, and Coin on left lane
function spawnSmallObstacleRightCenterCoinLeft() {
var smallObstacleRight = new SmallObstacle();
smallObstacleRight.x = lanes[2]; // Right lane
smallObstacleRight.y = -smallObstacleRight.height * 2;
if (!obstacles) {
obstacles = [];
}
obstacles.push(smallObstacleRight);
game.addChild(smallObstacleRight);
var smallObstacleCenter = new SmallObstacle();
smallObstacleCenter.x = lanes[1]; // Center lane
smallObstacleCenter.y = -smallObstacleCenter.height * 2;
obstacles.push(smallObstacleCenter);
game.addChild(smallObstacleCenter);
var coinLeft = new Coin();
coinLeft.x = lanes[0]; // Left lane
coinLeft.y = -coinLeft.height * 2;
if (!coins) {
coins = [];
}
coins.push(coinLeft);
game.addChild(coinLeft);
}
// Function to spawn a line of obstacles
function spawnObstacleLine() {
for (var i = 0; i < lanes.length; i++) {
var obstacle = new Obstacle();
obstacle.x = lanes[i];
obstacle.y = -obstacle.height * 2;
if (!obstacles) {
obstacles = [];
}
obstacles.push(obstacle);
game.addChild(obstacle);
}
}
function spawnSmallObstacleCenterCoinLeftPowerUpRight() {
var smallObstacleCenter = new SmallObstacle();
smallObstacleCenter.x = lanes[1]; // Center lane
smallObstacleCenter.y = -smallObstacleCenter.height * 2;
if (!obstacles) {
obstacles = [];
}
obstacles.push(smallObstacleCenter);
game.addChild(smallObstacleCenter);
var coinLeft = new Coin();
coinLeft.x = lanes[0]; // Left lane
coinLeft.y = -coinLeft.height * 2;
if (!coins) {
coins = [];
}
coins.push(coinLeft);
game.addChild(coinLeft);
var powerUpRight = new PowerUp();
powerUpRight.x = lanes[2]; // Right lane
powerUpRight.y = -powerUpRight.height * 2;
if (!powerups) {
powerups = [];
}
powerups.push(powerUpRight);
game.addChild(powerUpRight);
}
// Function to spawn SmallObstacles on the sides and a Coin in the middle
function spawnSmallObstaclesSidesCoinMiddle() {
var smallObstacleLeft = new SmallObstacle();
smallObstacleLeft.x = lanes[0]; // Left lane
smallObstacleLeft.y = -smallObstacleLeft.height * 2;
if (!obstacles) {
obstacles = [];
}
obstacles.push(smallObstacleLeft);
game.addChild(smallObstacleLeft);
var smallObstacleRight = new SmallObstacle();
smallObstacleRight.x = lanes[2]; // Right lane
smallObstacleRight.y = -smallObstacleRight.height * 2;
obstacles.push(smallObstacleRight);
game.addChild(smallObstacleRight);
var coinMiddle = new Coin();
coinMiddle.x = lanes[1]; // Middle lane
coinMiddle.y = -coinMiddle.height * 2;
if (!coins) {
coins = [];
}
coins.push(coinMiddle);
game.addChild(coinMiddle);
}
// Function to spawn SmallObstacle in the center and Coins on the sides
function spawnSmallObstacleCenterCoinSides() {
var smallObstacleCenter = new SmallObstacleCenterCoinSides();
smallObstacleCenter.x = lanes[1]; // Center lane
smallObstacleCenter.y = -smallObstacleCenter.height * 2;
if (!obstacles) {
obstacles = [];
}
obstacles.push(smallObstacleCenter);
game.addChild(smallObstacleCenter);
var coinLeft = new Coin();
coinLeft.x = lanes[0]; // Left lane
coinLeft.y = -coinLeft.height * 2;
if (!coins) {
coins = [];
}
coins.push(coinLeft);
game.addChild(coinLeft);
var coinRight = new Coin();
coinRight.x = lanes[2]; // Right lane
coinRight.y = -coinRight.height * 2;
coins.push(coinRight);
game.addChild(coinRight);
}
cartoon white circle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
cartoon light blue circle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
cartoon white square. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
black rectangle