/**** * Classes ****/ var Ghost = Container.expand(function () { var self = Container.call(this); var ghostGraphics = self.attachAsset('ghost', { anchorX: 0.5, anchorY: 0.5, alpha: 0.5 }); self.target = character; // Reference to the player character self.speed = 3; self.move = function () { var dx = self.target.x - self.x; var dy = self.target.y - self.y; var angle = Math.atan2(dy, dx); self.speedX = Math.cos(angle) * self.speed; self.speedY = Math.sin(angle) * self.speed; self.x += self.speedX; self.y += self.speedY; }; }); // PowerUp class var PowerUp = Container.expand(function () { var self = Container.call(this); var powerUpGraphics = self.attachAsset('block', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.move = function () { self.y += self.speed; self.on('down', function (obj) { var touchPos = obj.event.getLocalPosition(game); ghosts.forEach(function (ghost) { ghost.visible = false; }); }); }; }); // Character class var Character = Container.expand(function () { var self = Container.call(this); var characterGraphics = self.attachAsset('character', { anchorX: 0.5, anchorY: 0.5 }); self.on('down', function (obj) { var touchPos = obj.event.getLocalPosition(game); self.x = touchPos.x; self.y = touchPos.y; }); self.on('move', function (obj) { var touchPos = obj.event.getLocalPosition(game); self.x = touchPos.x; self.y = touchPos.y; }); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1b1b1b // Init game with a dark grey background }); /**** * Game Code ****/ // Initialize assets used in this game. // Initialize character function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) { descriptor.writable = true; } Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) { _defineProperties(Constructor.prototype, protoProps); } if (staticProps) { _defineProperties(Constructor, staticProps); } Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) { return t; } var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) { return i; } throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) { _setPrototypeOf(subClass, superClass); } } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) { return false; } if (Reflect.construct.sham) { return false; } if (typeof Proxy === "function") { return true; } try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var character = game.addChild(new Character()); character.x = 1024; character.y = 2632; // Initialize powerUps array var powerUps = []; // Initialize ghosts array var ghosts = []; // Initialize ghosts array var ghosts = []; // Initialize score var score = 0; var scoreTxt = new Text2(score.toString(), { size: 150, fill: "#ffffff" }); // ScaryStory class var ScaryStory = /*#__PURE__*/function (_Container) { _inherits(ScaryStory, _Container); var _super = _createSuper(ScaryStory); function ScaryStory() { var _this; _classCallCheck(this, ScaryStory); _this = _super.call(this); _this.text = new Text2('A long time ago...', { size: 100, fill: "#ff0000", align: 'center' }); _this.text.anchor.set(0.5, 0.5); _this.text.x = 1024; _this.text.y = 1366; _this.addChild(_this.text); _this.visible = false; return _this; } _createClass(ScaryStory, [{ key: "show", value: function show() { this.visible = true; var self = this; LK.setTimeout(function () { self.visible = false; }, 5000); } }]); return ScaryStory; }(Container); // Initialize scary story var scaryStory = new ScaryStory(); LK.gui.center.addChild(scaryStory); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Game tick event LK.on('tick', function () { // Move power-ups for (var i = powerUps.length - 1; i >= 0; i--) { powerUps[i].move(); // Collect power-up and increase scare level if (powerUps[i].intersects(character)) { // Increase scare level score++; // Update score text scoreTxt.setText(score.toString()); powerUps[i].destroy(); powerUps.splice(i, 1); } // Remove off-screen power-ups if (powerUps[i] && powerUps[i].y > 2782) { powerUps[i].destroy(); powerUps.splice(i, 1); } } // Move ghosts and check for collisions with the character to trigger jumpscare for (var j = ghosts.length - 1; j >= 0; j--) { ghosts[j].move(); // Check if ghost intersects with the character if (ghosts[j].intersects(character)) { // Trigger jumpscare triggerJumpscare(); // Remove the ghost that caused the jumpscare ghosts[j].destroy(); ghosts.splice(j, 1); // End the game LK.showGameOver(); // Break out of the loop as the game is over break; } } // Function to handle the jumpscare logic function triggerJumpscare() { // Display the screaming ghost asset and play jumpscare sound var jumpscareGhost = game.addChild(LK.getAsset('screamingGhost', { anchorX: 0.5, anchorY: 0.5 })); jumpscareGhost.x = game.width / 2; jumpscareGhost.y = game.height / 2; scoreTxt.visible = false; // Hide the score text // LK.playSound('jumpscareSound'); // Removed because LK.playSound is not a function // Set a timeout to remove the jumpscare after a short duration LK.setTimeout(function () { jumpscareGhost.destroy(); scoreTxt.visible = true; // Show the score text again }, 2000); // Display for 2 seconds } // Add new power-ups if (LK.ticks % 60 == 0) { var newPowerUp = new PowerUp(); newPowerUp.x = Math.random() * 2048; newPowerUp.y = -50; powerUps.push(newPowerUp); game.addChild(newPowerUp); } // Add new ghosts if (LK.ticks % 180 == 0) { var newGhost = new Ghost(); newGhost.x = Math.random() * 2048; newGhost.y = Math.random() * 2732; ghosts.push(newGhost); game.addChild(newGhost); } // Show scary story at a certain interval if (LK.ticks % 600 == 0) { scaryStory.show(); } // Update score score++; scoreTxt.setText(score.toString()); });
/****
* Classes
****/
var Ghost = Container.expand(function () {
var self = Container.call(this);
var ghostGraphics = self.attachAsset('ghost', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.5
});
self.target = character; // Reference to the player character
self.speed = 3;
self.move = function () {
var dx = self.target.x - self.x;
var dy = self.target.y - self.y;
var angle = Math.atan2(dy, dx);
self.speedX = Math.cos(angle) * self.speed;
self.speedY = Math.sin(angle) * self.speed;
self.x += self.speedX;
self.y += self.speedY;
};
});
// PowerUp class
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var powerUpGraphics = self.attachAsset('block', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.move = function () {
self.y += self.speed;
self.on('down', function (obj) {
var touchPos = obj.event.getLocalPosition(game);
ghosts.forEach(function (ghost) {
ghost.visible = false;
});
});
};
});
// Character class
var Character = Container.expand(function () {
var self = Container.call(this);
var characterGraphics = self.attachAsset('character', {
anchorX: 0.5,
anchorY: 0.5
});
self.on('down', function (obj) {
var touchPos = obj.event.getLocalPosition(game);
self.x = touchPos.x;
self.y = touchPos.y;
});
self.on('move', function (obj) {
var touchPos = obj.event.getLocalPosition(game);
self.x = touchPos.x;
self.y = touchPos.y;
});
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1b1b1b // Init game with a dark grey background
});
/****
* Game Code
****/
// Initialize assets used in this game.
// Initialize character
function _typeof(o) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, _typeof(o);
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) {
descriptor.writable = true;
}
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) {
_defineProperties(Constructor.prototype, protoProps);
}
if (staticProps) {
_defineProperties(Constructor, staticProps);
}
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _toPropertyKey(t) {
var i = _toPrimitive(t, "string");
return "symbol" == _typeof(i) ? i : String(i);
}
function _toPrimitive(t, r) {
if ("object" != _typeof(t) || !t) {
return t;
}
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != _typeof(i)) {
return i;
}
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
});
Object.defineProperty(subClass, "prototype", {
writable: false
});
if (superClass) {
_setPrototypeOf(subClass, superClass);
}
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _createSuper(Derived) {
var hasNativeReflectConstruct = _isNativeReflectConstruct();
return function _createSuperInternal() {
var Super = _getPrototypeOf(Derived),
result;
if (hasNativeReflectConstruct) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
function _possibleConstructorReturn(self, call) {
if (call && (_typeof(call) === "object" || typeof call === "function")) {
return call;
} else if (call !== void 0) {
throw new TypeError("Derived constructors may only return object or undefined");
}
return _assertThisInitialized(self);
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) {
return false;
}
if (Reflect.construct.sham) {
return false;
}
if (typeof Proxy === "function") {
return true;
}
try {
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
return true;
} catch (e) {
return false;
}
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
var character = game.addChild(new Character());
character.x = 1024;
character.y = 2632;
// Initialize powerUps array
var powerUps = [];
// Initialize ghosts array
var ghosts = [];
// Initialize ghosts array
var ghosts = [];
// Initialize score
var score = 0;
var scoreTxt = new Text2(score.toString(), {
size: 150,
fill: "#ffffff"
});
// ScaryStory class
var ScaryStory = /*#__PURE__*/function (_Container) {
_inherits(ScaryStory, _Container);
var _super = _createSuper(ScaryStory);
function ScaryStory() {
var _this;
_classCallCheck(this, ScaryStory);
_this = _super.call(this);
_this.text = new Text2('A long time ago...', {
size: 100,
fill: "#ff0000",
align: 'center'
});
_this.text.anchor.set(0.5, 0.5);
_this.text.x = 1024;
_this.text.y = 1366;
_this.addChild(_this.text);
_this.visible = false;
return _this;
}
_createClass(ScaryStory, [{
key: "show",
value: function show() {
this.visible = true;
var self = this;
LK.setTimeout(function () {
self.visible = false;
}, 5000);
}
}]);
return ScaryStory;
}(Container); // Initialize scary story
var scaryStory = new ScaryStory();
LK.gui.center.addChild(scaryStory);
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Game tick event
LK.on('tick', function () {
// Move power-ups
for (var i = powerUps.length - 1; i >= 0; i--) {
powerUps[i].move();
// Collect power-up and increase scare level
if (powerUps[i].intersects(character)) {
// Increase scare level
score++;
// Update score text
scoreTxt.setText(score.toString());
powerUps[i].destroy();
powerUps.splice(i, 1);
}
// Remove off-screen power-ups
if (powerUps[i] && powerUps[i].y > 2782) {
powerUps[i].destroy();
powerUps.splice(i, 1);
}
}
// Move ghosts and check for collisions with the character to trigger jumpscare
for (var j = ghosts.length - 1; j >= 0; j--) {
ghosts[j].move();
// Check if ghost intersects with the character
if (ghosts[j].intersects(character)) {
// Trigger jumpscare
triggerJumpscare();
// Remove the ghost that caused the jumpscare
ghosts[j].destroy();
ghosts.splice(j, 1);
// End the game
LK.showGameOver();
// Break out of the loop as the game is over
break;
}
}
// Function to handle the jumpscare logic
function triggerJumpscare() {
// Display the screaming ghost asset and play jumpscare sound
var jumpscareGhost = game.addChild(LK.getAsset('screamingGhost', {
anchorX: 0.5,
anchorY: 0.5
}));
jumpscareGhost.x = game.width / 2;
jumpscareGhost.y = game.height / 2;
scoreTxt.visible = false; // Hide the score text
// LK.playSound('jumpscareSound'); // Removed because LK.playSound is not a function
// Set a timeout to remove the jumpscare after a short duration
LK.setTimeout(function () {
jumpscareGhost.destroy();
scoreTxt.visible = true; // Show the score text again
}, 2000); // Display for 2 seconds
}
// Add new power-ups
if (LK.ticks % 60 == 0) {
var newPowerUp = new PowerUp();
newPowerUp.x = Math.random() * 2048;
newPowerUp.y = -50;
powerUps.push(newPowerUp);
game.addChild(newPowerUp);
}
// Add new ghosts
if (LK.ticks % 180 == 0) {
var newGhost = new Ghost();
newGhost.x = Math.random() * 2048;
newGhost.y = Math.random() * 2732;
ghosts.push(newGhost);
game.addChild(newGhost);
}
// Show scary story at a certain interval
if (LK.ticks % 600 == 0) {
scaryStory.show();
}
// Update score
score++;
scoreTxt.setText(score.toString());
});
Ghost that is spooky. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Player that is scared. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
screaming ghost. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.