/****
* Classes
****/
// BonusUnhealthyFood class
var BonusUnhealthyFood = Container.expand(function () {
var self = Container.call(this);
var foodGraphics = self.attachAsset('unhealthyFood', {
anchorX: 0.5,
anchorY: 0.5
});
self.scale.x *= 2; // Scale to 200%
self.scale.y *= 2; // Scale to 200%
self.type = 'unhealthyFood';
self.speed = Math.random() * 5 + 1; // Random speed between 1 and 6
self.move = function () {
self.y += self.speed;
};
});
// Cloud class
var Cloud = Container.expand(function () {
var self = Container.call(this);
var cloudGraphics = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.move = function () {
self.x -= self.speed;
};
});
// Cloud2 class
var Cloud2 = Container.expand(function () {
var self = Container.call(this);
var cloudGraphics = self.attachAsset('cloud2', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.move = function () {
self.x -= self.speed;
};
});
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Enemy update logic here
};
});
// Food class
var Food = Container.expand(function (type) {
var self = Container.call(this);
var foodGraphics = self.attachAsset(type, {
anchorX: 0.5,
anchorY: 0.5
});
self.type = type;
self.speed = Math.random() * 5 + 1; // Random speed between 1 and 6
self.move = function () {
self.y += self.speed;
};
});
// Assets will be automatically created based on usage in the code.
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Player update logic here
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Light blue background
});
/****
* Game Code
****/
var background = game.addChild(LK.getAsset('background', {
anchorX: 0.0,
anchorY: 0.0,
x: 0,
y: 0
}));
var player = game.addChild(new Player());
player.x = 1024; // Center horizontally
player.y = 2500; // Near the bottom
player.scale.x *= 1.30;
player.scale.y *= 1.30;
var enemy = game.addChild(new Enemy());
enemy.y = player.y; // Same y position as the player
var foods = [];
var score = 0;
var scoreTxt = new Text2(score.toString(), {
size: 150,
fill: "#ffffff"
});
LK.gui.top.addChild(scoreTxt);
// Create food items at intervals
var cloudCreationTimer = LK.setInterval(function () {
if (Math.random() > 0.5) {
var cloud = new Cloud();
cloud.x = 2048; // Start from the right
cloud.y = Math.random() * 500; // Random position at the top
game.addChild(cloud);
} else {
var cloud2 = new Cloud2();
cloud2.x = 2048; // Start from the right
cloud2.y = Math.random() * 500; // Random position at the top
game.addChild(cloud2);
// 80% chance to spawn a bonusUnhealthyFood
if (Math.random() < 0.8) {
var bonusFood = new BonusUnhealthyFood();
bonusFood.x = Math.random() * (2048 - 150) + 50; // Random position between 50 and game canvas width - 100
bonusFood.y = cloud2.y; // Same y position as the cloud2
foods.push(bonusFood);
game.addChild(bonusFood);
}
}
}, 5000);
var foodCreationTimer = LK.setInterval(function () {
var foodType = Math.random() > 0.5 ? 'healthyFood' : 'unhealthyFood';
var food = new Food(foodType);
food.x = Math.random() * 2048; // Random position across the width
food.y = 0; // Start from the top
foods.push(food);
game.addChild(food);
}, 2000);
// Touch event to move player
game.on('down', function (obj) {
var pos = obj.event.getLocalPosition(game);
player.x = pos.x;
});
// Game tick
LK.on('tick', function () {
if (score === -1 || player.intersects(enemy)) {
LK.showGameOver();
}
player.update();
enemy.update();
// Change enemy's x position randomly
if (LK.ticks % 60 == 0) {
// Every second
do {
enemy.x = Math.random() * 2048; // Random position across the width
} while (enemy.intersects(player)); // Ensure enemy's x position is not the same as player's x position and does not intersect with the player
}
game.children.forEach(function (child) {
if (child instanceof Cloud || child instanceof Cloud2) {
child.move();
if (child.x < -200) {
// Off screen
child.destroy();
}
}
});
for (var i = foods.length - 1; i >= 0; i--) {
foods[i].move();
if (foods[i].y > 2732) {
// Off screen
if (foods[i].type === 'unhealthyFood') {
score -= 1;
scoreTxt.setText(score.toString());
}
foods[i].destroy();
foods.splice(i, 1);
} else if (player.intersects(foods[i])) {
if (foods[i] instanceof BonusUnhealthyFood) {
score += 1;
if (player.scale.x < 3 && player.scale.y < 3) {
player.scale.x *= 1.20;
player.scale.y *= 1.20;
player.y -= player.height * 0.1; // Adjust the y position of the player when the player scales
}
} else if (foods[i].type === 'unhealthyFood') {
score += 1;
if (score % 5 == 0) {
if (player.scale.x < 3 && player.scale.y < 3) {
player.scale.x *= 1.30;
player.scale.y *= 1.30;
player.y -= player.height * 0.15; // Adjust the y position of the player when the player scales
}
}
} else if (foods[i].type === 'unhealthyFood') {
score += 1;
if (score % 5 == 0) {
if (player.scale.x < 3 && player.scale.y < 3) {
player.scale.x *= 1.30;
player.scale.y *= 1.30;
player.y -= player.height * 0.15; // Adjust the y position of the player when the player scales
}
}
} else {
score -= 1;
if (player.scale.x > 1 && player.scale.y > 1) {
player.scale.x /= 1.30;
player.scale.y /= 1.30;
player.y += player.height * 0.15; // Adjust the y position of the player when the player scales down
}
}
scoreTxt.setText(score.toString());
foods[i].destroy();
foods.splice(i, 1);
}
}
});
// Ensure the score is updated in the game
scoreTxt.setText(LK.getScore().toString()); /****
* Classes
****/
// BonusUnhealthyFood class
var BonusUnhealthyFood = Container.expand(function () {
var self = Container.call(this);
var foodGraphics = self.attachAsset('unhealthyFood', {
anchorX: 0.5,
anchorY: 0.5
});
self.scale.x *= 2; // Scale to 200%
self.scale.y *= 2; // Scale to 200%
self.type = 'unhealthyFood';
self.speed = Math.random() * 5 + 1; // Random speed between 1 and 6
self.move = function () {
self.y += self.speed;
};
});
// Cloud class
var Cloud = Container.expand(function () {
var self = Container.call(this);
var cloudGraphics = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.move = function () {
self.x -= self.speed;
};
});
// Cloud2 class
var Cloud2 = Container.expand(function () {
var self = Container.call(this);
var cloudGraphics = self.attachAsset('cloud2', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.move = function () {
self.x -= self.speed;
};
});
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Enemy update logic here
};
});
// Food class
var Food = Container.expand(function (type) {
var self = Container.call(this);
var foodGraphics = self.attachAsset(type, {
anchorX: 0.5,
anchorY: 0.5
});
self.type = type;
self.speed = Math.random() * 5 + 1; // Random speed between 1 and 6
self.move = function () {
self.y += self.speed;
};
});
// Assets will be automatically created based on usage in the code.
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Player update logic here
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Light blue background
});
/****
* Game Code
****/
var background = game.addChild(LK.getAsset('background', {
anchorX: 0.0,
anchorY: 0.0,
x: 0,
y: 0
}));
var player = game.addChild(new Player());
player.x = 1024; // Center horizontally
player.y = 2500; // Near the bottom
player.scale.x *= 1.30;
player.scale.y *= 1.30;
var enemy = game.addChild(new Enemy());
enemy.y = player.y; // Same y position as the player
var foods = [];
var score = 0;
var scoreTxt = new Text2(score.toString(), {
size: 150,
fill: "#ffffff"
});
LK.gui.top.addChild(scoreTxt);
// Create food items at intervals
var cloudCreationTimer = LK.setInterval(function () {
if (Math.random() > 0.5) {
var cloud = new Cloud();
cloud.x = 2048; // Start from the right
cloud.y = Math.random() * 500; // Random position at the top
game.addChild(cloud);
} else {
var cloud2 = new Cloud2();
cloud2.x = 2048; // Start from the right
cloud2.y = Math.random() * 500; // Random position at the top
game.addChild(cloud2);
// 80% chance to spawn a bonusUnhealthyFood
if (Math.random() < 0.8) {
var bonusFood = new BonusUnhealthyFood();
bonusFood.x = Math.random() * (2048 - 150) + 50; // Random position between 50 and game canvas width - 100
bonusFood.y = cloud2.y; // Same y position as the cloud2
foods.push(bonusFood);
game.addChild(bonusFood);
}
}
}, 5000);
var foodCreationTimer = LK.setInterval(function () {
var foodType = Math.random() > 0.5 ? 'healthyFood' : 'unhealthyFood';
var food = new Food(foodType);
food.x = Math.random() * 2048; // Random position across the width
food.y = 0; // Start from the top
foods.push(food);
game.addChild(food);
}, 2000);
// Touch event to move player
game.on('down', function (obj) {
var pos = obj.event.getLocalPosition(game);
player.x = pos.x;
});
// Game tick
LK.on('tick', function () {
if (score === -1 || player.intersects(enemy)) {
LK.showGameOver();
}
player.update();
enemy.update();
// Change enemy's x position randomly
if (LK.ticks % 60 == 0) {
// Every second
do {
enemy.x = Math.random() * 2048; // Random position across the width
} while (enemy.intersects(player)); // Ensure enemy's x position is not the same as player's x position and does not intersect with the player
}
game.children.forEach(function (child) {
if (child instanceof Cloud || child instanceof Cloud2) {
child.move();
if (child.x < -200) {
// Off screen
child.destroy();
}
}
});
for (var i = foods.length - 1; i >= 0; i--) {
foods[i].move();
if (foods[i].y > 2732) {
// Off screen
if (foods[i].type === 'unhealthyFood') {
score -= 1;
scoreTxt.setText(score.toString());
}
foods[i].destroy();
foods.splice(i, 1);
} else if (player.intersects(foods[i])) {
if (foods[i] instanceof BonusUnhealthyFood) {
score += 1;
if (player.scale.x < 3 && player.scale.y < 3) {
player.scale.x *= 1.20;
player.scale.y *= 1.20;
player.y -= player.height * 0.1; // Adjust the y position of the player when the player scales
}
} else if (foods[i].type === 'unhealthyFood') {
score += 1;
if (score % 5 == 0) {
if (player.scale.x < 3 && player.scale.y < 3) {
player.scale.x *= 1.30;
player.scale.y *= 1.30;
player.y -= player.height * 0.15; // Adjust the y position of the player when the player scales
}
}
} else if (foods[i].type === 'unhealthyFood') {
score += 1;
if (score % 5 == 0) {
if (player.scale.x < 3 && player.scale.y < 3) {
player.scale.x *= 1.30;
player.scale.y *= 1.30;
player.y -= player.height * 0.15; // Adjust the y position of the player when the player scales
}
}
} else {
score -= 1;
if (player.scale.x > 1 && player.scale.y > 1) {
player.scale.x /= 1.30;
player.scale.y /= 1.30;
player.y += player.height * 0.15; // Adjust the y position of the player when the player scales down
}
}
scoreTxt.setText(score.toString());
foods[i].destroy();
foods.splice(i, 1);
}
}
});
// Ensure the score is updated in the game
scoreTxt.setText(LK.getScore().toString());
broccoli. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. 8bit
fat boy. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. 8bit. no background.
burger. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. 8bit. no background.
city with skyscrapers with a big street at the bottom. in-Game background asset. 2d. High contrast. No shadows. 8bit.
an evil rubber duck. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. 8bit
an evil broccoli airship. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. 8bit
an evil burger airship. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. 8bit