Code edit (1 edits merged)
Please save this source code
User prompt
add pendulum effect to the player
User prompt
Please fix the bug: 'TypeError: Cannot set properties of undefined (setting 'height')' in or related to this line: 'this.rope.height = this.y;' Line Number: 254
User prompt
Please fix the bug: 'ReferenceError: rope is not defined' in or related to this line: 'rope.height = player.y;' Line Number: 254
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: 253
User prompt
rope should be attached on the top of the screen and go down until the top of the player
User prompt
do not rotate power up
User prompt
move rope up so that the end connects with the player top
User prompt
rope should be attached to player vertically on the top
User prompt
invert rope position
User prompt
Please fix the bug: 'Uncaught ReferenceError: ropeGraphics is not defined' in or related to this line: 'ropeGraphics.y = -playerGraphics.height / 2;' Line Number: 71
User prompt
Please fix the bug: 'ReferenceError: ropeGraphics is not defined' in or related to this line: 'ropeGraphics.rotation += 0.01;' Line Number: 49
User prompt
roate rope
User prompt
ivnert attached end to the player from rope
User prompt
invert pendulum anchor point for rope
Code edit (1 edits merged)
Please save this source code
User prompt
add slight pendulum effect to the rope. pendulum from top down
User prompt
add pendulum effect to the player
User prompt
rotate rope upside down
User prompt
rope should be attached to player
User prompt
rotate player a little bit
User prompt
rotate rope from the top
Code edit (5 edits merged)
Please save this source code
User prompt
make pednulum effect slower
User prompt
player and rope should be attached, and incle them very little like a pendulum effect
/****
* 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 / 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 ropeGraphics = self.attachAsset('rope', {
anchorX: 0.5,
anchorY: 1
});
ropeGraphics.y = -playerGraphics.height / 2;
self.update = function () {
// Create a pendulum effect by slightly inclining the player and rope
self.rotation = Math.sin(LK.ticks / 10) * 0.05;
};
});
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;
self.rotation += 0.01;
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)) {
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
});
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;