User prompt
add gradient to the circle from the center out
Code edit (1 edits merged)
Please save this source code
User prompt
add dim to the circle
User prompt
rope and player should move like a pendulum
User prompt
add a rope asset. rope should be attached to the top of the player
User prompt
add a new asset for player rope. Rope should start on the top and be connected to the top of the player
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'x')' in or related to this line: 'line.x = self.width / 2;' Line Number: 68
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'Rectangle')' in or related to this line: 'var line = new LK.Shape.Rectangle({' Line Number: 65
User prompt
add a small black line that comes from the top of the screen until the top of the payer
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'update')' in or related to this line: 'self.update = function () {' Line Number: 248
User prompt
player should have a very slow pendulum movement
User prompt
make player have a very very slow pendulum movement, but very small
User prompt
make powerup slowly rotate on its axis
User prompt
battery should also be darker when outside of the circle
User prompt
use power up sound when power up intersects with player
User prompt
when enemy is outside of circle, they should be way darker
User prompt
when a wave is spawned play mosquito sound
User prompt
on touch pay zap sound
User prompt
wings soudl not count as part of the enemy
Code edit (1 edits merged)
Please save this source code
User prompt
make moskito speed when falling 10 times faster
User prompt
when down is held and mosquito should be destroyed, instead, first rotate them 180 degrees, and have them fall downwards. once off screen, destroy them
Code edit (1 edits merged)
Please save this source code
Code edit (14 edits merged)
Please save this source code
/****
* 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('wing', {
anchorX: 0.5,
anchorY: 0.5
});
var rightWing = self.attachAsset('wing', {
anchorX: 0.5,
anchorY: 0.5
});
leftWing.x = -enemyGraphics.width / 2 - leftWing.width / 2;
rightWing.x = enemyGraphics.width / 2 + rightWing.width / 2;
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 / 20) * 2;
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) {
LK.showGameOver();
}
};
});
// 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 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;
}
};
});
/****
* 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);
for (var i = game.children.length - 1; i >= 0; i--) {
if (game.children[i] instanceof Enemy && isInsideCircle(game.children[i], circle)) {
game.children[i].destroy();
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
} else if (game.children[i] instanceof PowerUp && isInsideCircle(game.children[i], circle)) {
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
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
});
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;