/****
* Classes
****/
// Define the Hitman class
var Hitman = Container.expand(function () {
var self = Container.call(this);
var hitmanGraphics = self.createAsset('hitman', 'Hitman character', 0.5, 0.5);
self.target = null;
self.speed = 3;
self.moveLeft = function () {
self.x -= self.speed;
};
self.moveRight = function () {
self.x += self.speed;
};
self.targetX = self.x;
self.targetY = self.y;
self.setTargetPosition = function (x) {
self.targetX = x;
};
self.updatePosition = function () {
if (self.x < self.targetX) {
self.moveRight();
} else if (self.x > self.targetX) {
self.moveLeft();
}
};
});
// Define the Millionaire enemy class
var MillionaireEnemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.createAsset('millionaire', 'Millionaire enemy', 0.5, 0.5);
self.speed = 2;
self.patrol = function () {
self.x += self.speed;
if (self.x > 2048 - self.width / 2 || self.x < self.width / 2) {
self.speed *= -1;
}
};
});
// Define the Homeless enemy class
var HomelessEnemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.createAsset('homeless', 'Homeless enemy', 0.5, 0.5);
self.speed = 1;
self.patrol = function () {
self.x += self.speed;
if (self.x > 2048 - self.width / 2 || self.x < self.width / 2) {
self.speed *= -1;
}
};
});
// Define the RedSweater enemy class
var RedSweaterEnemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.createAsset('redsweater', 'Person in red sweater enemy', 0.5, 0.5);
self.speed = 2.5;
self.patrol = function () {
self.x += self.speed;
if (self.x > 2048 - self.width / 2 || self.x < self.width / 2) {
self.speed *= -1;
}
};
});
// Define the PinkLady enemy class
var PinkLadyEnemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.createAsset('pinklady', 'Woman in pink enemy', 0.5, 0.5);
self.speed = 1.5;
self.patrol = function () {
self.x += self.speed;
if (self.x > 2048 - self.width / 2 || self.x < self.width / 2) {
self.speed *= -1;
}
};
});
// Define the Elegant enemy class
var ElegantEnemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.createAsset('elegant', 'Elegant in suit enemy', 0.5, 0.5);
self.speed = 3;
self.patrol = function () {
self.x += self.speed;
if (self.x > 2048 - self.width / 2 || self.x < self.width / 2) {
self.speed *= -1;
}
};
});
// Define the PizzaGuy enemy class
var PizzaGuyEnemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.createAsset('pizzaguy', 'Pizza guy enemy', 0.5, 0.5);
self.speed = 2.2;
self.patrol = function () {
self.x += self.speed;
if (self.x > 2048 - self.width / 2 || self.x < self.width / 2) {
self.speed *= -1;
}
};
});
// Define the Bullet class for Hitman
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.createAsset('bullet', 'Bullet fired by Hitman', 0.5, 0.5);
self.speed = 10;
self.move = function () {
self.y -= self.speed;
};
});
// Define the Phone class
var Phone = Container.expand(function () {
var self = Container.call(this);
var phoneGraphics = self.createAsset('phone', 'Phone to receive messages', 0.5, 1);
self.messages = [];
self.messagesVisible = false;
self.addMessage = function (message, photoAssetId) {
self.messages.push({
message: message,
photo: photoAssetId
});
// Update the phone display with the new message and photo
var messageText = new Text2(message, {
size: 30,
fill: '#ffffff'
});
var photoSprite = self.createAsset(photoAssetId, 'Target photo', 0.5, 0.5);
// Position the message and photo on the phone display
// This is a simplified example, in a real scenario we would need to handle layout and scrolling
messageText.y = self.height - self.messages.length * 100;
photoSprite.y = messageText.y + messageText.height + 10;
photoSprite.width = self.width * 0.8; // Set the photo width to 80% of the phone width
photoSprite.height = photoSprite.width; // Keep the aspect ratio of the photo
photoSprite.x = self.width / 2; // Center the photo on the phone
self.addChild(messageText);
self.addChild(photoSprite);
};
self.toggleMessages = function () {
self.messagesVisible = !self.messagesVisible;
// Toggle the visibility of message elements and randomly display an enemy photo
var enemyTypes = ['millionaire', 'homeless', 'redsweater', 'pinklady', 'elegant', 'pizzaguy'];
var randomEnemyType = enemyTypes[Math.floor(Math.random() * enemyTypes.length)];
for (var i = 0; i < self.children.length; i++) {
self.children[i].visible = self.messagesVisible;
}
if (self.messagesVisible && self.messages.length > 0) {
var lastMessage = self.messages[self.messages.length - 1];
lastMessage.photo = randomEnemyType;
// Update the photo display with the new random enemy photo
var photoSprite = self.getChildByName('Target photo');
if (photoSprite) {
photoSprite.texture = LK.getAsset(randomEnemyType, 'Target photo', 0.5, 0.5).texture;
}
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Add background graphic
var backgroundGraphic = game.createAsset('background', 'Game background', 0, 0);
backgroundGraphic.width = 2048;
backgroundGraphic.height = 2732;
game.addChild(backgroundGraphic);
// Initialize important asset arrays
var enemies = [];
var bullets = [];
var hitman;
// Initialize the Hitman character
function initHitman() {
hitman = game.addChild(new Hitman());
hitman.x = 2048 / 2;
hitman.y = 2732 - 100;
}
// Initialize enemies
function initEnemies() {
var enemyClasses = [MillionaireEnemy, HomelessEnemy, RedSweaterEnemy, PinkLadyEnemy, ElegantEnemy, PizzaGuyEnemy];
for (var i = 0; i < enemyClasses.length; i++) {
var EnemyClass = enemyClasses[i];
var enemy = new EnemyClass();
enemy.x = 100 + i * 300; // Adjust spacing to fit all enemy types
enemy.y = 100;
enemies.push(enemy);
game.addChild(enemy);
}
}
// Check for bullet-enemy collisions
function checkCollisions() {
for (var b = bullets.length - 1; b >= 0; b--) {
for (var e = enemies.length - 1; e >= 0; e--) {
if (bullets[b].intersects(enemies[e])) {
if (hitman.target !== enemies[e]) {
LK.showGameOver();
} else {
enemies[e].destroy();
enemies.splice(e, 1);
}
bullets[b].destroy();
bullets.splice(b, 1);
break;
}
}
}
}
// Handle touch events for movement and shooting
function handleTouch(obj) {
var touchPos = obj.event.getLocalPosition(game);
hitman.setTargetPosition(touchPos.x);
// Check if the phone was touched and toggle messages
if (phone.intersects({
x: touchPos.x,
y: touchPos.y,
width: 1,
height: 1
})) {
phone.toggleMessages();
if (phone.messagesVisible && phone.messages.length > 0) {
var lastMessage = phone.messages[phone.messages.length - 1];
hitman.target = enemies.find(function (enemy) {
return enemy.createAsset === lastMessage.photo;
});
}
// Show the phone full-screen with messages
if (phone.messagesVisible) {
phone.scale.set(game.width / phone.width, game.height / phone.height);
phone.x = game.width / 2;
phone.y = game.height / 2;
phone.pivot.set(0.5, 0.5);
} else {
// Reset the phone to its original size and position
phone.scale.set(1, 1);
phone.x = 2048 - phone.width / 2;
phone.y = 2732 - phone.height / 2;
phone.pivot.set(0.5, 1);
}
return;
}
// Shoot a bullet
var bullet = new Bullet();
bullet.x = hitman.x;
bullet.y = hitman.y;
bullets.push(bullet);
game.addChild(bullet);
}
// Game tick update
LK.on('tick', function () {
// Move hitman towards target position
hitman.updatePosition();
// Move enemies
for (var i = 0; i < enemies.length; i++) {
enemies[i].patrol();
}
// Move bullets
for (var j = bullets.length - 1; j >= 0; j--) {
bullets[j].move();
// Remove bullets that are off-screen
if (bullets[j].y < -50) {
bullets[j].destroy();
bullets.splice(j, 1);
}
}
// Check for collisions
checkCollisions();
});
// Initialize game elements
initHitman();
initEnemies();
// Initialize the Phone object
var phone = game.addChild(new Phone());
phone.x = 2048 - phone.width / 2;
phone.y = 2732 / 2;
// Send a photo of the target to the hitman after 1 millisecond
LK.setTimeout(function () {
var enemyTypes = ['millionaire', 'homeless', 'redsweater', 'pinklady', 'elegant', 'pizzaguy'];
var randomEnemyType = enemyTypes[Math.floor(Math.random() * enemyTypes.length)];
phone.addMessage('Target acquired.', randomEnemyType);
}, 1);
// Add touch event listener to the game for movement and shooting
game.on('down', handleTouch); /****
* Classes
****/
// Define the Hitman class
var Hitman = Container.expand(function () {
var self = Container.call(this);
var hitmanGraphics = self.createAsset('hitman', 'Hitman character', 0.5, 0.5);
self.target = null;
self.speed = 3;
self.moveLeft = function () {
self.x -= self.speed;
};
self.moveRight = function () {
self.x += self.speed;
};
self.targetX = self.x;
self.targetY = self.y;
self.setTargetPosition = function (x) {
self.targetX = x;
};
self.updatePosition = function () {
if (self.x < self.targetX) {
self.moveRight();
} else if (self.x > self.targetX) {
self.moveLeft();
}
};
});
// Define the Millionaire enemy class
var MillionaireEnemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.createAsset('millionaire', 'Millionaire enemy', 0.5, 0.5);
self.speed = 2;
self.patrol = function () {
self.x += self.speed;
if (self.x > 2048 - self.width / 2 || self.x < self.width / 2) {
self.speed *= -1;
}
};
});
// Define the Homeless enemy class
var HomelessEnemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.createAsset('homeless', 'Homeless enemy', 0.5, 0.5);
self.speed = 1;
self.patrol = function () {
self.x += self.speed;
if (self.x > 2048 - self.width / 2 || self.x < self.width / 2) {
self.speed *= -1;
}
};
});
// Define the RedSweater enemy class
var RedSweaterEnemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.createAsset('redsweater', 'Person in red sweater enemy', 0.5, 0.5);
self.speed = 2.5;
self.patrol = function () {
self.x += self.speed;
if (self.x > 2048 - self.width / 2 || self.x < self.width / 2) {
self.speed *= -1;
}
};
});
// Define the PinkLady enemy class
var PinkLadyEnemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.createAsset('pinklady', 'Woman in pink enemy', 0.5, 0.5);
self.speed = 1.5;
self.patrol = function () {
self.x += self.speed;
if (self.x > 2048 - self.width / 2 || self.x < self.width / 2) {
self.speed *= -1;
}
};
});
// Define the Elegant enemy class
var ElegantEnemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.createAsset('elegant', 'Elegant in suit enemy', 0.5, 0.5);
self.speed = 3;
self.patrol = function () {
self.x += self.speed;
if (self.x > 2048 - self.width / 2 || self.x < self.width / 2) {
self.speed *= -1;
}
};
});
// Define the PizzaGuy enemy class
var PizzaGuyEnemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.createAsset('pizzaguy', 'Pizza guy enemy', 0.5, 0.5);
self.speed = 2.2;
self.patrol = function () {
self.x += self.speed;
if (self.x > 2048 - self.width / 2 || self.x < self.width / 2) {
self.speed *= -1;
}
};
});
// Define the Bullet class for Hitman
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.createAsset('bullet', 'Bullet fired by Hitman', 0.5, 0.5);
self.speed = 10;
self.move = function () {
self.y -= self.speed;
};
});
// Define the Phone class
var Phone = Container.expand(function () {
var self = Container.call(this);
var phoneGraphics = self.createAsset('phone', 'Phone to receive messages', 0.5, 1);
self.messages = [];
self.messagesVisible = false;
self.addMessage = function (message, photoAssetId) {
self.messages.push({
message: message,
photo: photoAssetId
});
// Update the phone display with the new message and photo
var messageText = new Text2(message, {
size: 30,
fill: '#ffffff'
});
var photoSprite = self.createAsset(photoAssetId, 'Target photo', 0.5, 0.5);
// Position the message and photo on the phone display
// This is a simplified example, in a real scenario we would need to handle layout and scrolling
messageText.y = self.height - self.messages.length * 100;
photoSprite.y = messageText.y + messageText.height + 10;
photoSprite.width = self.width * 0.8; // Set the photo width to 80% of the phone width
photoSprite.height = photoSprite.width; // Keep the aspect ratio of the photo
photoSprite.x = self.width / 2; // Center the photo on the phone
self.addChild(messageText);
self.addChild(photoSprite);
};
self.toggleMessages = function () {
self.messagesVisible = !self.messagesVisible;
// Toggle the visibility of message elements and randomly display an enemy photo
var enemyTypes = ['millionaire', 'homeless', 'redsweater', 'pinklady', 'elegant', 'pizzaguy'];
var randomEnemyType = enemyTypes[Math.floor(Math.random() * enemyTypes.length)];
for (var i = 0; i < self.children.length; i++) {
self.children[i].visible = self.messagesVisible;
}
if (self.messagesVisible && self.messages.length > 0) {
var lastMessage = self.messages[self.messages.length - 1];
lastMessage.photo = randomEnemyType;
// Update the photo display with the new random enemy photo
var photoSprite = self.getChildByName('Target photo');
if (photoSprite) {
photoSprite.texture = LK.getAsset(randomEnemyType, 'Target photo', 0.5, 0.5).texture;
}
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Add background graphic
var backgroundGraphic = game.createAsset('background', 'Game background', 0, 0);
backgroundGraphic.width = 2048;
backgroundGraphic.height = 2732;
game.addChild(backgroundGraphic);
// Initialize important asset arrays
var enemies = [];
var bullets = [];
var hitman;
// Initialize the Hitman character
function initHitman() {
hitman = game.addChild(new Hitman());
hitman.x = 2048 / 2;
hitman.y = 2732 - 100;
}
// Initialize enemies
function initEnemies() {
var enemyClasses = [MillionaireEnemy, HomelessEnemy, RedSweaterEnemy, PinkLadyEnemy, ElegantEnemy, PizzaGuyEnemy];
for (var i = 0; i < enemyClasses.length; i++) {
var EnemyClass = enemyClasses[i];
var enemy = new EnemyClass();
enemy.x = 100 + i * 300; // Adjust spacing to fit all enemy types
enemy.y = 100;
enemies.push(enemy);
game.addChild(enemy);
}
}
// Check for bullet-enemy collisions
function checkCollisions() {
for (var b = bullets.length - 1; b >= 0; b--) {
for (var e = enemies.length - 1; e >= 0; e--) {
if (bullets[b].intersects(enemies[e])) {
if (hitman.target !== enemies[e]) {
LK.showGameOver();
} else {
enemies[e].destroy();
enemies.splice(e, 1);
}
bullets[b].destroy();
bullets.splice(b, 1);
break;
}
}
}
}
// Handle touch events for movement and shooting
function handleTouch(obj) {
var touchPos = obj.event.getLocalPosition(game);
hitman.setTargetPosition(touchPos.x);
// Check if the phone was touched and toggle messages
if (phone.intersects({
x: touchPos.x,
y: touchPos.y,
width: 1,
height: 1
})) {
phone.toggleMessages();
if (phone.messagesVisible && phone.messages.length > 0) {
var lastMessage = phone.messages[phone.messages.length - 1];
hitman.target = enemies.find(function (enemy) {
return enemy.createAsset === lastMessage.photo;
});
}
// Show the phone full-screen with messages
if (phone.messagesVisible) {
phone.scale.set(game.width / phone.width, game.height / phone.height);
phone.x = game.width / 2;
phone.y = game.height / 2;
phone.pivot.set(0.5, 0.5);
} else {
// Reset the phone to its original size and position
phone.scale.set(1, 1);
phone.x = 2048 - phone.width / 2;
phone.y = 2732 - phone.height / 2;
phone.pivot.set(0.5, 1);
}
return;
}
// Shoot a bullet
var bullet = new Bullet();
bullet.x = hitman.x;
bullet.y = hitman.y;
bullets.push(bullet);
game.addChild(bullet);
}
// Game tick update
LK.on('tick', function () {
// Move hitman towards target position
hitman.updatePosition();
// Move enemies
for (var i = 0; i < enemies.length; i++) {
enemies[i].patrol();
}
// Move bullets
for (var j = bullets.length - 1; j >= 0; j--) {
bullets[j].move();
// Remove bullets that are off-screen
if (bullets[j].y < -50) {
bullets[j].destroy();
bullets.splice(j, 1);
}
}
// Check for collisions
checkCollisions();
});
// Initialize game elements
initHitman();
initEnemies();
// Initialize the Phone object
var phone = game.addChild(new Phone());
phone.x = 2048 - phone.width / 2;
phone.y = 2732 / 2;
// Send a photo of the target to the hitman after 1 millisecond
LK.setTimeout(function () {
var enemyTypes = ['millionaire', 'homeless', 'redsweater', 'pinklady', 'elegant', 'pizzaguy'];
var randomEnemyType = enemyTypes[Math.floor(Math.random() * enemyTypes.length)];
phone.addMessage('Target acquired.', randomEnemyType);
}, 1);
// Add touch event listener to the game for movement and shooting
game.on('down', handleTouch);
Ниндзя с винтовкой лежит. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Телефон с приложениями. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Патрон винтовки. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Богатый человек идёт. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Бомж идёт. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Дорога и кусты. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.