/****
* Classes
****/
// Bird class
var Bird = Container.expand(function () {
var self = Container.call(this);
var birdGraphics = self.attachAsset('bird', {
anchorX: 0.5,
anchorY: 0.5
});
self.direction = 1; // 1 for right, -1 for left
self.move = function () {
// Zigzag movement logic
self.y += 5; // Move downwards
if (self.x <= 0 || self.x >= 2048) {
self.direction *= -1; // Change direction on hitting screen bounds
}
self.x += 10 * self.direction; // Move horizontally in zigzag
};
});
// Assets will be automatically created based on usage in the code.
// Character class
var Character = Container.expand(function () {
var self = Container.call(this);
var characterGraphics = self.attachAsset('character', {
anchorX: 0.5,
anchorY: 0.5
});
self.targetX = self.x; // Initialize targetX
self.targetY = self.y; // Initialize targetY
self.update = function () {
// Smoothly move the character towards the target position
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 1) {
if (character.teleportActive) {
self.x = self.targetX;
self.y = self.targetY;
} else {
self.x += dx * 0.05;
self.y += dy * 0.05;
}
}
// Keep the character within the game boundaries
if (self.x < 0) {
self.x = 0;
} else if (self.x > 2048) {
self.x = 2048;
}
if (self.y < 0) {
self.y = 0;
} else if (self.y > 2732) {
self.y = 2732;
}
};
});
// Cloud class
var Cloud = Container.expand(function () {
var self = Container.call(this);
var cloudGraphics = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2
});
self.move = function () {
// Cloud movement logic here
self.y += 5; // The cloud moves downwards
};
});
// Collectible class
var Collectible = Container.expand(function () {
var self = Container.call(this);
var collectibleGraphics = self.attachAsset('collectible', {
anchorX: 0.5,
anchorY: 0.5
});
});
// EnemyCar class
var EnemyCar = Container.expand(function () {
var self = Container.call(this);
var enemyCarGraphics = self.attachAsset('enemyCar', {
anchorX: 0.5,
anchorY: 0.5
});
self.timer = 180; // 3 seconds in ticks (60 ticks per second)
self.speed = 0; // Initial speed
self.move = function () {
if (self.timer > 0) {
// Wait for 3 seconds
self.timer--;
if (self.timer === 0) {
// After 3 seconds, start moving at high speed
self.speed = 30; // High speed
}
} else {
// Move the enemy car to the left at high speed
self.x -= self.speed;
}
};
});
// Fish class
var Fish = Container.expand(function () {
var self = Container.call(this);
var fishGraphics = self.attachAsset('fish', {
anchorX: 0.5,
anchorY: 0.5
});
self.move = function () {
// Fish movement logic here
self.x -= 5; // The fish moves forward
};
});
// GoldenFish class
var GoldenFish = Container.expand(function () {
var self = Container.call(this);
var goldenFishGraphics = self.attachAsset('goldenFish', {
anchorX: 0.5,
anchorY: 0.5
});
self.move = function () {
// GoldenFish movement logic here
self.x -= 5; // The golden fish moves forward
};
});
// MegaDog class
var MegaDog = Container.expand(function () {
var self = Container.call(this);
var megaDogGraphics = self.attachAsset('megaDog', {
anchorX: 0.5,
anchorY: 0.5
});
self.move = function () {
// MegaDog movement logic here
self.x -= 2; // The mega dog moves forward
};
});
// ObeseDog class
var ObeseDog = Container.expand(function () {
var self = Container.call(this);
var obeseDogGraphics = self.attachAsset('obeseDog', {
anchorX: 0.5,
anchorY: 0.5
});
self.direction = 'left';
self.move = function () {
// ObeseDog movement logic here
if (self.direction === 'left') {
self.x -= 5; // The obese dog moves left
} else {
self.x += 5; // The obese dog moves right
}
};
});
// Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.move = function () {
// Obstacle movement logic here
self.x -= 5; // The obstacle (dog) moves forward
};
});
// PufferFish class
var PufferFish = Container.expand(function () {
var self = Container.call(this);
var pufferFishGraphics = self.attachAsset('pufferFish', {
anchorX: 0.5,
anchorY: 0.5
});
self.move = function () {
// PufferFish movement logic here
self.x -= 10; // The puffer fish moves to the left faster
};
});
// Teleport class
var Teleport = Container.expand(function () {
var self = Container.call(this);
var teleportGraphics = self.attachAsset('teleport', {
anchorX: 0.5,
anchorY: 0.5
});
self.disappearTimeout = null; // Holds the timeout for disappearing
self.activate = function () {
// Set a timeout for the teleport to disappear after 3 seconds if not touched
self.disappearTimeout = LK.setTimeout(function () {
self.destroy();
teleports.splice(teleports.indexOf(self), 1);
}, 3000);
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Light blue background to represent the sky
});
/****
* Game Code
****/
var enemyCars = [];
var character = game.addChild(new Character());
character.x = 200;
character.y = 2732 / 2; // Start in the middle of the screen vertically
var obstacles = [];
var collectibles = [];
var pufferFishes = []; // Array to track PufferFish instances
var teleports = []; // Array to track Teleport instances
var score = 0;
// Score display
var scoreTxt = new Text2(score.toString(), {
size: 150,
fill: "#ffffff"
});
LK.gui.top.addChild(scoreTxt);
// Touch event to move the character
game.on('down', function (obj) {
var pos = obj.event.getLocalPosition(game);
character.targetX = pos.x; // Set target position for character
character.targetY = pos.y; // Set target position for character
});
var fishes = [];
var goldenFishes = [];
var clouds = [];
var obeseDogs = [];
var megaDogs = [];
// Game tick event
LK.on('tick', function () {
character.update();
// Move obstacles and check for collision with the character
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].move();
if (obstacles[i].intersects(character)) {
// Game over logic
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
// Check for collision with clouds
for (var j = clouds.length - 1; j >= 0; j--) {
if (obstacles[i] instanceof Bird) {
continue;
} // Skip if obstacle is a Bird
if (obstacles[i].intersects(clouds[j])) {
// Create an obese dog
var newObeseDog = new ObeseDog();
newObeseDog.x = obstacles[i].x;
newObeseDog.y = obstacles[i].y;
obeseDogs.push(newObeseDog);
game.addChild(newObeseDog);
// Remove the obstacle and the cloud
obstacles[i].destroy();
obstacles.splice(i, 1);
clouds[j].destroy();
clouds.splice(j, 1);
break;
}
}
// Remove off-screen obstacles
if (obstacles[i] && obstacles[i].x < -100) {
obstacles[i].destroy();
obstacles.splice(i, 1);
}
}
// Spawn obstacles
if (LK.ticks % 120 == 0) {
// Every 2 seconds
var newObstacle = new Obstacle();
newObstacle.x = 2048;
// Prevent dogs from appearing in the lane where the wall is
do {
newObstacle.y = Math.random() * 2732;
} while (Math.abs(newObstacle.y - character.y) < character.height);
obstacles.push(newObstacle);
game.addChild(newObstacle);
}
// Check for collectible collision
for (var j = collectibles.length - 1; j >= 0; j--) {
if (collectibles[j].intersects(character)) {
score += 10; // Increase score
scoreTxt.setText(score.toString()); // Update score display
collectibles[j].destroy();
collectibles.splice(j, 1);
}
}
// Move fishes and check for collision with the character
for (var k = fishes.length - 1; k >= 0; k--) {
fishes[k].move();
if (fishes[k].intersects(character)) {
score += 1; // Increase score
scoreTxt.setText(score.toString()); // Update score display
if (score % 10 == 0 && score != 0) {
var newMegaDog = new MegaDog();
newMegaDog.x = 2048;
newMegaDog.y = Math.random() * 2732;
megaDogs.push(newMegaDog);
game.addChild(newMegaDog);
}
fishes[k].destroy();
fishes.splice(k, 1);
}
// Remove off-screen fishes
if (fishes[k] && fishes[k].x < -100) {
fishes[k].destroy();
fishes.splice(k, 1);
}
}
// Move golden fishes and check for collision with the character
for (var l = goldenFishes.length - 1; l >= 0; l--) {
goldenFishes[l].move();
if (goldenFishes[l].intersects(character)) {
// Remove one obese dog
if (obeseDogs.length > 0) {
obeseDogs[0].destroy();
obeseDogs.splice(0, 1);
}
goldenFishes[l].destroy();
goldenFishes.splice(l, 1);
}
// Remove off-screen golden fishes
if (goldenFishes[l] && goldenFishes[l].x < -100) {
goldenFishes[l].destroy();
goldenFishes.splice(l, 1);
}
}
// Spawn fishes
if (LK.ticks % 240 == 0) {
// Every 4 seconds
var newFish = new Fish();
newFish.x = 2048;
newFish.y = Math.random() * 2732;
fishes.push(newFish);
game.addChild(newFish);
}
// Spawn golden fishes
if (LK.ticks % 900 == 0) {
// Every 15 seconds
var newGoldenFish = new GoldenFish();
newGoldenFish.x = 2048;
newGoldenFish.y = Math.random() * 2732;
goldenFishes.push(newGoldenFish);
game.addChild(newGoldenFish);
}
// Spawn clouds
if (LK.ticks % 300 == 0) {
// Every 5 seconds
var newCloud = new Cloud();
newCloud.x = Math.random() * 2048;
newCloud.y = 0;
clouds.push(newCloud);
game.addChild(newCloud);
}
// Move clouds and check for collision with the character
for (var l = clouds.length - 1; l >= 0; l--) {
clouds[l].move();
if (clouds[l].intersects(character)) {
// Game over logic
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
// Remove off-screen clouds
if (clouds[l].y > 2732) {
clouds[l].destroy();
clouds.splice(l, 1);
}
}
// Move obese dogs and check for collision with the character
for (var m = obeseDogs.length - 1; m >= 0; m--) {
obeseDogs[m].move();
if (obeseDogs[m].intersects(character)) {
// Game over logic
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
// Change direction when the obese dog reaches the edge of the screen
if (obeseDogs[m].x <= 0 && obeseDogs[m].direction === 'left') {
obeseDogs[m].direction = 'right';
} else if (obeseDogs[m].x >= 2048 && obeseDogs[m].direction === 'right') {
obeseDogs[m].direction = 'left';
}
// Remove off-screen obese dogs
if (obeseDogs[m].x < -100 || obeseDogs[m].x > 2148) {
obeseDogs[m].destroy();
obeseDogs.splice(m, 1);
}
// Move mega dogs and check for collision with the character
for (var n = megaDogs.length - 1; n >= 0; n--) {
megaDogs[n].move();
if (megaDogs[n].intersects(character)) {
// Game over logic
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
// Remove off-screen mega dogs
if (megaDogs[n].x < -100) {
megaDogs[n].destroy();
megaDogs.splice(n, 1);
}
}
}
// Check for teleport collision and activate effect
for (var i = teleports.length - 1; i >= 0; i--) {
if (teleports[i].intersects(character)) {
character.teleportActive = true; // Activate teleport effect
// Deactivate teleport effect after 5 seconds
LK.setTimeout(function () {
character.teleportActive = false;
}, 5000);
teleports[i].destroy();
teleports.splice(i, 1);
}
}
// Move PufferFishes and check for collision with the character
for (var i = pufferFishes.length - 1; i >= 0; i--) {
pufferFishes[i].move();
if (pufferFishes[i].intersects(character)) {
score -= 1; // Decrease score by 1
scoreTxt.setText(score.toString()); // Update score display
pufferFishes[i].destroy();
pufferFishes.splice(i, 1);
}
// Remove off-screen PufferFishes
if (pufferFishes[i] && pufferFishes[i].x < -100) {
pufferFishes[i].destroy();
pufferFishes.splice(i, 1);
}
}
// Move enemy cars, check for off-screen, and end game on collision with character
for (var i = enemyCars.length - 1; i >= 0; i--) {
enemyCars[i].move();
if (enemyCars[i].intersects(character)) {
// End game if character touches the car
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
if (enemyCars[i].x < -300) {
// Assuming the width of the car is 300
enemyCars[i].destroy();
enemyCars.splice(i, 1);
}
}
// Spawn Birds
if (LK.ticks % 900 == 0) {
// Every 15 seconds
var newBird = new Bird();
newBird.x = Math.random() * 2048; // Start from a random horizontal position
newBird.y = 0; // Start from the top
game.addChild(newBird);
obstacles.push(newBird); // Add the newBird to the obstacles array for collision detection
}
// Spawn enemy cars
if (LK.ticks % 600 == 0) {
// Every 10 seconds
var newEnemyCar = new EnemyCar();
newEnemyCar.x = 2048; // Start from the right edge
newEnemyCar.y = Math.random() * 2732; // Position randomly on the vertical axis
game.addChild(newEnemyCar);
enemyCars.push(newEnemyCar); // Add the newEnemyCar to the global enemyCars array for tracking
}
// Spawn PufferFish for negative scoring
if (LK.ticks % 180 == 0 && score >= 1 && score % 2 == 0) {
// Appears at the beginning of 1 point and every 2 points thereafter
var newPufferFish = new PufferFish();
newPufferFish.x = 2048; // Start from the right edge
newPufferFish.y = Math.random() * 2732; // Position randomly on the vertical axis
game.addChild(newPufferFish);
pufferFishes.push(newPufferFish); // Add the newPufferFish to the global pufferFishes array for tracking
}
// Spawn Teleport every 5 points, ensuring only 1 teleport appears at a time
if (score % 5 == 0 && score != 0 && teleports.length === 0 && !character.teleportActive) {
var newTeleport = new Teleport();
newTeleport.x = Math.random() * 2048;
newTeleport.y = Math.random() * 2732;
teleports.push(newTeleport);
game.addChild(newTeleport);
newTeleport.activate();
}
// Spawn collectibles
if (LK.ticks % 180 == 0) {
// Every 3 seconds
var newCollectible = new Collectible();
newCollectible.x = 2048;
newCollectible.y = Math.random() * 2732;
collectibles.push(newCollectible);
game.addChild(newCollectible);
}
}); /****
* Classes
****/
// Bird class
var Bird = Container.expand(function () {
var self = Container.call(this);
var birdGraphics = self.attachAsset('bird', {
anchorX: 0.5,
anchorY: 0.5
});
self.direction = 1; // 1 for right, -1 for left
self.move = function () {
// Zigzag movement logic
self.y += 5; // Move downwards
if (self.x <= 0 || self.x >= 2048) {
self.direction *= -1; // Change direction on hitting screen bounds
}
self.x += 10 * self.direction; // Move horizontally in zigzag
};
});
// Assets will be automatically created based on usage in the code.
// Character class
var Character = Container.expand(function () {
var self = Container.call(this);
var characterGraphics = self.attachAsset('character', {
anchorX: 0.5,
anchorY: 0.5
});
self.targetX = self.x; // Initialize targetX
self.targetY = self.y; // Initialize targetY
self.update = function () {
// Smoothly move the character towards the target position
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 1) {
if (character.teleportActive) {
self.x = self.targetX;
self.y = self.targetY;
} else {
self.x += dx * 0.05;
self.y += dy * 0.05;
}
}
// Keep the character within the game boundaries
if (self.x < 0) {
self.x = 0;
} else if (self.x > 2048) {
self.x = 2048;
}
if (self.y < 0) {
self.y = 0;
} else if (self.y > 2732) {
self.y = 2732;
}
};
});
// Cloud class
var Cloud = Container.expand(function () {
var self = Container.call(this);
var cloudGraphics = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2
});
self.move = function () {
// Cloud movement logic here
self.y += 5; // The cloud moves downwards
};
});
// Collectible class
var Collectible = Container.expand(function () {
var self = Container.call(this);
var collectibleGraphics = self.attachAsset('collectible', {
anchorX: 0.5,
anchorY: 0.5
});
});
// EnemyCar class
var EnemyCar = Container.expand(function () {
var self = Container.call(this);
var enemyCarGraphics = self.attachAsset('enemyCar', {
anchorX: 0.5,
anchorY: 0.5
});
self.timer = 180; // 3 seconds in ticks (60 ticks per second)
self.speed = 0; // Initial speed
self.move = function () {
if (self.timer > 0) {
// Wait for 3 seconds
self.timer--;
if (self.timer === 0) {
// After 3 seconds, start moving at high speed
self.speed = 30; // High speed
}
} else {
// Move the enemy car to the left at high speed
self.x -= self.speed;
}
};
});
// Fish class
var Fish = Container.expand(function () {
var self = Container.call(this);
var fishGraphics = self.attachAsset('fish', {
anchorX: 0.5,
anchorY: 0.5
});
self.move = function () {
// Fish movement logic here
self.x -= 5; // The fish moves forward
};
});
// GoldenFish class
var GoldenFish = Container.expand(function () {
var self = Container.call(this);
var goldenFishGraphics = self.attachAsset('goldenFish', {
anchorX: 0.5,
anchorY: 0.5
});
self.move = function () {
// GoldenFish movement logic here
self.x -= 5; // The golden fish moves forward
};
});
// MegaDog class
var MegaDog = Container.expand(function () {
var self = Container.call(this);
var megaDogGraphics = self.attachAsset('megaDog', {
anchorX: 0.5,
anchorY: 0.5
});
self.move = function () {
// MegaDog movement logic here
self.x -= 2; // The mega dog moves forward
};
});
// ObeseDog class
var ObeseDog = Container.expand(function () {
var self = Container.call(this);
var obeseDogGraphics = self.attachAsset('obeseDog', {
anchorX: 0.5,
anchorY: 0.5
});
self.direction = 'left';
self.move = function () {
// ObeseDog movement logic here
if (self.direction === 'left') {
self.x -= 5; // The obese dog moves left
} else {
self.x += 5; // The obese dog moves right
}
};
});
// Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.move = function () {
// Obstacle movement logic here
self.x -= 5; // The obstacle (dog) moves forward
};
});
// PufferFish class
var PufferFish = Container.expand(function () {
var self = Container.call(this);
var pufferFishGraphics = self.attachAsset('pufferFish', {
anchorX: 0.5,
anchorY: 0.5
});
self.move = function () {
// PufferFish movement logic here
self.x -= 10; // The puffer fish moves to the left faster
};
});
// Teleport class
var Teleport = Container.expand(function () {
var self = Container.call(this);
var teleportGraphics = self.attachAsset('teleport', {
anchorX: 0.5,
anchorY: 0.5
});
self.disappearTimeout = null; // Holds the timeout for disappearing
self.activate = function () {
// Set a timeout for the teleport to disappear after 3 seconds if not touched
self.disappearTimeout = LK.setTimeout(function () {
self.destroy();
teleports.splice(teleports.indexOf(self), 1);
}, 3000);
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Light blue background to represent the sky
});
/****
* Game Code
****/
var enemyCars = [];
var character = game.addChild(new Character());
character.x = 200;
character.y = 2732 / 2; // Start in the middle of the screen vertically
var obstacles = [];
var collectibles = [];
var pufferFishes = []; // Array to track PufferFish instances
var teleports = []; // Array to track Teleport instances
var score = 0;
// Score display
var scoreTxt = new Text2(score.toString(), {
size: 150,
fill: "#ffffff"
});
LK.gui.top.addChild(scoreTxt);
// Touch event to move the character
game.on('down', function (obj) {
var pos = obj.event.getLocalPosition(game);
character.targetX = pos.x; // Set target position for character
character.targetY = pos.y; // Set target position for character
});
var fishes = [];
var goldenFishes = [];
var clouds = [];
var obeseDogs = [];
var megaDogs = [];
// Game tick event
LK.on('tick', function () {
character.update();
// Move obstacles and check for collision with the character
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].move();
if (obstacles[i].intersects(character)) {
// Game over logic
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
// Check for collision with clouds
for (var j = clouds.length - 1; j >= 0; j--) {
if (obstacles[i] instanceof Bird) {
continue;
} // Skip if obstacle is a Bird
if (obstacles[i].intersects(clouds[j])) {
// Create an obese dog
var newObeseDog = new ObeseDog();
newObeseDog.x = obstacles[i].x;
newObeseDog.y = obstacles[i].y;
obeseDogs.push(newObeseDog);
game.addChild(newObeseDog);
// Remove the obstacle and the cloud
obstacles[i].destroy();
obstacles.splice(i, 1);
clouds[j].destroy();
clouds.splice(j, 1);
break;
}
}
// Remove off-screen obstacles
if (obstacles[i] && obstacles[i].x < -100) {
obstacles[i].destroy();
obstacles.splice(i, 1);
}
}
// Spawn obstacles
if (LK.ticks % 120 == 0) {
// Every 2 seconds
var newObstacle = new Obstacle();
newObstacle.x = 2048;
// Prevent dogs from appearing in the lane where the wall is
do {
newObstacle.y = Math.random() * 2732;
} while (Math.abs(newObstacle.y - character.y) < character.height);
obstacles.push(newObstacle);
game.addChild(newObstacle);
}
// Check for collectible collision
for (var j = collectibles.length - 1; j >= 0; j--) {
if (collectibles[j].intersects(character)) {
score += 10; // Increase score
scoreTxt.setText(score.toString()); // Update score display
collectibles[j].destroy();
collectibles.splice(j, 1);
}
}
// Move fishes and check for collision with the character
for (var k = fishes.length - 1; k >= 0; k--) {
fishes[k].move();
if (fishes[k].intersects(character)) {
score += 1; // Increase score
scoreTxt.setText(score.toString()); // Update score display
if (score % 10 == 0 && score != 0) {
var newMegaDog = new MegaDog();
newMegaDog.x = 2048;
newMegaDog.y = Math.random() * 2732;
megaDogs.push(newMegaDog);
game.addChild(newMegaDog);
}
fishes[k].destroy();
fishes.splice(k, 1);
}
// Remove off-screen fishes
if (fishes[k] && fishes[k].x < -100) {
fishes[k].destroy();
fishes.splice(k, 1);
}
}
// Move golden fishes and check for collision with the character
for (var l = goldenFishes.length - 1; l >= 0; l--) {
goldenFishes[l].move();
if (goldenFishes[l].intersects(character)) {
// Remove one obese dog
if (obeseDogs.length > 0) {
obeseDogs[0].destroy();
obeseDogs.splice(0, 1);
}
goldenFishes[l].destroy();
goldenFishes.splice(l, 1);
}
// Remove off-screen golden fishes
if (goldenFishes[l] && goldenFishes[l].x < -100) {
goldenFishes[l].destroy();
goldenFishes.splice(l, 1);
}
}
// Spawn fishes
if (LK.ticks % 240 == 0) {
// Every 4 seconds
var newFish = new Fish();
newFish.x = 2048;
newFish.y = Math.random() * 2732;
fishes.push(newFish);
game.addChild(newFish);
}
// Spawn golden fishes
if (LK.ticks % 900 == 0) {
// Every 15 seconds
var newGoldenFish = new GoldenFish();
newGoldenFish.x = 2048;
newGoldenFish.y = Math.random() * 2732;
goldenFishes.push(newGoldenFish);
game.addChild(newGoldenFish);
}
// Spawn clouds
if (LK.ticks % 300 == 0) {
// Every 5 seconds
var newCloud = new Cloud();
newCloud.x = Math.random() * 2048;
newCloud.y = 0;
clouds.push(newCloud);
game.addChild(newCloud);
}
// Move clouds and check for collision with the character
for (var l = clouds.length - 1; l >= 0; l--) {
clouds[l].move();
if (clouds[l].intersects(character)) {
// Game over logic
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
// Remove off-screen clouds
if (clouds[l].y > 2732) {
clouds[l].destroy();
clouds.splice(l, 1);
}
}
// Move obese dogs and check for collision with the character
for (var m = obeseDogs.length - 1; m >= 0; m--) {
obeseDogs[m].move();
if (obeseDogs[m].intersects(character)) {
// Game over logic
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
// Change direction when the obese dog reaches the edge of the screen
if (obeseDogs[m].x <= 0 && obeseDogs[m].direction === 'left') {
obeseDogs[m].direction = 'right';
} else if (obeseDogs[m].x >= 2048 && obeseDogs[m].direction === 'right') {
obeseDogs[m].direction = 'left';
}
// Remove off-screen obese dogs
if (obeseDogs[m].x < -100 || obeseDogs[m].x > 2148) {
obeseDogs[m].destroy();
obeseDogs.splice(m, 1);
}
// Move mega dogs and check for collision with the character
for (var n = megaDogs.length - 1; n >= 0; n--) {
megaDogs[n].move();
if (megaDogs[n].intersects(character)) {
// Game over logic
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
// Remove off-screen mega dogs
if (megaDogs[n].x < -100) {
megaDogs[n].destroy();
megaDogs.splice(n, 1);
}
}
}
// Check for teleport collision and activate effect
for (var i = teleports.length - 1; i >= 0; i--) {
if (teleports[i].intersects(character)) {
character.teleportActive = true; // Activate teleport effect
// Deactivate teleport effect after 5 seconds
LK.setTimeout(function () {
character.teleportActive = false;
}, 5000);
teleports[i].destroy();
teleports.splice(i, 1);
}
}
// Move PufferFishes and check for collision with the character
for (var i = pufferFishes.length - 1; i >= 0; i--) {
pufferFishes[i].move();
if (pufferFishes[i].intersects(character)) {
score -= 1; // Decrease score by 1
scoreTxt.setText(score.toString()); // Update score display
pufferFishes[i].destroy();
pufferFishes.splice(i, 1);
}
// Remove off-screen PufferFishes
if (pufferFishes[i] && pufferFishes[i].x < -100) {
pufferFishes[i].destroy();
pufferFishes.splice(i, 1);
}
}
// Move enemy cars, check for off-screen, and end game on collision with character
for (var i = enemyCars.length - 1; i >= 0; i--) {
enemyCars[i].move();
if (enemyCars[i].intersects(character)) {
// End game if character touches the car
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
if (enemyCars[i].x < -300) {
// Assuming the width of the car is 300
enemyCars[i].destroy();
enemyCars.splice(i, 1);
}
}
// Spawn Birds
if (LK.ticks % 900 == 0) {
// Every 15 seconds
var newBird = new Bird();
newBird.x = Math.random() * 2048; // Start from a random horizontal position
newBird.y = 0; // Start from the top
game.addChild(newBird);
obstacles.push(newBird); // Add the newBird to the obstacles array for collision detection
}
// Spawn enemy cars
if (LK.ticks % 600 == 0) {
// Every 10 seconds
var newEnemyCar = new EnemyCar();
newEnemyCar.x = 2048; // Start from the right edge
newEnemyCar.y = Math.random() * 2732; // Position randomly on the vertical axis
game.addChild(newEnemyCar);
enemyCars.push(newEnemyCar); // Add the newEnemyCar to the global enemyCars array for tracking
}
// Spawn PufferFish for negative scoring
if (LK.ticks % 180 == 0 && score >= 1 && score % 2 == 0) {
// Appears at the beginning of 1 point and every 2 points thereafter
var newPufferFish = new PufferFish();
newPufferFish.x = 2048; // Start from the right edge
newPufferFish.y = Math.random() * 2732; // Position randomly on the vertical axis
game.addChild(newPufferFish);
pufferFishes.push(newPufferFish); // Add the newPufferFish to the global pufferFishes array for tracking
}
// Spawn Teleport every 5 points, ensuring only 1 teleport appears at a time
if (score % 5 == 0 && score != 0 && teleports.length === 0 && !character.teleportActive) {
var newTeleport = new Teleport();
newTeleport.x = Math.random() * 2048;
newTeleport.y = Math.random() * 2732;
teleports.push(newTeleport);
game.addChild(newTeleport);
newTeleport.activate();
}
// Spawn collectibles
if (LK.ticks % 180 == 0) {
// Every 3 seconds
var newCollectible = new Collectible();
newCollectible.x = 2048;
newCollectible.y = Math.random() * 2732;
collectibles.push(newCollectible);
game.addChild(newCollectible);
}
});
cat. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Dog which goes to the left. 2D, Without background
Wall. 2D, Without background
cartoon fish. 2D, Without background
cartoon cloud. 2D, Without background
Cloud Dog. 2D
cartoon golden fish. 2D
Mega dog. 2D cartoon, no background
Bird. 2D cartoon, no background
Red car 2D. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Puffer fish. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
teleport 2D. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.