/****
* Classes
****/
var Creature = Container.expand(function () {
var self = Container.call(this);
var creatureGraphics = self.attachAsset('creature', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.x += (player.x - self.x) * 0.02;
self.y += (player.y - self.y) * 0.02;
};
});
// Enemy class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {};
});
// VhsTape class
var VhsTape = Container.expand(function () {
var self = Container.call(this);
var tapeGraphics = self.attachAsset('vhsTape', {
anchorX: 0.5,
anchorY: 0.5
});
self.collected = false;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize assets for the game
var player = game.addChild(new Player());
player.x = 1024; // Center horizontally
player.y = 2500; // Position towards the bottom
var creature = game.addChild(new Creature());
creature.x = 0; // Start at left edge
creature.y = 1366; // Center vertically
var vhsTapes = [];
// Create vhs tapes
for (var i = 0; i < 5; i++) {
var tape = new VhsTape();
tape.x = Math.random() * 2048; // Random position horizontally
tape.y = Math.random() * 2732; // Random position vertically
vhsTapes.push(tape);
game.addChild(tape);
}
// Touch event to move player
var targetPos;
game.on('down', function (obj) {
targetPos = obj.event.getLocalPosition(game);
});
LK.on('tick', function () {
if (targetPos) {
player.x += (targetPos.x - player.x) * 0.1;
player.y += (targetPos.y - player.y) * 0.1;
}
creature.update();
});
// Game tick
LK.on('tick', function () {
// Collision detection (simplified)
vhsTapes.forEach(function (tape) {
if (tape.intersects(player) && !tape.collected) {
tape.collected = true;
tape.visible = false;
// Update score
LK.setScore(LK.getScore() + 1);
}
});
// Check if all tapes are collected
if (creature.intersects(player)) {
// Trigger jumpscare
var jumpscare = game.addChild(LK.getAsset('jumpscare', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366,
scaleX: 20,
scaleY: 20
}));
// Hide player
player.visible = false;
// Wait 3 seconds and reset game
LK.setTimeout(function () {
LK.showGameOver();
}, 3000);
} else if (LK.getScore() == 5) {
// Remove creature
creature.destroy();
// Display 'You Won' text
var winText = new Text2('You Won!', {
size: 150,
fill: '#ffffff'
});
winText.anchor.set(0.5, 0);
LK.gui.center.addChild(winText);
// Wait 3 seconds and reset game
LK.setTimeout(function () {
LK.showGameOver();
}, 3000);
}
}); /****
* Classes
****/
var Creature = Container.expand(function () {
var self = Container.call(this);
var creatureGraphics = self.attachAsset('creature', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.x += (player.x - self.x) * 0.02;
self.y += (player.y - self.y) * 0.02;
};
});
// Enemy class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {};
});
// VhsTape class
var VhsTape = Container.expand(function () {
var self = Container.call(this);
var tapeGraphics = self.attachAsset('vhsTape', {
anchorX: 0.5,
anchorY: 0.5
});
self.collected = false;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize assets for the game
var player = game.addChild(new Player());
player.x = 1024; // Center horizontally
player.y = 2500; // Position towards the bottom
var creature = game.addChild(new Creature());
creature.x = 0; // Start at left edge
creature.y = 1366; // Center vertically
var vhsTapes = [];
// Create vhs tapes
for (var i = 0; i < 5; i++) {
var tape = new VhsTape();
tape.x = Math.random() * 2048; // Random position horizontally
tape.y = Math.random() * 2732; // Random position vertically
vhsTapes.push(tape);
game.addChild(tape);
}
// Touch event to move player
var targetPos;
game.on('down', function (obj) {
targetPos = obj.event.getLocalPosition(game);
});
LK.on('tick', function () {
if (targetPos) {
player.x += (targetPos.x - player.x) * 0.1;
player.y += (targetPos.y - player.y) * 0.1;
}
creature.update();
});
// Game tick
LK.on('tick', function () {
// Collision detection (simplified)
vhsTapes.forEach(function (tape) {
if (tape.intersects(player) && !tape.collected) {
tape.collected = true;
tape.visible = false;
// Update score
LK.setScore(LK.getScore() + 1);
}
});
// Check if all tapes are collected
if (creature.intersects(player)) {
// Trigger jumpscare
var jumpscare = game.addChild(LK.getAsset('jumpscare', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366,
scaleX: 20,
scaleY: 20
}));
// Hide player
player.visible = false;
// Wait 3 seconds and reset game
LK.setTimeout(function () {
LK.showGameOver();
}, 3000);
} else if (LK.getScore() == 5) {
// Remove creature
creature.destroy();
// Display 'You Won' text
var winText = new Text2('You Won!', {
size: 150,
fill: '#ffffff'
});
winText.anchor.set(0.5, 0);
LK.gui.center.addChild(winText);
// Wait 3 seconds and reset game
LK.setTimeout(function () {
LK.showGameOver();
}, 3000);
}
});