User prompt
Please fix the bug: 'TypeError: glitchGraphics.scale.set is not a function' in or related to this line: 'glitchGraphics.scale.set(scale, scale);' Line Number: 504
User prompt
Delete error
User prompt
Add pibby glitch
User prompt
Add anime
User prompt
Add all of the enemies
User prompt
Add enemy
User prompt
Add all of the enemies
User prompt
Add villager make villager run away from the enemies if the enemies touch villager villager get pippy glitch And turn into an enemy āŖš” Consider importing and using the following plugins: @upit/tween.v1
User prompt
Add villager
User prompt
Add enemyshape2 enemy shape 2 is a enemy
User prompt
Please fix the bug: 'ReferenceError: findNearestEnemy is not defined' in or related to this line: 'self.targetEnemy = findNearestEnemy(self.x, self.y);' Line Number: 50
User prompt
Please fix the bug: 'ReferenceError: findNearestEnemy is not defined' in or related to this line: 'self.targetEnemy = findNearestEnemy(self.x, self.y);' Line Number: 50
User prompt
Please fix the bug: 'ReferenceError: findNearestEnemy is not defined' in or related to this line: 'self.targetEnemy = findNearestEnemy(self.x, self.y);' Line Number: 50
User prompt
Please fix the bug: 'ReferenceError: findNearestEnemy is not defined' in or related to this line: 'self.targetEnemy = findNearestEnemy(self.x, self.y);' Line Number: 50
User prompt
Please fix the bug: 'ReferenceError: findNearestEnemy is not defined' in or related to this line: 'self.targetEnemy = findNearestEnemy(self.x, self.y);' Line Number: 50
User prompt
Please fix the bug: 'ReferenceError: findNearestEnemy is not defined' in or related to this line: 'self.targetEnemy = findNearestEnemy(self.x, self.y);' Line Number: 50
User prompt
Add dummy1 dummy one is helping the player defeat the pippy apocalypse
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'fill')' in or related to this line: 'corruptionText.style.fill = corruptionLevel > 75 ? "#FF0000" : "#FF00FF";' Line Number: 361
Code edit (1 edits merged)
Please save this source code
User prompt
Glitch Escape: Cartoon Apocalypse
Initial prompt
Pibby glitch apocalypse
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var DebugPower = Container.expand(function () {
var self = Container.call(this);
var powerGraphics = self.attachAsset('debugPowerShape', {
anchorX: 0.5,
anchorY: 0.5
});
self.rotateSpeed = 0.03;
self.update = function () {
// Rotate continuously
powerGraphics.rotation += self.rotateSpeed;
};
return self;
});
var Dummy1 = Container.expand(function () {
var self = Container.call(this);
var dummyGraphics = self.attachAsset('Dummy1', {
anchorX: 0.5,
anchorY: 0.5
});
// Dummy1 properties and methods
self.speed = 5;
self.targetEnemy = null;
self.attackDamage = 20;
self.attackRange = 150;
self.update = function () {
// Find the nearest enemy
self.targetEnemy = findNearestEnemy(self.x, self.y);
if (self.targetEnemy) {
// Move towards the target enemy
var dx = self.targetEnemy.x - self.x;
var dy = self.targetEnemy.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > self.speed) {
var ratio = self.speed / distance;
self.x += dx * ratio;
self.y += dy * ratio;
} else {
self.x = self.targetEnemy.x;
self.y = self.targetEnemy.y;
}
// Check if within attack range
if (distance < self.attackRange) {
attackEnemy(self.targetEnemy, self.attackDamage);
}
}
};
return self;
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemyShape', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3 + Math.random() * 2;
self.moveAngle = Math.random() * Math.PI * 2;
self.changeDirectionTimer = 0;
self.changeDirectionInterval = 60 + Math.floor(Math.random() * 60);
self.damage = 10;
self.update = function () {
// Change direction occasionally
self.changeDirectionTimer++;
if (self.changeDirectionTimer >= self.changeDirectionInterval) {
self.moveAngle = Math.random() * Math.PI * 2;
self.changeDirectionTimer = 0;
self.changeDirectionInterval = 60 + Math.floor(Math.random() * 60);
}
// Move in current direction
self.x += Math.cos(self.moveAngle) * self.speed;
self.y += Math.sin(self.moveAngle) * self.speed;
// Bounce off walls
if (self.x < 50) {
self.x = 50;
self.moveAngle = Math.PI - self.moveAngle;
} else if (self.x > 2048 - 50) {
self.x = 2048 - 50;
self.moveAngle = Math.PI - self.moveAngle;
}
if (self.y < 50) {
self.y = 50;
self.moveAngle = -self.moveAngle;
} else if (self.y > 2732 - 50) {
self.y = 2732 - 50;
self.moveAngle = -self.moveAngle;
}
// Add a glitchy rotation
enemyGraphics.rotation += 0.05;
};
return self;
});
var Enemyshape2 = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('Enemyshape2', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 50; // Example health
self.speed = 2 + Math.random() * 1;
self.moveAngle = Math.random() * Math.PI * 2;
self.changeDirectionTimer = 0;
self.changeDirectionInterval = 90 + Math.floor(Math.random() * 90);
self.damage = 15;
self.update = function () {
// Change direction occasionally
self.changeDirectionTimer++;
if (self.changeDirectionTimer >= self.changeDirectionInterval) {
self.moveAngle = Math.random() * Math.PI * 2;
self.changeDirectionTimer = 0;
self.changeDirectionInterval = 90 + Math.floor(Math.random() * 90);
}
// Move in current direction
self.x += Math.cos(self.moveAngle) * self.speed;
self.y += Math.sin(self.moveAngle) * self.speed;
// Bounce off walls
if (self.x < 50) {
self.x = 50;
self.moveAngle = Math.PI - self.moveAngle;
} else if (self.x > 2048 - 50) {
self.x = 2048 - 50;
self.moveAngle = Math.PI - self.moveAngle;
}
if (self.y < 50) {
self.y = 50;
self.moveAngle = -self.moveAngle;
} else if (self.y > 2732 - 50) {
self.y = 2732 - 50;
self.moveAngle = -self.moveAngle;
}
// Rotate slowly
enemyGraphics.rotation += 0.02;
};
return self;
});
var GlitchWall = Container.expand(function () {
var self = Container.call(this);
var wallGraphics = self.attachAsset('glitchWall', {
anchorX: 0.5,
anchorY: 0.5
});
self.glitchTimer = 0;
self.glitchInterval = 10;
self.update = function () {
// Visual glitch effect
self.glitchTimer++;
if (self.glitchTimer % self.glitchInterval === 0) {
// Random color shifts
wallGraphics.tint = Math.random() > 0.5 ? 0xff00ff : 0x00ffff;
// Random position shifts
wallGraphics.x = Math.random() * 10 - 5;
wallGraphics.y = Math.random() * 10 - 5;
}
if (self.glitchTimer >= 60) {
self.glitchTimer = 0;
wallGraphics.x = 0;
wallGraphics.y = 0;
}
};
return self;
});
var Pixel = Container.expand(function () {
var self = Container.call(this);
var pixelGraphics = self.attachAsset('pixelShape', {
anchorX: 0.5,
anchorY: 0.5
});
// Add a pulsing animation
self.pulseDirection = 1;
self.pulseSpeed = 0.02;
self.baseScale = 1;
self.update = function () {
// Pulse effect
var scale = pixelGraphics.scale.x;
scale += self.pulseSpeed * self.pulseDirection;
if (scale > 1.2) {
scale = 1.2;
self.pulseDirection = -1;
} else if (scale < 0.8) {
scale = 0.8;
self.pulseDirection = 1;
}
pixelGraphics.scale.set(scale, scale);
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('playerShape', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 100;
self.speed = 8;
self.isMoving = false;
self.targetX = 0;
self.targetY = 0;
self.debugPower = 0;
self.isInvulnerable = false;
self.moveTowards = function (targetX, targetY) {
self.isMoving = true;
self.targetX = targetX;
self.targetY = targetY;
};
self.stopMoving = function () {
self.isMoving = false;
};
self.takeDamage = function (amount) {
if (!self.isInvulnerable) {
self.health -= amount;
LK.getSound('hurt').play();
self.isInvulnerable = true;
playerGraphics.alpha = 0.5;
// Flash effect
LK.effects.flashObject(self, 0xff0000, 300);
LK.setTimeout(function () {
self.isInvulnerable = false;
playerGraphics.alpha = 1.0;
}, 1500);
if (self.health <= 0) {
self.health = 0;
gameOver();
}
}
};
self.collectPixel = function () {
self.health = Math.min(100, self.health + 10);
LK.getSound('collect').play();
};
self.collectDebugPower = function () {
self.debugPower++;
LK.getSound('powerup').play();
};
self.useDebugPower = function () {
if (self.debugPower > 0) {
self.debugPower--;
return true;
}
return false;
};
self.update = function () {
if (self.isMoving) {
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > self.speed) {
var ratio = self.speed / distance;
self.x += dx * ratio;
self.y += dy * ratio;
} else {
self.x = self.targetX;
self.y = self.targetY;
self.isMoving = false;
}
}
};
return self;
});
var Villager = Container.expand(function () {
var self = Container.call(this);
var villagerGraphics = self.attachAsset('Villager', {
anchorX: 0.5,
anchorY: 0.5
});
// Villager properties and methods
self.health = 50;
self.speed = 4;
self.isGlitching = false;
self.glitchTimer = 0;
self.fearRadius = 300; // Distance at which villager senses enemies
self.transformationTimer = 0;
self.update = function () {
if (self.isGlitching) {
// Handle glitching animation
self.glitchTimer++;
// Visual glitch effect
if (self.glitchTimer % 5 === 0) {
// Random color shifts
villagerGraphics.tint = Math.random() > 0.5 ? 0xff00ff : 0x00ffff;
// Random position shifts
villagerGraphics.x = Math.random() * 10 - 5;
villagerGraphics.y = Math.random() * 10 - 5;
// Increase transformation timer
self.transformationTimer++;
// After enough glitching, transform into enemy
if (self.transformationTimer >= 30) {
self.transformIntoEnemy();
return;
}
}
} else {
// Run away from nearby enemies
var nearestEnemy = null;
var shortestDistance = Infinity;
// Find the nearest enemy
for (var i = 0; i < enemies.length; i++) {
var enemy = enemies[i];
var dx = enemy.x - self.x;
var dy = enemy.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// Check for enemy collision
if (self.intersects(enemy)) {
// Start glitching process when touched by enemy
self.startGlitching();
break;
}
if (distance < shortestDistance) {
shortestDistance = distance;
nearestEnemy = enemy;
}
}
// Run away if enemy is within fear radius
if (nearestEnemy && shortestDistance < self.fearRadius) {
// Calculate direction away from enemy
var dx = self.x - nearestEnemy.x;
var dy = self.y - nearestEnemy.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
// Normalize and apply speed
dx = dx / distance * self.speed;
dy = dy / distance * self.speed;
// Move away from enemy
self.x += dx;
self.y += dy;
// Keep within game boundaries
if (self.x < 50) self.x = 50;
if (self.x > GAME_WIDTH - 50) self.x = GAME_WIDTH - 50;
if (self.y < 50) self.y = 50;
if (self.y > GAME_HEIGHT - 50) self.y = GAME_HEIGHT - 50;
}
}
}
};
self.startGlitching = function () {
if (!self.isGlitching) {
self.isGlitching = true;
self.glitchTimer = 0;
self.transformationTimer = 0;
// Visual feedback with tween
tween(villagerGraphics, {
alpha: 0.5
}, {
duration: 300,
easing: tween.easeInOut
});
// Play sound effect
LK.getSound('hurt').play();
}
};
self.transformIntoEnemy = function () {
// Create a new enemy at the villager's position
var newEnemy = Math.random() < 0.5 ? new Enemy() : new Enemyshape2();
newEnemy.x = self.x;
newEnemy.y = self.y;
game.addChild(newEnemy);
enemies.push(newEnemy);
// Visual effect
LK.effects.flashObject(newEnemy, 0xff00ff, 500);
// Remove villager
var index = villagers.indexOf(self);
if (index !== -1) {
villagers.splice(index, 1);
}
self.destroy();
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000033
});
/****
* Game Code
****/
// Game constants
var GAME_WIDTH = 2048;
var GAME_HEIGHT = 2732;
var MAX_ENEMIES = 15;
var MAX_PIXELS = 10;
var MAX_WALLS = 8;
var MAX_DEBUG_POWERS = 3;
var CORRUPTION_INTERVAL = 10000; // 10 seconds
var LEVEL_UP_SCORE = 10;
// Game variables
var villagers = []; // Array to hold villagers
var player;
var pixels = [];
var enemies = [];
var walls = [];
var debugPowers = [];
var score = 0;
var level = 1;
var corruptionLevel = 0;
var gameActive = true;
var lastCorruptionTime = 0;
var dummy1; // Add dummy1 variable
// UI elements
var scoreText;
var healthBar;
var healthBarBg;
var levelText;
var debugPowerText;
var corruptionText;
// Initialize game elements
function initializeGame() {
// Clear existing elements if needed
clearGameElements();
// Create player
player = new Player();
player.x = GAME_WIDTH / 2;
player.y = GAME_HEIGHT - 200;
game.addChild(player);
// Create Dummy1
dummy1 = new Dummy1();
dummy1.x = GAME_WIDTH / 2 - 150; // Position Dummy1 near the player
dummy1.y = GAME_HEIGHT - 200;
game.addChild(dummy1);
// Initialize UI
createUI();
// Generate initial game objects
spawnPixels(MAX_PIXELS);
spawnWalls(level);
spawnDebugPowers(1);
spawnVillagers(5); // Spawn 5 villagers initially
// Start corruption process
lastCorruptionTime = Date.now();
// Reset game state
score = 0;
corruptionLevel = 0;
level = 1;
gameActive = true;
// Update UI
updateUI();
// Play background music
LK.playMusic('gameTheme');
}
function clearGameElements() {
// Remove all existing game elements
if (player) {
player.destroy();
player = null;
}
if (dummy1) {
// Clear Dummy1
dummy1.destroy();
dummy1 = null;
}
for (var i = 0; i < pixels.length; i++) {
pixels[i].destroy();
}
pixels = [];
for (var i = 0; i < enemies.length; i++) {
enemies[i].destroy();
}
enemies = [];
for (var i = 0; i < walls.length; i++) {
walls[i].destroy();
}
walls = [];
for (var i = 0; i < debugPowers.length; i++) {
debugPowers[i].destroy();
}
debugPowers = [];
}
for (var i = 0; i < villagers.length; i++) {
villagers[i].destroy();
}
villagers = [];
function createUI() {
// Score text
scoreText = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0, 0);
scoreText.x = 120;
scoreText.y = 50;
LK.gui.addChild(scoreText);
// Level text
levelText = new Text2('Level: 1', {
size: 60,
fill: 0xFFFFFF
});
levelText.anchor.set(0.5, 0);
levelText.x = GAME_WIDTH / 2;
levelText.y = 50;
LK.gui.addChild(levelText);
// Debug power counter
debugPowerText = new Text2('Debug Powers: 0', {
size: 60,
fill: 0xFFFF00
});
debugPowerText.anchor.set(1, 0);
debugPowerText.x = GAME_WIDTH - 120;
debugPowerText.y = 50;
LK.gui.addChild(debugPowerText);
// Health bar background
healthBarBg = LK.getAsset('playerShape', {
anchorX: 0,
anchorY: 0,
width: 400,
height: 30,
tint: 0x666666
});
healthBarBg.x = GAME_WIDTH / 2 - 200;
healthBarBg.y = 120;
LK.gui.addChild(healthBarBg);
// Health bar
healthBar = LK.getAsset('playerShape', {
anchorX: 0,
anchorY: 0,
width: 400,
height: 30,
tint: 0x00ff00
});
healthBar.x = GAME_WIDTH / 2 - 200;
healthBar.y = 120;
LK.gui.addChild(healthBar);
// Corruption text
corruptionText = new Text2('Corruption: 0%', {
size: 50,
fill: 0xFF00FF
});
corruptionText.anchor.set(0.5, 0);
corruptionText.x = GAME_WIDTH / 2;
corruptionText.y = 160;
LK.gui.addChild(corruptionText);
}
function updateUI() {
// Update score display
scoreText.setText('Score: ' + score);
// Update health bar
healthBar.width = player.health / 100 * 400;
healthBar.tint = player.health > 50 ? 0x00ff00 : player.health > 25 ? 0xffff00 : 0xff0000;
// Update level display
levelText.setText('Level: ' + level);
// Update debug power counter
debugPowerText.setText('Debug Powers: ' + player.debugPower);
// Update corruption display
corruptionText.setText('Corruption: ' + corruptionLevel + '%');
// Use setStyle instead of directly accessing style which is undefined
corruptionText.setStyle({
fill: corruptionLevel > 75 ? "#FF0000" : "#FF00FF"
});
}
function findNearestEnemy(x, y) {
var nearestEnemy = null;
var shortestDistance = Infinity;
for (var i = 0; i < enemies.length; i++) {
var enemy = enemies[i];
var dx = enemy.x - x;
var dy = enemy.y - y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < shortestDistance) {
shortestDistance = distance;
nearestEnemy = enemy;
}
}
return nearestEnemy;
}
function attackEnemy(enemy, damage) {
enemy.health -= damage; // Assuming enemies have a health property
if (enemy.health <= 0) {
enemy.destroy();
enemies.splice(enemies.indexOf(enemy), 1);
// Optionally, increase score or spawn something on enemy defeat
}
}
function spawnPixels(count) {
for (var i = 0; i < count; i++) {
var pixel = new Pixel();
pixel.x = 100 + Math.random() * (GAME_WIDTH - 200);
pixel.y = 100 + Math.random() * (GAME_HEIGHT - 200);
game.addChild(pixel);
pixels.push(pixel);
}
}
function spawnEnemies(count) {
for (var i = 0; i < count; i++) {
var enemy;
if (Math.random() < 0.5) {
// 50% chance to spawn original enemy
enemy = new Enemy();
} else {
// 50% chance to spawn Enemyshape2
enemy = new Enemyshape2();
}
// Spawn from edges
if (Math.random() < 0.5) {
enemy.x = Math.random() < 0.5 ? 50 : GAME_WIDTH - 50;
enemy.y = 50 + Math.random() * (GAME_HEIGHT - 100);
} else {
enemy.x = 50 + Math.random() * (GAME_WIDTH - 100);
enemy.y = Math.random() < 0.5 ? 50 : GAME_HEIGHT - 50;
}
game.addChild(enemy);
enemies.push(enemy);
}
}
function spawnWalls(count) {
for (var i = 0; i < count; i++) {
var wall = new GlitchWall();
wall.x = 200 + Math.random() * (GAME_WIDTH - 400);
wall.y = 200 + Math.random() * (GAME_HEIGHT - 400);
// Randomize rotation
wall.rotation = Math.random() * Math.PI * 2;
game.addChild(wall);
walls.push(wall);
}
}
function spawnDebugPowers(count) {
for (var i = 0; i < count; i++) {
var power = new DebugPower();
power.x = 100 + Math.random() * (GAME_WIDTH - 200);
power.y = 100 + Math.random() * (GAME_HEIGHT - 200);
game.addChild(power);
debugPowers.push(power);
}
}
function increaseCorruption() {
corruptionLevel += 5;
if (corruptionLevel >= 100) {
gameOver();
return;
}
// Visual feedback for corruption increase
LK.effects.flashScreen(0xff00ff, 300);
// Spawn more enemies as corruption increases
var enemiesToSpawn = Math.min(3, MAX_ENEMIES - enemies.length);
if (enemiesToSpawn > 0) {
spawnEnemies(enemiesToSpawn);
}
// Update UI
updateUI();
}
function spawnVillagers(count) {
for (var i = 0; i < count; i++) {
var villager = new Villager();
villager.x = 100 + Math.random() * (GAME_WIDTH - 200);
villager.y = 100 + Math.random() * (GAME_HEIGHT - 200);
game.addChild(villager);
villagers.push(villager);
}
}
function levelUp() {
level++;
// Spawn new walls
spawnWalls(1);
// Spawn debug power
if (level % 2 === 0 && debugPowers.length < MAX_DEBUG_POWERS) {
spawnDebugPowers(1);
}
// Visual feedback for level up
LK.effects.flashScreen(0x00ffff, 500);
// Update UI
updateUI();
}
function useDebugPower() {
if (player.useDebugPower()) {
// Clear nearby enemies
var powerRadius = 300;
for (var i = enemies.length - 1; i >= 0; i--) {
var enemy = enemies[i];
var dx = enemy.x - player.x;
var dy = enemy.y - player.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < powerRadius) {
enemy.destroy();
enemies.splice(i, 1);
}
}
// Visual effect
LK.effects.flashScreen(0xffff00, 300);
// Update UI
updateUI();
return true;
}
return false;
}
function gameOver() {
gameActive = false;
LK.showGameOver();
}
function checkCollisions() {
// Check player collision with pixels
for (var i = pixels.length - 1; i >= 0; i--) {
if (player.intersects(pixels[i])) {
player.collectPixel();
pixels[i].destroy();
pixels.splice(i, 1);
// Increment score
score++;
LK.setScore(score);
// Check for level up
if (score % LEVEL_UP_SCORE === 0) {
levelUp();
}
// Spawn new pixel if below max
if (pixels.length < MAX_PIXELS) {
spawnPixels(1);
}
updateUI();
}
}
// Check player collision with enemies
for (var i = 0; i < enemies.length; i++) {
if (player.intersects(enemies[i])) {
player.takeDamage(enemies[i].damage);
updateUI();
}
}
// Check Dummy1 collision with enemies (Optional, Dummy1's attack is handled in its update)
// Check player collision with walls
for (var i = 0; i < walls.length; i++) {
if (player.intersects(walls[i])) {
player.takeDamage(5);
// Push player away from wall
var dx = player.x - walls[i].x;
var dy = player.y - walls[i].y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
var pushX = dx / distance * 30;
var pushY = dy / distance * 30;
player.x += pushX;
player.y += pushY;
}
updateUI();
}
}
// Check player collision with debug powers
for (var i = debugPowers.length - 1; i >= 0; i--) {
if (player.intersects(debugPowers[i])) {
player.collectDebugPower();
debugPowers[i].destroy();
debugPowers.splice(i, 1);
updateUI();
}
}
// Check villager collisions with enemies
// Note: This is now handled directly in the Villager.update method for better control
}
// Handle player movement
function handlePlayerMovement(x, y) {
if (gameActive) {
player.moveTowards(x, y);
}
}
// Game input handlers
game.down = function (x, y, obj) {
handlePlayerMovement(x, y);
// Use debug power on double tap
if (Date.now() - lastTapTime < 300) {
useDebugPower();
}
lastTapTime = Date.now();
};
game.move = function (x, y, obj) {
if (player.isMoving) {
handlePlayerMovement(x, y);
}
};
game.up = function (x, y, obj) {
player.stopMoving();
};
var lastTapTime = 0;
// Main game update loop
game.update = function () {
if (!gameActive) return;
// Update player
player.update();
// Update Dummy1
if (dummy1) {
dummy1.update();
}
// Update game objects
for (var i = 0; i < pixels.length; i++) {
pixels[i].update();
}
for (var i = 0; i < enemies.length; i++) {
enemies[i].update();
}
for (var i = 0; i < walls.length; i++) {
walls[i].update();
}
for (var i = 0; i < debugPowers.length; i++) {
debugPowers[i].update();
}
// Update villagers
for (var i = 0; i < villagers.length; i++) {
villagers[i].update();
}
// Check collisions
checkCollisions();
// Boundary check for player
if (player.x < 50) player.x = 50;
if (player.x > GAME_WIDTH - 50) player.x = GAME_WIDTH - 50;
if (player.y < 50) player.y = 50;
if (player.y > GAME_HEIGHT - 50) player.y = GAME_HEIGHT - 50;
// Check if we need to increase corruption
var currentTime = Date.now();
if (currentTime - lastCorruptionTime > CORRUPTION_INTERVAL) {
increaseCorruption();
lastCorruptionTime = currentTime;
}
// Spawn enemies over time based on corruption level
if (LK.ticks % 180 === 0 && enemies.length < MAX_ENEMIES) {
var spawnChance = 0.2 + corruptionLevel / 100 * 0.5;
if (Math.random() < spawnChance) {
spawnEnemies(1);
}
}
// Occasionally spawn pixels if below max
if (LK.ticks % 300 === 0 && pixels.length < MAX_PIXELS) {
spawnPixels(1);
}
};
// Initialize the game
initializeGame(); ===================================================================
--- original.js
+++ change.js
@@ -270,11 +270,107 @@
anchorY: 0.5
});
// Villager properties and methods
self.health = 50;
+ self.speed = 4;
+ self.isGlitching = false;
+ self.glitchTimer = 0;
+ self.fearRadius = 300; // Distance at which villager senses enemies
+ self.transformationTimer = 0;
self.update = function () {
- // Villagers can have simple behaviors or just be passive elements
+ if (self.isGlitching) {
+ // Handle glitching animation
+ self.glitchTimer++;
+ // Visual glitch effect
+ if (self.glitchTimer % 5 === 0) {
+ // Random color shifts
+ villagerGraphics.tint = Math.random() > 0.5 ? 0xff00ff : 0x00ffff;
+ // Random position shifts
+ villagerGraphics.x = Math.random() * 10 - 5;
+ villagerGraphics.y = Math.random() * 10 - 5;
+ // Increase transformation timer
+ self.transformationTimer++;
+ // After enough glitching, transform into enemy
+ if (self.transformationTimer >= 30) {
+ self.transformIntoEnemy();
+ return;
+ }
+ }
+ } else {
+ // Run away from nearby enemies
+ var nearestEnemy = null;
+ var shortestDistance = Infinity;
+ // Find the nearest enemy
+ for (var i = 0; i < enemies.length; i++) {
+ var enemy = enemies[i];
+ var dx = enemy.x - self.x;
+ var dy = enemy.y - self.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ // Check for enemy collision
+ if (self.intersects(enemy)) {
+ // Start glitching process when touched by enemy
+ self.startGlitching();
+ break;
+ }
+ if (distance < shortestDistance) {
+ shortestDistance = distance;
+ nearestEnemy = enemy;
+ }
+ }
+ // Run away if enemy is within fear radius
+ if (nearestEnemy && shortestDistance < self.fearRadius) {
+ // Calculate direction away from enemy
+ var dx = self.x - nearestEnemy.x;
+ var dy = self.y - nearestEnemy.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance > 0) {
+ // Normalize and apply speed
+ dx = dx / distance * self.speed;
+ dy = dy / distance * self.speed;
+ // Move away from enemy
+ self.x += dx;
+ self.y += dy;
+ // Keep within game boundaries
+ if (self.x < 50) self.x = 50;
+ if (self.x > GAME_WIDTH - 50) self.x = GAME_WIDTH - 50;
+ if (self.y < 50) self.y = 50;
+ if (self.y > GAME_HEIGHT - 50) self.y = GAME_HEIGHT - 50;
+ }
+ }
+ }
};
+ self.startGlitching = function () {
+ if (!self.isGlitching) {
+ self.isGlitching = true;
+ self.glitchTimer = 0;
+ self.transformationTimer = 0;
+ // Visual feedback with tween
+ tween(villagerGraphics, {
+ alpha: 0.5
+ }, {
+ duration: 300,
+ easing: tween.easeInOut
+ });
+ // Play sound effect
+ LK.getSound('hurt').play();
+ }
+ };
+ self.transformIntoEnemy = function () {
+ // Create a new enemy at the villager's position
+ var newEnemy = Math.random() < 0.5 ? new Enemy() : new Enemyshape2();
+ newEnemy.x = self.x;
+ newEnemy.y = self.y;
+ game.addChild(newEnemy);
+ enemies.push(newEnemy);
+ // Visual effect
+ LK.effects.flashObject(newEnemy, 0xff00ff, 500);
+ // Remove villager
+ var index = villagers.indexOf(self);
+ if (index !== -1) {
+ villagers.splice(index, 1);
+ }
+ self.destroy();
+ };
return self;
});
/****
@@ -650,8 +746,10 @@
debugPowers.splice(i, 1);
updateUI();
}
}
+ // Check villager collisions with enemies
+ // Note: This is now handled directly in the Villager.update method for better control
}
// Handle player movement
function handlePlayerMovement(x, y) {
if (gameActive) {
Modern App Store icon, high definition, square with rounded corners, for a game titled "Glitch Escape: Cartoon Apocalypse" and with the description "Navigate a cartoon character through a world being consumed by digital corruption. Dodge glitched enemies, collect uncorrupted pixels, and use debugging powers to survive the spreading digital apocalypse. Race against time to reach the source code and save the cartoon universe from total corruption.". No text on icon!
Pibby. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Pibby glitch wall. In-Game asset. High contrast. No shadows
Pibby glitch pomni. In-Game asset. High contrast. No shadows
DebugPower. In-Game asset. High contrast. No shadows
Little pibby glitch. In-Game asset. 2d. High contrast. No shadows
Pixel shape. In-Game asset. 2d. High contrast. No shadows
Corrupted among Us. In-Game asset. High contrast. No shadows
Pibby finn. In-Game asset. High contrast. No shadows