/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Pet = Container.expand(function (petType) {
var self = Container.call(this);
self.petType = petType;
self.isHealed = false;
self.isSelected = false;
self.ailments = [];
// Create pet body
var body = self.attachAsset(petType, {
anchorX: 0.5,
anchorY: 0.5
});
// Add ailments based on pet type
self.createAilments = function () {
if (self.petType === 'lizard') {
// Add flies in tummy
for (var i = 0; i < 3; i++) {
var fly = self.attachAsset('fly', {
anchorX: 0.5,
anchorY: 0.5,
x: (Math.random() - 0.5) * 100,
y: (Math.random() - 0.5) * 80
});
self.ailments.push(fly);
}
} else if (self.petType === 'rabbit') {
// Add red bumps
for (var i = 0; i < 4; i++) {
var bump = self.attachAsset('redBump', {
anchorX: 0.5,
anchorY: 0.5,
x: (Math.random() - 0.5) * 150,
y: (Math.random() - 0.5) * 200
});
self.ailments.push(bump);
}
} else if (self.petType === 'cat') {
// Add injury to ear
var injury = self.attachAsset('injury', {
anchorX: 0.5,
anchorY: 0.5,
x: -80,
y: -100
});
self.ailments.push(injury);
} else if (self.petType === 'frog') {
// Add orange bumps on head
for (var i = 0; i < 3; i++) {
var bump = self.attachAsset('orangeBump', {
anchorX: 0.5,
anchorY: 0.5,
x: (Math.random() - 0.5) * 120,
y: -60 + (Math.random() - 0.5) * 40
});
self.ailments.push(bump);
}
}
};
self.createAilments();
self.down = function (x, y, obj) {
if (!self.isSelected && !self.isHealed) {
LK.getSound('select').play();
selectedPet = self;
self.isSelected = true;
// Highlight selected pet
tween(body, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 200
});
// Update instruction text
updateInstructionText();
} else if (self.isSelected && !self.isHealed) {
// Treat ailment
self.treatAilment(x, y);
}
};
self.treatAilment = function (localX, localY) {
for (var i = self.ailments.length - 1; i >= 0; i--) {
var ailment = self.ailments[i];
var distance = Math.sqrt(Math.pow(localX - ailment.x, 2) + Math.pow(localY - ailment.y, 2));
if (distance < 30) {
// Create heal effect
var healEffect = self.attachAsset('healEffect', {
anchorX: 0.5,
anchorY: 0.5,
x: ailment.x,
y: ailment.y,
alpha: 0.8
});
// Animate heal effect
tween(healEffect, {
scaleX: 2,
scaleY: 2,
alpha: 0
}, {
duration: 500,
onFinish: function onFinish() {
healEffect.destroy();
}
});
// Remove ailment
ailment.destroy();
self.ailments.splice(i, 1);
LK.getSound('heal').play();
LK.setScore(LK.getScore() + 10);
scoreText.setText(LK.getScore());
break;
}
}
// Check if all ailments are healed
if (self.ailments.length === 0) {
self.healPet();
}
};
self.healPet = function () {
self.isHealed = true;
self.isSelected = false;
selectedPet = null;
// Flash green to show healing
LK.effects.flashObject(self, 0x00FF00, 1000);
// Scale back to normal
tween(body, {
scaleX: 1,
scaleY: 1
}, {
duration: 200
});
// Increase score bonus
LK.setScore(LK.getScore() + 50);
scoreText.setText(LK.getScore());
petsHealed++;
updateInstructionText();
// Check win condition
if (petsHealed >= 10) {
LK.showYouWin();
}
// Respawn after delay
LK.setTimeout(function () {
self.respawn();
}, 2000);
};
self.respawn = function () {
self.isHealed = false;
self.isSelected = false;
// Clear existing ailments
for (var i = 0; i < self.ailments.length; i++) {
self.ailments[i].destroy();
}
self.ailments = [];
// Create new ailments
self.createAilments();
// Reset scale
body.scaleX = 1;
body.scaleY = 1;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var selectedPet = null;
var petsHealed = 0;
// Create pets
var lizard = game.addChild(new Pet('lizard'));
lizard.x = 512;
lizard.y = 600;
var rabbit = game.addChild(new Pet('rabbit'));
rabbit.x = 1536;
rabbit.y = 600;
var cat = game.addChild(new Pet('cat'));
cat.x = 512;
cat.y = 1400;
var frog = game.addChild(new Pet('frog'));
frog.x = 1536;
frog.y = 1400;
// Create UI
var titleText = new Text2('Pet Doctor Clinic', {
size: 120,
fill: 0x2E7D32
});
titleText.anchor.set(0.5, 0);
LK.gui.top.addChild(titleText);
var scoreText = new Text2('Score: 0', {
size: 80,
fill: 0x1976D2
});
scoreText.anchor.set(1, 0);
LK.gui.topRight.addChild(scoreText);
scoreText.x = -20;
scoreText.y = 20;
var instructionText = new Text2('Tap a sick pet to select it!', {
size: 60,
fill: 0x4A4A4A
});
instructionText.anchor.set(0.5, 0);
LK.gui.center.addChild(instructionText);
instructionText.y = 800;
function updateInstructionText() {
if (selectedPet && !selectedPet.isHealed) {
var instructions = {
'lizard': 'Tap the flies to remove them!',
'rabbit': 'Tap the red bumps to heal them!',
'cat': 'Tap the injury to treat it!',
'frog': 'Tap the orange bumps to cure them!'
};
instructionText.setText(instructions[selectedPet.petType]);
} else {
instructionText.setText('Tap a sick pet to select it!');
}
}
// Initialize score
scoreText.setText('Score: ' + LK.getScore());
game.update = function () {
// Game logic updates handled by pet classes
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Pet = Container.expand(function (petType) {
var self = Container.call(this);
self.petType = petType;
self.isHealed = false;
self.isSelected = false;
self.ailments = [];
// Create pet body
var body = self.attachAsset(petType, {
anchorX: 0.5,
anchorY: 0.5
});
// Add ailments based on pet type
self.createAilments = function () {
if (self.petType === 'lizard') {
// Add flies in tummy
for (var i = 0; i < 3; i++) {
var fly = self.attachAsset('fly', {
anchorX: 0.5,
anchorY: 0.5,
x: (Math.random() - 0.5) * 100,
y: (Math.random() - 0.5) * 80
});
self.ailments.push(fly);
}
} else if (self.petType === 'rabbit') {
// Add red bumps
for (var i = 0; i < 4; i++) {
var bump = self.attachAsset('redBump', {
anchorX: 0.5,
anchorY: 0.5,
x: (Math.random() - 0.5) * 150,
y: (Math.random() - 0.5) * 200
});
self.ailments.push(bump);
}
} else if (self.petType === 'cat') {
// Add injury to ear
var injury = self.attachAsset('injury', {
anchorX: 0.5,
anchorY: 0.5,
x: -80,
y: -100
});
self.ailments.push(injury);
} else if (self.petType === 'frog') {
// Add orange bumps on head
for (var i = 0; i < 3; i++) {
var bump = self.attachAsset('orangeBump', {
anchorX: 0.5,
anchorY: 0.5,
x: (Math.random() - 0.5) * 120,
y: -60 + (Math.random() - 0.5) * 40
});
self.ailments.push(bump);
}
}
};
self.createAilments();
self.down = function (x, y, obj) {
if (!self.isSelected && !self.isHealed) {
LK.getSound('select').play();
selectedPet = self;
self.isSelected = true;
// Highlight selected pet
tween(body, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 200
});
// Update instruction text
updateInstructionText();
} else if (self.isSelected && !self.isHealed) {
// Treat ailment
self.treatAilment(x, y);
}
};
self.treatAilment = function (localX, localY) {
for (var i = self.ailments.length - 1; i >= 0; i--) {
var ailment = self.ailments[i];
var distance = Math.sqrt(Math.pow(localX - ailment.x, 2) + Math.pow(localY - ailment.y, 2));
if (distance < 30) {
// Create heal effect
var healEffect = self.attachAsset('healEffect', {
anchorX: 0.5,
anchorY: 0.5,
x: ailment.x,
y: ailment.y,
alpha: 0.8
});
// Animate heal effect
tween(healEffect, {
scaleX: 2,
scaleY: 2,
alpha: 0
}, {
duration: 500,
onFinish: function onFinish() {
healEffect.destroy();
}
});
// Remove ailment
ailment.destroy();
self.ailments.splice(i, 1);
LK.getSound('heal').play();
LK.setScore(LK.getScore() + 10);
scoreText.setText(LK.getScore());
break;
}
}
// Check if all ailments are healed
if (self.ailments.length === 0) {
self.healPet();
}
};
self.healPet = function () {
self.isHealed = true;
self.isSelected = false;
selectedPet = null;
// Flash green to show healing
LK.effects.flashObject(self, 0x00FF00, 1000);
// Scale back to normal
tween(body, {
scaleX: 1,
scaleY: 1
}, {
duration: 200
});
// Increase score bonus
LK.setScore(LK.getScore() + 50);
scoreText.setText(LK.getScore());
petsHealed++;
updateInstructionText();
// Check win condition
if (petsHealed >= 10) {
LK.showYouWin();
}
// Respawn after delay
LK.setTimeout(function () {
self.respawn();
}, 2000);
};
self.respawn = function () {
self.isHealed = false;
self.isSelected = false;
// Clear existing ailments
for (var i = 0; i < self.ailments.length; i++) {
self.ailments[i].destroy();
}
self.ailments = [];
// Create new ailments
self.createAilments();
// Reset scale
body.scaleX = 1;
body.scaleY = 1;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var selectedPet = null;
var petsHealed = 0;
// Create pets
var lizard = game.addChild(new Pet('lizard'));
lizard.x = 512;
lizard.y = 600;
var rabbit = game.addChild(new Pet('rabbit'));
rabbit.x = 1536;
rabbit.y = 600;
var cat = game.addChild(new Pet('cat'));
cat.x = 512;
cat.y = 1400;
var frog = game.addChild(new Pet('frog'));
frog.x = 1536;
frog.y = 1400;
// Create UI
var titleText = new Text2('Pet Doctor Clinic', {
size: 120,
fill: 0x2E7D32
});
titleText.anchor.set(0.5, 0);
LK.gui.top.addChild(titleText);
var scoreText = new Text2('Score: 0', {
size: 80,
fill: 0x1976D2
});
scoreText.anchor.set(1, 0);
LK.gui.topRight.addChild(scoreText);
scoreText.x = -20;
scoreText.y = 20;
var instructionText = new Text2('Tap a sick pet to select it!', {
size: 60,
fill: 0x4A4A4A
});
instructionText.anchor.set(0.5, 0);
LK.gui.center.addChild(instructionText);
instructionText.y = 800;
function updateInstructionText() {
if (selectedPet && !selectedPet.isHealed) {
var instructions = {
'lizard': 'Tap the flies to remove them!',
'rabbit': 'Tap the red bumps to heal them!',
'cat': 'Tap the injury to treat it!',
'frog': 'Tap the orange bumps to cure them!'
};
instructionText.setText(instructions[selectedPet.petType]);
} else {
instructionText.setText('Tap a sick pet to select it!');
}
}
// Initialize score
scoreText.setText('Score: ' + LK.getScore());
game.update = function () {
// Game logic updates handled by pet classes
};