Code edit (3 edits merged)
Please save this source code
User prompt
add score when enemy is in circle when screen is touched instead of when enemy is destroyed
User prompt
add score the moment the enemy is turned upside down not when its destroyed
Code edit (4 edits merged)
Please save this source code
User prompt
add some dim to circle
User prompt
delay game over sound for half a second
Code edit (1 edits merged)
Please save this source code
User prompt
when enemy stats increasing its size, start moving the wings further away from the enemy too
User prompt
when enemy is growing move wings sideways the saame amount it is growing
User prompt
Please make sure wings of enemy stay on the sides of it and does not overlap with player when it is increasing its size
User prompt
when enemy is growing in size powerup should not be collected anymore
User prompt
play game over sound when enemy starts growing
User prompt
enemy that increases its size should be brought to the top layer of z axis
User prompt
make sure wings stay on the sides of the enemy even if it si growing in size
User prompt
when enemy size and wings increase, make sure the position of wings keeps relative to size of enemy
User prompt
also increase size of enemy wings when enemy size increases
User prompt
when first enemy touche player then prevent player from touching screen anymore
Code edit (1 edits merged)
Please save this source code
User prompt
for enemy that increase its size, do it progressively
User prompt
only increase the size of the first enemy to hit player
User prompt
when enemy touches player, before game over, increase size of enemy to cover all the screen and play gameover sound, then game over.
User prompt
make circle move sideways in sync with player
User prompt
winghs should also dim like enemy when otside of circle
User prompt
make wings a just a little further from enemy
User prompt
separate left and right wing assets
/****
* Classes
****/
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
var leftWing = self.attachAsset('leftWing', {
anchorX: 0.5,
anchorY: 0.5,
flipX: 1
});
var rightWing = self.attachAsset('rightWing', {
anchorX: 0.5,
anchorY: 0.5
});
leftWing.x = -enemyGraphics.width / 2.5 - leftWing.width / 2.5;
rightWing.x = enemyGraphics.width / 2.5 + rightWing.width / 2.5;
self.speed = 4 + waveNumber * enemySpeedIncrement; // Initialize enemy speed with progression
self.update = function () {
var dx = player.x - self.x;
var dy = player.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
leftWing.y = Math.sin(LK.ticks / 5) * 10;
rightWing.y = Math.sin(LK.ticks / 5) * 10;
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed + Math.sin(LK.ticks / 5) * 5;
var dx = self.x - player.x;
var dy = self.y - player.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < enemyGraphics.width / 2 + player.width / 2) {
LK.showGameOver();
}
// Check if enemy is outside of the circle
if (!isInsideCircle(self, circle)) {
// Make enemy darker
enemyGraphics.alpha = 0.5;
} else {
// Restore enemy brightness
enemyGraphics.alpha = 1;
}
};
});
// Create a player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
var rope = self.attachAsset('rope', {
anchorX: 0.5,
anchorY: 1
});
rope.y = -playerGraphics.height / 2;
});
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var powerUpGraphics = self.attachAsset('powerUp', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 4 + waveNumber * enemySpeedIncrement; // Initialize power-up speed with progression
self.update = function () {
var dx = player.x - self.x;
var dy = player.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
// Add a scale effect to the powerup to make it seem cartoony
self.scale.x = 1 + Math.sin(LK.ticks / 10) * 0.1;
self.scale.y = 1 + Math.sin(LK.ticks / 10) * 0.1;
var dx = self.x - player.x;
var dy = self.y - player.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < self.width / 2 + player.width / 2) {
self.destroy();
circle.scale.x *= 1.25;
circle.scale.y *= 1.25;
LK.getSound('powerup').play();
}
// Check if power up is outside of the circle
if (!isInsideCircle(self, circle)) {
// Make power up darker
powerUpGraphics.alpha = 0.5;
} else {
// Restore power up brightness
powerUpGraphics.alpha = 1;
}
};
});
/****
* Initialize Game
****/
// Add player to the game
//<Assets used in the game will automatically appear here>
//<Write entity 'classes' with empty functions for important behavior here>
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
function isInsideCircle(object, circle) {
var dx = object.x - circle.x;
var dy = object.y - circle.y;
var distance = Math.sqrt(dx * dx + dy * dy);
return distance < circle.width / 2;
}
game.down = function (x, y, obj) {
console.log("Screen was pressed at", x, y);
LK.getSound('zap').play();
for (var i = game.children.length - 1; i >= 0; i--) {
if (game.children[i] instanceof Enemy && isInsideCircle(game.children[i], circle)) {
game.children[i].rotation = Math.PI;
game.children[i].speed = 25;
game.children[i].update = function () {
this.y += this.speed;
if (this.y > 2732 + 50) {
this.destroy();
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
}
};
} else if (game.children[i] instanceof PowerUp && isInsideCircle(game.children[i], circle)) {
// Create a smoke effect when powerup is destroyed
var smoke = LK.getAsset('smoke', {
anchorX: 0.5,
anchorY: 0.5,
x: game.children[i].x,
y: game.children[i].y
});
game.addChild(smoke);
// Play smoke sound
LK.getSound('smoke').play();
// Play smoke sound
LK.getSound('smoke').play();
// Animate the smoke to fade out and increase in size
var smokeAnimation = LK.setInterval(function () {
smoke.alpha -= 0.1;
smoke.scale.x += 0.1;
smoke.scale.y += 0.1;
// Once the smoke is fully transparent, remove it
if (smoke.alpha <= 0) {
smoke.destroy();
LK.clearInterval(smokeAnimation);
}
}, 100);
game.children[i].destroy();
}
}
circle.scale.x *= 0.9;
circle.scale.y *= 0.9;
// Add flash effect as a replacement for shake
LK.effects.flashScreen(0xffff00, 200); // Flash yellow for 500ms
};
function spawnPowerUp() {
var powerUp = new PowerUp();
if (player) {
var side = Math.floor(Math.random() * 4);
if (side == 0) {
// Top
powerUp.x = Math.random() * 2048;
powerUp.y = -50;
} else if (side == 1) {
// Right
powerUp.x = 2048 + 50;
powerUp.y = Math.random() * 2732;
} else if (side == 2) {
// Bottom
powerUp.x = Math.random() * 2048;
powerUp.y = 2732 + 50;
} else {
// Left
powerUp.x = -50;
powerUp.y = Math.random() * 2732;
}
game.addChild(powerUp);
}
}
// Power-ups will now spawn between waves
// Spawn enemies from outside the screen
function spawnEnemy() {
var enemy = new Enemy();
var side = Math.floor(Math.random() * 4);
if (side == 0) {
// Top
enemy.x = Math.random() * 2048;
enemy.y = -50;
} else if (side == 1) {
// Right
enemy.x = 2048 + 50;
enemy.y = Math.random() * 2732;
} else if (side == 2) {
// Bottom
enemy.x = Math.random() * 2048;
enemy.y = 2732 + 50;
} else {
// Left
enemy.x = -50;
enemy.y = Math.random() * 2732;
}
game.addChild(enemy);
}
// Variables to manage waves and power-up spawning
var waveNumber = 0;
var enemiesPerWave = 5;
var enemiesSpawned = 0;
var waveInterval = 5000; // 5 seconds between waves
var enemySpeedIncrement = 0.25; // Speed increment per wave
var enemiesPerWaveIncrement = 1; // Additional enemies per wave
function startNextWave() {
waveNumber++;
enemiesSpawned = 0;
enemiesPerWave += enemiesPerWaveIncrement; // Increase number of enemies per wave
Enemy.prototype.speed += enemySpeedIncrement; // Increase enemy speed
PowerUp.prototype.speed += enemySpeedIncrement; // Increase power-up speed
LK.getSound('mosquito').play(); // Play mosquito sound when a wave is spawned
spawnEnemiesInWave();
}
function spawnEnemiesInWave() {
if (enemiesSpawned < enemiesPerWave) {
spawnEnemy();
enemiesSpawned++;
LK.setTimeout(spawnEnemiesInWave, 500); // 0.5 seconds between enemy spawns
} else {
// Spawn power-up after the wave
LK.setTimeout(spawnPowerUp, 1000);
// Start the next wave after a delay
LK.setTimeout(startNextWave, waveInterval);
}
}
// Create a circle in the center of the screen
var circle = new Container();
var circleGraphics = circle.attachAsset('circle', {
anchorX: 0.5,
anchorY: 0.5
});
// Add gradient effect to the circle
// Create a gradient effect for the circle
// The LK engine does not support the filters object or the AlphaFilter method.
// Therefore, we cannot apply a gradient effect to the circle in this way.
// We will need to find another way to achieve the desired visual effect.
game.addChild(circle);
circle.x = 2048 / 2;
circle.y = 2732 / 2;
// Initialize score text
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Update score text whenever the score changes
LK.on('scoreChange', function () {
scoreTxt.setText(LK.getScore());
});
// Start the first wave
startNextWave();
// Add player to the game
var player = new Player();
game.addChild(player);
player.x = 2048 / 2; // Center player horizontally
player.y = 2732 / 2; // Center player vertically;
player.update = function () {
if (this.rope) {
this.rope.height = this.y;
}
// Add pendulum effect
this.x = 2048 / 2 + Math.sin(LK.ticks / 60) * 30;
};