/****
* Classes
****/
// Define the Bullet class
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet3D', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -10;
self.update = function () {
self.y += self.speed;
};
});
// Define the DigitalAI class
var DigitalAI = Container.expand(function () {
var self = Container.call(this);
var aiGraphics = self.attachAsset('player3D', {
anchorX: 0.5,
anchorY: 0.5
});
self.provideAnswer = function (question) {
// Simple logic to provide answers
if (question.includes("outside world")) {
return "The outside world is vast and full of opportunities.";
} else if (question.includes("inside world")) {
return "The inside world is complex and full of challenges.";
} else if (question.includes("game")) {
return "This game is a thrilling adventure!";
} else if (question.includes("player")) {
return "You are the hero of this game!";
} else if (question.includes("game")) {
return "This game is a thrilling adventure!";
} else if (question.includes("player")) {
return "You are the hero of this game!";
} else {
return "I don't have an answer to that question.";
}
};
});
// Define the Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemyFace3D', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
// Enemy update logic
self.y += self.speed;
};
});
// Define the HumanPlayer class
var HumanPlayer = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('humanBody3D', {
anchorX: 0.5,
anchorY: 0.5
});
self.gunGraphics = self.attachAsset('gun3D', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Human player update logic
};
self.move = function (x, y) {
self.x = x;
self.y = y;
self.gunGraphics.x = self.x;
self.gunGraphics.y = self.y - 50;
};
});
//<Assets used in the game will automatically appear here>
// Define the Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player3D', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Player update logic
};
self.move = function (x, y) {
self.x = x;
self.y = y;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize human player
var humanPlayer = game.addChild(new HumanPlayer());
humanPlayer.x = 2048 / 2;
humanPlayer.y = 2732 - 200;
// Initialize DigitalAI
var digitalAI = game.addChild(new DigitalAI());
digitalAI.x = 100;
digitalAI.y = 100;
// Create a free fire like environment
var warZone = [];
for (var i = 0; i < 25; i++) {
var newWarrior = new Enemy();
newWarrior.x = Math.random() * 2048;
newWarrior.y = Math.random() * 2732;
warZone.push(newWarrior);
game.addChild(newWarrior);
}
// Initialize enemies array
var enemies = [];
// Initialize bullets array
var bullets = [];
// Score display
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Handle player movement
game.move = function (x, y, obj) {
humanPlayer.move(x, y);
};
// Handle shooting
game.down = function (x, y, obj) {
if (x < 200 && y < 200) {
// Interact with DigitalAI
var question = prompt("Ask DigitalAI a question:");
var answer = digitalAI.provideAnswer(question);
alert(answer);
} else {
var newBullet = new Bullet();
newBullet.x = humanPlayer.gunGraphics.x;
newBullet.y = humanPlayer.gunGraphics.y;
bullets.push(newBullet);
game.addChild(newBullet);
}
};
// Update game state
game.update = function () {
// Update human player
humanPlayer.update();
// Update enemies
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].update();
if (enemies[i].y > 2732) {
enemies[i].destroy();
enemies.splice(i, 1);
}
}
// Update bullets
for (var j = bullets.length - 1; j >= 0; j--) {
bullets[j].update();
if (bullets[j].y < 0) {
bullets[j].destroy();
bullets.splice(j, 1);
}
}
// Check for collisions
for (var k = bullets.length - 1; k >= 0; k--) {
for (var l = enemies.length - 1; l >= 0; l--) {
if (bullets[k].intersects(enemies[l])) {
bullets[k].destroy();
bullets.splice(k, 1);
enemies[l].destroy();
enemies.splice(l, 1);
// Update score
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
break;
}
}
}
// Spawn new enemies
if (LK.ticks % 60 == 0) {
var newEnemy = new Enemy();
newEnemy.x = Math.random() * 2048;
newEnemy.y = -50;
enemies.push(newEnemy);
game.addChild(newEnemy);
}
}; /****
* Classes
****/
// Define the Bullet class
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet3D', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -10;
self.update = function () {
self.y += self.speed;
};
});
// Define the DigitalAI class
var DigitalAI = Container.expand(function () {
var self = Container.call(this);
var aiGraphics = self.attachAsset('player3D', {
anchorX: 0.5,
anchorY: 0.5
});
self.provideAnswer = function (question) {
// Simple logic to provide answers
if (question.includes("outside world")) {
return "The outside world is vast and full of opportunities.";
} else if (question.includes("inside world")) {
return "The inside world is complex and full of challenges.";
} else if (question.includes("game")) {
return "This game is a thrilling adventure!";
} else if (question.includes("player")) {
return "You are the hero of this game!";
} else if (question.includes("game")) {
return "This game is a thrilling adventure!";
} else if (question.includes("player")) {
return "You are the hero of this game!";
} else {
return "I don't have an answer to that question.";
}
};
});
// Define the Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemyFace3D', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
// Enemy update logic
self.y += self.speed;
};
});
// Define the HumanPlayer class
var HumanPlayer = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('humanBody3D', {
anchorX: 0.5,
anchorY: 0.5
});
self.gunGraphics = self.attachAsset('gun3D', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Human player update logic
};
self.move = function (x, y) {
self.x = x;
self.y = y;
self.gunGraphics.x = self.x;
self.gunGraphics.y = self.y - 50;
};
});
//<Assets used in the game will automatically appear here>
// Define the Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player3D', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Player update logic
};
self.move = function (x, y) {
self.x = x;
self.y = y;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize human player
var humanPlayer = game.addChild(new HumanPlayer());
humanPlayer.x = 2048 / 2;
humanPlayer.y = 2732 - 200;
// Initialize DigitalAI
var digitalAI = game.addChild(new DigitalAI());
digitalAI.x = 100;
digitalAI.y = 100;
// Create a free fire like environment
var warZone = [];
for (var i = 0; i < 25; i++) {
var newWarrior = new Enemy();
newWarrior.x = Math.random() * 2048;
newWarrior.y = Math.random() * 2732;
warZone.push(newWarrior);
game.addChild(newWarrior);
}
// Initialize enemies array
var enemies = [];
// Initialize bullets array
var bullets = [];
// Score display
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Handle player movement
game.move = function (x, y, obj) {
humanPlayer.move(x, y);
};
// Handle shooting
game.down = function (x, y, obj) {
if (x < 200 && y < 200) {
// Interact with DigitalAI
var question = prompt("Ask DigitalAI a question:");
var answer = digitalAI.provideAnswer(question);
alert(answer);
} else {
var newBullet = new Bullet();
newBullet.x = humanPlayer.gunGraphics.x;
newBullet.y = humanPlayer.gunGraphics.y;
bullets.push(newBullet);
game.addChild(newBullet);
}
};
// Update game state
game.update = function () {
// Update human player
humanPlayer.update();
// Update enemies
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].update();
if (enemies[i].y > 2732) {
enemies[i].destroy();
enemies.splice(i, 1);
}
}
// Update bullets
for (var j = bullets.length - 1; j >= 0; j--) {
bullets[j].update();
if (bullets[j].y < 0) {
bullets[j].destroy();
bullets.splice(j, 1);
}
}
// Check for collisions
for (var k = bullets.length - 1; k >= 0; k--) {
for (var l = enemies.length - 1; l >= 0; l--) {
if (bullets[k].intersects(enemies[l])) {
bullets[k].destroy();
bullets.splice(k, 1);
enemies[l].destroy();
enemies.splice(l, 1);
// Update score
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
break;
}
}
}
// Spawn new enemies
if (LK.ticks % 60 == 0) {
var newEnemy = new Enemy();
newEnemy.x = Math.random() * 2048;
newEnemy.y = -50;
enemies.push(newEnemy);
game.addChild(newEnemy);
}
};