/****
* Classes
****/
// Bullet class
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -20;
self.update = function () {
self.y += self.speed;
if (self.y < 0) {
self.destroy();
}
};
});
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 7;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
//<Assets used in the game will automatically appear here>
// Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
// Hero update logic
};
self.move = function (x, y) {
self.prevX = self.x;
self.prevY = self.y;
self.x = x;
self.y = y;
self.isMovingBackward = self.y < self.prevY;
};
});
var Loot = Container.expand(function () {
var self = Container.call(this);
var lootGraphics = self.attachAsset('loot', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
var TheSlapper = Container.expand(function () {
var self = Container.call(this);
var theSlapperGraphics = self.attachAsset('theSlapper', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.lives = 3;
self.update = function () {
// The Slapper update logic
};
self.move = function (x, y) {
self.prevX = self.x;
self.prevY = self.y;
self.x = x;
self.y = y;
self.isMovingBackward = self.y < self.prevY;
};
self.slap = function (enemy) {
enemy.destroy();
score += 10;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Show popup at the beginning to choose Will Smith
var popupText = new Text2('Switch to the Slapper?', {
size: 100,
fill: "#ffffff",
align: "center"
});
popupText.anchor.set(0.5, 0.5);
popupText.x = 1024;
popupText.y = 1366;
game.addChild(popupText);
var yesButton = new Text2('Yes', {
size: 100,
fill: "#00ff00",
align: "center"
});
yesButton.anchor.set(0.5, 0.5);
yesButton.x = 824;
yesButton.y = 1566;
game.addChild(yesButton);
var noButton = new Text2('No', {
size: 100,
fill: "#ff0000",
align: "center"
});
noButton.anchor.set(0.5, 0.5);
noButton.x = 1224;
noButton.y = 1566;
game.addChild(noButton);
yesButton.down = function () {
game.removeChild(popupText);
game.removeChild(yesButton);
game.removeChild(noButton);
hero.destroy();
hero = game.addChild(new TheSlapper());
hero.x = 1024;
hero.y = 2500;
};
noButton.down = function () {
game.removeChild(popupText);
game.removeChild(yesButton);
game.removeChild(noButton);
};
// Intro cutscene
var introText = new Text2('Fortnite 2: Fort Harder\n\nMade by Epic Games', {
size: 100,
fill: "#ffffff",
align: "center"
});
introText.anchor.set(0.5, 0.5);
introText.x = 1024;
introText.y = 1366;
game.addChild(introText);
// Fade out intro text after 3 seconds
var introTimer = LK.setTimeout(function () {
var fadeInterval = LK.setInterval(function () {
introText.alpha -= 0.02;
if (introText.alpha <= 0) {
LK.clearInterval(fadeInterval);
game.removeChild(introText);
}
}, 16.67); // Approximately 60 times per second
}, 3000);
// Initialize variables
var hero = game.addChild(new Hero());
var willSmith = null;
var willSmithPopupShown = false;
hero.x = 1024;
hero.y = 2500;
var enemies = [];
var bullets = [];
var score = 0;
// Create score text
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Handle hero movement
game.down = function (x, y, obj) {
if (hero instanceof TheSlapper) {
for (var i = enemies.length - 1; i >= 0; i--) {
if (hero.intersects(enemies[i])) {
hero.slap(enemies[i]);
enemies.splice(i, 1);
break;
}
}
hero.move(x, y); // Add movement for Will Smith
} else {
hero.move(x, y);
}
};
game.move = function (x, y, obj) {
hero.move(x, y); // Add movement for Will Smith
};
game.up = function (x, y, obj) {
// No action needed on up
};
// Spawn enemies
var spawnEnemy = function spawnEnemy() {
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = 0;
enemies.push(enemy);
game.addChild(enemy);
};
// Fire bullets
var fireBullet = function fireBullet() {
if (!(hero instanceof TheSlapper)) {
var bullet = new Bullet();
bullet.x = hero.x;
bullet.y = hero.y;
bullets.push(bullet);
game.addChild(bullet);
}
};
// Update game state
game.update = function () {
// Update score
scoreTxt.setText(score);
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].speed = 7 + Math.floor(score / 100); // Increase enemy speed as score increases
enemies[i].update();
if (enemies[i].y >= 2732) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
} else if (enemies[i].intersects(hero)) {
if (!(hero instanceof TheSlapper)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
}
// Update bullets
for (var j = bullets.length - 1; j >= 0; j--) {
bullets[j].speed = -20; // Bullet speed is constant
bullets[j].update();
for (var k = enemies.length - 1; k >= 0; k--) {
if (bullets[j].intersects(enemies[k])) {
enemies[k].destroy();
var loot = new Loot();
loot.x = enemies[k].x;
loot.y = enemies[k].y;
game.addChild(loot);
bullets[j].destroy();
enemies.splice(k, 1);
bullets.splice(j, 1);
score += 10;
break;
}
}
}
// Check if slapper intersects with enemies
if (hero instanceof TheSlapper) {
for (var i = enemies.length - 1; i >= 0; i--) {
if (hero.intersects(enemies[i])) {
hero.slap(enemies[i]);
enemies.splice(i, 1);
break;
}
}
}
// Update loot
for (var l = game.children.length - 1; l >= 0; l--) {
if (game.children[l] instanceof Loot) {
game.children[l].update();
if (hero.intersects(game.children[l])) {
game.children[l].destroy();
score += 5; // Increase score by 5 when loot is collected
}
}
}
// Fire bullet every 30 ticks
if (LK.ticks % 30 == 0) {
fireBullet();
}
// Spawn enemy more progressively
if (LK.ticks % (50 - Math.floor(score / 100)) == 0) {
spawnEnemy();
}
};
A piece of gold. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A military general holding a rifle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A bullet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A military goon with a pocket knife. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An insane, deranged man with a large right hand. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.