/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Building = Container.expand(function () {
var self = Container.call(this);
var buildingGraphics = self.attachAsset('building', {
anchorX: 0.5,
anchorY: 1.0
});
self.depth = Math.random() * 0.5 + 0.5;
buildingGraphics.scaleX = self.depth;
buildingGraphics.scaleY = self.depth;
buildingGraphics.alpha = 0.3 + self.depth * 0.7;
return self;
});
var Citizen = Container.expand(function () {
var self = Container.call(this);
var citizenGraphics = self.attachAsset('citizen', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.saved = false;
self.fallSpeed = 3;
self.update = function () {
if (!self.saved) {
self.y += self.fallSpeed;
}
};
return self;
});
var Cloud = Container.expand(function () {
var self = Container.call(this);
var cloudGraphics = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 1;
cloudGraphics.alpha = 0.6;
self.update = function () {
self.x -= self.speed;
if (self.x < -100) {
self.x = 2148;
}
};
return self;
});
var Superman = Container.expand(function () {
var self = Container.call(this);
var supermanGraphics = self.attachAsset('superman', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.flying = false;
self.targetX = 0;
self.targetY = 0;
self.flyTo = function (x, y) {
self.targetX = x;
self.targetY = y;
self.flying = true;
};
self.update = function () {
if (self.flying) {
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 10) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
} else {
self.flying = false;
}
}
};
return self;
});
var Villain = Container.expand(function () {
var self = Container.call(this);
var villainGraphics = self.attachAsset('villain', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 4;
self.direction = 1;
self.defeated = false;
self.update = function () {
if (!self.defeated) {
self.x += self.speed * self.direction;
if (self.x < 100 || self.x > 1948) {
self.direction *= -1;
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
game.setBackgroundColor(0x87CEEB);
// Game variables
var superman;
var citizens = [];
var villains = [];
var buildings = [];
var clouds = [];
var gameSpeed = 1;
var citizenSpawnTimer = 0;
var villainSpawnTimer = 0;
var difficultyTimer = 0;
// UI Elements
var scoreText = new Text2('Puntuación: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
var livesText = new Text2('Ciudadanos Salvados: 0', {
size: 50,
fill: 0xFFFFFF
});
livesText.anchor.set(0, 0);
livesText.x = 120;
livesText.y = 120;
LK.gui.topLeft.addChild(livesText);
// Initialize Superman
superman = game.addChild(new Superman());
superman.x = 1024;
superman.y = 1800;
// Create background buildings
for (var i = 0; i < 8; i++) {
var building = game.addChild(new Building());
building.x = i * 256 + 128;
building.y = 2732;
buildings.push(building);
}
// Create background clouds
for (var i = 0; i < 5; i++) {
var cloud = game.addChild(new Cloud());
cloud.x = i * 400 + 200;
cloud.y = 300 + Math.random() * 400;
clouds.push(cloud);
}
// Game event handlers
game.down = function (x, y, obj) {
superman.flyTo(x, y);
};
game.move = function (x, y, obj) {
superman.flyTo(x, y);
};
// Spawn functions
function spawnCitizen() {
var citizen = game.addChild(new Citizen());
citizen.x = Math.random() * 1848 + 100;
citizen.y = 100;
citizens.push(citizen);
}
function spawnVillain() {
var villain = game.addChild(new Villain());
villain.x = Math.random() * 1848 + 100;
villain.y = Math.random() * 1000 + 500;
villains.push(villain);
}
// Main game loop
game.update = function () {
// Update timers
citizenSpawnTimer++;
villainSpawnTimer++;
difficultyTimer++;
// Spawn citizens
if (citizenSpawnTimer > 120 / gameSpeed) {
spawnCitizen();
citizenSpawnTimer = 0;
}
// Spawn villains
if (villainSpawnTimer > 180 / gameSpeed) {
spawnVillain();
villainSpawnTimer = 0;
}
// Increase difficulty
if (difficultyTimer > 1800) {
gameSpeed += 0.1;
difficultyTimer = 0;
}
// Update citizens
for (var i = citizens.length - 1; i >= 0; i--) {
var citizen = citizens[i];
// Check if citizen fell off screen
if (citizen.y > 2732) {
citizen.destroy();
citizens.splice(i, 1);
continue;
}
// Check collision with Superman
if (superman.intersects(citizen) && !citizen.saved) {
citizen.saved = true;
LK.setScore(LK.getScore() + 10);
scoreText.setText('Puntuación: ' + LK.getScore());
livesText.setText('Ciudadanos Salvados: ' + Math.floor(LK.getScore() / 10));
// Visual effect
LK.effects.flashObject(citizen, 0x00ff00, 500);
LK.getSound('rescue').play();
// Remove citizen after brief delay
tween(citizen, {
alpha: 0
}, {
duration: 500,
onFinish: function onFinish() {
citizen.destroy();
}
});
citizens.splice(i, 1);
}
}
// Update villains
for (var i = villains.length - 1; i >= 0; i--) {
var villain = villains[i];
// Check collision with Superman
if (superman.intersects(villain) && !villain.defeated) {
villain.defeated = true;
LK.setScore(LK.getScore() + 25);
scoreText.setText('Puntuación: ' + LK.getScore());
// Visual effect
LK.effects.flashObject(villain, 0xff0000, 800);
LK.getSound('defeat').play();
// Remove villain after brief delay
tween(villain, {
alpha: 0,
scaleX: 0.1,
scaleY: 0.1
}, {
duration: 800,
onFinish: function onFinish() {
villain.destroy();
}
});
villains.splice(i, 1);
}
}
// Check win condition
if (LK.getScore() >= 500) {
LK.showYouWin();
}
// Update UI
scoreText.setText('Puntuación: ' + LK.getScore());
livesText.setText('Ciudadanos Salvados: ' + Math.floor(LK.getScore() / 10));
};
// Start background music
LK.playMusic('cityTheme'); /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Building = Container.expand(function () {
var self = Container.call(this);
var buildingGraphics = self.attachAsset('building', {
anchorX: 0.5,
anchorY: 1.0
});
self.depth = Math.random() * 0.5 + 0.5;
buildingGraphics.scaleX = self.depth;
buildingGraphics.scaleY = self.depth;
buildingGraphics.alpha = 0.3 + self.depth * 0.7;
return self;
});
var Citizen = Container.expand(function () {
var self = Container.call(this);
var citizenGraphics = self.attachAsset('citizen', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.saved = false;
self.fallSpeed = 3;
self.update = function () {
if (!self.saved) {
self.y += self.fallSpeed;
}
};
return self;
});
var Cloud = Container.expand(function () {
var self = Container.call(this);
var cloudGraphics = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 1;
cloudGraphics.alpha = 0.6;
self.update = function () {
self.x -= self.speed;
if (self.x < -100) {
self.x = 2148;
}
};
return self;
});
var Superman = Container.expand(function () {
var self = Container.call(this);
var supermanGraphics = self.attachAsset('superman', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.flying = false;
self.targetX = 0;
self.targetY = 0;
self.flyTo = function (x, y) {
self.targetX = x;
self.targetY = y;
self.flying = true;
};
self.update = function () {
if (self.flying) {
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 10) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
} else {
self.flying = false;
}
}
};
return self;
});
var Villain = Container.expand(function () {
var self = Container.call(this);
var villainGraphics = self.attachAsset('villain', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 4;
self.direction = 1;
self.defeated = false;
self.update = function () {
if (!self.defeated) {
self.x += self.speed * self.direction;
if (self.x < 100 || self.x > 1948) {
self.direction *= -1;
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
game.setBackgroundColor(0x87CEEB);
// Game variables
var superman;
var citizens = [];
var villains = [];
var buildings = [];
var clouds = [];
var gameSpeed = 1;
var citizenSpawnTimer = 0;
var villainSpawnTimer = 0;
var difficultyTimer = 0;
// UI Elements
var scoreText = new Text2('Puntuación: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
var livesText = new Text2('Ciudadanos Salvados: 0', {
size: 50,
fill: 0xFFFFFF
});
livesText.anchor.set(0, 0);
livesText.x = 120;
livesText.y = 120;
LK.gui.topLeft.addChild(livesText);
// Initialize Superman
superman = game.addChild(new Superman());
superman.x = 1024;
superman.y = 1800;
// Create background buildings
for (var i = 0; i < 8; i++) {
var building = game.addChild(new Building());
building.x = i * 256 + 128;
building.y = 2732;
buildings.push(building);
}
// Create background clouds
for (var i = 0; i < 5; i++) {
var cloud = game.addChild(new Cloud());
cloud.x = i * 400 + 200;
cloud.y = 300 + Math.random() * 400;
clouds.push(cloud);
}
// Game event handlers
game.down = function (x, y, obj) {
superman.flyTo(x, y);
};
game.move = function (x, y, obj) {
superman.flyTo(x, y);
};
// Spawn functions
function spawnCitizen() {
var citizen = game.addChild(new Citizen());
citizen.x = Math.random() * 1848 + 100;
citizen.y = 100;
citizens.push(citizen);
}
function spawnVillain() {
var villain = game.addChild(new Villain());
villain.x = Math.random() * 1848 + 100;
villain.y = Math.random() * 1000 + 500;
villains.push(villain);
}
// Main game loop
game.update = function () {
// Update timers
citizenSpawnTimer++;
villainSpawnTimer++;
difficultyTimer++;
// Spawn citizens
if (citizenSpawnTimer > 120 / gameSpeed) {
spawnCitizen();
citizenSpawnTimer = 0;
}
// Spawn villains
if (villainSpawnTimer > 180 / gameSpeed) {
spawnVillain();
villainSpawnTimer = 0;
}
// Increase difficulty
if (difficultyTimer > 1800) {
gameSpeed += 0.1;
difficultyTimer = 0;
}
// Update citizens
for (var i = citizens.length - 1; i >= 0; i--) {
var citizen = citizens[i];
// Check if citizen fell off screen
if (citizen.y > 2732) {
citizen.destroy();
citizens.splice(i, 1);
continue;
}
// Check collision with Superman
if (superman.intersects(citizen) && !citizen.saved) {
citizen.saved = true;
LK.setScore(LK.getScore() + 10);
scoreText.setText('Puntuación: ' + LK.getScore());
livesText.setText('Ciudadanos Salvados: ' + Math.floor(LK.getScore() / 10));
// Visual effect
LK.effects.flashObject(citizen, 0x00ff00, 500);
LK.getSound('rescue').play();
// Remove citizen after brief delay
tween(citizen, {
alpha: 0
}, {
duration: 500,
onFinish: function onFinish() {
citizen.destroy();
}
});
citizens.splice(i, 1);
}
}
// Update villains
for (var i = villains.length - 1; i >= 0; i--) {
var villain = villains[i];
// Check collision with Superman
if (superman.intersects(villain) && !villain.defeated) {
villain.defeated = true;
LK.setScore(LK.getScore() + 25);
scoreText.setText('Puntuación: ' + LK.getScore());
// Visual effect
LK.effects.flashObject(villain, 0xff0000, 800);
LK.getSound('defeat').play();
// Remove villain after brief delay
tween(villain, {
alpha: 0,
scaleX: 0.1,
scaleY: 0.1
}, {
duration: 800,
onFinish: function onFinish() {
villain.destroy();
}
});
villains.splice(i, 1);
}
}
// Check win condition
if (LK.getScore() >= 500) {
LK.showYouWin();
}
// Update UI
scoreText.setText('Puntuación: ' + LK.getScore());
livesText.setText('Ciudadanos Salvados: ' + Math.floor(LK.getScore() / 10));
};
// Start background music
LK.playMusic('cityTheme');
Believe me, Superman flies from behind. In-Game asset. High contrast. No shadows
make a superman villain. In-Game asset. High contrast. No shadows
make citizens fall. In-Game asset. No shadows. 2d
build buildings next to each other. In-Game asset. High contrast. No shadows
make clouds. In-Game asset. High contrast. No shadows