/****
* Classes
****/
// Define a class for Aloe
var Aloe = Container.expand(function () {
var self = Container.call(this);
var aloeGraphics = self.attachAsset('aloe', {
anchorX: 0.5,
anchorY: 0.5
});
self.shieldActive = true; // Shield is active initially
// Method to deactivate the shield
self.deactivateShield = function () {
self.shieldActive = false;
self.destroy(); // Remove Aloe from the game
};
// Update method for Aloe
self.update = function () {
// Calculate the angle for orbiting
if (!self.angle) {
self.angle = 0;
}
self.angle += 0.05; // Adjust speed of orbiting by changing this value
// Calculate new position for Aloe to orbit around the player
var radius = 150; // Distance from the player
self.x = player.x + radius * Math.cos(self.angle);
self.y = player.y + radius * Math.sin(self.angle);
// Check for collisions with enemies
for (var i = enemies.length - 1; i >= 0; i--) {
if (self.intersects(enemies[i])) {
enemies[i].destroy();
enemies.splice(i, 1);
self.destroy(); // Destroy Aloe as well
break; // Exit the loop as Aloe is destroyed
}
}
};
});
// Define a class for BossEnemy
var BossEnemy = Container.expand(function () {
var self = Container.call(this);
var bossGraphics = self.attachAsset('boss', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 1;
self.hitPoints = 10; // Boss requires multiple hits to be destroyed
self.update = function () {
self.y += self.speed;
if (self.lastY <= redLine.y && self.y > redLine.y) {
var newBossEnemy = new BossEnemy();
newBossEnemy.x = self.x;
newBossEnemy.y = self.y;
enemies.push(newBossEnemy);
game.addChild(newBossEnemy);
}
self.lastY = self.y;
if (self.y > 2732) {
self.y = 0;
self.x = Math.random() * 2048;
}
};
self.takeHit = function () {
self.hitPoints -= 1;
if (self.hitPoints <= 0) {
self.destroy();
}
};
});
// Define a class for bullets
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -5;
self.update = function () {
self.x += self.speedX || 0;
self.y += self.speedY || self.speed;
if (self.y < 0 || self.x < 0 || self.x > 2048 || self.y > 2732) {
self.destroy();
}
if (!self.soundPlayed) {
// Play bullet1 sound when bullet is used
LK.getSound('bullet1').play({
loop: false
});
self.soundPlayed = true;
}
};
});
// Define a class for the context menu
var ContextMenu = Container.expand(function () {
var self = Container.call(this);
var menuText = new Text2('Start Game', {
size: 150,
fill: 0xFFFFFF
});
menuText.anchor.set(0.5, 0.5);
self.addChild(menuText);
self.update = function () {
// Update logic for context menu
};
});
// Define a class for enemies
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.hitPoints = 1; // Requires one hit to be destroyed
self.update = function () {
self.takeHit = function () {
self.hitPoints -= 1;
if (self.hitPoints <= 0) {
self.destroy();
}
};
self.y += self.speed;
if (self.lastY <= redLine.y && self.y > redLine.y) {
var newEnemy = new Enemy();
newEnemy.x = self.x;
newEnemy.y = self.y;
enemies.push(newEnemy);
game.addChild(newEnemy);
}
self.lastY = self.y;
if (self.y > 2732) {
self.y = 0;
self.x = Math.random() * 2048;
}
};
});
// Define a class for Fleisch
var Fleisch = Container.expand(function () {
var self = Container.call(this);
var fleischGraphics = self.attachAsset('Fleisch', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Add close distance multiple shots ability for Fleisch
if (player.lastY !== undefined && player.y !== player.lastY) {
self.x += (player.y - player.lastY) * 0.4; // Adjust the multiplier for desired sensitivity
}
if (LK.ticks % Math.max(30, 600 * Math.pow(0.5, Math.floor(player.currency / 50))) == 0) {
for (var angle = -0.2; angle <= 0.2; angle += 0.1) {
var newBullet = new Bullet();
newBullet.x = self.x;
newBullet.y = self.y;
newBullet.speedX = Math.sin(angle) * self.speed;
newBullet.speedY = Math.cos(angle) * self.speed;
newBullet.lastY = newBullet.y;
newBullet.lastIntersecting = newBullet.intersects(centerNode);
bullets.push(newBullet);
game.addChild(newBullet);
}
}
};
});
var Kaktus = Container.expand(function () {
var self = Container.call(this);
var kaktusGraphics = self.attachAsset('Kaktus', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Kaktus destroys every unit it intersects with
for (var i = enemies.length - 1; i >= 0; i--) {
if (self.intersects(enemies[i])) {
enemies[i].destroy();
enemies.splice(i, 1);
self.destroy(); // Destroy Kaktus as well
break; // Exit the loop as Kaktus is destroyed
}
}
};
});
// Define a class for Pfeilchen
var Pfeilchen = Container.expand(function () {
var self = Container.call(this);
var pfeilchenGraphics = self.attachAsset('Pfeilchen', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.shootDirection = 'up'; // Default shooting direction
// Method to shoot bullets in the specified direction
self.shoot = function () {
var bullet = new Bullet();
bullet.x = self.x;
bullet.y = self.y;
bullet.speedX = 0; // Initialize speedX
bullet.speedY = 0; // Initialize speedY
switch (self.shootDirection) {
case 'up':
bullet.speedY = -self.speed;
break;
case 'down':
bullet.speedY = self.speed;
break;
case 'left':
bullet.speedX = -self.speed;
break;
case 'right':
bullet.speedX = self.speed;
break;
}
bullets.push(bullet);
game.addChild(bullet);
};
self.update = function () {
// Update logic for Pfeilchen
};
});
// Define a class for plants
var Plant = Container.expand(function () {
var self = Container.call(this);
self.update = function () {
// Update logic for plants
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Define a class for the player character
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.slot = 0; // Add slot property to player
self.currency = 0; // Initialize currency property
self.update = function () {
// Update logic for player
};
});
// Define a class for rose
var Rose = Container.expand(function () {
var self = Container.call(this);
var roseGraphics = self.attachAsset('rose', {
anchorX: 0.5,
anchorY: 0.5,
rotation: -Math.PI / 2 // Rotate 90 degrees to the left
});
// Add a red line above the Rose
var redLine = new Container();
var lineGraphics = LK.getAsset('redLine', {
anchorX: 0.5,
anchorY: 0.5
});
lineGraphics.x = 0; // Center the red line horizontally
lineGraphics.y = -roseGraphics.height / 2 - 10; // Position the red line above the Rose
redLine.addChild(lineGraphics);
self.addChild(redLine);
self.speed = 5;
self.update = function () {
if (self.y < 0) {
self.destroy();
}
if (LK.ticks % Math.max(60, 600 * Math.pow(0.9, Math.floor(player.currency / 10))) == 0) {
var newBullet = new Bullet();
newBullet.x = self.x;
newBullet.y = self.y;
var dx = fleisch.x - self.x;
var dy = fleisch.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
newBullet.speedX = dx / distance * self.speed;
newBullet.speedY = dy / distance * self.speed;
newBullet.lastY = newBullet.y;
newBullet.lastIntersecting = newBullet.intersects(centerNode);
bullets.push(newBullet);
game.addChild(newBullet);
}
};
});
// Define a class for the Shop
var Shop = Container.expand(function () {
var self = Container.call(this);
var shopGraphics = self.attachAsset('menu', {
anchorX: 0.5,
anchorY: 0.5
});
self.visible = false; // Initially hidden
// Method to show the shop
self.show = function () {
self.visible = true;
};
// Method to hide the shop
self.hide = function () {
self.visible = false;
};
// Method to purchase an upgrade
self.purchaseUpgrade = function (cost, upgradeFunction) {
if (player.currency >= cost) {
player.currency -= cost;
currencyText.setText('Currency: ' + player.currency);
upgradeFunction();
}
};
// Example upgrade function
self.upgradePlant = function () {
self.purchaseUpgrade(10, function () {
// Implement the upgrade logic here
console.log("Plant upgraded!");
});
};
});
// Define a class for Sonne
var Sonne = Container.expand(function () {
var self = Container.call(this);
var sonneGraphics = self.attachAsset('Sonne', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = 0;
self.x = Math.random() * 2048;
}
// Automatic shooting logic for Sonne
if (LK.ticks % 120 == 0) {
// Adjust the frequency as needed
for (var i = 0; i < enemies.length; i++) {
var enemy = enemies[i];
var newBullet = new Bullet();
newBullet.x = self.x;
newBullet.y = self.y;
var dx = enemy.x - self.x;
var dy = enemy.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
newBullet.speedX = dx / distance * self.speed;
newBullet.speedY = dy / distance * self.speed;
newBullet.lastY = newBullet.y;
newBullet.lastIntersecting = newBullet.intersects(enemy);
bullets.push(newBullet);
game.addChild(newBullet);
}
}
};
});
// Define a class for ToughEnemy
var ToughEnemy = Container.expand(function () {
var self = Container.call(this);
var toughEnemyGraphics = self.attachAsset('toughEnemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.hitPoints = 2; // Requires two hits to be destroyed
self.update = function () {
self.y += self.speed;
if (self.lastY <= redLine.y && self.y > redLine.y) {
var newToughEnemy = new ToughEnemy();
newToughEnemy.x = self.x;
newToughEnemy.y = self.y;
enemies.push(newToughEnemy);
game.addChild(newToughEnemy);
}
self.lastY = self.y;
if (self.y > 2732) {
self.y = 0;
self.x = Math.random() * 2048;
}
};
self.takeHit = function () {
self.hitPoints -= 1;
if (self.hitPoints <= 0) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize the shop
var shop = game.addChild(new Shop());
shop.x = 1024; // Center horizontally on the screen
shop.y = 1366; // Center vertically on the screen
var background = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
});
game.addChild(background); // Ensure background is added to the game
background.zIndex = -1; // Ensure background is always at the back
// Initialize Pfeilchen
var pfeilchen = game.addChild(new Pfeilchen());
pfeilchen.x = 1024; // Center horizontally on the screen
pfeilchen.y = 1466; // Move Pfeilchen 100 pixels down
// Initialize game state
var gameState = "menu";
// Initialize level
var level = 1;
// Initialize level text
var levelText;
// Initialize currency text
var currencyText = new Text2('Currency: 0', {
size: 100,
fill: 0xFFFFFF
});
currencyText.anchor.set(0.5, 0);
LK.gui.top.addChild(currencyText);
// Initialize shop button
var shopButton = LK.getAsset('menu', {
anchorX: 1,
anchorY: 1,
x: 2048,
y: 2732
});
shopButton.anchor.set(1, 1);
shopButton.x = 2048 - shopButton.width; // Adjust position to ensure visibility on the right edge
shopButton.y = 2732 - shopButton.height; // Adjust position to ensure visibility at the bottom edge
shopButton.interactive = true;
shopButton.visible = true; // Make visible when game starts
shopButton.on('down', function () {
shop.show();
});
// Add a text label 'Shop' to the bottom right
var shopText = new Text2('Shop', {
size: 100,
fill: 0xFFFFFF
});
shopText.anchor.set(1, 1);
shopText.x = 2048; // Position at the right edge
shopText.y = 2732; // Position at the bottom edge
shopText.interactive = true;
shopText.on('down', function () {
shop.show();
});
LK.gui.bottomRight.addChild(shopText);
LK.gui.bottomRight.addChild(shopButton);
// Initialize context menu
var contextMenu = game.addChild(new ContextMenu());
contextMenu.x = 1024;
contextMenu.y = 1366;
contextMenu.visible = true; // Make the context menu visible during the game
// Initialize players
var players = [];
var player = game.addChild(new Player());
player.x = 1024;
player.y = 1366;
players.push(player);
// Initialize centerNode
var centerNode = game.addChild(LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
// Initialize Fleisch
var fleisch = new Fleisch();
game.addChild(fleisch);
fleisch.x = 1024; // Center horizontally on the screen
fleisch.y = 100; // Move Fleisch 80 pixels down from its current position
fleisch.visible = true; // Initialize Fleisch as visible
fleisch.interactive = true; // Enable Fleisch interaction
// Initialize redLine
var redLine = LK.getAsset('redLine', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 2732 - 106.22 / 2 - 10 // Position redLine above the Rose using Rose's height
});
game.addChild(redLine);
// Initialize rose
var rose = game.addChild(new Rose());
rose.x = 1024; // Center horizontally on the screen
rose.y = 2732 - rose.height / 2; // Position Rose at the bottom of the screen
// Initialize Aloe
var aloe = new Aloe();
aloe.x = 0; // Position Aloe at the top left corner
aloe.y = 0;
game.addChild(aloe);
// Initialize Sonne
var sonne = game.addChild(new Sonne());
sonne.x = Math.random() * 2048;
sonne.y = Math.random() * 100;
// Initialize plants
var plants = [];
for (var i = 0; i < 5; i++) {
var plant = new Plant();
plant.x = Math.random() * 2048;
plant.y = Math.random() * 2732;
plants.push(plant);
game.addChild(plant);
}
// Initialize enemies
var enemies = [];
// Initialize bullets
var bullets = [];
// Handle player movement
game.move = function (x, y, obj) {
player.lastY = player.y;
player.x = x;
player.y = y;
};
// Handle shooting
game.down = function (x, y, obj) {
if (gameState === "menu") {
gameState = "playing";
contextMenu.destroy();
LK.playMusic('Song1'); // Play song1 in the background after starting the game
shopButton.visible = true; // Show shop button when game starts
// Initialize level text
levelText = new Text2('Level: ' + level, {
size: 100,
fill: 0xFFFFFF
});
levelText.anchor.set(0.5, 1);
LK.gui.bottom.addChild(levelText);
// Removed automatic enemy generation when game starts
} else if (gameState === "playing") {
// Handle shooting for Pfeilchen
// Determine shooting direction based on player input
if (x < pfeilchen.x) {
pfeilchen.shootDirection = 'left';
} else if (x > pfeilchen.x) {
pfeilchen.shootDirection = 'right';
} else if (y < pfeilchen.y) {
pfeilchen.shootDirection = 'up';
} else {
pfeilchen.shootDirection = 'down';
}
pfeilchen.shoot();
// Handle shooting for Player
var playerBullet = new Bullet();
playerBullet.x = player.x;
playerBullet.y = player.y;
playerBullet.speedX = (x - player.x) / Math.sqrt(Math.pow(x - player.x, 2) + Math.pow(y - player.y, 2)) * player.speed;
playerBullet.speedY = (y - player.y) / Math.sqrt(Math.pow(x - player.x, 2) + Math.pow(y - player.y, 2)) * player.speed;
bullets.push(playerBullet);
game.addChild(playerBullet);
}
};
// Update game state
game.update = function () {
if (gameState === "playing") {
// Update player
player.update();
// Update enemies
for (var i = 0; i < enemies.length; i++) {
enemies[i].update();
}
// Update bullets
for (var j = bullets.length - 1; j >= 0; j--) {
bullets[j].update();
if (bullets[j].y < 0 || bullets[j].x < 0 || bullets[j].x > 2048 || bullets[j].y > 2732) {
bullets.splice(j, 1);
}
}
// Check for collisions
for (var k = bullets.length - 1; k >= 0; k--) {
for (var l = enemies.length - 1; l >= 0; l--) {
if (bullets[k].intersects(enemies[l])) {
bullets[k].destroy();
bullets.splice(k, 1);
enemies[l].takeHit();
if (enemies[l].hitPoints <= 0) {
player.currency += enemies[l] instanceof BossEnemy ? 10 : enemies[l] instanceof ToughEnemy ? 5 : 1;
currencyText.setText('Currency: ' + player.currency);
LK.getSound('pew1').play({
loop: false
}); // Play pew1 sound when an enemy is destroyed
enemies.splice(l, 1);
// Check if 10 enemies have been destroyed
if (player.currency % 5 === 0) {
if (game.children.filter(function (child) {
return child instanceof Kaktus;
}).length < 20) {
var newKaktus = new Kaktus();
newKaktus.x = player.x;
newKaktus.y = player.y;
game.addChild(newKaktus);
}
}
if (player.currency % 10 === 0) {
if (game.children.filter(function (child) {
return child instanceof Aloe;
}).length < 11) {
var newAloe = new Aloe();
newAloe.x = player.x;
newAloe.y = player.y;
game.addChild(newAloe);
}
}
}
break;
}
}
}
// Check for collisions between Aloe and enemies
for (var n = enemies.length - 1; n >= 0; n--) {
if (aloe.intersects(enemies[n])) {
enemies[n].destroy();
enemies.splice(n, 1);
}
}
// Check for collisions between player and enemies
for (var m = 0; m < players.length; m++) {
for (var n = enemies.length - 1; n >= 0; n--) {
if (players[m].intersects(enemies[n])) {
if (aloe.parent) {
// Check if Aloe is on the screen
aloe.deactivateShield(); // Use Aloe's shield to take the hit
} else {
players[m].destroy();
players.splice(m, 1);
}
break;
}
}
}
// Display game over when no players are left
if (players.length === 0) {
LK.showGameOver();
}
// Reinitialize rose when it's destroyed
if (!rose.parent) {
rose = game.addChild(LK.getAsset('rose', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 1366
}));
}
// Increase level and start the next level immediately if all enemies are destroyed
if (enemies.length === 0) {
// Unlock Rose when reaching level 5
if (level === 5) {
rose.visible = true; // Make Rose visible
}
level++;
levelText.setText('Level: ' + level);
// Generate enemies for the next level
var enemyCount = 5; // Limit the number of enemies to 5 per level
for (var i = 0; i < enemyCount; i++) {
var enemy;
if (level > 15) {
enemy = Math.random() < 0.33 ? new BossEnemy() : Math.random() < 0.5 ? new ToughEnemy() : new Enemy();
} else if (level > 10) {
enemy = new BossEnemy();
} else if (level > 5) {
enemy = new ToughEnemy();
} else {
enemy = new Enemy();
}
enemy.x = Math.random() * 2048;
enemy.y = Math.random() * 1000;
enemies.push(enemy);
game.addChild(enemy);
}
}
} else if (gameState === "menu") {
// Update context menu
contextMenu.update();
}
};
// Example condition to open the shop
if (player.currency >= 20 && !shop.visible) {
shop.show();
}
// Example condition to close the shop
if (shop.visible) {
shop.hide();
} /****
* Classes
****/
// Define a class for Aloe
var Aloe = Container.expand(function () {
var self = Container.call(this);
var aloeGraphics = self.attachAsset('aloe', {
anchorX: 0.5,
anchorY: 0.5
});
self.shieldActive = true; // Shield is active initially
// Method to deactivate the shield
self.deactivateShield = function () {
self.shieldActive = false;
self.destroy(); // Remove Aloe from the game
};
// Update method for Aloe
self.update = function () {
// Calculate the angle for orbiting
if (!self.angle) {
self.angle = 0;
}
self.angle += 0.05; // Adjust speed of orbiting by changing this value
// Calculate new position for Aloe to orbit around the player
var radius = 150; // Distance from the player
self.x = player.x + radius * Math.cos(self.angle);
self.y = player.y + radius * Math.sin(self.angle);
// Check for collisions with enemies
for (var i = enemies.length - 1; i >= 0; i--) {
if (self.intersects(enemies[i])) {
enemies[i].destroy();
enemies.splice(i, 1);
self.destroy(); // Destroy Aloe as well
break; // Exit the loop as Aloe is destroyed
}
}
};
});
// Define a class for BossEnemy
var BossEnemy = Container.expand(function () {
var self = Container.call(this);
var bossGraphics = self.attachAsset('boss', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 1;
self.hitPoints = 10; // Boss requires multiple hits to be destroyed
self.update = function () {
self.y += self.speed;
if (self.lastY <= redLine.y && self.y > redLine.y) {
var newBossEnemy = new BossEnemy();
newBossEnemy.x = self.x;
newBossEnemy.y = self.y;
enemies.push(newBossEnemy);
game.addChild(newBossEnemy);
}
self.lastY = self.y;
if (self.y > 2732) {
self.y = 0;
self.x = Math.random() * 2048;
}
};
self.takeHit = function () {
self.hitPoints -= 1;
if (self.hitPoints <= 0) {
self.destroy();
}
};
});
// Define a class for bullets
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -5;
self.update = function () {
self.x += self.speedX || 0;
self.y += self.speedY || self.speed;
if (self.y < 0 || self.x < 0 || self.x > 2048 || self.y > 2732) {
self.destroy();
}
if (!self.soundPlayed) {
// Play bullet1 sound when bullet is used
LK.getSound('bullet1').play({
loop: false
});
self.soundPlayed = true;
}
};
});
// Define a class for the context menu
var ContextMenu = Container.expand(function () {
var self = Container.call(this);
var menuText = new Text2('Start Game', {
size: 150,
fill: 0xFFFFFF
});
menuText.anchor.set(0.5, 0.5);
self.addChild(menuText);
self.update = function () {
// Update logic for context menu
};
});
// Define a class for enemies
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.hitPoints = 1; // Requires one hit to be destroyed
self.update = function () {
self.takeHit = function () {
self.hitPoints -= 1;
if (self.hitPoints <= 0) {
self.destroy();
}
};
self.y += self.speed;
if (self.lastY <= redLine.y && self.y > redLine.y) {
var newEnemy = new Enemy();
newEnemy.x = self.x;
newEnemy.y = self.y;
enemies.push(newEnemy);
game.addChild(newEnemy);
}
self.lastY = self.y;
if (self.y > 2732) {
self.y = 0;
self.x = Math.random() * 2048;
}
};
});
// Define a class for Fleisch
var Fleisch = Container.expand(function () {
var self = Container.call(this);
var fleischGraphics = self.attachAsset('Fleisch', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Add close distance multiple shots ability for Fleisch
if (player.lastY !== undefined && player.y !== player.lastY) {
self.x += (player.y - player.lastY) * 0.4; // Adjust the multiplier for desired sensitivity
}
if (LK.ticks % Math.max(30, 600 * Math.pow(0.5, Math.floor(player.currency / 50))) == 0) {
for (var angle = -0.2; angle <= 0.2; angle += 0.1) {
var newBullet = new Bullet();
newBullet.x = self.x;
newBullet.y = self.y;
newBullet.speedX = Math.sin(angle) * self.speed;
newBullet.speedY = Math.cos(angle) * self.speed;
newBullet.lastY = newBullet.y;
newBullet.lastIntersecting = newBullet.intersects(centerNode);
bullets.push(newBullet);
game.addChild(newBullet);
}
}
};
});
var Kaktus = Container.expand(function () {
var self = Container.call(this);
var kaktusGraphics = self.attachAsset('Kaktus', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Kaktus destroys every unit it intersects with
for (var i = enemies.length - 1; i >= 0; i--) {
if (self.intersects(enemies[i])) {
enemies[i].destroy();
enemies.splice(i, 1);
self.destroy(); // Destroy Kaktus as well
break; // Exit the loop as Kaktus is destroyed
}
}
};
});
// Define a class for Pfeilchen
var Pfeilchen = Container.expand(function () {
var self = Container.call(this);
var pfeilchenGraphics = self.attachAsset('Pfeilchen', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.shootDirection = 'up'; // Default shooting direction
// Method to shoot bullets in the specified direction
self.shoot = function () {
var bullet = new Bullet();
bullet.x = self.x;
bullet.y = self.y;
bullet.speedX = 0; // Initialize speedX
bullet.speedY = 0; // Initialize speedY
switch (self.shootDirection) {
case 'up':
bullet.speedY = -self.speed;
break;
case 'down':
bullet.speedY = self.speed;
break;
case 'left':
bullet.speedX = -self.speed;
break;
case 'right':
bullet.speedX = self.speed;
break;
}
bullets.push(bullet);
game.addChild(bullet);
};
self.update = function () {
// Update logic for Pfeilchen
};
});
// Define a class for plants
var Plant = Container.expand(function () {
var self = Container.call(this);
self.update = function () {
// Update logic for plants
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Define a class for the player character
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.slot = 0; // Add slot property to player
self.currency = 0; // Initialize currency property
self.update = function () {
// Update logic for player
};
});
// Define a class for rose
var Rose = Container.expand(function () {
var self = Container.call(this);
var roseGraphics = self.attachAsset('rose', {
anchorX: 0.5,
anchorY: 0.5,
rotation: -Math.PI / 2 // Rotate 90 degrees to the left
});
// Add a red line above the Rose
var redLine = new Container();
var lineGraphics = LK.getAsset('redLine', {
anchorX: 0.5,
anchorY: 0.5
});
lineGraphics.x = 0; // Center the red line horizontally
lineGraphics.y = -roseGraphics.height / 2 - 10; // Position the red line above the Rose
redLine.addChild(lineGraphics);
self.addChild(redLine);
self.speed = 5;
self.update = function () {
if (self.y < 0) {
self.destroy();
}
if (LK.ticks % Math.max(60, 600 * Math.pow(0.9, Math.floor(player.currency / 10))) == 0) {
var newBullet = new Bullet();
newBullet.x = self.x;
newBullet.y = self.y;
var dx = fleisch.x - self.x;
var dy = fleisch.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
newBullet.speedX = dx / distance * self.speed;
newBullet.speedY = dy / distance * self.speed;
newBullet.lastY = newBullet.y;
newBullet.lastIntersecting = newBullet.intersects(centerNode);
bullets.push(newBullet);
game.addChild(newBullet);
}
};
});
// Define a class for the Shop
var Shop = Container.expand(function () {
var self = Container.call(this);
var shopGraphics = self.attachAsset('menu', {
anchorX: 0.5,
anchorY: 0.5
});
self.visible = false; // Initially hidden
// Method to show the shop
self.show = function () {
self.visible = true;
};
// Method to hide the shop
self.hide = function () {
self.visible = false;
};
// Method to purchase an upgrade
self.purchaseUpgrade = function (cost, upgradeFunction) {
if (player.currency >= cost) {
player.currency -= cost;
currencyText.setText('Currency: ' + player.currency);
upgradeFunction();
}
};
// Example upgrade function
self.upgradePlant = function () {
self.purchaseUpgrade(10, function () {
// Implement the upgrade logic here
console.log("Plant upgraded!");
});
};
});
// Define a class for Sonne
var Sonne = Container.expand(function () {
var self = Container.call(this);
var sonneGraphics = self.attachAsset('Sonne', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = 0;
self.x = Math.random() * 2048;
}
// Automatic shooting logic for Sonne
if (LK.ticks % 120 == 0) {
// Adjust the frequency as needed
for (var i = 0; i < enemies.length; i++) {
var enemy = enemies[i];
var newBullet = new Bullet();
newBullet.x = self.x;
newBullet.y = self.y;
var dx = enemy.x - self.x;
var dy = enemy.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
newBullet.speedX = dx / distance * self.speed;
newBullet.speedY = dy / distance * self.speed;
newBullet.lastY = newBullet.y;
newBullet.lastIntersecting = newBullet.intersects(enemy);
bullets.push(newBullet);
game.addChild(newBullet);
}
}
};
});
// Define a class for ToughEnemy
var ToughEnemy = Container.expand(function () {
var self = Container.call(this);
var toughEnemyGraphics = self.attachAsset('toughEnemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.hitPoints = 2; // Requires two hits to be destroyed
self.update = function () {
self.y += self.speed;
if (self.lastY <= redLine.y && self.y > redLine.y) {
var newToughEnemy = new ToughEnemy();
newToughEnemy.x = self.x;
newToughEnemy.y = self.y;
enemies.push(newToughEnemy);
game.addChild(newToughEnemy);
}
self.lastY = self.y;
if (self.y > 2732) {
self.y = 0;
self.x = Math.random() * 2048;
}
};
self.takeHit = function () {
self.hitPoints -= 1;
if (self.hitPoints <= 0) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize the shop
var shop = game.addChild(new Shop());
shop.x = 1024; // Center horizontally on the screen
shop.y = 1366; // Center vertically on the screen
var background = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
});
game.addChild(background); // Ensure background is added to the game
background.zIndex = -1; // Ensure background is always at the back
// Initialize Pfeilchen
var pfeilchen = game.addChild(new Pfeilchen());
pfeilchen.x = 1024; // Center horizontally on the screen
pfeilchen.y = 1466; // Move Pfeilchen 100 pixels down
// Initialize game state
var gameState = "menu";
// Initialize level
var level = 1;
// Initialize level text
var levelText;
// Initialize currency text
var currencyText = new Text2('Currency: 0', {
size: 100,
fill: 0xFFFFFF
});
currencyText.anchor.set(0.5, 0);
LK.gui.top.addChild(currencyText);
// Initialize shop button
var shopButton = LK.getAsset('menu', {
anchorX: 1,
anchorY: 1,
x: 2048,
y: 2732
});
shopButton.anchor.set(1, 1);
shopButton.x = 2048 - shopButton.width; // Adjust position to ensure visibility on the right edge
shopButton.y = 2732 - shopButton.height; // Adjust position to ensure visibility at the bottom edge
shopButton.interactive = true;
shopButton.visible = true; // Make visible when game starts
shopButton.on('down', function () {
shop.show();
});
// Add a text label 'Shop' to the bottom right
var shopText = new Text2('Shop', {
size: 100,
fill: 0xFFFFFF
});
shopText.anchor.set(1, 1);
shopText.x = 2048; // Position at the right edge
shopText.y = 2732; // Position at the bottom edge
shopText.interactive = true;
shopText.on('down', function () {
shop.show();
});
LK.gui.bottomRight.addChild(shopText);
LK.gui.bottomRight.addChild(shopButton);
// Initialize context menu
var contextMenu = game.addChild(new ContextMenu());
contextMenu.x = 1024;
contextMenu.y = 1366;
contextMenu.visible = true; // Make the context menu visible during the game
// Initialize players
var players = [];
var player = game.addChild(new Player());
player.x = 1024;
player.y = 1366;
players.push(player);
// Initialize centerNode
var centerNode = game.addChild(LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
// Initialize Fleisch
var fleisch = new Fleisch();
game.addChild(fleisch);
fleisch.x = 1024; // Center horizontally on the screen
fleisch.y = 100; // Move Fleisch 80 pixels down from its current position
fleisch.visible = true; // Initialize Fleisch as visible
fleisch.interactive = true; // Enable Fleisch interaction
// Initialize redLine
var redLine = LK.getAsset('redLine', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 2732 - 106.22 / 2 - 10 // Position redLine above the Rose using Rose's height
});
game.addChild(redLine);
// Initialize rose
var rose = game.addChild(new Rose());
rose.x = 1024; // Center horizontally on the screen
rose.y = 2732 - rose.height / 2; // Position Rose at the bottom of the screen
// Initialize Aloe
var aloe = new Aloe();
aloe.x = 0; // Position Aloe at the top left corner
aloe.y = 0;
game.addChild(aloe);
// Initialize Sonne
var sonne = game.addChild(new Sonne());
sonne.x = Math.random() * 2048;
sonne.y = Math.random() * 100;
// Initialize plants
var plants = [];
for (var i = 0; i < 5; i++) {
var plant = new Plant();
plant.x = Math.random() * 2048;
plant.y = Math.random() * 2732;
plants.push(plant);
game.addChild(plant);
}
// Initialize enemies
var enemies = [];
// Initialize bullets
var bullets = [];
// Handle player movement
game.move = function (x, y, obj) {
player.lastY = player.y;
player.x = x;
player.y = y;
};
// Handle shooting
game.down = function (x, y, obj) {
if (gameState === "menu") {
gameState = "playing";
contextMenu.destroy();
LK.playMusic('Song1'); // Play song1 in the background after starting the game
shopButton.visible = true; // Show shop button when game starts
// Initialize level text
levelText = new Text2('Level: ' + level, {
size: 100,
fill: 0xFFFFFF
});
levelText.anchor.set(0.5, 1);
LK.gui.bottom.addChild(levelText);
// Removed automatic enemy generation when game starts
} else if (gameState === "playing") {
// Handle shooting for Pfeilchen
// Determine shooting direction based on player input
if (x < pfeilchen.x) {
pfeilchen.shootDirection = 'left';
} else if (x > pfeilchen.x) {
pfeilchen.shootDirection = 'right';
} else if (y < pfeilchen.y) {
pfeilchen.shootDirection = 'up';
} else {
pfeilchen.shootDirection = 'down';
}
pfeilchen.shoot();
// Handle shooting for Player
var playerBullet = new Bullet();
playerBullet.x = player.x;
playerBullet.y = player.y;
playerBullet.speedX = (x - player.x) / Math.sqrt(Math.pow(x - player.x, 2) + Math.pow(y - player.y, 2)) * player.speed;
playerBullet.speedY = (y - player.y) / Math.sqrt(Math.pow(x - player.x, 2) + Math.pow(y - player.y, 2)) * player.speed;
bullets.push(playerBullet);
game.addChild(playerBullet);
}
};
// Update game state
game.update = function () {
if (gameState === "playing") {
// Update player
player.update();
// Update enemies
for (var i = 0; i < enemies.length; i++) {
enemies[i].update();
}
// Update bullets
for (var j = bullets.length - 1; j >= 0; j--) {
bullets[j].update();
if (bullets[j].y < 0 || bullets[j].x < 0 || bullets[j].x > 2048 || bullets[j].y > 2732) {
bullets.splice(j, 1);
}
}
// Check for collisions
for (var k = bullets.length - 1; k >= 0; k--) {
for (var l = enemies.length - 1; l >= 0; l--) {
if (bullets[k].intersects(enemies[l])) {
bullets[k].destroy();
bullets.splice(k, 1);
enemies[l].takeHit();
if (enemies[l].hitPoints <= 0) {
player.currency += enemies[l] instanceof BossEnemy ? 10 : enemies[l] instanceof ToughEnemy ? 5 : 1;
currencyText.setText('Currency: ' + player.currency);
LK.getSound('pew1').play({
loop: false
}); // Play pew1 sound when an enemy is destroyed
enemies.splice(l, 1);
// Check if 10 enemies have been destroyed
if (player.currency % 5 === 0) {
if (game.children.filter(function (child) {
return child instanceof Kaktus;
}).length < 20) {
var newKaktus = new Kaktus();
newKaktus.x = player.x;
newKaktus.y = player.y;
game.addChild(newKaktus);
}
}
if (player.currency % 10 === 0) {
if (game.children.filter(function (child) {
return child instanceof Aloe;
}).length < 11) {
var newAloe = new Aloe();
newAloe.x = player.x;
newAloe.y = player.y;
game.addChild(newAloe);
}
}
}
break;
}
}
}
// Check for collisions between Aloe and enemies
for (var n = enemies.length - 1; n >= 0; n--) {
if (aloe.intersects(enemies[n])) {
enemies[n].destroy();
enemies.splice(n, 1);
}
}
// Check for collisions between player and enemies
for (var m = 0; m < players.length; m++) {
for (var n = enemies.length - 1; n >= 0; n--) {
if (players[m].intersects(enemies[n])) {
if (aloe.parent) {
// Check if Aloe is on the screen
aloe.deactivateShield(); // Use Aloe's shield to take the hit
} else {
players[m].destroy();
players.splice(m, 1);
}
break;
}
}
}
// Display game over when no players are left
if (players.length === 0) {
LK.showGameOver();
}
// Reinitialize rose when it's destroyed
if (!rose.parent) {
rose = game.addChild(LK.getAsset('rose', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 1366
}));
}
// Increase level and start the next level immediately if all enemies are destroyed
if (enemies.length === 0) {
// Unlock Rose when reaching level 5
if (level === 5) {
rose.visible = true; // Make Rose visible
}
level++;
levelText.setText('Level: ' + level);
// Generate enemies for the next level
var enemyCount = 5; // Limit the number of enemies to 5 per level
for (var i = 0; i < enemyCount; i++) {
var enemy;
if (level > 15) {
enemy = Math.random() < 0.33 ? new BossEnemy() : Math.random() < 0.5 ? new ToughEnemy() : new Enemy();
} else if (level > 10) {
enemy = new BossEnemy();
} else if (level > 5) {
enemy = new ToughEnemy();
} else {
enemy = new Enemy();
}
enemy.x = Math.random() * 2048;
enemy.y = Math.random() * 1000;
enemies.push(enemy);
game.addChild(enemy);
}
}
} else if (gameState === "menu") {
// Update context menu
contextMenu.update();
}
};
// Example condition to open the shop
if (player.currency >= 20 && !shop.visible) {
shop.show();
}
// Example condition to close the shop
if (shop.visible) {
shop.hide();
}
2D squirrel with cowboy hat. Single Game Texture. In-Game asset. 2d. High contrast. No shadows
crosshair. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Aloe. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
meat eating plant. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
fly. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
red dot. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
rose. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Cactee. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
pfeilchen flower. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
sparkling sun. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Lock. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows