User prompt
We can not move?
User prompt
Then we shoul move with right mouse click and attack with left mouse click. But you can make 3 fixed spawn points rather than random positions. Enemies should not spawn consecutively from the same spawn point. This prevents the player from camping near a single spawn and easily winning the game with the bow.
User prompt
ncrease the movement speed of the main character slightly. The character should attack with left mouse click, and move to the position where the right mouse button is clicked. Additionally, enemies should spawn from a fixed spawn point instead of appearing randomly.
User prompt
Enemies should actively try to attack the main character instead of moving randomly. If an enemy collides with the main character, the player should die, and a Restart button should appear. This means the main character needs a physical body (sprite/model), and the other mechanics should be implemented accordingly.
Code edit (1 edits merged)
Please save this source code
User prompt
Age of Ignorance
Initial prompt
Game Title: Age of Ignorance I want to make a text-based MMORPG game. After pressing the "Start Game" button, an outer space background should appear with the text: "You are born. Choose your gender." Right below the text, there should be 2 options: boy and girl. If we press boy, a screen should appear saying: "Congratulations! You were born as a boy in 400s Arabia." Then the game should start. If we press girl, a screen should appear saying: "Congratulations! You were born as a girl in 400s Arabia and were buried alive." After that, a Restart button should appear. When restarted, it should take us back to the gender selection screen. This time, the player must select boy in order to continue. Then the game should start. In the game, our goal is to use our bow and arrow to kill the European enemies coming towards us. Enemies should spawn endlessly, and for each enemy we kill, two more should appear. Every enemy we kill gives us 1 point, and if we reach 30 points, we win the game. To kill the enemies, it should be enough to simply click on them.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Arrow = Container.expand(function () {
var self = Container.call(this);
var arrowGraphics = self.attachAsset('arrow', {
anchorX: 0.5,
anchorY: 0.5
});
self.targetX = 0;
self.targetY = 0;
self.speed = 15;
self.directionX = 0;
self.directionY = 0;
self.setTarget = function (targetX, targetY) {
self.targetX = targetX;
self.targetY = targetY;
var dx = targetX - self.x;
var dy = targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
self.directionX = dx / distance;
self.directionY = dy / distance;
// Rotate arrow to face target
arrowGraphics.rotation = Math.atan2(dy, dx);
};
self.update = function () {
self.x += self.directionX * self.speed;
self.y += self.directionY * self.speed;
};
return self;
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2 + Math.random() * 3;
self.directionX = (Math.random() - 0.5) * 2;
self.directionY = (Math.random() - 0.5) * 2;
self.update = function () {
// Move towards player if player exists
if (player) {
var dx = player.x - self.x;
var dy = player.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
self.directionX = dx / distance;
self.directionY = dy / distance;
}
}
self.x += self.directionX * self.speed;
self.y += self.directionY * self.speed;
// Keep in bounds
self.x = Math.max(40, Math.min(2008, self.x));
self.y = Math.max(40, Math.min(2692, self.y));
};
self.down = function (x, y, obj) {
// Enemy clicked - kill it
killEnemy(self);
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.targetX = 1024;
self.targetY = 2600;
self.update = function () {
// Move towards target position smoothly
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 5) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000011
});
/****
* Game Code
****/
var gameState = 'genderSelection'; // 'genderSelection', 'playing', 'gameOver', 'victory'
var score = 0;
var enemies = [];
var arrows = [];
var player = null;
// UI Elements
var titleText = new Text2('Age of Ignorance', {
size: 80,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 400;
var instructionText = new Text2('Choose your gender to begin:', {
size: 50,
fill: 0xCCCCCC
});
instructionText.anchor.set(0.5, 0.5);
instructionText.x = 1024;
instructionText.y = 600;
var boyButton = new Text2('Boy', {
size: 60,
fill: 0x4CAF50
});
boyButton.anchor.set(0.5, 0.5);
boyButton.x = 824;
boyButton.y = 800;
var girlButton = new Text2('Girl', {
size: 60,
fill: 0xE91E63
});
girlButton.anchor.set(0.5, 0.5);
girlButton.x = 1224;
girlButton.y = 800;
var gameOverText = new Text2('', {
size: 50,
fill: 0xFF4444
});
gameOverText.anchor.set(0.5, 0.5);
gameOverText.x = 1024;
gameOverText.y = 1000;
var restartText = new Text2('Touch to restart', {
size: 40,
fill: 0x888888
});
restartText.anchor.set(0.5, 0.5);
restartText.x = 1024;
restartText.y = 1200;
var scoreText = new Text2('Score: 0', {
size: 50,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
var victoryText = new Text2('Victory! You survived the Age of Ignorance!', {
size: 60,
fill: 0x00FF00
});
victoryText.anchor.set(0.5, 0.5);
victoryText.x = 1024;
victoryText.y = 1366;
// Add background
var background = game.addChild(LK.getAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
}));
// Add stars to background
var stars = [];
for (var i = 0; i < 200; i++) {
var star = LK.getAsset('arrow', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.1,
scaleY: 0.1,
x: Math.random() * 2048,
y: Math.random() * 2732
});
star.tint = 0xffffff;
star.alpha = Math.random() * 0.8 + 0.2;
stars.push(star);
game.addChild(star);
}
// Initialize gender selection screen
function showGenderSelection() {
gameState = 'genderSelection';
game.addChild(titleText);
game.addChild(instructionText);
game.addChild(boyButton);
game.addChild(girlButton);
// Clear any existing game elements
clearGame();
}
function showGameOverScreen(message) {
gameState = 'gameOver';
gameOverText.setText(message);
game.addChild(gameOverText);
game.addChild(restartText);
}
function startGame() {
gameState = 'playing';
score = 0;
// Clear gender selection UI
game.removeChild(titleText);
game.removeChild(instructionText);
game.removeChild(boyButton);
game.removeChild(girlButton);
game.removeChild(gameOverText);
game.removeChild(restartText);
game.removeChild(victoryText);
// Create player
player = new Player();
player.x = 1024;
player.y = 2600;
game.addChild(player);
// Add game UI
LK.gui.top.addChild(scoreText);
updateScore();
// Spawn initial enemies
spawnEnemies(2);
}
function clearGame() {
// Remove all enemies
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].destroy();
}
enemies = [];
// Remove all arrows
for (var j = arrows.length - 1; j >= 0; j--) {
arrows[j].destroy();
}
arrows = [];
// Remove player
if (player && player.parent) {
player.destroy();
player = null;
}
// Remove score from GUI
if (scoreText.parent) {
LK.gui.top.removeChild(scoreText);
}
}
function spawnEnemies(count) {
for (var i = 0; i < count; i++) {
var enemy = new Enemy();
// Spawn from fixed point at top center with slight variation
enemy.x = 1024 + (Math.random() - 0.5) * 200;
enemy.y = 100;
enemies.push(enemy);
game.addChild(enemy);
}
}
function killEnemy(enemy) {
if (gameState !== 'playing') return;
// Play sound
LK.getSound('enemyHit').play();
// Remove enemy
var index = enemies.indexOf(enemy);
if (index > -1) {
enemies.splice(index, 1);
enemy.destroy();
// Update score
score += 1;
updateScore();
// Check victory condition
if (score >= 30) {
showVictory();
return;
}
// Spawn 2 new enemies
spawnEnemies(2);
}
}
function updateScore() {
scoreText.setText('Score: ' + score + '/30');
LK.setScore(score);
}
function showVictory() {
gameState = 'victory';
clearGame();
game.addChild(victoryText);
game.addChild(restartText);
LK.showYouWin();
}
function shootArrow(targetX, targetY) {
if (gameState !== 'playing' || !player) return;
var arrow = new Arrow();
arrow.x = player.x;
arrow.y = player.y;
arrow.setTarget(targetX, targetY);
arrows.push(arrow);
game.addChild(arrow);
LK.getSound('bowShoot').play();
// Remove arrow after 3 seconds
LK.setTimeout(function () {
var index = arrows.indexOf(arrow);
if (index > -1) {
arrows.splice(index, 1);
if (arrow.parent) {
arrow.destroy();
}
}
}, 3000);
}
// Event handlers
game.down = function (x, y, obj) {
if (gameState === 'genderSelection') {
// Check button clicks
var boyBounds = {
left: boyButton.x - 100,
right: boyButton.x + 100,
top: boyButton.y - 40,
bottom: boyButton.y + 40
};
var girlBounds = {
left: girlButton.x - 100,
right: girlButton.x + 100,
top: girlButton.y - 40,
bottom: girlButton.y + 40
};
if (x >= boyBounds.left && x <= boyBounds.right && y >= boyBounds.top && y <= boyBounds.bottom) {
startGame();
} else if (x >= girlBounds.left && x <= girlBounds.right && y >= girlBounds.top && y <= girlBounds.bottom) {
showGameOverScreen('You were buried alive. The Age of Ignorance claims another victim.');
}
} else if (gameState === 'playing') {
// Left click shoots arrow, right click moves player
if (obj.event && obj.event.button === 0) {
// Left click - shoot arrow
shootArrow(x, y);
} else if (obj.event && obj.event.button === 2) {
// Right click - move player
if (player) {
player.targetX = Math.max(30, Math.min(2018, x));
player.targetY = Math.max(30, Math.min(2702, y));
}
} else {
// Default behavior for touch devices (shoot arrow)
shootArrow(x, y);
}
} else if (gameState === 'gameOver' || gameState === 'victory') {
showGenderSelection();
}
};
game.update = function () {
if (gameState === 'playing') {
// Check player-enemy collisions
if (player) {
for (var e = 0; e < enemies.length; e++) {
var enemy = enemies[e];
if (player.intersects(enemy)) {
showGameOverScreen('You were killed by European enemies! The Age of Ignorance continues...');
return;
}
}
}
// Update arrows
for (var i = arrows.length - 1; i >= 0; i--) {
var arrow = arrows[i];
// Check if arrow hit any enemy
for (var j = enemies.length - 1; j >= 0; j--) {
var enemy = enemies[j];
if (arrow.intersects(enemy)) {
// Remove arrow
arrows.splice(i, 1);
arrow.destroy();
// Kill enemy
killEnemy(enemy);
break;
}
}
// Remove arrows that go off screen
if (arrow && (arrow.x < -100 || arrow.x > 2148 || arrow.y < -100 || arrow.y > 2832)) {
arrows.splice(i, 1);
arrow.destroy();
}
}
// Check for game over condition (too many enemies)
if (enemies.length > 100) {
showGameOverScreen('Overwhelmed by enemies! The Age of Ignorance continues...');
}
}
// Animate stars
for (var k = 0; k < stars.length; k++) {
stars[k].alpha = 0.2 + Math.sin(LK.ticks * 0.01 + k) * 0.3;
}
};
// Prevent right-click context menu
game.on('rightdown', function (x, y, obj) {
if (gameState === 'playing') {
// Right click - move player
if (player) {
player.targetX = Math.max(30, Math.min(2018, x));
player.targetY = Math.max(30, Math.min(2702, y));
}
}
});
// Start with gender selection
showGenderSelection(); ===================================================================
--- original.js
+++ change.js
@@ -71,9 +71,9 @@
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
- self.speed = 5;
+ self.speed = 8;
self.targetX = 1024;
self.targetY = 2600;
self.update = function () {
// Move towards target position smoothly
@@ -242,10 +242,11 @@
}
function spawnEnemies(count) {
for (var i = 0; i < count; i++) {
var enemy = new Enemy();
- enemy.x = Math.random() * 1800 + 124;
- enemy.y = Math.random() * 2400 + 166;
+ // Spawn from fixed point at top center with slight variation
+ enemy.x = 1024 + (Math.random() - 0.5) * 200;
+ enemy.y = 100;
enemies.push(enemy);
game.addChild(enemy);
}
}
@@ -322,14 +323,22 @@
} else if (x >= girlBounds.left && x <= girlBounds.right && y >= girlBounds.top && y <= girlBounds.bottom) {
showGameOverScreen('You were buried alive. The Age of Ignorance claims another victim.');
}
} else if (gameState === 'playing') {
- // Move player towards touch point
- if (player) {
- player.targetX = Math.max(30, Math.min(2018, x));
- player.targetY = Math.max(30, Math.min(2702, y));
+ // Left click shoots arrow, right click moves player
+ if (obj.event && obj.event.button === 0) {
+ // Left click - shoot arrow
+ shootArrow(x, y);
+ } else if (obj.event && obj.event.button === 2) {
+ // Right click - move player
+ if (player) {
+ player.targetX = Math.max(30, Math.min(2018, x));
+ player.targetY = Math.max(30, Math.min(2702, y));
+ }
+ } else {
+ // Default behavior for touch devices (shoot arrow)
+ shootArrow(x, y);
}
- shootArrow(x, y);
} else if (gameState === 'gameOver' || gameState === 'victory') {
showGenderSelection();
}
};
@@ -375,6 +384,16 @@
for (var k = 0; k < stars.length; k++) {
stars[k].alpha = 0.2 + Math.sin(LK.ticks * 0.01 + k) * 0.3;
}
};
+// Prevent right-click context menu
+game.on('rightdown', function (x, y, obj) {
+ if (gameState === 'playing') {
+ // Right click - move player
+ if (player) {
+ player.targetX = Math.max(30, Math.min(2018, x));
+ player.targetY = Math.max(30, Math.min(2702, y));
+ }
+ }
+});
// Start with gender selection
showGenderSelection();
\ No newline at end of file