/**** * Classes ****/ // BadDoctor class var BadDoctor = Container.expand(function () { var self = Container.call(this); var badDoctorGraphics = self.attachAsset('badDoctor', { anchorX: 0.5, anchorY: 0.5 }); self.move = function () { self.y += 8 + Math.floor(LK.ticks / (1800 * 30)); // Increase speed over time at 30 second intervals }; }); // EvilMonster class var EvilMonster = Container.expand(function () { var self = Container.call(this); var evilMonsterGraphics = self.attachAsset('evilMonster', { anchorX: 0.5, anchorY: 0.5 }); self.move = function () { self.y += 12 + Math.floor(LK.ticks / (1800 * 30)); // Increase speed over time at 30 second intervals }; }); // HealthPowerUp class var HealthPowerUp = Container.expand(function () { var self = Container.call(this); var healthPowerUpGraphics = self.attachAsset('healthPowerUp', { anchorX: 0.5, anchorY: 0.5 }); self.move = function () { self.y += 4 + Math.floor(LK.ticks / (1800 * 30)); // Increase speed over time at 30 second intervals }; }); var Medication = Container.expand(function () { var self = Container.call(this); var medicationGraphics = self.attachAsset('medication', { anchorX: 0.5, anchorY: 0.5 }); self.move = function () { self.y += 4 + Math.floor(LK.ticks / (1800 * 30)); // Increase speed over time at 30 second intervals }; }); // Assets will be automatically created based on usage in the code. // Patient class var Patient = Container.expand(function () { var self = Container.call(this); var patientGraphics = self.attachAsset('patient', { anchorX: 0.5, anchorY: 0.5 }); self.health = 100; self.move = function (x, y) { self.x += x; self.y += y; }; self.updateHealth = function (amount) { self.health += amount; if (self.health <= 0) { LK.showGameOver(); } else { // Ensure health bar scales correctly with patient's health, considering the initial width var healthBarMaxWidth = 2048; // Maximum width of the health bar var healthPercentage = self.health / 100; // Convert health to a percentage healthBar.width = healthBarMaxWidth * healthPercentage; // Scale health bar width according to health percentage } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff", anchorX: 0.5, // Center horizontally anchorY: 0.0 // Anchor at the top }); scoreTxt.x = 1024; // Center horizontally scoreTxt.y = 75; // Position above the health bar LK.gui.top.addChild(scoreTxt); // Generate medications LK.setInterval(function () { var medication = new Medication(); medication.x = Math.random() * 2048; // Random position across the width medication.y = 0; // Start from the top medications.push(medication); game.addChild(medication); }, 3000); // Every 3 seconds var medications = []; var healthBar = game.addChild(LK.getAsset('healthBar', { x: 1024, // Center horizontally y: 25, // Position at the top with half height as Y to center vertically anchorX: 0.5, anchorY: 0.5 })); var patient = game.addChild(new Patient()); patient.x = 1024; // Center horizontally patient.y = 2400; // Start near the bottom var badDoctors = []; var healthPowerUps = []; var evilMonsters = []; // Touch event to move patient game.on('down', function (obj) { var pos = obj.event.getLocalPosition(game); var moveX = pos.x - patient.x; var moveY = pos.y - patient.y; patient.move(moveX, moveY); }); // Generate bad doctors LK.setInterval(function () { var badDoctor = new BadDoctor(); badDoctor.x = Math.random() * 2048; // Random position across the width badDoctor.y = 0; // Start from the top badDoctors.push(badDoctor); game.addChild(badDoctor); }, 1000); // Every 1 second // Generate health power ups LK.setInterval(function () { var healthPowerUp = new HealthPowerUp(); healthPowerUp.x = Math.random() * 2048; // Random position across the width healthPowerUp.y = 0; // Start from the top healthPowerUps.push(healthPowerUp); game.addChild(healthPowerUp); }, 5000); // Every 5 seconds // Generate evil monsters LK.setInterval(function () { var evilMonster = new EvilMonster(); evilMonster.x = Math.random() * 2048; // Random position across the width evilMonster.y = 0; // Start from the top evilMonsters.push(evilMonster); game.addChild(evilMonster); }, 5000); // Every 5 seconds // Game tick LK.on('tick', function () { // Move badDoctors for (var i = badDoctors.length - 1; i >= 0; i--) { badDoctors[i].move(); // Check collision with patient if (badDoctors[i].intersects(patient)) { patient.updateHealth(-10); // Reduce health on collision badDoctors[i].destroy(); badDoctors.splice(i, 1); } // Remove off-screen badDoctors else if (badDoctors[i].y > 2732) { badDoctors[i].destroy(); badDoctors.splice(i, 1); } } // Move healthPowerUps for (var i = healthPowerUps.length - 1; i >= 0; i--) { healthPowerUps[i].move(); // Check collision with patient if (healthPowerUps[i].intersects(patient)) { patient.updateHealth(100); // Restore health on collision healthPowerUps[i].destroy(); healthPowerUps.splice(i, 1); } // Remove off-screen healthPowerUps else if (healthPowerUps[i].y > 2732) { healthPowerUps[i].destroy(); healthPowerUps.splice(i, 1); } } // Move medications for (var i = medications.length - 1; i >= 0; i--) { medications[i].move(); // Check collision with patient if (medications[i].intersects(patient)) { LK.setScore(LK.getScore() + 1); // Increase score on collision medications[i].destroy(); medications.splice(i, 1); } // Remove off-screen medications else if (medications[i].y > 2732) { medications[i].destroy(); medications.splice(i, 1); } } // Move evilMonsters for (var i = evilMonsters.length - 1; i >= 0; i--) { evilMonsters[i].move(); // Check collision with patient if (evilMonsters[i].intersects(patient)) { patient.updateHealth(-patient.health); // Instantly kill the player on collision evilMonsters[i].destroy(); evilMonsters.splice(i, 1); } // Remove off-screen evilMonsters else if (evilMonsters[i].y > 2732) { evilMonsters[i].destroy(); evilMonsters.splice(i, 1); } } });
/****
* Classes
****/
// BadDoctor class
var BadDoctor = Container.expand(function () {
var self = Container.call(this);
var badDoctorGraphics = self.attachAsset('badDoctor', {
anchorX: 0.5,
anchorY: 0.5
});
self.move = function () {
self.y += 8 + Math.floor(LK.ticks / (1800 * 30)); // Increase speed over time at 30 second intervals
};
});
// EvilMonster class
var EvilMonster = Container.expand(function () {
var self = Container.call(this);
var evilMonsterGraphics = self.attachAsset('evilMonster', {
anchorX: 0.5,
anchorY: 0.5
});
self.move = function () {
self.y += 12 + Math.floor(LK.ticks / (1800 * 30)); // Increase speed over time at 30 second intervals
};
});
// HealthPowerUp class
var HealthPowerUp = Container.expand(function () {
var self = Container.call(this);
var healthPowerUpGraphics = self.attachAsset('healthPowerUp', {
anchorX: 0.5,
anchorY: 0.5
});
self.move = function () {
self.y += 4 + Math.floor(LK.ticks / (1800 * 30)); // Increase speed over time at 30 second intervals
};
});
var Medication = Container.expand(function () {
var self = Container.call(this);
var medicationGraphics = self.attachAsset('medication', {
anchorX: 0.5,
anchorY: 0.5
});
self.move = function () {
self.y += 4 + Math.floor(LK.ticks / (1800 * 30)); // Increase speed over time at 30 second intervals
};
});
// Assets will be automatically created based on usage in the code.
// Patient class
var Patient = Container.expand(function () {
var self = Container.call(this);
var patientGraphics = self.attachAsset('patient', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 100;
self.move = function (x, y) {
self.x += x;
self.y += y;
};
self.updateHealth = function (amount) {
self.health += amount;
if (self.health <= 0) {
LK.showGameOver();
} else {
// Ensure health bar scales correctly with patient's health, considering the initial width
var healthBarMaxWidth = 2048; // Maximum width of the health bar
var healthPercentage = self.health / 100; // Convert health to a percentage
healthBar.width = healthBarMaxWidth * healthPercentage; // Scale health bar width according to health percentage
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff",
anchorX: 0.5,
// Center horizontally
anchorY: 0.0 // Anchor at the top
});
scoreTxt.x = 1024; // Center horizontally
scoreTxt.y = 75; // Position above the health bar
LK.gui.top.addChild(scoreTxt);
// Generate medications
LK.setInterval(function () {
var medication = new Medication();
medication.x = Math.random() * 2048; // Random position across the width
medication.y = 0; // Start from the top
medications.push(medication);
game.addChild(medication);
}, 3000); // Every 3 seconds
var medications = [];
var healthBar = game.addChild(LK.getAsset('healthBar', {
x: 1024,
// Center horizontally
y: 25,
// Position at the top with half height as Y to center vertically
anchorX: 0.5,
anchorY: 0.5
}));
var patient = game.addChild(new Patient());
patient.x = 1024; // Center horizontally
patient.y = 2400; // Start near the bottom
var badDoctors = [];
var healthPowerUps = [];
var evilMonsters = [];
// Touch event to move patient
game.on('down', function (obj) {
var pos = obj.event.getLocalPosition(game);
var moveX = pos.x - patient.x;
var moveY = pos.y - patient.y;
patient.move(moveX, moveY);
});
// Generate bad doctors
LK.setInterval(function () {
var badDoctor = new BadDoctor();
badDoctor.x = Math.random() * 2048; // Random position across the width
badDoctor.y = 0; // Start from the top
badDoctors.push(badDoctor);
game.addChild(badDoctor);
}, 1000); // Every 1 second
// Generate health power ups
LK.setInterval(function () {
var healthPowerUp = new HealthPowerUp();
healthPowerUp.x = Math.random() * 2048; // Random position across the width
healthPowerUp.y = 0; // Start from the top
healthPowerUps.push(healthPowerUp);
game.addChild(healthPowerUp);
}, 5000); // Every 5 seconds
// Generate evil monsters
LK.setInterval(function () {
var evilMonster = new EvilMonster();
evilMonster.x = Math.random() * 2048; // Random position across the width
evilMonster.y = 0; // Start from the top
evilMonsters.push(evilMonster);
game.addChild(evilMonster);
}, 5000); // Every 5 seconds
// Game tick
LK.on('tick', function () {
// Move badDoctors
for (var i = badDoctors.length - 1; i >= 0; i--) {
badDoctors[i].move();
// Check collision with patient
if (badDoctors[i].intersects(patient)) {
patient.updateHealth(-10); // Reduce health on collision
badDoctors[i].destroy();
badDoctors.splice(i, 1);
}
// Remove off-screen badDoctors
else if (badDoctors[i].y > 2732) {
badDoctors[i].destroy();
badDoctors.splice(i, 1);
}
}
// Move healthPowerUps
for (var i = healthPowerUps.length - 1; i >= 0; i--) {
healthPowerUps[i].move();
// Check collision with patient
if (healthPowerUps[i].intersects(patient)) {
patient.updateHealth(100); // Restore health on collision
healthPowerUps[i].destroy();
healthPowerUps.splice(i, 1);
}
// Remove off-screen healthPowerUps
else if (healthPowerUps[i].y > 2732) {
healthPowerUps[i].destroy();
healthPowerUps.splice(i, 1);
}
}
// Move medications
for (var i = medications.length - 1; i >= 0; i--) {
medications[i].move();
// Check collision with patient
if (medications[i].intersects(patient)) {
LK.setScore(LK.getScore() + 1); // Increase score on collision
medications[i].destroy();
medications.splice(i, 1);
}
// Remove off-screen medications
else if (medications[i].y > 2732) {
medications[i].destroy();
medications.splice(i, 1);
}
}
// Move evilMonsters
for (var i = evilMonsters.length - 1; i >= 0; i--) {
evilMonsters[i].move();
// Check collision with patient
if (evilMonsters[i].intersects(patient)) {
patient.updateHealth(-patient.health); // Instantly kill the player on collision
evilMonsters[i].destroy();
evilMonsters.splice(i, 1);
}
// Remove off-screen evilMonsters
else if (evilMonsters[i].y > 2732) {
evilMonsters[i].destroy();
evilMonsters.splice(i, 1);
}
}
});
a sprite of a doctor. a 2d sprite of a doctor
a sprite of a male person in a hospital gown. a 2d sprite of a male person in a hospital gown
a sprite of a health pack. a 2d sprite of a health pack
a sprite of a virus monster. a 2d sprite of a virus monster
a sprite of medication pill. a 2d sprite of a yellow medication pill