/****
* Classes
****/
// Doctor class representing the player character
var Doctor = Container.expand(function () {
var self = Container.call(this);
var doctorGraphics = self.attachAsset('doctor', {
anchorX: 0.5,
anchorY: 0.5
});
self.move = function (x, y, obj) {
var game_position = game.toLocal(obj.global);
self.x = game_position.x;
self.y = game_position.y;
};
});
//<Assets used in the game will automatically appear here>
// Heart class representing the collectible heart
var Heart = Container.expand(function () {
var self = Container.call(this);
var heartGraphics = self.attachAsset('heart', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.y += 5; // Move downwards
if (self.y > 2732) {
self.destroy();
}
};
});
// Poison class representing the harmful collectible
var Poison = Container.expand(function () {
var self = Container.call(this);
var poisonGraphics = self.attachAsset('poison', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.y += 5; // Move downwards
if (self.y > 2732) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundImage: 'tummy'
});
/****
* Game Code
****/
var doctor = new Doctor();
doctor.x = 2048 / 2;
doctor.y = 2500;
game.addChild(doctor);
var hearts = [];
var poisons = [];
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
function spawnHeart() {
var heart = new Heart();
heart.x = Math.random() * 2048;
heart.y = -50;
hearts.push(heart);
game.addChild(heart);
}
function spawnPoison() {
var poison = new Poison();
poison.x = Math.random() * 2048;
poison.y = -50;
poisons.push(poison);
game.addChild(poison);
}
var dragNode = null;
// Declare the handleMove function
function handleMove(x, y, obj) {
//Get event position in relation to game object
if (dragNode) {
dragNode.x = x;
dragNode.y = y;
}
}
game.down = function (x, y, obj) {
//Set drag node to doctor.
dragNode = doctor;
//Also call move handler right away to make effect instant.
handleMove(x, y, obj);
};
game.move = handleMove;
game.update = function () {
if (LK.ticks % 60 == 0) {
spawnHeart();
spawnPoison();
}
for (var i = hearts.length - 1; i >= 0; i--) {
if (doctor.intersects(hearts[i])) {
score += 1;
scoreTxt.setText(score);
hearts[i].destroy();
hearts.splice(i, 1);
LK.getSound('CollectHeart').play();
if (score == 20) {
var fanfare = game.attachAsset('fanfare', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
var fanfareSound = LK.getSound('fanfareSound');
fanfareSound.play();
doctor.destroy();
scoreTxt.destroy();
LK.setTimeout(function () {
LK.showGameOver();
}, fanfareSound.duration * 1000);
}
}
}
for (var j = poisons.length - 1; j >= 0; j--) {
if (doctor.intersects(poisons[j])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
};
//Mouse or touch up on game object
game.up = function (x, y, obj) {
dragNode = null;
}; /****
* Classes
****/
// Doctor class representing the player character
var Doctor = Container.expand(function () {
var self = Container.call(this);
var doctorGraphics = self.attachAsset('doctor', {
anchorX: 0.5,
anchorY: 0.5
});
self.move = function (x, y, obj) {
var game_position = game.toLocal(obj.global);
self.x = game_position.x;
self.y = game_position.y;
};
});
//<Assets used in the game will automatically appear here>
// Heart class representing the collectible heart
var Heart = Container.expand(function () {
var self = Container.call(this);
var heartGraphics = self.attachAsset('heart', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.y += 5; // Move downwards
if (self.y > 2732) {
self.destroy();
}
};
});
// Poison class representing the harmful collectible
var Poison = Container.expand(function () {
var self = Container.call(this);
var poisonGraphics = self.attachAsset('poison', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.y += 5; // Move downwards
if (self.y > 2732) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundImage: 'tummy'
});
/****
* Game Code
****/
var doctor = new Doctor();
doctor.x = 2048 / 2;
doctor.y = 2500;
game.addChild(doctor);
var hearts = [];
var poisons = [];
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
function spawnHeart() {
var heart = new Heart();
heart.x = Math.random() * 2048;
heart.y = -50;
hearts.push(heart);
game.addChild(heart);
}
function spawnPoison() {
var poison = new Poison();
poison.x = Math.random() * 2048;
poison.y = -50;
poisons.push(poison);
game.addChild(poison);
}
var dragNode = null;
// Declare the handleMove function
function handleMove(x, y, obj) {
//Get event position in relation to game object
if (dragNode) {
dragNode.x = x;
dragNode.y = y;
}
}
game.down = function (x, y, obj) {
//Set drag node to doctor.
dragNode = doctor;
//Also call move handler right away to make effect instant.
handleMove(x, y, obj);
};
game.move = handleMove;
game.update = function () {
if (LK.ticks % 60 == 0) {
spawnHeart();
spawnPoison();
}
for (var i = hearts.length - 1; i >= 0; i--) {
if (doctor.intersects(hearts[i])) {
score += 1;
scoreTxt.setText(score);
hearts[i].destroy();
hearts.splice(i, 1);
LK.getSound('CollectHeart').play();
if (score == 20) {
var fanfare = game.attachAsset('fanfare', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
var fanfareSound = LK.getSound('fanfareSound');
fanfareSound.play();
doctor.destroy();
scoreTxt.destroy();
LK.setTimeout(function () {
LK.showGameOver();
}, fanfareSound.duration * 1000);
}
}
}
for (var j = poisons.length - 1; j >= 0; j--) {
if (doctor.intersects(poisons[j])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
};
//Mouse or touch up on game object
game.up = function (x, y, obj) {
dragNode = null;
};
A doctor. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A heart. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A bottle of poison. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A person's inside of their stomach. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An image of doctors saving a person from an emergency situation. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.