/**** * Classes ****/ //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Capybara class representing the player character var Capybara = Container.expand(function () { var self = Container.call(this); var capybaraGraphics = self.attachAsset('capybara', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.health = 3; // Add health property self.update = function () { // Capybara update logic }; }); // Dungeon class representing the game map var Dungeon = Container.expand(function () { var self = Container.call(this); self.update = function () { // Dungeon update logic }; }); // Enemy class representing enemies in the dungeon var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Enemy update logic }; }); // Sword class representing a sword item that the capybara can collect var Sword = Container.expand(function () { var self = Container.call(this); var swordGraphics = self.attachAsset('sword', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Sword update logic }; }); // Trap class representing traps in the dungeon var Trap = Container.expand(function () { var self = Container.call(this); var trapGraphics = self.attachAsset('trap', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Trap update logic }; }); // Treasure class representing treasures to collect var Treasure = Container.expand(function () { var self = Container.call(this); var treasureGraphics = self.attachAsset('treasure', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Treasure update logic }; }); /**** * Initialize Game ****/ var game = new LK.Game({ // No title, no description // Always backgroundColor is black backgroundColor: 0x000000 }); /**** * Game Code ****/ var dungeonBackground = LK.getAsset('dungeonBackground', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366 }); game.addChild(dungeonBackground); // Initialize game elements var dungeon = game.addChild(new Dungeon()); // Initialize swords array to hold up to 2 swords var swords = []; for (var i = 0; i < 2; i++) { var sword = new Sword(); sword.x = Math.random() * 2048; sword.y = Math.random() * 2732; swords.push(sword); dungeon.addChild(sword); } var capybara = dungeon.addChild(new Capybara()); capybara.x = 1024; // Center horizontally capybara.y = 1366; // Center vertically var traps = []; var treasures = []; var scoreCounter = new Text2('Score: 0', { size: 50, fill: 0xFFFFFF }); scoreCounter.anchor.set(1, 0); // Anchor to the top-right corner LK.gui.topRight.addChild(scoreCounter); // Create traps, treasures, enemies, walls and doors var enemies = []; var walls = []; for (var i = 0; i < 30; i++) { var trap = new Trap(); trap.x = Math.random() * 2048; trap.y = Math.random() * 2732; traps.push(trap); dungeon.addChild(trap); var treasure = new Treasure(); treasure.x = Math.random() * 2048; treasure.y = Math.random() * 2732; treasures.push(treasure); dungeon.addChild(treasure); var enemy = new Enemy(); enemy.x = Math.random() * 2048; enemy.y = Math.random() * 2732; enemies.push(enemy); dungeon.addChild(enemy); } // Handle game updates game.update = function () { // Update capybara capybara.update(); // Update swords swords.forEach(function (sword, index) { sword.update(); if (capybara.intersects(sword)) { // Handle capybara collecting the sword capybara.hasSword = true; sword.destroy(); swords.splice(index, 1); } }); // Update traps traps.forEach(function (trap) { trap.update(); if (capybara.intersects(trap)) { // Handle capybara hitting a trap LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } }); // Update treasures treasures.forEach(function (treasure, index) { treasure.update(); if (capybara.intersects(treasure)) { // Handle capybara collecting a treasure LK.setScore(LK.getScore() + 50); scoreCounter.setText('Score: ' + LK.getScore()); treasure.destroy(); treasures.splice(index, 1); // Set a timeout to respawn the treasure after 10 seconds LK.setTimeout(function () { var newTreasure = new Treasure(); newTreasure.x = Math.random() * 2048; newTreasure.y = Math.random() * 2732; treasures.push(newTreasure); dungeon.addChild(newTreasure); }, 10000); } }); // Update enemies enemies.forEach(function (enemy) { enemy.update(); if (capybara.intersects(enemy)) { if (capybara.hasSword) { // Defeat the enemy if capybara has a sword enemy.destroy(); enemies.splice(enemies.indexOf(enemy), 1); // Respawn the enemy after 15 seconds LK.setTimeout(function () { var newEnemy = new Enemy(); newEnemy.x = Math.random() * 2048; newEnemy.y = Math.random() * 2732; enemies.push(newEnemy); dungeon.addChild(newEnemy); }, 15000); } else { // Handle capybara hitting an enemy capybara.health -= 1; // Decrease health by 1 if (capybara.health <= 0) { // If health is 0 or less, show game over LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } } }); // Check win condition if (LK.getScore() >= 1000) { LK.showYouWin(); } }; // Handle touch events for moving the capybara game.down = function (x, y, obj) { capybara.x = x; capybara.y = y; }; game.move = function (x, y, obj) { // Store the current position var oldX = capybara.x; var oldY = capybara.y; // Move the capybara capybara.x = x; capybara.y = y; }; game.up = function (x, y, obj) { // Stop moving capybara };
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Capybara class representing the player character
var Capybara = Container.expand(function () {
var self = Container.call(this);
var capybaraGraphics = self.attachAsset('capybara', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.health = 3; // Add health property
self.update = function () {
// Capybara update logic
};
});
// Dungeon class representing the game map
var Dungeon = Container.expand(function () {
var self = Container.call(this);
self.update = function () {
// Dungeon update logic
};
});
// Enemy class representing enemies in the dungeon
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Enemy update logic
};
});
// Sword class representing a sword item that the capybara can collect
var Sword = Container.expand(function () {
var self = Container.call(this);
var swordGraphics = self.attachAsset('sword', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Sword update logic
};
});
// Trap class representing traps in the dungeon
var Trap = Container.expand(function () {
var self = Container.call(this);
var trapGraphics = self.attachAsset('trap', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Trap update logic
};
});
// Treasure class representing treasures to collect
var Treasure = Container.expand(function () {
var self = Container.call(this);
var treasureGraphics = self.attachAsset('treasure', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Treasure update logic
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
// No title, no description
// Always backgroundColor is black
backgroundColor: 0x000000
});
/****
* Game Code
****/
var dungeonBackground = LK.getAsset('dungeonBackground', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
});
game.addChild(dungeonBackground);
// Initialize game elements
var dungeon = game.addChild(new Dungeon());
// Initialize swords array to hold up to 2 swords
var swords = [];
for (var i = 0; i < 2; i++) {
var sword = new Sword();
sword.x = Math.random() * 2048;
sword.y = Math.random() * 2732;
swords.push(sword);
dungeon.addChild(sword);
}
var capybara = dungeon.addChild(new Capybara());
capybara.x = 1024; // Center horizontally
capybara.y = 1366; // Center vertically
var traps = [];
var treasures = [];
var scoreCounter = new Text2('Score: 0', {
size: 50,
fill: 0xFFFFFF
});
scoreCounter.anchor.set(1, 0); // Anchor to the top-right corner
LK.gui.topRight.addChild(scoreCounter);
// Create traps, treasures, enemies, walls and doors
var enemies = [];
var walls = [];
for (var i = 0; i < 30; i++) {
var trap = new Trap();
trap.x = Math.random() * 2048;
trap.y = Math.random() * 2732;
traps.push(trap);
dungeon.addChild(trap);
var treasure = new Treasure();
treasure.x = Math.random() * 2048;
treasure.y = Math.random() * 2732;
treasures.push(treasure);
dungeon.addChild(treasure);
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = Math.random() * 2732;
enemies.push(enemy);
dungeon.addChild(enemy);
}
// Handle game updates
game.update = function () {
// Update capybara
capybara.update();
// Update swords
swords.forEach(function (sword, index) {
sword.update();
if (capybara.intersects(sword)) {
// Handle capybara collecting the sword
capybara.hasSword = true;
sword.destroy();
swords.splice(index, 1);
}
});
// Update traps
traps.forEach(function (trap) {
trap.update();
if (capybara.intersects(trap)) {
// Handle capybara hitting a trap
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
});
// Update treasures
treasures.forEach(function (treasure, index) {
treasure.update();
if (capybara.intersects(treasure)) {
// Handle capybara collecting a treasure
LK.setScore(LK.getScore() + 50);
scoreCounter.setText('Score: ' + LK.getScore());
treasure.destroy();
treasures.splice(index, 1);
// Set a timeout to respawn the treasure after 10 seconds
LK.setTimeout(function () {
var newTreasure = new Treasure();
newTreasure.x = Math.random() * 2048;
newTreasure.y = Math.random() * 2732;
treasures.push(newTreasure);
dungeon.addChild(newTreasure);
}, 10000);
}
});
// Update enemies
enemies.forEach(function (enemy) {
enemy.update();
if (capybara.intersects(enemy)) {
if (capybara.hasSword) {
// Defeat the enemy if capybara has a sword
enemy.destroy();
enemies.splice(enemies.indexOf(enemy), 1);
// Respawn the enemy after 15 seconds
LK.setTimeout(function () {
var newEnemy = new Enemy();
newEnemy.x = Math.random() * 2048;
newEnemy.y = Math.random() * 2732;
enemies.push(newEnemy);
dungeon.addChild(newEnemy);
}, 15000);
} else {
// Handle capybara hitting an enemy
capybara.health -= 1; // Decrease health by 1
if (capybara.health <= 0) {
// If health is 0 or less, show game over
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
}
});
// Check win condition
if (LK.getScore() >= 1000) {
LK.showYouWin();
}
};
// Handle touch events for moving the capybara
game.down = function (x, y, obj) {
capybara.x = x;
capybara.y = y;
};
game.move = function (x, y, obj) {
// Store the current position
var oldX = capybara.x;
var oldY = capybara.y;
// Move the capybara
capybara.x = x;
capybara.y = y;
};
game.up = function (x, y, obj) {
// Stop moving capybara
};
Trampa de osos pixelado. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Un cofre del tesoro pixelado. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Dungeon pixelado. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Espada pixelado. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows